Tuesday, September 30, 2008

What is a VLAN? How to Setup a VLAN on a Cisco Switch

url:http://www.petri.co.il/csc_setup_a_vlan_on_a_cisco_switch.htm


What is a VLAN? How to Setup a VLAN on a Cisco Switch

Have you ever wondered what a Virtual LAN (or VLAN) is or been unclear as to why you would want one? If so, I have been in your place at one time too. Since then, I have learned a lot about what a VLAN is and how it can help me. In this article, I will share that knowledge with you.

Preparing for Cisco CCNP Exams? These are the videos you need to get certified...


Whether you are studying for the BCSI, BCMSN, ONT, ISCW or all four, Train Signal's Cisco CCNP Training Series is the best out there. The instructor uses a "hands-on" method for teaching complex technologies. Each video covers all the bases and gives you more than enough test prep to pass any of your CCNP exams!

Daniel Petri

Click Here to Watch the Cisco CCNP Training Videos!
What is a LAN?

Okay, most of you already know what a LAN is but let’s give it a definition to make sure. We have to do this because, if you don’t know what a LAN is, you can’t understand what a VLAN is.

A LAN is a local area network and is defined as all devices in the same broadcast domain. If you remember, routers stop broadcasts, switches just forward them.
What is a VLAN?

As I said, a VLAN is a virtual LAN. In technical terms, a VLAN is a broadcast domain created by switches. Normally, it is a router creating that broadcast domain. With VLAN’s, a switch can create the broadcast domain.

This works by, you, the administrator, putting some switch ports in a VLAN other than 1, the default VLAN. All ports in a single VLAN are in a single broadcast domain.

Because switches can talk to each other, some ports on switch A can be in VLAN 10 and other ports on switch B can be in VLAN 10. Broadcasts between these devices will not be seen on any other port in any other VLAN, other than 10. However, these devices can all communicate because they are on the same VLAN. Without additional configuration, they would not be able to communicate with any other devices, not in their VLAN.
Are VLANs required?

It is important to point out that you don’t have to configure a VLAN until your network gets so large and has so much traffic that you need one. Many times, people are simply using VLAN’s because the network they are working on was already using them.

Another important fact is that, on a Cisco switch, VLAN’s are enabled by default and ALL devices are already in a VLAN. The VLAN that all devices are already in is VLAN 1. So, by default, you can just use all the ports on a switch and all devices will be able to talk to one another.
When do I need a VLAN?

You need to consider using VLAN’s in any of the following situations:

*

You have more than 200 devices on your LAN
*

You have a lot of broadcast traffic on your LAN
*

Groups of users need more security or are being slowed down by too many broadcasts?
*

Groups of users need to be on the same broadcast domain because they are running the same applications. An example would be a company that has VoIP phones. The users using the phone could be on a different VLAN, not with the regular users.
*

Or, just to make a single switch into multiple virtual switches.

Why not just subnet my network?

A common question is why not just subnet the network instead of using VLAN’s? Each VLAN should be in its own subnet. The benefit that a VLAN provides over a subnetted network is that devices in different physical locations, not going back to the same router, can be on the same network. The limitation of subnetting a network with a router is that all devices on that subnet must be connected to the same switch and that switch must be connected to a port on the router.

With a VLAN, one device can be connected to one switch, another device can be connected to another switch, and those devices can still be on the same VLAN (broadcast domain).
How can devices on different VLAN’s communicate?

Devices on different VLAN’s can communicate with a router or a Layer 3 switch. As each VLAN is its own subnet, a router or Layer 3 switch must be used to route between the subnets.
What is a trunk port?

When there is a link between two switches or a router and a switch that carries the traffic of more than one VLAN, that port is a trunk port.

A trunk port must run a special trunking protocol. The protocol used would be Cisco’s proprietary Inter-switch link (ISL) or the IEEE standard 802.1q.
How do I create a VLAN?

Configuring VLAN’s can vary even between different models of Cisco switches. Your goals, no matter what the commands are, is to:

*

Create the new VLAN’s
*

Put each port in the proper VLAN

Let’s say we wanted to create VLAN’s 5 and 10. We want to put ports 2 & 3 in VLAN 5 (Marketing) and ports 4 and 5 in VLAN 10 (Human Resources). On a Cisco 2950 switch, here is how you would do it:

At this point, only ports 2 and 3 should be able to communicate with each other and ports 4 & 5 should be able to communicate. That is because each of these is in its own VLAN. For the device on port 2 to communicate with the device on port 4, you would have to configure a trunk port to a router so that it can strip off the VLAN information, route the packet, and add back the VLAN information.
What do VLAN’s offer?

VLAN’s offer higher performance for medium and large LAN’s because they limit broadcasts. As the amount of traffic and the number of devices grow, so does the number of broadcast packets. By using VLAN’s you are containing broadcasts.

VLAN’s also provide security because you are essentially putting one group of devices, in one VLAN, on their own network.
Article Summary

Here is what we have learned:

*

A VLAN is a broadcast domain formed by switches
*

Administrators must create the VLAN’s then assign what port goes in what VLAN, manually.
*

VLAN’s provide better performance for medium and large LAN’s.
*

All devices, by default, are in VLAN 1.
*

A trunk port is a special port that runs ISL or 802.1q so that it can carry traffic from more than one VLAN.
*

For devices in different VLAN’s to communicate, you must use a router of Layer 3 switch.

Friday, September 26, 2008

Giới thiệu các phương thức Cr@ck Passwords - Cách đề phòng

Giới thiệu các phương thức Cr@ck Passwords - Cách đề phòng
Giới thiệu các phương thức Cr@ck Passwords - Cách đề phòng
Username Password là hai vấn đề nhạy cảm nhất trong một máy tính, một mạng nhỏ cho tới mạng Internet. Trong bài viết này tôi trình bày với các bạn tổng quát về các phương thức xác thực, các cách phá mật khẩu và các Tools sử dụng để phá mật khẩu. Từ đó các bạn sẽ biết cách tự bảo vệ mình trước các cuộc tấn công.
Trong bài viết này tôi sẽ trình bày chi tiết với các bạn những phần sau:
- Authentication – xác thực
- Authentication Mechanisms – Các phương thức xác thực
- Phá Password
- Những tấn công dựa vào phá Password
- Thực hiện một quá trình phá Password
- Phân chia các loại tấn công
- Các công cụ sử dụng để phá Password.
- Các phương thức cụ thể.
Các bước tiến hành trong quá trình tấn công phá mật khẩu
1. Xác thực – Authentication
- Xác thực là một quá trình nhận dạng người dùng
- Trong hệ thống mạng máy tính, xác thực chủ yếu sử dụng LoginID (Username) và Password.
- Biết mật khẩu của một tài khoản là điều cần thiết để xác thực
- Nhưng Password có thể bị mất, bị đánh cắp, bị thay đổi và bị phá, điều này dẫn tới nguy cơ bảo mật cho hệ thống.
2. Các phương thức xác thực
Hầu hết các phương thức xác thực đều dựa trên:
+ Những gì bạn biết (Username Password)
+ Những gì bạn có (Smart Card, Certificate)
+ Những gì là bạn (Sinh trắc học)
- HTTP Authentication – Xác thực trên WEB.
+ Basic Authentication
+ Digest Authentication
- Kết hợp với phương thức xác thực NTLM của Windows
- Negotiate Authentication – Thỏa thuận xác thực
- Xác thực dựa vào Certificate.
- Xác thực dựa vào Forms
- Xác thực dựa vào RSA Secure Token
- Xác thực dựa vào Sinh trắc học (xác thực vân tay, mặt, mắt….)
2.1. HTTP Authentications
a. Basic Authentication
- Là một phương thức xác thực phổ thông có trên nền tảng ứng dụng Web.
- Nó sẽ xuất hiện ra khi Client yêu cầu những thông tin phải được xác thực.
- Giới hạn những giao thức, cho phép những kẻ tấn công khai thác.
- Sử dụng SSL để mã hóa dữ liệu Username Password để truyền giữa Client và Server.
b. Degest Authentication
- Được thiết kế để nâng cao bảo mật hơn phương thức Basic Authentication
- Được dựa trên nền tảng xác thực Challenge-Response
- Nâng cao bảo bảo mật hơn phương thức Basic Authentication, hệ thống sẽ mã hóa Usernaem Password trước khi truyền đi trên mạng.
2.2. Kết hợp với phương thức xác thực NTLM của Windows
- Sử dụng công nghệ xác thực NT LAN Manager (NTLM) cho HTTP
- Chỉ làm việc với IE và trên nền tảng Web server là IIS.
- Kết hợp với xác thực trên Windows sẽ thích hợp cho môi trường mạng cục bộ của doanh nghiệp
- Nó là một phương thức xác thực mà không phải truyền bất kỳ thông tin nào về Username password trên mạng.
2.3. Xác thực Negotiate.
- Đây là một phương thức xác thực mở rộng cho NTLM Authentication
- Cung cấp xác thực dựa trên nền tảng Kerberos
- Sử dụng quá trình thương lượng để quyết định mức độ bảo mật được sử dụng.
- Nó được cấu hình và sử dụng không chỉ cho mạng cục bộ.
2.4. Xác thực dựa vào Certificate.
- Sử dụng Public Key để mã hóa và chứng chỉ số (Digital Certificate) để xác thực người dùng.
- Nó được quan tâm và kết hợp với phương thức xác thực two-factor. Khi một người dùng biết được Username Password người đó còn phải cung cấp Certificate nữa thì mới được xác thực.
- Người dùng có thể bị đánh cắp Certtificate.
- Rất nhiều phần mềm hiện nay hỗ trợ xác thực qua chứng chỉ số.
2.5. Xác thực dựa vào Forms-Based.
- Nó không được hỗ trợ trên nền tảng HTTP và SSL
- Nó là một lựa chọn cao cấp cho phương thức xác thực sử dụng một Form, và thường tích hợp dạng HTML.
- Là một phương thức xác thực rất phổ biết trên Internet.
2.6. Phương thức xác thực RSA SecurID Token
- PHương thức xác thực SecureID sử dụng một "token – Vé, card). Có một thiết bị phần cứng sẽ sinh ra các mã xác thực sau mỗi 60 giây và sử dụng một tấm Card để giải mã key.
- Một người dùng thực hiện quá trình xác thực và tài nguyên mạng sẽ phải điền mã PIN và số hiển thị cho SecureID cho mỗi thời gian đó.
2.7. Biometrics Authentications
This image has been resized. Click this bar to view the full image. The original image is sized 597x303.
- Một hệ thống xác thực dựa vào Sinh trắc học sẽ phải có những thiết bị nhận diện được người dùng dựa vào các yếu tố sinh học như: Vân tay, mắt, mặt, bàn tay….
- Đây là một phương thức xác thực có tính bảo mật rất cao và thuận tiện cho người sử dụng không phải nhớ mật khẩu hay mang theo một tấm Card.
3. Làm thế nào để có một mật khẩu bảo mật.
- Áp đặt chính sách độ dài tối thiểu của mật khẩu là 8 và tốt nhất là 15
- Yêu cầu phải có những ký tự đặc biệt, số, chữ hoa, chữ thường trong một mật khẩu
- Không sử dụng bất kỳ từ khóa nào trong từ điển English hay những nước khác
- Không sử dụng Password giông tên Username, và phải thay đổi thường xuyên
- Chọn Password bạn dễ dàng sử dụng mà người khác khó đoán biết được.
4. Những khuyến cáo đặt password khác
- Đừng bao giờ chỉ đặt một ký tự đặc biệt sau một từ khóa ví dụ: Không đặt password là: vnexperts1
- Đừng bao giờ sử dụng ghép hai từ với nhau để được một Password ví như: vnevne
- Không đặt Password dễ đoán
- Không đặt password quá ngắn
- Không đặt Password mà từ thường xuyên gõ đúng như: asdf;lkj
- Hãy thay đổi mật khẩu thường xuyên ít nhất một tháng một lần – Hãy thay đổi ngay lập tức khi phát hiện ra mật khẩu của mình bị người khác sử dụng.
- Đừng bao giờ chứa Password trên máy tính của bạn – nhiều người có thói quen vào các trang web và lưu lại mật khẩu của mình điều này không bảo mật bởi mã hóa trong máy tính dễ dàng bị giải mã.
- Các mật khẩu trong Windows lưu vào các file .pwl không được bảo mật.
- Không nói cho người khác biết mật khẩu của mình.
- Không gửi mail và tránh đặt trùng Password trên nhiều ứng dụng
- Không ghi Password của mình ra cho dễ nhớ.
- Khi gõ Password hãy cẩn thận với các loại Keyloger và người xem chộm
5. Hacker lấy mật khẩu của bạn qua những phương pháp.
- Xem bạn gõ mật khẩu
- Tìm xem bạn có ghi mật khẩu của mình ra giấy hay không
- Đoán mật khẩu dựa vào các số quen thuộc như: 123456, 654321…
- Sử dụng phương thức tấn công Brute Force
+ Đây là phương thức tổng hợp các ký tự lần lượt để tấn tìm ra mật khẩu.
- Sử dụng phương thức tấn công Dictionary Attack
+ Phương thức tấn công này tìm mật khẩu trong một bộ từ điển được sinh ra trước đó.
- Cách tạo ra một mật khẩu khó:
+ Chẳng hạn mật khẩu của tôi ban đầu định đặt là: yeuemnhieu
+ Giờ tôi viết hoa chữ Y và chữ U thành: YeUemnhieU
+ Chữ E trong bảng chữ cái đứng vị chí 5 mật khẩu tôi thành: Y5U5mnhi5U
+ Chữ i tôi đổi thành ! mật khẩu thành Y5U5mnh!5U
+ Password của tôi đủ 10 ký tự có số, có hoa, có thường, có ký tự đặc biệt.
6. Xóa Password đã được lưu trong vWindows XP
- Vào run gõ: Rundll32.exe Keymgr.dll, KRShowKeyMgr
- Sẽ hiện ra bảng tương tự dưới đây và bạn hãy xóa hết những mật khẩu đã được lưu trong hệ thống.
7. Phá mật khẩu tổng quát
- Về định nghĩa một Password Cr@cker là chương trình có thể giải mã được mật khẩu hay có thể vô hiệu hóa được mật khẩu.
- Password Cr@cker có hai phương pháp chính đó là: Brute Force và Dictionary Attack, ngoài ra hiện nay mới có chương trình phá mật khẩu thông minh hơn hai kiểu cổ điển trên đó là phương thức tìm Password: Smart Table Recovery – đáp ứng tốc độ tìm mật khẩurất nhanh.
- Password Cr@cker cũng có thể là một chương trình dùng để giải mã những mật khẩu đã được mã hóa, ví như các mật khẩu được lưu trong IE, Firefox,…
8. Mục tiêu của các chương trình tìm mật khẩu.
- Trên hệ thống Windows và Linux có hai tài khoản toàn quyền trong hệ thống đó là: root và Administrator, và mục tiêu tấn công là tìm được password của hai tài khoản đó
- Khi tìm được Password của tài khoản có quyền quản trị kẻ tấn công sẽ toàn quyền với máy đích.
- Kẻ tấn công cũng có thể dùng các phần mềm Sniffer để tóm các gói tin Username Password được truyền đi trong hệ thống mạng.
- Và ảnh hưởng của việc bị chiếm mất quyền quản trị tùy thuộc hoàn toàn vào dữ liệu và các ứng dụng trong hệt hống.
9. Chương trình Password Cr@cker hoạt động như thế nào ?

