PsExec使用总结

PsExec是一款free software,可以在连接没有telnet服务的远程windows系统。

http://technet.microsoft.com/zh-cn/sysinternals/bb897553(en-us).aspx

PsExec v1.94
By Mark Russinovich
Published: January 4, 2008
Introduction
Utilities like Telnet and remote control programs like Symantec's PC Anywhere let you execute programs on remote systems, but they can be a pain to set up and require that you install client software on the remote systems that you wish to access. PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software. PsExec's most powerful uses include launching interactive command-prompts on remote systems and remote-enabling tools like IpConfig that otherwise do not have the ability to show information about remote systems.

Note: some anti-virus scanners report that one or more of the tools are infected with a "remote admin" virus. None of the PsTools contain viruses, but they have been used by viruses, which is why they trigger virus notifications.


 Top of page
Installation
Just copy PsExec onto your executable path. Typing "psexec" displays its usage syntax.

PsExec works on Windows Server 2008, Vista, NT 4.0, Win2K, Windows XP and Server 2003 including x64 versions of Windows.


 Top of page
Usage
See the July 2004 issue of Windows IT Pro Magazine for Mark's article that covers advanced usage of PsExec.

usage: psexec [//computer[,computer2[,...] | @file][-u user [-p psswd]][-n s][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,... ] cmd [arguments]

computer

Direct PsExec to run the application on the computer or computers specified. If you omit the computer name PsExec runs the application on the local system and if you enter a computer name of "//*" PsExec runs the applications on all computers in the current domain.

@file

Directs PsExec to run the command on each computer listed in the text file specified.

-a

Separate processors on which the application can run with commas where 1 is the lowest numbered CPU. For example, to run the application on CPU 2 and CPU 4, enter: "-a 2,4"

-c

Copy the specified program to the remote system for execution. If you omit this option then the application must be in the system's path on the remote system.

-d

Don't wait for application to terminate. Only use this option for non-interactive applications.

-e

Does not load the specified account's profile.

-f

Copy the specified program to the remote system even if the file already exists on the remote system.

-i

Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.

-l

Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity.

-n

Specifies timeout in seconds connecting to remote computers.

-p

Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.

-s

Run remote process in the System account .

-u

Specifies optional user name for login to remote computer.

-v

Copy the specified file only if it has a higher version number or is newer on than the one on the remote system.

-w

Set the working directory of the process (relative to the remote computer).

-x

Display the UI on the Winlogon desktop (local system only).

-priority

Specifies -low, -belownormal, -abovenormal, -high or -realtime to run the process at a different priority. Use -background to run at low memory and I/O priority on Vista.

program

Name of the program to execute.

arguments

Arguments to pass (note that file paths must be absolute paths on the target system)

You can enclose applications that have spaces in their name with quotation marks e.g. "psexec //marklap "c:/long name/app.exe". Input is only passed to the remote system when you press the enter key, and typing Ctrl-C terminates the remote process.

If you omit a username the remote process runs in the same account from which you execute PsExec, but because the remote process is impersonating it will not have access to network resources on the remote system. When you specify a username the remote process executes in the account specified, and will have access to any network resources the account has access to. Note that the password is transmitted in clear text to the remote system.

You can use the current version of PsExec as a Runas replacement when you target the local system because PsExec does not require you to be an administrator.


 Top of page
Examples
This article I wrote describes how PsExec works and gives tips on how to use it:

http://www.winnetmag.com/Windows/Issues/IssueID/714/Index.html

The following command launches an interactive command prompt on //marklap:

psexec //marklap cmd

This command executes IpConfig on the remote system with the /all switch, and displays the resulting output locally:

psexec //marklap ipconfig /all

This command copies the program test.exe to the remote system and executes it interactively:

psexec //marklap -c test.exe

Specify the full path to a program that is already installed on a remote system if its not on the system's path:

psexec //marklap c:/bin/test.exe

Run Regedit interactively in the System account to view the contents of the SAM and SECURITY keys::

psexec -i -d -s c:/windows/regedit.exe

To run Internet Explorer as with limited-user privileges use this command:

psexec -l -d "c:/program files/internet explorer/iexplore.exe"

psexec是一个远程执行工具,你可以像使用telnet一样使用它。
它的使用格式为:
psexec //远程机器ip [-u username [-p password]] [-c [-f]] [-i][-d] program [argum
ents]
它的参数有:
-c <[路径]文件名>:拷贝文件到远程机器并运行(注意:运行结束后文件会自动删除)
-d 不等待程序执行完就返回,(比如要让远程机器运行tftp服务端的时候使用,不然psexec
命令会一直等待tftp程序结束才会返回)
-i 在远程机器上运行一个名为psexesvc进程,(到底什么用弄不明白)
假设我在远程机器ip有一个账号,账号名是:abc 密码是:123
比如想要用telnet一样在远程系统上执行命令可以打:
psexec //远程机器ip -u abc -p 123 cmd
如果想要远程机器执行本地c:/srm.exe文件可以打:
psexec //远程机器ip -u abc -p 123 -c c:/srm.exe
如果想要让远程机器执行本地上tftp服务端,(假设tftp服务端在本地c:/tftp32.exe),可以
打:
psexec //远程机器ip -u abc -p 123 -c c:/tftp32.exe -d

 

