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
Thursday, September 25, 2008
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.
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 = "
' 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 = "
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
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, 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
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
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
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
- chỉ đinh loại giao thức: -p
- chỉ định card mạng vào: -i
- chỉ định card mạng ra: -o
- 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
- chỉ định cổng đích: --dport
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
- 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
Subscribe to:
Posts (Atom)