- Để hiểu được một Password Cr@cker làm việc như thế nào chúng ta cần phải hiểu được các chương trình quản lý Password thực hiện ra sao. Hầu hết các chương trình quản lý Password đều mã hóa Password theo một phương thức nào đó.
- Mật khẩu sau khi được tạo ra và lưu vào trong hệ thống sẽ được mã hóa, hệ thống sẽ chứa Key để giải mã mật khẩu.
- Những phần mềm Password Cr@cker sẽ tìm cách lấy được các đoạn mật mã đó.
-Sau khi đã lấy được các đoạn mật mã trên máy của nạn nhân chúng sẽ tiến hành giải mã mật khẩu bằng những phương thức cụ thể cho từng tình huống.
10. Các dạng Password Cr@cker
- Dictionary Attack: Tìm mật khẩu trong một file từ điển tạo sẵn
- Brute Force Attack: Tìm mật khẩu bằng cách tổ hợp các ký tự
- Hybird Attack: Lai giữa hai phương thức trên
- Smart Table Recovery Attack: Phương thức tấn công tìm mật khẩu thông minh nhất dựa trên các bảng dữ liệu – Khoảng 700MB dữ liệu text.
11. Tìm Password bằng phương thức đơn giản
- Đoán mật khẩu
- Thay thế đoạn URL
12. Tìm Password bằng giải mã Cookies
- Với chương trình CT cookie Spy 2.0
- Cookies thương lưu lại rất nhiều thông tin quan trọng của người dùng khi truy cập vào Internet như Username và Password truy cập vào một Website.
- Với phần mềm này bạn có thể tìm kiếm các Cookies được lưu dữ trong hệ thống và giải mã chúng để tìm Username Password.
13. Tấn công Dictionary Attack.
- Tạo từ điển dùng phần mềm: Dictionary Maker
This image has been resized. Click this bar to view the full image. The original image is sized 595x352.
14. Danh sách các Tools Password Cr@ckers
-LophtCr@ck - WebCr@cker
- John The Ripper - Munga Bunga
- Brutus - ReadCookies
- Obiwan - SnadBoy
- Authforce - WinSSLMiM
- Hydra - RAR
- Cain & Abel Gammaprog
Hầu hết các tools này đều miễn phí và nếu có phí thì hoàn toàn Cr@ck được một cách dễ dàng
Hầu hết chúng đều có khả năng sử dụng tất cả các loại tấn công trên, đều có thể Export Username Password từ một hệ thống Local hay Remote.
- Theo kinh nghiệm của tôi hay dùng đó là: Cain & Abel tuy nhiên phần mềm này mạnh về giải mã và Sniffer hơn. LophCr@ck có lẽ Cr@ck khá nhanh bất kỳ password nào dài dưới 10 ký tự máy tính của tôi chỉ cần khoảng hơn 1 giờ là có thể giải mã được.
- John the Ripper đây là phần mềm chuyên phá mật khẩu trong môi trường Unix và sử dụng mã hóa DES, Extend DES, MD5 cũng tích hợp nhiều phương pháp giải mã.
- Brutus là một chương trình Online hay Remote Password Cr@cker. Tấn công tới một hệ thống như máy chủ IIS, Windows, Modem ADSL…. Chúng thử lần lượt Username và Password nhất định để tấn công vào máy chủ
- Obiwan khắc phục nhược điểm của Brutus là có độ trễ khi sử dụng Username Password sai.
- Authforce dựa vào HTTP Basic Authentication hỗ trợ việc thử Username Password tới một site nhất định
- MessenPass có thể giải nén được hầu hết các tài khoản chát như Yahoo, MSN…
Lưu ý từ phiên bản YM 7 password không bao giờ được lưu ở máy Local lên phần mềm này không Cr@ck được.
- Wireless WEP Key Password Spy đây là một tools hỗ trợ giải mã để truy cập vào một hệ thống mạng vWireless đặt mật khẩu.
(Theo Vnexperts Research Department)
__________________
This image has been resized. Click this bar to view the full image. The original image is sized 750x200.


Quy định chung của diễn đàn:

_http://forum.itlab.com.vn/forum/showthread.php?t=478

Pass mặc định của diễn đàn: www.itlab.com.vn

Phần mềm dùng để nối file: FFSJ

_http://www.jaist.ac.jp/~hoangle/filesj/index.html


url:http://forum.itlab.com.vn/forum/showthread.php?t=4299

Thursday, September 25, 2008

How to configure RPC dynamic port allocation to work with firewalls

url:http://support.microsoft.com/kb/154596

How to configure RPC dynamic port allocation to work with firewalls
View products that this article applies to.
Article ID : 154596
Last Review : October 26, 2007
Revision : 14.3
This article was previously published under Q154596
SUMMARY
Remote Procedure Call (RPC) dynamic port allocation is used by remote administration applications such as Dynamic Host Configuration Protocol (DHCP) Manager, Windows Internet Name Service (WINS) Manager, and so on. RPC dynamic port allocation will instruct the RPC program to use a particular random port above 1024.

Customers using firewalls may want to control which ports RPC is using so that their firewall router can be configured to forward only these Transmission Control Protocol (TCP) ports.