另外:

psexec还可以通过连接已打开的远程桌面启动桌面程序。

例:C:/>psexec.exe //servername -u administrator -p password-s -d -i 1 C:/windows/sy
stem32/notepad.exe

其中,-i 后面的数字1 是remote desk top的session ID,可以通过远程服务管理器查看(注意不是通过set s命令)

### WMI Create Process and PsExec Remote Execution Techniques #### WMI Create Process Windows Management Instrumentation (WMI) 是 Windows 操作系统中用于管理和监控硬件和软件资源的重要组件。通过 WMI,可以远程创建进程并执行命令,这在渗透测试或红队演练中非常有用。 WMI 提供了一个名为 `Win32_Process` 的类,该类包含一个名为 `Create` 的方法,允许在本地或远程主机上启动新的进程。此功能可以通过 PowerShell 脚本或其他编程语言调用 WMI 接口来实现。例如,使用 PowerShell 可以如下方式调用 `Win32_Process.Create` 方法: ```powershell $computer = "RemoteComputerName" $username = "RemoteUsername" $password = "RemotePassword" $securePassword = ConvertTo-SecureString $password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword) Invoke-WmiMethod -ComputerName $computer -Credential $credential -Class Win32_Process -Name Create -ArgumentList @("notepad.exe") ``` 上述代码片段展示了如何使用 PowerShell 远程连接到另一台计算机,并在目标机器上启动记事本程序。这里的关键在于使用了 `Invoke-WmiMethod` 命令,它能够调用 WMI 对象的方法。这种方法不仅可以用来启动简单的应用程序,还可以用来执行更复杂的命令或脚本,从而实现对远程系统的管理或控制[^1]。 #### PsExec Remote Execution Techniques PsExec 是 Sysinternals 工具集的一部分,由 Mark Russinovich 开发,后被微软收购。PsExec 允许用户在本地或远程系统上执行进程,而无需预先安装客户端软件。这种工具对于系统管理员来说非常有用,因为它可以简化远程故障排除和维护任务。 使用 PsExec 进行远程执行的基本命令格式如下: ```cmd psexec \\targetmachine -u username -p password command ``` 其中,`\\targetmachine` 表示目标计算机的名称或 IP 地址;`-u` 和 `-p` 参数分别指定用于登录目标计算机的用户名和密码;`command` 表示要在目标计算机上执行的命令或程序。 PsExec 的工作原理涉及到与目标计算机上的服务控制管理器 (Service Control Manager, SCM) 通信,通过 SCM 创建一个新的服务实例来执行指定的命令。这种方式的优势在于不需要在目标计算机上安装额外的服务或代理程序,只需确保目标计算机上的文件和打印机共享服务已启用即可。此外,由于 PsExec 使用的是标准的 Windows 网络协议,因此它可以穿透大多数防火墙设置[^2]。 #### 安全性和防御措施 尽管 WMI 和 PsExec 提供了强大的远程执行能力,但它们也成为了攻击者利用的目标。恶意行为者可能会滥用这些合法的工具和技术来进行未经授权的活动,如横向移动、持久化访问或数据泄露等。为了防止这种情况的发生,组织应该采取一系列安全措施,包括但不限于: - **最小权限原则**:确保用户和服务账户仅拥有完成其任务所需的最小权限。 - **网络隔离**:合理规划网络结构,限制不必要的跨网段通信,特别是涉及敏感操作的通信。 - **审计和监控**:定期审查日志文件,监控异常行为,尤其是那些涉及远程执行的活动。 - **更新和补丁管理**:保持操作系统和所有软件的最新状态,及时应用安全更新以修复已知漏洞。 以上措施有助于减少因 WMI 和 PsExec 被滥用而导致的安全风险,同时也能提高整个 IT 环境的整体安全性。
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值