Many RPC servers in Windows let you specify the server port. When you can specify a dedicated server port, you know what traffic flows between the hosts across the firewall, and you can define the that is traffic allowed much better. You can find a comprehensive list of Server ports that are used in Windows and major Microsoft products can be found in Microsoft Knowledge Base article 832017. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
832017 (http://support.microsoft.com/kb/832017/) Service overview and network port requirements for the Windows Server system
The article also lists the RPC servers and which RPC servers can be configured to use custom server ports beyond the facilities that RPC offers. Use the method that is described in this article only if the RPC server does not offer a way to define the server port.

The following registry entries apply to Windows NT 4.0 and above. They do not apply to previous versions of Windows NT. Even though you can configure the port used by the client to communicate with the server, the client must be able to reach the server by its actual IP address. You cannot use DCOM through firewalls that do address translation (e.g. where a client connects to virtual address 198.252.145.1, which the firewall maps transparently to the server's actual address of, say, 192.100.81.101). This is because DCOM stores raw IP addresses in the interface marshaling packets and if the client cannot connect to the address specified in the packet, it will not work.

For more information, see the Microsoft white paper Using Distributed COM with Firewalls. To do this, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/ms809327.aspx (http://msdn2.microsoft.com/en-us/library/ms809327.aspx)

Back to the top
MORE INFORMATION
The values (and Internet key) discussed below do not appear in the registry; they must be added manually using the Registry Editor. Also, note that you must use Regedt32.exe instead of Regedit.exe to add the REG_MULTI_SZ value.

Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 (http://support.microsoft.com/kb/322756/) How to back up and restore the registry in Windows


With Registry Editor, you can modify the following parameters for RPC. The RPC Port key values discussed below are all located in the following key in the registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Rpc\Internet\ Key Data Type

Ports REG_MULTI_SZ
Specifies a set of IP port ranges consisting of either all the ports available from the Internet or all the ports not available from the Internet. Each string represents a single port or an inclusive set of ports. For example, a single port may be represented by 5984, and a set of ports may be represented by 5000-5100. If any entries are outside the range of 0 to 65535, or if any string cannot be interpreted, the RPC runtime treats the entire configuration as invalid.
PortsInternetAvailable REG_SZ Y or N (not case-sensitive)
If Y, the ports listed in the Ports key are all the Internet-available ports on that computer. If N, the ports listed in the Ports key are all those ports that are not Internet-available.
UseInternetPorts REG_SZ ) Y or N (not case-sensitive
Specifies the system default policy.
If Y, the processes using the default will be assigned ports from the set of Internet-available ports, as defined previously.
If N, the processes using the default will be assigned ports from the set of intranet-only ports.
Example:
1. Add the Internet key under: HKEY_LOCAL_MACHINE\Software\Microsoft\Rpc
2. Under the Internet key, add the values "Ports" (MULTI_SZ), "PortsInternetAvailable" (REG_SZ), and "UseInternetPorts" (REG_SZ).

In this example ports 5000 through 5100 inclusive have been arbitrarily selected to help illustrate how the new registry key can be configured. For example, the new registry key appears as follows:
Ports: REG_MULTI_SZ: 5000-5100
PortsInternetAvailable: REG_SZ: Y
UseInternetPorts: REG_SZ: Y
3. Restart the server. All applications that use RPC dynamic port allocation use ports 5000 through 5100, inclusive. In most environments, a minimum of 100 ports should be opened, because several system services rely on these RPC ports to communicate with each other.
You should open up a range of ports above port 5000. Port numbers below 5000 may already be in use by other applications and could cause conflicts with your DCOM application(s). Furthermore, previous experience shows that a minimum of 100 ports should be opened, because several system services rely on these RPC ports to communicate with each other.

Note The minimum number of ports may differ from computer to computer and depends on the configuration of the computer.

Back to the top
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
167128 (http://support.microsoft.com/kb/167128/) Network ports used by remote helpdesk functions
179442 (http://support.microsoft.com/kb/179442/) How to configure a firewall for domains and trusts
263293 (http://support.microsoft.com/kb/263293/) Windows 2000 NAT does not translate Netlogon traffic
319553 (http://support.microsoft.com/kb/319553/) How to restrict FRS replication traffic to a specific static port
224196 (http://support.microsoft.com/kb/224196/) Restricting Active Directory replication traffic and client RPC traffic to a specific port
If you use Windows Server 2003, you can use the RPC Configuration Tool (RPCCfg.exe) from the Windows Server 2003 Resource Kit to complete the process that is described in this article. To obtain the RPC Configuration Tool, visit the following Microsoft Web site:
http://www.microsoft.com/downloads/details.aspx?FamilyID=0f9cde2f-8632-4da8-ae70-645e1ddaf369&DisplayLang=en (http://www.microsoft.com/downloads/details.aspx?FamilyID=0f9cde2f-8632-4da8-ae70-645e1ddaf369&DisplayLang=en)

Back to the top
APPLIES TO
• Microsoft Windows Server 2003, Standard Edition (32-bit x86)
• Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
• Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)
• Microsoft Windows Server 2003, Enterprise Edition for Itanium-based Systems
• Microsoft Windows Server 2003, Datacenter Edition for Itanium-Based Systems
• Microsoft Windows 2000 Professional Edition
• Microsoft Windows 2000 Server
• Microsoft Windows 2000 Advanced Server
• Microsoft Windows 2000 Datacenter Server
• Microsoft Windows NT Server 4.0 Standard Edition

WMIC Samples

WMIC Samples
url:http://blogs.technet.com/jhoward/archive/2005/02/23/378726.aspx


As promised, here are the sample WMIC commands I demonstrated in the Automating Windows Server 2003 session yesterday evening in Reading. Hope they are useful to you.

Update static IP address
wmic nicconfig where index=9 call enablestatic("192.168.16.4"), ("255.255.255.0")

Change network gateway
wmic nicconfig where index=9 call setgateways("192.168.16.4", "192.168.16.5"),(1,2)

Enable DHCP
wmic nicconfig where index=9 call enabledhcp

Service Management
wmic service where caption="DHCP Client" call changestartmode "Disabled"

Start an application
wmic process call create "calc.exe"

Terminate an application
wmic process where name="calc.exe" call terminate

Change process priority
wmic process where name="explorer.exe" call setpriority 64

Get list of process identifiers
wmic process where (Name='svchost.exe') get name,processid

Information about harddrives
wmic logicaldisk where drivetype=3 get name, freespace, systemname, filesystem, size, volumeserialnumber

Information about os
wmic os get bootdevice, buildnumber, caption, freespaceinpagingfiles, installdate, name, systemdrive, windowsdirectory /format:htable > c:\osinfo.htm

Information about files
wmic path cim_datafile where "Path='\\windows\\system32\\wbem\\' and FileSize>1784088" > c:\wbemfiles.txt

Process list
wmic process get /format:htable > c:\process.htm

Retrieve list of warning and error events not from system or security logs
WMIC NTEVENT WHERE "EventType<3 AND LogFile != 'System' AND LogFile != 'Security'" GET LogFile, SourceName, EventType, Message, TimeGenerated /FORMAT:"htable.xsl":" datatype = number":" sortby = EventType" > c:\appevent.htm

Tuesday, September 23, 2008

Active Directory Service Interfaces (ADSI) Benefits

url:http://www.activexperts.com/activmonitor/windowsmanagement/adsi/

Active Directory Service Interfaces (ADSI) Benefits

ADSI Basics
Active Directory Services Interface (ADSI) is a set of COM (Common Object Model) programming Interfaces. Like ODBC, ADSI provides common access to directories by adding a provider for each directory protocol type.
Windows 2000 contains providers for:

* WinNT – access to Windows NT 3.51 and Windows NT4;
* LDAP – LDAP directories including Windows 2000 Active Directory, Site Server 3.0, Microsoft Exchange and third party LDAP servers;
* NDS – Novell NDS.

Benefits of accessing directories with ADSI:

* Open Architecture – Any directory provider can implement an ADSI interface;
* Directory Service Independent – Applications are not bound to a vendor's proprietary directory service since it is using an API;
* Security – ADSI supports authentication.


ADSI Architecture
ADSI objects are COM objects, which represent objects in an underlying directory service. Objects can be container objects (like Folders) or Leaf objects (like Files). Each object has a unique ADSI path – a provider name followed by an object path. ADSI provides an abstract schema which describes the type of objects and attributes supported by each provider. Objects are read into cache when GetInfo or GetObject are called. Changes reside in cached memory on the client until a SetInfo is issued. SetInfo writes data back to the underlying directory store.


LDAP provider and serverless binding
The preferred method for connecting to an object is to use serverless binding; this means that the server is not explicitly provided; the default domain controller is the source of the LDAP requests. If the requested operations cannot be serviced in the local domain, a referral to the correct server is generated when possible, and the closest server is given.
A serverless path is of the form LDAP://object. To bind to the domain DNS object which is the root container of the domain naming context:

Set Odse = GetObject( "LDAP//DC=corp,DC=Microsoft,DC=com")


RootDse
The RootDse is a special LDAP object that exists on all LDAP v3 servers. With it you can write scripts that are independent of the domain or enterprise on whih they are run:

Set Odse = GetObject( "LDAP://RootDse" )

For example, to reference an object in the current domain you can read the value for DefaultNamingContext to determine the current domain:

' Get path to the configuration naming context.
Set RootDse = GetObject( "LDAP//RootDse" )
Path = "LDAP://" & RootDse.get( "DefaultNamingContext" )

Domain-based information such as users, groups, and computers resides in the domain naming context. Enterprise configuration information such as sites and subnets can be found in the Configuration Naming context. You can learn the path to naming contexts by examining ConfigurationNamingContext and SchemaNamingContext.


Non-windows 2000 clients
ADSI serverless binding is not avalable on Windows NT4 or Windows 98, so on these platforms you must always supply the name of an LDAP server for the connections:

Set Odse = GetObject( "LDAP//servername/RootDse" )

Using the Global Catalog
A global catalog (GC) server is a domain controller that contains a partial read-only replica of every object in every naming context. The replica is used to quickly search the enterprise for an object. The GC contains all objects from all naming contexts, but it is partial in that it contains only attributes designated for replication to the GC. The GC is accessed using port 3268 or by the GC provider as alias. In ADSI any reference to the GC is mapped to the LDAP provider on port 3268. Some of the common uses for searching the GC are:

* Finding user's address book information;
* Looking up members of a universal group;
* Mapping the User Principal Name to a specific User Account.


Reading an object
To read an object you must first use GetObject to bind to it:

Set objUser = GetObject( "LDAP://CN=wjohnson;CN=Users;DC=klm,DC=com" )

This fills the object cache in the client's memory with the object's attributes. You can access each attribute by it's name:

WScript.Echo objUser.givenName & " " & objUser.sn & " " & objUser.mail
Set objUser = Nothing


Updating an object
To update attributes on an existing object, you have to first bind to the object with GetObject, set each attribute's value (to update the values in the local object cache on the client), then issue a SetInfo to write the changes back to the directory. This example sets the mail address and the user's last name on user account:

Set objUser = GetObject( "LDAP://CN=wjohnson,CN=User,DC=klm,DC=com" )
objUser.mail = "wjohnson@klm.com"
objUser.sn = "wjohnson"
objUser.SetInfo
Set objUser = Nothing


Enumerating a container
To enumerate a container such as on OU, first bind to the OU and then use a loop to enumerate the container's object. To list all objects in the Users container:

Set ou = GetObject( "LDAP://CN=Users,DC=klm,DC=com" )
For each obj in ou
WScript.Echo obj.Name
Next


Searching
OLE DB provides a common way to query for information in a database-like way. The ADSI OLE DB provider allows you to use ActiveX Data Object (ADOs) to search the Active Directory. The provider is read-only, so if you need to modify an object after you search for it, use GetObject with the AdsPath
To search the Active Directory you must first create the ADO connection and command objects:

' list all objects in the domain naming context
Dim con, rs, Com
Set con = WScript.CreateObject( "ADODB.Connection" )
Set com = WScript.CreateObject( "ADODB.Command" )

Next, open the ADO provider:

' Open a connection object
con.Provider = "ADsDSObject"
con.Open "Active Directory Provider"

Then set the command object to use the current connection object, and build the query using either a simple SQL format or the LDAP search filter format (used in the example below). The query specifies the search's starting path and a filter for matching (the sample below looks for any type of object). Then list the attributes you want the query to return. Finally, specify the depth of the search: subtree for a deep search, base for a single object, or one level for searching a container.

Set Com.ActiveConnection = con
Com.CommandText = ";(objectClass=*);adspath;subtree"

' Set the preferences for Search

Com.Properties( "Page Size" ) = 512
Com.Properties( "TimeOut" ) = 30 ' seconds

When you execute the query, the results are retuned in a recordset. Loop through the recordset and print out the value, then move on to the next record.

While Not rs.EOF
WScript.Echo rs.Fields( "AdsPath").Value
Rs.MoveNext
Wend




Managing Domain Information

Extracting Computer Information
Network Administrators have always wanted an easy way to get a list of network workstations along with operating system and service pack information. You can now do this by using new attributes on Windows 2000 computer accounts to identify the computer's current status. The computer object is now automatically updated with information (from the netlogon service during secure channel setup) about the client's operating system, operating system version, and service pack level. You can identify unused or possibly inactive computer accounts; accounts that have never been used do not have the operating system and version attributes set. If the whenChanged attribute is more than a month old, the computer probably is not active on a network making periodic password changes. The whenChanged attribute is a non-replicated attribute which means it is calculated on each DC. The lastLogon attribute is not replicated between DCs; to determine the last logon time you have to examine it on all DCs.

Attrinbutes of interest:

* Name – Computer name
* dnsHostName – Full DNS hostname of the machine;
* UserAccountControl – Type of account: ADS_UF_WORKSTATION_TRUST_ACCOUNT, ADS_UF_SERVER_TRUST_ACCOUNT;
* operatingSystem – Windows NT, Windows 2000 Server, Windows 2000 Professional;
* operatingSystemVersion – Operating system version and build;
* operatingSystemServicePack – Operating system service pack numbe;r
* operatingSystemHotfix – List of hotfixes;
* whenCreated – When the object was created;
* whenChanged – When the object was modified.

Locating Computers Based on Computer Account Attributes:

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"SELECT Name, Location, operatingSystemVersion FROM " _
& "'LDAP://DC=fabrikam,DC=com' WHERE objectClass='computer' " _
& "and operatingSystemVersion = '5.0 (2195)'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop



Trust Relation Ships
When you want to document your configuration, it is useful to have a list of all domain trust relation ships, especially during migrations, when you usually have a mix of trusts between Windows 2000 domains. Windows NT account domains, and Windows NT 4.0 resource domains. Each trust relationship in a domain has a trusted domain object that resides in the System container in the Domain naming context:

* flatName – The NetBIOS name of the domain for this trust;
* trustDirection – The direction of the established trust relationship: 0=disabled; 1=inbound; 2=outbound; 3=both (trusted and trusting);
* trustPartner – A string representing the DNS-style name of Windows 2000 domains or the NetBIOS name of down-level trust domains;
* trustType – The type of trust relationship established to the domain: 1=downlevel trust; 2=Windows 2000 trust; 3=MIT; 4=DCE.



Creating User Accounts
When creating a new user account, you must set the CN (unique in the account's OU) and Samaccountname (unique in the domain) attributes. The userPrincipalName attribute (unique in the enterprise) is optional. To create a new user in the OU:

Dim salesOU as IADsContainer
Set salesOU = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=COM")
Set usr = salesOU.Create("user", "CN=Jay Adams")
usr.Put "sAMAccountName", "jayadams"
usr.Put "userPrincipalName", "jayadams@fabrikam.com"
usr.Put "title", "Marketing Manager"
usr.SetInfo

usr.SetPassword "seahorse"
usr.AccountDisabled = False
usr.SetInfo



Creating Groups
There are three scopes for groups:

* Universal;
* Global;
* Domain Local.

Groups are of these types:

* Security – To control access to resources, and to use them as e-mail distribution lists;
* Distribution – Only used for e-mail distribution lists.

Group type is required. Specify an integer that contains the flags that specify the group type and scope using these combinations:

* Global security – ADS_GROUP_TYPE_GLOBAL_GROUP | ADS_GROUP_TYPE_SECURITY_ENABLED;
* Domain local security – ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP | ADS_GROUP_TYPE_SECURITY_ENABLED;
* Universal security – ADS_GROUP_TYPE_UNIVERSAL_GROUP | ADS_GROUP_TYPE_SECURITY_ENABLED;
* Domain local distribution – ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP;
* Universal Distribution – ADS_GROUP_TYPE_DOMAIN_UNIVERSAL_GROUP.

The process of creating a group is similar to other objects. First bind to the OU which will contain the group. Next create the group object. Then set the group type, and samAccountName for down-level clients.

Set ou = GetObject( "LDAP://OU=DSys,DC=Northwind,DC=tld" )
Set grp = ou.Create( "group", "CN=Distributed System Admin" )

' Creating a domain local group
grp.Put "groupType", ADS_GROUP_TYPE_LOCAL Or ADS_GROUP_TYPE_SECURITY_ENABLED
grp.Put "samAccountName", "DSysAdmin"
grp.SetInfo

Use the add method to add members to a group using the path to the user's object.

' Adding a user to a group
grp.Add( "LDAP://CN=James Smith,OU=Marketing,OU=DSys,DC=Northwind,DC=tld" )




Managing Enterprise Configuration Information
Configuration information is global information shared among all domains in the enterprise and usually managed by the enterprise administrator.

Partitions
The partitions container's crossRef objects list the enterprise naming contexts – one for Configuration, one for Schema and one for each Domain. You can add objects to point to partitions on other LDAP servers that are not part of the enterprise, in which case you generate an LDAP referral to the proper partition when requesting an object from that portion of the namespace.

This script enumerates crossRef objects in the partitions container:

On Error Resume Next

msgbox "This script enumerates crossRef objects in the partitions container."

sPrefix = "LDAP://"

' Get distinguished name for config container and build ADsPath to partitions container.
Set root= GetObject(sPrefix & "rootDSE")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on GetObject method for rootDSE"
End If
sConfigDN = root.Get("configurationNamingContext")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Get method"
End If
sContainerDN = "cn=Partitions," & sConfigDN

'''''''''''''''''''''''''''''''''''''''
' Bind to the container
'''''''''''''''''''''''''''''''''''''''
Set cont= GetObject(sPrefix & sContainerDN)
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on GetObject method for partitions container"
End If
'''''''''''''''''''''''''''''''''''''''
' Enumerate the container.
''''''''''''''''''''''''''''''''''''''
For Each obj In cont
strText = strText & "Name: " & obj.Get("name") & vbCrLf
values = obj.GetEx("objectClass")
For Each value In values
sValue = value
Next
strText = strText & " objectClass: " & sValue & vbCrLf
strText = strText & " DnsRoot: " & obj.Get("dnsRoot") & vbCrLf
strText = strText & " NCName: " & obj.Get("NCName") & vbCrLf
sTrustParent = obj.Get("trustParent")
If (Err.Number = 0) Then
strText = strText & " TrustParent: " & sTrustParent & vbCrLf
Else
Err.Clear
End If
sNetBIOSName = obj.Get("nETBIOSName")
If (Err.Number = 0) Then
strText = strText & " NETBIOSName: " & sNetBIOSName & vbCrLf
Else
Err.Clear
End If
Next

show_items strText, "Display crossRef"


'''''''''''''''''''''''''''''''''''''''
' Display subroutines
'''''''''''''''''''''''''''''''''''''''
Sub show_items(strText, strName)
MsgBox strText, vbInformation, "Create CrossRef"
End Sub

Sub BailOnFailure(ErrNum, ErrText) strText = "Error 0x" & Hex(ErrNum) & " " & ErrText
MsgBox strText, vbInformation, "ADSI Error"
WScript.Quit
End Sub



Listing Domain Controllers
Each domain controller in the enterprise is represented by several objects:

* A computer object residing in the Domain renaming context (the computer account for the machine);
* a nTDSDSA object (NTDS settings) residing in the Configuration naming context. NTDS settings is a container that represents an instance of the directory service; it holds the DC's inbound replication connections. If you accidentally remove a NTDS Settings, the DC owning the object will resurrect the deleted object;
* A Servers object residing under the object in the DC's site.

To get a list of all enterprise DCs, issue a query with a base path of the site's container that searches for object category nTDSDSA. Some attributes of interest:

* AdsPath - Use the full path to the object to find the parent object, which contains the DNS hostname of the DCs;
* HasMasterNCs - A multi-valued list of all the writable naming contexts. For this release of Windows 2000, these are Schema, Configuration and Domain;
* Options - Bit 1 indicates if this DC is also GC.

Listing domain controllers:

' Get the Configuration Naming Context
Set oRootDSE = GetObject("LDAP://RootDSE")
strConfigNC = oRootDSE.Get("configurationNamingContext")

' Set up the oConnectionection
set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "ADs Provider"

' Build the query
strQuery = "">;(objectClass=nTDSDSA);ADsPath;subtree"

set oCmd = CreateObject("ADODB.Command")
oCmd.ActiveConnection = oConnection
oCmd.CommandText = strQuery
Set oRecordset = oCmd.Execute

' Iterate through the results
If oRecordset.Eof and oRecordSet.Bof Then
WScript.Echo "No Domain Controllers were found"
Else
While Not oRecordset.EOF
Set oParent = GetObject(GetObject(oRecordset.Fields("ADsPath")).Parent)
' Output the name of the server
WScript.Echo "Server: " & oParent.cn & " dNSHostName: " & oParent.dNSHostName
oRecordset.MoveNext
Wend
End if



FSMO
Flexible Single-Master Operations (FSMO) implements operations (there are only a few) that must be handled in a single master replication model. There are five FSMO roles, two per enterprise and three per domain, and you can use scripting to find out which DCs hold which FSMO roles.


Schema Master
The Schema Master is unique in the entire enterprise; it alone can create new classes or attributes, after which it replicates updates to all domains in the forest. To identify it, read the value of fsmoRoleOwner attribute on the Schema container found under the Configuration container. Schema and Configuration naming contexts are enterprise wide and reside on all domain controllers.

Set objRootDse = GetObject( "LDAP://RootDse" )
Set objSchema = GetObject( "LDAP://" & objRootDse.get( "SchemaNamingContext" ))
WScript.Echo objSchema.fsmoRoleOwner



Domain Naming Master
The Domain Naming Master is unique in the enterprise; it manages the addition and removal of domains into the forest. To identify it, read the partitions container object and examine its fsmoRoleOwner attribute:

Set objRootDse = GetObject( "LDAP://RootDse" )
Set objDomains = GetObject( "LDAP://CN=Partitions," & _
objRootDse.Get( "ConfigurationNamingContext" ))
WScript.Echo objDomains.fsmoRoleOwner



PDC Emulator
The PDC Emulator is a per-domain role. To identify it, read the value of the fsmoRoleOwner attribute on the DomainDNS object:

Set objRootDse = GetObject( "LDAP://RootDse" )
Set objPDC = GetObject( "LDAP://" & objRootDse.Get( "DefaultNamingContext" ))
WScript.Echo objDomains.fsmoRoleOwner



RID Master
The RID Master is a per-domain role. It allocates RID blocks for all DCs in a domain that are used for SIDs in security principals such as users and groups. To identify it, read the value of the fsmoRoleOwner attribute on the RIDManager object of name CN="Rid Manager$" found in the domain's System Container:

Set objRootDse = GetObject( "LDAP://RootDse" )
Set objRID = GetObject( "LDAP://CN=Rid Manager$,CN=System," & _
objRootDse.Get( "DefaultNamingContext" ))
WScript.Echo objDomains.fsmoRoleOwner



Infrastructure Master
The Infrastructure Master is a per-domain role. To identify it, read the value of the fsmoRoleOwner attribute on the InfrastructureUpdate object for the domain:

Set objRootDse = GetObject( "LDAP://RootDse" )
Set objInfra = GetObject( "LDAP://CN=Infrastructure," & _
objRootDse.Get( "DefaultNamingContext" ))
WScript.Echo objDomains.fsmoRoleOwner



ADSI Samples
Click here to view ADSI samples.

Scripts to manage Folders activexperts.com

url: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/folders/#CreateNewFolders.htm


Download ActiveXperts Network Monitor 7.0 (6239 KB - .exe file)
Download Manual (653 KB - .pdf file)
ActiveXperts.com > ActiveXperts Network Monitor > WindowsManagement > Scripts > Files and Folders > Folders
Scripts to manage Folders
Changing Folder Attributes
Compressing Folders
Copying a Folder
Copying Folders Using WMI
Copying Folders Using the Shell Object
Creating a Folder
Creating New Folders
Deleting a Folder
Deleting Folders
Enumerating All the Folders on a Computer
Enumerating Folder Attributes
Enumerating Folder Properties
Enumerating Folders Using Dates
Enumerating a Specific Set of Folders
Enumerating Subfolders in a Folder
Finding Folders by Date
Identifying Shell Object Verbs
Moving a Folder
Moving Folders Using the Shell Object
Moving Folders Using WMI
Renaming a Folder
Renaming Folders
Retrieving Folder Properties
Uncompressing Folders
Using the Browse for Folder Dialog Box
Using Recursion to Enumerate Subfolders
Using Wildcards in a Folder Query
Verifying that a Folder Exists



Changing Folder Attributes

Demonstration script that uses the FileSystemObject to check if a folder is hidden and, if it is not, hides it. Script must be run on the local computer. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
If objFolder.Attributes = objFolder.Attributes AND 2 Then
objFolder.Attributes = objFolder.Attributes XOR 2
End If


Compressing Folders

Compresses the folder C:\Scripts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Compress
Wscript.Echo errResults
Next


Copying a Folder

Demonstration script that uses the FileSystemObject to copy a folder to a new location. Script must be run on the local computer.

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C:\Scripts" , "C:\FSO" , OverWriteFiles


Copying Folders Using WMI

Uses WMI to copy the folder C:\Scripts to D:\Archive.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery( _
"Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Copy("D:\Archive")
Wscript.Echo errResults
Next


Copying Folders Using the Shell Object

Uses the Shell object to copy the folder C:\Scripts to D:\Archives. Displays the Copying Files progress dialog as the folder is being copied.

Const FOF_CREATEPROGRESSDLG = &H0&
ParentFolder = "D:\Archive"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "C:\Scripts", FOF_CREATEPROGRESSDLG


Creating a Folder

Demonstration script that uses the FileSystemObject to create a folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\FSO")


Creating New Folders

Uses the Shell object to create a new folder named C:\Archive.

ParentFolder = "C:\"
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.NameSpace(ParentFolder)
objFolder.NewFolder "Archive"


Deleting a Folder

Demonstration script that uses the FileSystemObject to delete a folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\FSO")


Deleting Folders

Deletes the folder C:\Scripts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Delete
Wscript.Echo errResults
Next


Enumerating All the Folders on a Computer

Returns a list of all the folders on a computer. This can take 15 minutes or more to complete, depending on the number of folders on the computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory")
For Each objFolder in colFolders
Wscript.Echo objFolder.Name
Next


Enumerating Folder Attributes

Demonstration script that uses the FileSystemObject to enumerate the attributes of a folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
If objFolder.Attributes AND 2 Then
Wscript.Echo "Hidden folder."
End If
If objFolder.Attributes AND 4 Then
Wscript.Echo "System folder."
End If
If objFolder.Attributes AND 16 Then
Wscript.Echo "Folder."
End If
If objFolder.Attributes AND 32 Then
Wscript.Echo "Archive bit set."
End If
If objFolder.Attributes AND 2048 Then
Wscript.Echo "Compressed folder."
End If


Enumerating Folder Properties

Demonstration script that uses the FileSystemObject to enumerate the properties of a folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Scripts")
Wscript.Echo "Date created: " & objFolder.DateCreated
Wscript.Echo "Date last accessed: " & objFolder.DateLastAccessed
Wscript.Echo "Date last modified: " & objFolder.DateLastModified
Wscript.Echo "Drive: " & objFolder.Drive
Wscript.Echo "Is root folder: " & objFolder.IsRootFolder
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Parent folder: " & objFolder.ParentFolder
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Short name: " & objFolder.ShortName
Wscript.Echo "Short path: " & objFolder.ShortPath
Wscript.Echo "Size: " & objFolder.Size
Wscript.Echo "Type: " & objFolder.Type


Enumerating Folders Using Dates

Lists all the folders on a computer that were created after 3/1/2002.

Const LOCAL_TIME = True
Set dtmTargetDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
dtmTargetDate.SetVarDate "3/1/2002", LOCAL_TIME
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory Where " _
& "CreationDate > '" & dtmTargetDate & "'")
For each objFolder in colFolders
dtmConvertedDate.Value = objFolder.CreationDate
Wscript.Echo objFolder.Name & VbTab & _
dtmConvertedDate.GetVarDate(LOCAL_TIME)
Next


Enumerating a Specific Set of Folders

Returns a list of all the hidden folders on a computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Win32_Directory Where Hidden = True")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next


Enumerating Subfolders in a Folder

Demonstration script that uses the FileSystemObject to return the folder name and size for all the subfolders in a folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next


Finding Folders by Date

Finds all the folders created after March 1, 2002. To modify this script, you must modify the following items in the value assigned to the variable dtmTargetDate: 2002 -- Change this to the target year (for example, 1999). 03 -- Change this to the target month (01 for January, 02 for February … 12 for December). 01 -- Change this to the target day (01 for the first day of the month, 02 for the second, etc.). -420 -- To assure the correct results, change this to the offset between your time zone and Greenwich Mean Time. If you do not know the offset, use the script Determining Time Zone Offset from Greenwich Mean Time.

On Error Resume Next
dtmTargetDate = "20020301000000.000000-420"
strComputer = "."

Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory Where CreationDate > '" & _
dtmtargetDate & "'")

For Each objFolder in colFolders
Wscript.Echo objFolder.Name
Next


Identifying Shell Object Verbs

Returns a list of Shell object verbs (context menu items) for the Recycle Bin.

Const RECYCLE_BIN = &Ha&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(RECYCLE_BIN)
Set objFolderItem = objFolder.Self
Set colVerbs = objFolderItem.Verbs
For i = 0 to colVerbs.Count - 1
Wscript.Echo colVerbs.Item(i)
Next


Moving a Folder

Demonstration script that uses the FileSystermObject to move a folder from one location to another. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\Scripts" , "M:\helpdesk\management"


Moving Folders Using the Shell Object

Uses the Shell object to move the folder C:\Scripts to D:\Archives. Displays the Copying Files progress dialog as the folder is being moved.

Const FOF_CREATEPROGRESSDLG = &H0&
TargetFolder = "D:\Archive"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.MoveHere "C:\Scripts", FOF_CREATEPROGRESSDLG


Moving Folders Using WMI

Uses WMI to move the folder C:\Scripts to C:\Admins\Documents\Archive\VBScript.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Rename("C:\Admins\Documents\Archive\VBScript")
Wscript.Echo errResults
Next


Renaming a Folder

Demonstration script that uses the FileSystemObject to rename a folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\FSO\Samples" , "C:\FSO\Scripts"


Renaming Folders

Renames the folder C:\Scripts to C:\Repository.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Rename("C:\Script Repository")
Wscript.Echo errResults
Next


Retrieving Folder Properties

Lists the properties of the folder C:\Scripts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService. _
ExecQuery("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
Wscript.Echo "Archive: " & objFolder.Archive
Wscript.Echo "Caption: " & objFolder.Caption
Wscript.Echo "Compressed: " & objFolder.Compressed
Wscript.Echo "Compression method: " & objFolder.CompressionMethod
Wscript.Echo "Creation date: " & objFolder.CreationDate
Wscript.Echo "Encrypted: " & objFolder.Encrypted
Wscript.Echo "Encryption method: " & objFolder.EncryptionMethod
Wscript.Echo "Hidden: " & objFolder.Hidden
Wscript.Echo "In use count: " & objFolder.InUseCount
Wscript.Echo "Last accessed: " & objFolder.LastAccessed
Wscript.Echo "Last modified: " & objFolder.LastModified
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Readable: " & objFolder.Readable
Wscript.Echo "System: " & objFolder.System
Wscript.Echo "Writeable: " & objFolder.Writeable
Next


Uncompressing Folders

Uncompresses the folder C:\Scripts.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Uncompress
Wscript.Echo errResults
Next


Using the Browse for Folder Dialog Box

Uses the Shell object to display the Browse for Folder dialog box. After a folder has been selected, the script reports whether or not the folder is read-only.

Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
objPath = Replace(objPath, "\", "\\")
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = '" & objPath & "'")
For Each objFile in colFiles
Wscript.Echo "Readable: " & objFile.Readable
Next


Using Recursion to Enumerate Subfolders

Demonstration script that uses the FileSystemObject to recursively list all the subfolders (and their subfolders) within a folder. Script must be run on the local computer.

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Scripts")
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
ShowSubFolders Subfolder
Next
End Sub


Using Wildcards in a Folder Query

Returns a list of all the folders whose path begins with C:\S.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '%c:\\S%'")
For Each objFolder in colFolders
Wscript.Echo "Name: " & objFolder.Name
Next


Verifying that a Folder Exists

Demonstration script that uses the FileSystemObject to verify that a folder exists. If the folder does exist, the script binds to that folder. Script must be run on the local computer.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\FSO") Then
Set objFolder = objFSO.GetFolder("C:\FSO")
Else
Wscript.Echo "Folder does not exist.”
End If

Monday, September 22, 2008

Another way to download from rapidshare

url:http://shailendra88.blogspot.com/2008/02/another-way-to-download-from-rapidshare.html

Friday, February 22, 2008
Another way to download from rapidshare
Posted by Shailendra at 8:35 PM


Are you tired of downloading from rapidshare for its time limits ?Then this the perfect way to download without waiting limits.

Previously I mentioned about some scripts which will bypass the timelimit,but a software named RapidDowner is far more better than this.You have to just enter the rapidshare url and specify some proxy from the list and RapidDowner does the rest of work.This program to by pass the 110 minute waiting time limit and make it in a few minutes. Built on the .net framework and forum supported. Make rapidshare your easy free hosting service.

[Download RapidDowner]

Friday, September 12, 2008

Danh sách các forum hacker vietnam

http://www.vnsecurity.com
http://www.vnmagic.org
http://ww.hvaonline.net
http://www.vnbrain.net
http://www.hcegroup.net
http://www.viethacker.org
http://www.thegioingam.biz
http://www.vietxpert.name
http://www.vhz.vn
http://www.vnres.net
http://www.hack2learn.net
http://www.viet4all.biz
http:www.vietfrauders.org
http:www.en-hack.net
http:www.viet4all.biz
http:www.beyeugroup.com
http:www.vniss

url:http://www.binhphuoc.org/diendan/showthread.php?t=3821

bộ sưu tập tổng hợp link down các video dạy hack(full version)

bộ sưu tập tổng hợp link down các video dạy hack(full version)
có thể 1 số link đã die mong ae thông cảm dùm,link nào die ae kiếm cái khác fix dùm nha


1> http://warezshare.com/download.php?f...df7d54a71f7663
2> http://thanhnamhp.com.vn/cfm.rar
3> http://www.filenanny.com/files/46ecc.../Hacklocal.rar
bug local backup data
4> http://www.mediamax.com/vipundergrou...kup%20data.zip
5>hack shop cfm
http://www.mediamax.com/vipundergroup/Hosted/cfm.rar
6>down load hack
http://www.mediamax.com/vipundergrou...d/download.rar
7>bug esyndicat
http://www.mediamax.com/vipundergrou..._esyndicat.rar
8>bug ezupload
http://www.mediamax.com/vipundergrou...upload-leo.rar
9>file manager bug
http://www.mediamax.com/vipundergrou...le_Manager.rar
10>get root 1
http://www.mediamax.com/vipundergrou...d/getroot1.rar
11>get root2
http://www.mediamax.com/vipundergrou...d/getroot2.rar
12>get root3
http://www.mediamax.com/vipundergrou...d/getroot3.rar
13>Hacking vbb 3.6.6 bug XSS
http://www.mediamax.com/vipundergrou...g%20XXS%29.rar
14>hide backdoor1
http://www.mediamax.com/vipundergrou...0backdoor1.rar
15>hide backdoor2
http://www.mediamax.com/vipundergrou...0backdoor2.rar
16>how i get free host (hack host demo)
http://www.mediamax.com/vipundergrou...etfreehost.rar
17>Invision_Power_Board_2[1].1.7_Password_Change_Demonstration
http://www.mediamax.com/vipundergrou..._Power_Board_2
18>local hack1
http://www.mediamax.com/vipundergrou...al%20hack1.rar
19>local hack2
http://www.mediamax.com/vipundergrou...al%20hack2.rar
20>local hack3
http://www.mediamax.com/vipundergrou...al%20hack3.rar
21>Phim huong dan hack co ban nhat
http://www.mediamax.com/vipundergrou...dan%20hack.rar
22>phpbb
http://www.mediamax.com/vipundergroup/Hosted/phpbb.rar
23>Remote destop hack
http://www.mediamax.com/vipundergrou...Remote-vnc.rar
24>rEmOtEr_VS_Microsoft
http://www.mediamax.com/vipundergrou..._Microsoft.rar
25>SQL injection1
http://www.mediamax.com/vipundergrou...Linjection.rar
26>SQL injection2
http://www.mediamax.com/vipundergrou...injection2.rar
27>how to hack thanhhoa.gov.vn
http://www.mediamax.com/vipundergrou...d/thanhhoa.rar
28>upload hack1
http://www.mediamax.com/vipundergrou...ed/upload1.rar
29>upload hack2
http://www.mediamax.com/vipundergrou...ed/upload2.rar
30>upload hack3
http://www.mediamax.com/vipundergrou...ed/upload3.rar
31>vbb 3.5.x bug ugrade
http://www.mediamax.com/vipundergrou...g%20ugrade.rar
32>video fake ip
http://www.mediamax.com/vipundergrou...0fake%20ip.rar
windows exploit
33>http://www.mediamax.com/vipundergrou...ws-exploit.rar
34>xsst unnelling-video
http://www.mediamax.com/vipundergrou...ling-video.zip
35>Yahoo Fake [FuLL ViDEO bY HeliOs]
http://www.mediamax.com/vipundergrou...ahoo%20Fake%20[FuLL%20ViDEO%20bY%20HeliOs].rar
36>hackshop
http://www.mediamax.com/vipundergrou...d/hackshop.rar
37>video tut backconnect "Moi nguoi fale Ip thif down duoc bang link nay"
http://freewebtown.com/hackingvn/vid...backconect.rar
38>SQL Injection 4
http://www.box.net/shared/static/rsuoufbpj1.rar
or http://rapidshare.com/files/59957095/leo2.rar
39>Demo how i got root on server HPTVIETNAM
http://www.megaupload.com/?d=1KGA9NGK
40>Backdoor and JPG
http://str0ke213.tradebit.com/pub/8/57.swf
41>Crack MD5 user online and Cain
http://dl1.filmshare24h.net/md5-password-cracking.swf
42>hack computer trên mạng internet!
http://www.y0ume.net/video/hack%20computer.rar
43>409 Video hack
http://www.forcehacker.com/videos.html
44>một cách ẩn shell
http://www.y0ume.net/video/chenshell.rar
45>Một đống video hacking nhìu wá
http://137.132.19.24/security_course/vid_tutorials/
46>Windows Password Hacking (Video)
http://www.youtube.com/watch?v=vZDgR...search=laporte
47>iFrame DoS Explained
http://one.revver.com/watch/211124
48>Hack Shop CFM ,Remote PC,Check CC
http://uploadingit.com/files/197409_...S(Fix%202).zip
49>video hacking from PLD
http://rapidshare.de/files/36172349/Sec.Videos1.rar
http://rapidshare.de/files/36169967/Sec.Videos2.rar
50>video clip attack thanhhoa.gov.vn
khoai.bop.vu/thanhhoa.rar
51>TUT hack shop asp moi!!!!!!!!!!!!!!!
http://207.210.226.130/~thomaser/tool/hackasp.rar
52>upload hacking phần 2
http://thanhnamhp.com.vn/upload.rar
http://www.videos.learntohell.net/infectedgif.swf
53>VNC Remote video
http://kid1412.110mb.com/Remote-vnc.rar
http://kid1412.110mb.com/VNC.zip
54>1 kho video nữa nè
Anh em down thoải mái nha
http://aria-security.net/UPDATES/1st/Video/
http://video.hackinthebox.org/2006.html
http://chaosradio.ccc.de/22c3_m4v_563.html
http://shmoocon.org/2006/presentations.html
How Get Root Safe Mode On Server
http://www.freewebs.com/lyokha/CraVideos.rar
55> windows fun
http://warezshare.com/download.php?f...541ea58e44c56f
http://warezshare.com/download.php?f...10ddc3e346dbe2
56>Include shell trong PHP
phan 1: http://www.megaupload.com/vn/?d=9YW156EC
phan 2: http://www.megaupload.com/?d=Y8HFO9EH
57>video chào mừng 2/9
http://www.megaupload.com/?d=I92BALB5
58>==>>Windows server rooting<<==
http://www.freewebs.com/lyokha/winserverrooting.avi.flv
59>Video Local r00t Update 2007 - zer0c00l
http://rapidshare.com/files/51844339/r00t2007.rar.html
60>video dùng trojan Shark 2
http://freewebtown.com/hackingvn/videohack/sharK 2 Tutorial.rar
61>clip hack VBB với lỗi SQL injection ( mod RPG Inferno v2.4)
http://69.89.31.82/~seyiloco/leo9x/leo.rar
http://69.89.31.82/~seyiloco/leo9x/leo.txt
http://69.89.31.82/~seyiloco/leo9x/milw0rm.txt
62>Video hacking , bug upload :-D
http://www.megaupload.com/?d=S7W44YQ0
63>Chèn Backdoor vào tập tin JPG
http://str0ke213.tradebit.com/pub/8/57.swf
64>getroot
http://quangtrungschool.org/upload/getroot1.rar
65>[Video] Include Shell VBB & Hide Backdoor for newbie
http://www.box.net/public/2koz7exe6q
66>Video hack ibf
http://www.badongo.com/file/3562304
http://www.quangtrungschool.org/upload/Hack_ipf.rar
67>video download by pass!
http://66.165.236.155/~wayland/Tut.zip
68>Exploit For vBulletin_all_version
http://www.megaupload.com/?d=YK270LVU
69>Include shell với PhpBB
http://rapidshare.com/files/9742816/...shell.rar.html
http://www.4shared.com/file/8167032/...ludeshell.html
70>Video Music Thai Anh exp-do Langtuhoahao found !!!
http://orange.smartwavetech.com/~yeu...on_thaianh.rar
71>tài nguyên video
http://www.irdu.nus.edu.sg/security_...vid_tutorials/
72>Video Lesson - Inject Trojan 2 Web vs Hack Infobar Sp2
Link : http://z0mbie12.net/videoclip/exe2vbs-videohacking2.rar
73>Invision Power Board 2.1.7 (Debug) Remote Password Change Demonstration
http://rapidshare.com/files/19230640...onstration.rar
or
http://rapidshare.com/files/2155224/ipb217.swf
74>Bugs local backup data
tp://tailieumang.info/Tut.zip
75>SYN Flood
http://k49c.net/gk/SYNFlood.rar
76>Hacking Movies
http://2600.ir/pages/videoclips.htm
77>tut hack site ezupload (video)
http://www.megaupload.com/?d=GCSXUELR
78>1 site rất hay
http://www.giaiphapantoan.com/index....per&Itemid=112
79>Video Get root Linux 2.4.25
http://www.megaupload.com/?d=T9BCFRF4 or
http://www.4shared.com/file/8358713/...ot_Access.html
80>sử dụng bug eGallery trong PHP-Nuke để upshell lên server
http://milw0rm.com/video/watch.php?id=29
81>1 site security video
www.learnsecurityonline.com
http://phreaknic.wilpig.org/
http://www.hackerscenter.com/video/
http://www.illegalworld.com/
82>Video hacking phpinjection
http://video.antichat.org/download_150.html


url:http://www.binhphuoc.org/diendan/showthread.php?t=1158

Thiết lập tường lửa Iptables cho Linux

Thiết lập tường lửa Iptables cho Linux
Lời mở đầu
Trong bài viết này, mình sẽ hướng dẫn cho bạn cách thiết lập tường lửa Iptables trên Linux. Bài viết gồm hai phần chính: phần I sẽ giới thiệu cơ bản về cách thức hoạt động của Iptables và phần II sẽ hướng dẫn bạn lập cấu hình Iptables cho một máy chủ phục vụ Web cụ thể
Bạn download file kèm theo tại địa chỉ IPtables

Phần I: Giới thiệu về Iptables

Iptables là một tường lửa ứng dụng lọc gói dữ liệu rất mạnh, miễn phí và có sẵn trên Linux.. Netfilter/Iptables gồm 2 phần là Netfilter ở trong nhân Linux và Iptables nằm ngoài nhân. Iptables chịu trách nhiệm giao tiếp giữa người dùng và Netfilter để đẩy các luật của người dùng vào cho Netfiler xử lí. Netfilter tiến hành lọc các gói dữ liệu ở mức IP. Netfilter làm việc trực tiếp trong nhân, nhanh và không làm giảm tốc độ của hệ thống.
Hình Kèm Theo

Cách đổi địa chỉ IP động (dynamic NAT)
Trước khi đi vào phần chính, mình cần giới thiệu với các bạn về công nghệ đổi địa chỉ NAT động và đóng giả IP Masquerade. Hai từ này được dùng rất nhiều trong Iptables nên bạn phải biết. Nếu bạn đã biết NAT động và Masquerade, bạn có thể bỏ qua phần này.

NAT động là một trong những kĩ thuật chuyển đổi địa chỉ IP NAT (Network Address Translation). Các địa chỉ IP nội bộ được chuyển sang IP NAT như sau:

NAT Router đảm nhận việc chuyển dãy IP nội bộ 169.168.0.x sang dãy IP mới 203.162.2.x. Khi có gói liệu với IP nguồn là 192.168.0.200 đến router, router sẽ đổi IP nguồn thành 203.162.2.200 sau đó mới gởi ra ngoài. Quá trình này gọi là SNAT (Source-NAT, NAT nguồn). Router lưu dữ liệu trong một bảng gọi là bảng NAT động. Ngược lại, khi có một gói từ liệu từ gởi từ ngoài vào với IP đích là 203.162.2.200, router sẽ căn cứ vào bảng NAT động hiện tại để đổi địa chỉ đích 203.162.2.200 thành địa chỉ đích mới là 192.168.0.200. Quá trình này gọi là DNAT (Destination-NAT, NAT đích). Liên lạc giữa 192.168.0.200 và 203.162.2.200 là hoàn toàn trong suốt (transparent) qua NAT router. NAT router tiến hành chuyển tiếp (forward) gói dữ liệu từ 192.168.0.200 đến 203.162.2.200 và ngược lại.
Hình Kèm Theo

Cách đóng giả địa chỉ IP (masquerade)
Đây là một kĩ thuật khác trong NAT.

NAT Router chuyển dãy IP nội bộ 192.168.0.x sang một IP duy nhất là 203.162.2.4 bằng cách dùng các số hiệu cổng (port-number) khác nhau. Chẳng hạn khi có gói dữ liệu IP với nguồn 192.168.0.168:1204, đích 211.200.51.15:80 đến router, router sẽ đổi nguồn thành 203.162.2.4:26314 và lưu dữ liệu này vào một bảng gọi là bảng masquerade động. Khi có một gói dữ liệu từ ngoài vào với nguồn là 221.200.51.15:80, đích 203.162.2.4:26314 đến router, router sẽ căn cứ vào bảng masquerade động hiện tại để đổi đích từ 203.162.2.4:26314 thành 192.168.0.164:1204. Liên lạc giữa các máy trong mạng LAN với máy khác bên ngoài hoàn toàn trong suốt qua router.
Hình Kèm Theo



Cấu trúc của Iptables
Iptables được chia làm 4 bảng (table): bảng filter dùng để lọc gói dữ liệu, bảng nat dùng để thao tác với các gói dữ liệu được NAT nguồn hay NAT đích, bảng mangle dùng để thay đổi các thông số trong gói IP và bảng conntrack dùng để theo dõi các kết nối. Mỗi table gồm nhiều mắc xích (chain). Chain gồm nhiều luật (rule) để thao tác với các gói dữ liệu. Rule có thể là ACCEPT (chấp nhận gói dữ liệu), DROP (thả gói), REJECT (loại bỏ gói) hoặc tham chiếu (reference) đến một chain khác.
--------------------------------------------------------------------------------

Quá trình chuyển gói dữ liệu qua Netfilter
Gói dữ liệu (packet) chạy trên chạy trên cáp, sau đó đi vào card mạng (chẳng hạn như eth0). Đầu tiên packet sẽ qua chain PREROUTING (trước khi định tuyến). Tại đây, packet có thể bị thay đổi thông số (mangle) hoặc bị đổi địa chỉ IP đích (DNAT). Đối với packet đi vào máy, nó sẽ qua chain INPUT. Tại chain INPUT, packet có thể được chấp nhận hoặc bị hủy bỏ. Tiếp theo packet sẽ được chuyển lên cho các ứng dụng (client/server) xử lí và tiếp theo là được chuyển ra chain OUTPUT. Tại chain OUTPUT, packet có thể bị thay đổi các thông số và bị lọc chấp nhận ra hay bị hủy bỏ. Đối với packet forward qua máy, packet sau khi rời chain PREROUTING sẽ qua chain FORWARD. Tại chain FORWARD, nó cũng bị lọc ACCEPT hoặc DENY. Packet sau khi qua chain FORWARD hoặc chain OUTPUT sẽ đến chain POSTROUTING (sau khi định tuyến). Tại chain POSTROUTING, packet có thể được đổi địa chỉ IP nguồn (SNAT) hoặc MASQUERADE. Packet sau khi ra card mạng sẽ được chuyển lên cáp để đi đến máy tính khác trên mạng.
Hình Kèm Theo



Các tham số dòng lệnh thường gặp của Iptables
1. Gọi trợ giúp

Để gọi trợ giúp về Iptables, bạn gõ lệnh $ man iptables hoặc $ iptables --help. Chẳng hạn nếu bạn cần biết về các tùy chọn của match limit, bạn gõ lệnh $ iptables -m limit --help.

2. Các tùy chọn để chỉ định thông số

- chỉ định tên table: -t , ví dụ -t filter, -t nat, .. nếu không chỉ định table, giá trị mặc định là filter

- chỉ đinh loại giao thức: -p , ví dụ -p tcp, -p udp hoặc -p ! udp để chỉ định các giao thức không phải là udp

- chỉ định card mạng vào: -i , ví dụ: -i eth0, -i lo

- chỉ định card mạng ra: -o , ví dụ: -o eth0, -o pp0

- chỉ định địa chỉ IP nguồn: -s <địa_chỉ_ip_nguồn>, ví dụ: -s 192.168.0.0/24 (mạng 192.168.0 với 24 bít mạng), -s 192.168.0.1-192.168.0.3 (các IP 192.168.0.1, 192.168.0.2, 192.168.0.3).

- chỉ định địa chỉ IP đích: -d <địa_chỉ_ip_đích>, tương tự như -s

- chỉ định cổng nguồn: --sport , ví dụ: --sport 21 (cổng 21), --sport 22:88 (các cổng 22 .. 88), --sport :80 (các cổng <=80), --sport 22: (các cổng >=22)

- chỉ định cổng đích: --dport , tương tự như --sport

3. Các tùy chọn để thao tác với chain

- tạo chain mới: iptables -N

- xóa hết các luật đã tạo trong chain: iptables -X

- đặt chính sách cho các chain `built-in` (INPUT, OUTPUT & FORWARD): iptables -P , ví dụ: iptables -P INPUT ACCEPT để chấp nhận các packet vào chain INPUT

- liệt kê các luật có trong chain: iptables -L

- xóa các luật có trong chain (flush chain): iptables -F

- reset bộ đếm packet về 0: iptables -Z

4. Các tùy chọn để thao tác với luật

- thêm luật: -A (append)

- xóa luật: -D (delete)

- thay thế luật: -R (replace)

- chèn thêm luật: -I (insert)

Mình sẽ cho ví dụ minh họa về các tùy chọn này ở phần sau.
--------------------------------------------------------------------------------

Phân biệt giữa ACCEPT, DROP và REJECT packet
- ACCEPT: chấp nhận packet

- DROP: thả packet (không hồi âm cho client)

- REJECT: loại bỏ packet (hồi âm cho client bằng một packet khác)

Ví dụ:

# iptables -A INPUT -i eth0 --dport 80 -j ACCEPT chấp nhận các packet vào cổng 80 trên card mạng eth0

# iptables -A INPUT -i eth0 -p tcp --dport 23 -j DROP thả các packet đến cổng 23 dùng giao thức TCP trên card mạng eth0

# iptables -A INPUT -i eth1 -s ! 10.0.0.1-10.0.0.5 --dport 22 -j REJECT --reject-with tcp-reset gởi gói TCP với cờ RST=1 cho các kết nối không đến từ dãy địa chỉ IP 10.0.0.1..5 trên cổng 22, card mạng eth1

# iptables -A INPUT -p udp --dport 139 -j REJECT --reject-with icmp-port-unreachable gởi gói ICMP `port-unreachable` cho các kết nối đến cổng 139, dùng giao thức UDP
--------------------------------------------------------------------------------

Phân biệt giữa NEW, ESTABLISHED và RELATED
- NEW: mở kết nối mới

- ESTABLISHED: đã thiết lập kết nối

- RELATED: mở một kết nối mới trong kết nối hiện tại

Ví dụ:
# iptables -P INPUT DROP đặt chính sách cho chain INPUT là DROP

# iptables -A INPUT -p tcp --syn -m state --state NEW -j ACCEPT chỉ chấp nhận các gói TCP mở kết nối đã set cờ SYN=1

# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT không đóng các kết nối đang được thiết lập, đồng thời cũng cho phép mở các kết nối mới trong kết nối được thiết lập

# iptables -A INPUT -p tcp -j DROP các gói TCP còn lại đều bị DROP
--------------------------------------------------------------------------------

Tùy chọn --limit, --limit-burst
--limit-burst: mức đỉnh, tính bằng số packet

--limit: tốc độ khi chạm mức đỉnh, tính bằng số packet/s(giây), m(phút), d(giờ) hoặc h(ngày)

Mình lấy ví dụ cụ thể để bạn dễ hiểu:

# iptables -N test
# iptables -A test -m limit --limit-burst 5 --limit 2/m -j RETURN
# iptables -A test -j DROP
# iptables -A INPUT -i lo -p icmp --icmp-type echo-request -j test
Đầu tiên lệnh iptables -N test để tạo một chain mới tên là test (table mặc định là filter). Tùy chọn -A test (append) để thêm luật mới vào chain test. Đối với chain test, mình giới hạn limit-burst ở mức 5 gói, limit là 2 gói/phút, nếu thỏa luật sẽ trở về (RETURN) còn không sẽ bị DROP. Sau đó mình nối thêm chain test vào chain INPUT với tùy chọn card mạng vào là lo, giao thức icmp, loại icmp là echo-request. Luật này sẽ giới hạn các gói PING tới lo là 2 gói/phút sau khi đã đạt tới 5 gói.

Bạn thử ping đến localhost xem sao?

$ ping -c 10 localhost

Chỉ 5 gói đầu trong phút đầu tiên được chấp nhận, thỏa luật RETURN đó. Bây giờ đã đạt đến mức đỉnh là 5 gói, lập tức Iptables sẽ giới hạn PING tới lo là 2 gói trên mỗi phút bất chấp có bao nhiêu gói được PING tới lo đi nữa. Nếu trong phút tới không có gói nào PING tới, Iptables sẽ giảm limit đi 2 gói tức là tốc độ đang là 2 gói/phút sẽ tăng lên 4 gói/phút. Nếu trong phút nữa không có gói đến, limit sẽ giảm đi 2 nữa là trở về lại trạng thái cũ chưa đạt đến mức đỉnh 5 gói. Quá trình cứ tiếp tục như vậy. Bạn chỉ cần nhớ đơn giản là khi đã đạt tới mức đỉnh, tốc độ sẽ bị giới hạn bởi tham số--limit. Nếu trong một đơn vị thời gian tới không có gói đến, tốc độ sẽ tăng lên đúng bằng --limit đến khi trở lại trạng thái chưa đạt mức --limit-burst thì thôi.

Để xem các luật trong Iptables bạn gõ lệnh $ iptables -L -nv (-L tất cả các luật trong tất cả các chain, table mặc định là filter, -n liệt kê ở dạng số, v để xem chi tiết)

# iptables -L -nv
Chain INPUT (policy ACCEPT 10 packets, 840 bytes)
pkts bytes target prot opt in out source destination
10 840 test icmp -- lo * 0.0.0.0/0 0.0.0.0/0 icmp type 8

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 15 packets, 1260 bytes)
pkts bytes target prot opt in out source destination

Chain test (1 references)
pkts bytes target prot opt in out source destination
5 420 RETURN all -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 2/min burst 5
5 420 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
# iptables -Z reset counter
# iptables -F flush luật
# iptables -X xóa chain đã tạo
--------------------------------------------------------------------------------

Redirect cổng
Iptables hổ trợ tùy chọn -j REDIRECT cho phép bạn đổi hướng cổng một cách dễ dàng. Ví dụ như SQUID đang listen trên cổng 3128/tcp. Để redirect cổng 80 đến cổng 3128 này bạn làm như sau:

# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128
SNAT & MASQUERADE

Để tạo kết nối `transparent` giữa mạng LAN 192.168.0.1 với Internet bạn lập cấu hình cho tường lửa Iptables như sau:

# echo 1 > /proc/sys/net/ipv4/ip_forward cho phép forward các packet qua máy chủ đặt Iptables
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 210.40.2.71 đổi IP nguồn cho các packet ra card mạng eth0 là 210.40.2.71. Khi nhận được packet vào từ Internet, Iptables sẽ tự động đổi IP đích 210.40.2.71 thành IP đích tương ứng của máy tính trong mạng LAN 192.168.0/24.

Hoặc bạn có thể dùng MASQUERADE thay cho SNAT như sau:

# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

(MASQUERADE thường được dùng khi kết nối đến Internet là pp0 và dùng địa chỉ IP động)
Hình Kèm Theo



Giả sử bạn đặt các máy chủ Proxy, Mail và DNS trong mạng DMZ. Để tạo kết nối trong suốt từ Internet vào các máy chủ này bạn là như sau:

# echo 1 > /proc/sys/net/ipv4/ip_forward
# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.2
# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 25 -j DNAT --to-destination 192.168.1.3
# iptables -t nat -A PREROUTING -i eth0 -p udp --dport 53 -j DNAT --to-destination 192.168.1.4
--------------------------------------------------------------------------------
Hình Kèm Theo

(sưu tập và chỉnh sửa )
Phần II: Lập cấu hình Iptables cho máy chủ phục vụ Web
--------------------------------------------------------------------------------

Phần này mình sẽ trình bày qua ví dụ cụ thể và chỉ hướng dẫn các bạn lọc packet vào. Các packet `forward` và 'output' bạn tự làm nha.

Giả sử như máy chủ phục vụ Web kết nối mạng trực tiếp vào Internet qua card mạng eth0, địa chỉ IP là 1.2.3.4. Bạn cần lập cấu hình tường lửa cho Iptables đáp ứng các yêu cầu sau:
- cổng TCP 80 (chạy apache) mở cho mọi người truy cập web
- cổng 21 (chạy proftpd) chỉ mở cho webmaster (dùng để upload file lên public_html)
- cổng 22 (chạy openssh) chỉ mở cho admin (cung cấp shell `root` cho admin để nâng cấp & patch lỗi cho server khi cần)
- cổng UDP 53 (chạy tinydns) để phục vụ tên miền (đây chỉ là ví dụ)
- chỉ chấp nhận ICMP PING tới với code=0x08, các loại packet còn lại đều bị từ chối.
--------------------------------------------------------------------------------

Bước 1: thiết lập các tham số cho nhân
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 10 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 0 > /proc/sys/net/ipv4/conf/eth0/accept_source_route

tcp_syncookies=1 bật chức năng chống DoS SYN qua syncookie của Linux
tcp_fin_timeout=10 đặt thời gian timeout cho quá trình đóng kết nối TCP là 10 giây
tcp_keepalive_time=1800 đặt thời gian giữ kết nối TCP là 1800 giây
...

Các tham số khác bạn có thể xem chi tiết trong tài liệu đi kèm của nhân Linux.
--------------------------------------------------------------------------------

Bước 2: nạp các môđun cần thiết cho Iptables
Để sử dụng Iptables, bạn cần phải nạp trước các môđun cần thiết. Ví dụ nếu bạn muốn dùng chức năng LOG trong Iptables, bạn phải nạp môđun ipt_LOG vào trước bằng lệnh # modprobe ipt_LOG.

MODULES="ip_tables iptable_filter ipt_LOG ipt_limit ipt_REJECT ipt_state
for i in $MODULES; do
/sbin/modprobe $MODULES
done
--------------------------------------------------------------------------------

Bước 3: nguyên tắc đặt luật là "drop trước, accept sau"
Đây là nguyên tắc mà bạn nên tuân theo. Đầu tiên hãy đóng hết các cổng, sau đó mở dần cách cổng cần thiết. Cách này tránh cho bạn gặp sai sót trong khi đặt luật cho Iptables.

iptables -P INPUT DROP thả packet trước

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT giữ các kết nối hiện tại và chấp nhận các kết nối có liên quan

iptables -A INPUT -i lo -s 127.0.0.1 -j ACCEPT chấp nhận các gói vào looback từ IP 127.0.0.1
iptables -A INPUT -i lo -s 1.2.3.4 -j ACCEPT và 1.2.3.4

BANNED_IP="10.0.0.0/8 192.168.0.0/16 172.16.0.0/12 224.0.0.0/4 240.0.0.0/5"
for i in $BANNED_IP; do
iptables -A INPUT -i eth0 -s $i -j DROP thả các gói dữ liệu đến từ các IP nằm trong danh sách cấm BANNER_IP
done
--------------------------------------------------------------------------------

Bước 4: lọc ICMP vào và chặn ngập lụt PING
LOG của Iptables sẽ được ghi vào file /var/log/firewall.log. Bạn phải sửa lại cấu hình cho SYSLOG như sau:

# vi /etc/syslog.conf
kern.=debug /var/log/firewall.log
# /etc/rc.d/init.d/syslogd restart

Đối với các gói ICMP đến, chúng ta sẽ đẩy qua chain CHECK_PINGFLOOD để kiểm tra xem hiện tại đamg bị ngập lụt PING hay không, sau đó mới cho phép gói vào. Nếu đang bị ngập lụt PING, môđun LOG sẽ tiến hành ghi nhật kí ở mức giới hạn --limit $LOG_LIMIT và --limit-burst $LOG_LIMIT_BURST, các gói PING ngập lụt sẽ bị thả hết.

LOG_LEVEL="debug"

LOG_LIMIT=3/m
LOG_LIMIT_BURST=1

PING_LIMIT=500/s
PING_LIMIT_BURST=100

iptables -A CHECK_PINGFLOOD -m limit --limit $PING_LIMIT --limit-burst $PING_LIMIT_BURST -j RETURN
iptables -A CHECK_PINGFLOOD -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=PINGFLOOD:warning a=DROP "
iptables -A CHECK_PINGFLOOD -j DROP

iptables -A INPUT -i eth0 -p icmp --icmp-type echo-request -j CHECK_PINGFLOOD
iptables -A INPUT -i eth0 -p icmp --icmp-type echo-request -j ACCEPT
--------------------------------------------------------------------------------

Bước 5: reject quét cổng TCP và UDP
Ở đây bạn tạo sẵn chain reject quét cổng, chúng ta sẽ đẩy vào chain INPUT sau. Đối với gói TCP, chúng ta reject bằng gói TCP với cờ SYN=1 còn đối với gói UDP, chúng ta sẽ reject bằng gói ICMP `port-unreachable`

iptables-N REJECT_PORTSCAN
iptables-A REJECT_PORTSCAN -p tcp -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=PORTSCAN:tcp a=REJECT "
iptables-A REJECT_PORTSCAN -p udp -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=PORTSCAN:udp a=REJECT "
iptables-A REJECT_PORTSCAN -p tcp -j REJECT --reject-with tcp-reset
iptables-A REJECT_PORTSCAN -p udp -j REJECT --reject-with icmp-port-unreachable


--------------------------------------------------------------------------------

Bước 6: phát hiện quét cổng bằng Nmap
iptables-N DETECT_NMAP
iptables-A DETECT_NMAP -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:XMAS a=DROP "
iptables-A DETECT_NMAP -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:XMAS-PSH a=DROP "
iptables-A DETECT_NMAP -p tcp --tcp-flags ALL ALL -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:XMAS-ALL a=DROP "
iptables-A DETECT_NMAP -p tcp --tcp-flags ALL FIN -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:FIN a=DROP "
iptables-A DETECT_NMAP -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:SYN-RST a=DROP "
iptables-A DETECT_NMAP -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:SYN-FIN a=DROP "
iptables-A DETECT_NMAP -p tcp --tcp-flags ALL NONE -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=NMAP:NULL a=DROP "
iptables-A DETECT_NMAP -j DROP
iptables-A INPUT -i eth0 -p tcp ! --syn -m state --state NEW -j DETECT_NMAP

Đối với các gói TCP đến eth0 mở kết nối nhưng không đặt SYN=1 chúng ta sẽ chuyển sang chain DETECT_NMAP. Đây là những gói không hợp lệ và hầu như là quét cổng bằng nmap hoặc kênh ngầm. Chain DETECT_NMAP sẽ phát hiện ra hầu hết các kiểu quét của Nmap và tiến hành ghi nhật kí ở mức --limit $LOG_LIMIT và --limit-burst $LOG_LIMIT_BURST. Ví dụ để kiểm tra quét XMAS, bạn dùng tùy chọn --tcp-flags ALL FIN,URG,PSH nghĩa là 3 cờ FIN, URG và PSH được bật, các cờ khác đều bị tắt. Các gói qua chain DETECT_NMAP sau đó sẽ bị DROP hết.
--------------------------------------------------------------------------------

Bước 7: chặn ngập lụt SYN
Gói mở TCP với cờ SYN được set 1 là hợp lệ nhưng không ngoại trừ khả năng là các gói SYN dùng để ngập lụt. Vì vậy, ở dây bạn đẩy các gói SYN còn lại qua chain CHECK_SYNFLOOD để kiểm tra ngập lụt SYN như sau:

iptables-N CHECK_SYNFLOOD
iptables-A CHECK_SYNFLOOD -m limit --limit $SYN_LIMIT --limit-burst $SYN_LIMIT_BURST -j RETURN
iptables-A CHECK_SYNFLOOD -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=SYNFLOOD:warning a=DROP "
iptables-A CHECK_SYNFLOOD -j DROP
iptables-A INPUT -i eth0 -p tcp --syn -j CHECK_SYNFLOOD
--------------------------------------------------------------------------------

Bước 8: giới hạn truy cập SSH cho admin
SSH_IP="1.1.1.1"
iptables -N SSH_ACCEPT
iptables -A SSH_ACCEPT -m state --state NEW -j LOG --log-level $LOG_LEVEL --log-prefix "fp=SSH:admin a=ACCEPT "
iptables -A SSH_ACCEPT -j ACCEPT
iptables -N SSH_DENIED
iptables -A SSH_DENIED -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=SSH:attempt a=REJECT "
iptables -A SSH_DENIED -p tcp -j REJECT --reject-with tcp-reset
for i in $SSH_IP; do
iptables -A INPUT -i eth0 -p tcp -s $i --dport 22 -j SSH_ACCEPT
done
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -j SSH_DENIED
--------------------------------------------------------------------------------

Bước 9: giới hạn FTP cho web-master
FTP_IP="2.2.2.2"
iptables -N FTP_ACCEPT
iptables -A FTP_ACCEPT -m state --state NEW -j LOG --log-level $LOG_LEVEL --log-prefix "fp=FTP:webmaster a=ACCEPT "
iptables -A FTP_ACCEPT -j ACCEPT
iptables -N FTP_DENIED
iptables -A FTP_DENIED -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=FTP:attempt a=REJECT "
iptables -A FTP_DENIED -p tcp -j REJECT --reject-with tcp-reset
for i in $FTP_IP; do
iptables -A INPUT -i eth0 -p tcp -s $i --dport 21 -j FTP_ACCEPT
done
iptables -A INPUT -i eth0 -p tcp --dport 21 -m state --state NEW -j FTP_DENIED


--------------------------------------------------------------------------------

Bước 10: lọc TCP vào
iptables -N TCP_INCOMING
iptables -A TCP_INCOMING -p tcp --dport 80 -j ACCEPT
iptables -A TCP_INCOMING -p tcp -j REJECT_PORTSCAN
iptables -A INPUT -i eth0 -p tcp -j TCP_INCOMING
Bước 11: lọc UDP vào và chặn ngập lụt UDP
iptables -N CHECK_UDPFLOOD
iptables -A CHECK_UDPFLOOD -m limit --limit $UDP_LIMIT --limit-burst $UDP_LIMIT_BURST -j RETURN
iptables -A CHECK_UDPFLOOD -m limit --limit $LOG_LIMIT --limit-burst $LOG_LIMIT_BURST -j LOG --log-level $LOG_LEVEL --log-prefix "fp=UDPFLOOD:warning a=DROP "
iptables -A CHECK_UDPFLOOD -j DROP
iptables -A INPUT -i eth0 -p udp -j CHECK_UDPFLOOD

iptables -N UDP_INCOMING
iptables -A UDP_INCOMING -p udp --dport 53 -j ACCEPT
iptables -A UDP_INCOMING -p udp -j REJECT_PORTSCAN
iptables -A INPUT -i eth0 -p udp -j UDP_INCOMING

Để hạn chế khả năng bị DoS và tăng cường tốc độ cho máy chủ phục vụ web, bạn có thể dùng cách tải cân bằng (load-balacing) như sau:

Cách 1: chạy nhiều máy chủ phục vụ web trên các địa chỉ IP Internet khác nhau. Ví dụ, ngoài máy chủ phục vụ web hiện tại 1.2.3.4, bạn có thể đầu tư thêm các máy chủ phục vụ web mới 1.2.3.2, 1.2.3.3, 1.2.3.4, 1.2.3.5. Điểm yếu của cách này là tốn nhiều địa chỉ IP Internet.

Cách 2: đặt các máy chủ phục vụ web trong một mạng DMZ. Cách này tiết kiệm được nhiều địa chỉ IP nhưng bù lại bạn gateway Iptables 1.2.3.4 - 192.168.0.254 có thể load nặng hơn trước và yêu cầu bạn đầu tư tiền cho đường truyền mạng từ gateway ra Internet.

Bạn dùng DNAT trên gateway 1.2.3.4 để chuyển tiếp các gói dữ liệu từ client đến một trong các máy chủ phục vụ web trong mạng DMZ hoặc mạng LAN như sau:

# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.1-192.168.0.4
--------------------------------------------------------------------------------

Mình đã trình bày xong các bạn về cách cấu hình tường lửa Iptables trên Linux. Hi vọng là bạn có thể nắm được các vấn đề mà mình đã trình bày và có thể tự mình đặt luật cho Iptables để bảo vệ cho máy chủ của bạn. Chúc bạn thành công.
(sưu tập và chỉnh sửa )


۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩ Chữ ký của ghost_vn ۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩۩

url:http://haiphongit.com/forum/showthread.php?t=2831