远程工具psexec

简介:

Windows Sysinternals工具下载地址:

Sysinternals Suite-------https://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

PsExec-------------------https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx



实用工具(如 Telnet)和远程控制程序(如 Symantec 的 PC Anywhere)使您可以在远程系统上执行程序,但安装它们非常困难,并且需要您在想要访问的远程系统上安装客户端软件。PsExec 是一个轻型的 telnet 替代工具,它使您无需手动安装客户端软件即可执行其他系统上的进程,并且可以获得与控制台应用程序相当的完全交互性。PsExec 最强大的功能之一是在远程系统和远程支持工具(如 IpConfig)中启动交互式命令提示窗口,以便显示无法通过其他方式显示的有关远程系统的信息。


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

computer

指示 PsExec 在指定的一台或多台计算机上运行应用程序。如果省略计算机名称,则 PsExec 将在本地系统上运行应用程序;如果输入计算机名称“\\*”,则 PsExec 将在当前域中的所有计算机上运行应用程序。

@file

指示 PsExec 在指定的文本文件中列出的每台计算机上运行命令

-a

用逗号分隔可以运行应用程序的处理器,CPU 编号最小为 1。例如,要在 CPU 2 和 CPU 4 上运行应用程序,请输入:“-a 2,4”

-c

将指定的程序复制到远程系统以便执行。如果省略此选项,则应用程序必须位于远程系统上的系统路径中。

-d

不等待应用程序终止。请只对非交互式应用程序使用此选项。

-e

不加载指定帐户的配置文件。

-f

将指定的程序复制到远程系统,即使远程系统中已存在该文件。

-i

运行程序,以便它与远程系统中指定会话的桌面进行交互。如果未指定会话,则进程将在控制台会话中运行。

-l

以受限用户身份(去除 Administrators 组的权限,并且只允许使用分配给 Users 组的权限)运行进程。在 Windows Vista 上,此进程将以“低完整性”运行。

-n

指定与远程计算机连接的超时(秒)。

-p

指定用户名的密码(可选)。如果省略此选项,系统将提示您输入隐藏密码。

-s

在系统帐户中运行远程进程。

-u

指定用于登录远程计算机的可选用户名。

-v

仅在指定文件具有更高版本号或该文件比远程系统上的文件新时复制该文件。

-w

设置进程的工作目录(相对于远程计算机)。

-x

在 Winlogon 桌面上显示 UI(仅限于本地系统)。

-priority

指定 –low、-belownormal、-abovenormal、-high 或 -realtime 按不同优先级运行进程。

program

要执行的程序的名称。

arguments

要传递的参数(请注意,文件路径必须是目标系统中的绝对路径

对于其名称中含有空格的应用程序,可以在其两侧加引号,例如,psexec \\marklap "c:\long name\app.exe"。按下 Enter 键时,仅将输入内容传递到远程系统。键入 Ctrl-C 可终止远程进程。

如果省略用户名,则远程进程将以执行 PsExec 时所使用的相同帐户运行,但由于远程进程以模仿方式运行,因此它无权访问远程系统上的网络资源。指定用户名时,远程进程将以指定的帐户执行,并可访问该帐户有权访问的任何网络资源。请注意,密码是以明文形式传递到远程系统的。

当目标系统是本地系统时,由于 PsExec 不需要您具有管理员权限,因此您可以使用当前版本的 PsExec 来取代 Runas。


示例

编辑

以下命令可在 \\marklap 上启动交互式命令提示窗口:

psexec \\marklap cmd

此命令通过 /all 开关在远程系统上执行 IpConfig,并在本地显示输出结果:

psexec \\marklap ipconfig /all

此命令将程序 test.exe 复制到远程系统,并以交互方式执行此程序:

psexec \\marklap -c test.exe

如果远程系统中已经安装的程序不在系统路径中,请指定该程序的完整路径:

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

在系统帐户中以交互方式运行 Regedit,以便查看 SAM 和 SECURITY 注册表项的内容:

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

要以受限用户权限运行 Internet Explorer,请使用此命令:

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


执行普通系统命令:

psexec \\ip -u user -p passwd cmd /c dir D:\


--------------------------------------------------------------------------------------


(1)psexec
psexec是一个远程执行工具,你可以像使用telnet一样使用它。
它的使用格式为:
psexec \\远程机器ip [-u username [-p password]] [-c [-f]] [-i][-d] program [arguments]
它的参数有:
-u后面跟用户名 -p后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
-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
(后面例子不再重复-u和-p的用法)

psexec \\远程机器ip -u abc -p 123 -c c:\a.bat  (让远程服务器执行本地写好的批处理)

(2)psservice
psservice是一个服务管理程序。
它的使用格式为:
psservice [\\远程机器ip [-u username] [-p password]] <command> <options>
它的参数只有:
-u 后面跟用户名 -p后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
它的command有:
query [服务名]:显示某一服务的状态,如不填服务名则显示所有服务的状态。
config <服务名>:显示某一服务的配置。
start <服务名>:启动某一服务。
stop <服务名>:停止某一服务。
testart <服务名>:停止某一服务并重新启动它。
pause <服务名>:暂停某一服务。
cont <服务名>:恢复暂停的服务。
depend <服务名>:显示某一服务依存关系。
find <服务名>:在网络种搜寻指定的服务。
比如你想查看在远程机器上的telnet服务的状态可以打:
psservice \\远程机器ip query tlntsvr     (tlntsvr为telnet服务的服务名)
比如你查看远程机器上的telnet服务的配置可以打:
psservice \\远程机器ip config tlntsvr
比如你想启动远程机器上的telnet服务可以打:
psservice \\远程机器ip start tlntsvr
其他用法以此类推。

(3)pssuspend
pssuspend是一个暂时停止进程的软件
它的使用格式为:
pssuspend [-r] [\\远程机器ip [-u username] [-p password]] <process name | process id>
它有三个参数:
-u:后面跟用户名 -p:后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
-r:恢复进程。
比如要暂时停止一个pid号为999,名称为srm.exe的进程可以打:
pssuspend \\远程机器ip 999   或   pssuspend \\远程机器ip srm
如果想要恢复它就可以打pssuspend -r \\远程机器ip 999 或   pssuspend -r \\远程机器ip srm

(4)psinfo
psinfo是一个搜集机器软硬件信息的工具,它可以获得操作系统信息,硬件信息和软件信息。
它的使用格式为:
psinfo [-h] [-s] [-d] [-c] [\\远程机器ip [-u username [-p password]]]
它的参数有:
-u:后面跟用户名 -p:后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
-h:是显示它安装了哪些补丁包
-s:是显示它装了哪些软件
-d:是显示磁盘信息。
比如我只想看远程机器的软硬件信息和只用打:
psinfo \\远程机器ip
假如我还想看看它装了哪些补丁包可以打
psinfo -h \\远程机器ip
假如我还想看看它磁盘信息可以打:
psinfo -d \\远程机器ip
如果我想看它装了哪些软件可以打:
psinfo -s \\远程机器ip
简单吧.

(5)pslist
pslist是一个查看进程的程序。
它的使用格式为:
pslist [-d] [-m] [-x][-t][-s [n] [-r n] [\\远程机器ip [-u username] [-p password]] [name | pid]
它的参数有:
-u:后面跟用户名 -p:后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
-s:是使用任务管理器模式实时查看进程,可以按ESC键退出。
-r <秒数>:是和-s连用的一个参数,它用来指定任务管理器模式是的刷新间隔。(默认的刷新间隔为1秒)
-d:示各个进程的cpu使用信息。
-m:显示各个进程的存储器使用信息。
-x:非常详细显示进程的所有信息。
-t:以树型方式显示进程。
比如要查看远程机器ip上的进程的cpu使用信息可以打:
pslist -d \\远程机器ip
比如要查看一个pid号为999,名称为srm.exe进程的存储器使用信息可以打:
pslist -m \\远程机器ip 999 或 pslist -m \\远程机器ip srm
比如要以任务管理器模式实时查看61.12.23.4上进程情况,并且刷新间隔为3秒可以打:
pslist -s -n 3 \\远程机器ip

(6)psuptime
psuptime是一个了解远程机器运行了多久的命令。
使用它只需要打:psuptime \\远程机器ip

(7)psshutdown
psshutdown是一个远程关机命令。
它的使用格式为:
psshutdown [[-s | -r | -k [-t nn][-m "消息"][-f]] -a | -l | -o] [\\远程机器ip]
它的参数有:
-a:取消以前执行的关机指令。
-t:离关机还有多少秒。(默认是20秒)
-s:关闭机器。
-m:是要显示的信息。
-f:是关机是不保存运行的程序。
-r:表示重启。
-l:表示锁定电脑。
-o:表示注销用户。
比如我想让远程机器30秒后关闭并显示(要关机了,请保存文件)则打:
psshutdown -t 30 -s -m "要关机了,请保存文件" \\远程机器ip
如果是要重起的话打:
psshutdown -t 30 -m "要关机了,请保存文件" -r \\远程机器ip
如果要取消刚才的指令可以打:
psshutdown -a \\远程机器ip
其他参数以此类推。

(8)psfile
psfile是一个显示机器上的会话和有什么文件被网络中的用户的打开的命令。
它的使用格式为:
psfile [\\远程机器ip [-u Username [-p Password]]] [[Id | path] [-c]]
它的参数有:
-u 后面跟用户名 -p后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
-c:关闭会话或文件
比如我想看看远程机器上的会话和被远程用户打开的文件可以打:
psfile \\远程机器ip
接着就会显示
[33] C:\WINNT
  User:   ADMINISTRATOR
  Locks: 0
  Access: Read
[63] \PIPE\srvsvc
  User:   ADMINISTRATOR
  Locks: 0
  Access: Read Write
接着我想关闭id为33,路径为c:\winnt的这个会话可以打
psfile \\远程机器ip 33 -c   或   psfile \\远程机器ip c:\winnt -c

(9)psloggedon
psloggedon是一个显示目前谁登陆的机器的命令。
它的参数只有:
-l只显示本地登陆用户而不显示其它的网络登陆用户
-x不显示登陆时间
比如说要显示远程机器现在登陆的用户可以打:
psloggedon \\远程机器ip

(10)psgetsid
psgetsid是一个远程获取账号sid信息的工具。
它的使用格式为:
psgetsid [\\远程机器ip [-u username [-p password]]] [account]
它的参数有
-u 后面跟用户名 -p后面是跟密码的,如果建立ipc连接后这两个参数则不需要。(如果没有-p参数,则输入命令后会要求你输入密码)
比如要看远程机器上账号名为abc的sid信息可以打:
psgetsid \\远程机器ip abc

(11)pskill
pskill是一个杀除进程的程序。
它的使用格式为:
pskill [\\远程机器ip [-u username] [-p password]] <process name | process id>
比如要杀除一个pid号为999,名称为srm.exe的进程可以打:
pskill \\远程机器ip 999   或   pskill \\远程机器ip srm

(12)psloglist
psloglist
psloglist是一个查看系统事件记录的程序。
它的使用格式为:
psloglist [\\远程机器ip [-u username [-p password]]] [-s [-t delimiter]] [-n # | -d #] [-c][-x][-r][-a mm/dd/yy][-b mm/dd/yy][-f filter] [-l event log file] <eventlog> 
它的参数有:
-u 后面跟用户名 -p后面是跟密码的,如果建立ipc连接后这两个参数则不需要。
-c:显示事件之后清理事件记录
-l <事件记录文件名>:用于查看事件记录文件
-n <n>:只显示最近的n条系统事件记录。
-d <n>:只显示n天以前的系统事件记录
-a mm/dd/yy:显示mm/dd/yy以后的系统事件记录
-b mm/dd/yy:显示mm/dd/yy以前的系统事件记录
-f <事件类型>:只显示指定的事件类型的系统事件记录。
-x:显示事件数据代码
-r:从旧到新排列(如不加则默认是从新到旧排列)
-s:以一个事件为一行的格式显示,中间默认以逗号格开各个信息。
-t <字符>:这个参数和-s连用,以来改变-s中默认的逗号。
如果我想看远程机器的系统事件记录只用打:
psloglist \\远程机器ip 123
比如我想看最近的10条error类型的记录可以打:
psloglist \\远程机器ip -n 10 -f error


---------------------------------------------------------------------------------


PsExec (PsTools)


Execute a command-line process on a remote machine.


Syntax

      psexec \\computer[,computer[,..] [options] command [arguments]


      psexec @run_file [options] command [arguments]


Options:


   computer   The computer on which psexec will run command. Default = local system 

              To run against all computers in the current domain enter "\\*"

               

   @run_file  Run command on every computer listed in the text file specified.


   command    Name of the program to execute


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


   -a n,n,... Set processor affinity to n. Processors are numbered as 1,2,3,4 etc

              so to run the application on CPU 2 and CPU 4, enter: "-a 2,4"


   -c         Copy the program (command)to the remote system for execution.

   -c -f      Copy even if the file already exists on the remote system.

   -c -v      Copy only if the file is a higher version or is newer than the remote copy.


   If you omit the -c option then the application must be in the system path on the remote system.


   -d         Don’t wait for the application to terminate.

              Only use for non-interactive applications.


   -e         Do NOT load the specified account’s profile.

              (In early versions of PSEXEC: Load the user account's profile, don’t use with -s)


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


   -h         Run with the account's elevated token, if available. (Vista or higher)


   -i         Interactive - Run the program so that it interacts with the desktop on the remote system.

              If no session is specified, the process runs in the console session.


   -l         Limited - Run process as limited user.  Run with Low Integrity.

              Strips the Administrators group and allows only privileges assigned to the Users group.


   -n s       Specify a timeout (s seconds) for connecting to the remote computer.


   -p psswd   Specify a password for user (optional). Passed as clear text.

              If omitted, you will be prompted to enter a hidden password.


   -r         The name of the remote service to create or interact with.


   -s         Run remote process in the SYSTEM account (use with caution).


   -u user    Specify a user name for login to remote computer(optional).


   -v         Copy the specified file only if it has a higher version number or is newer

              than the one on the remote system.


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


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


   -low, -belownormal, -abovenormal, -high or -realtime

              These options will run the process at a different priority.

              also -background (Vista and above) will run at low memory and I/O priority.


   -accepteula Suppress the display of the license dialog.


For PsExec to work, File and Printer sharing must be enabled on the remote computer.


PsExec can also be used to start GUI applications, but in that case the GUI will appear on the remote machine.


Input is passed to the remote system when you press the enter key - typing Ctrl-C will terminate the remote process.


When you specify a username the remote process will execute in that account, and will have access to that account's network resources.


If you omit username the remote process will run 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.


If you do specify an alternative username/password, then PsExec will send the password in clear text. This can be a security risk if unauthorized network sniffers could intercept traffic between the local and remote system.


PsExec does not require you to be an administrator of the local filesystem, with the correct password psexec will allow UserA to run commands as UserB - a Runas replacement.


If you kill a PsExec process, you might also need to manually remove the background service:

sc.exe \\workstation64 delete psexesvc


PsExec can also be used to start a process (on a remote or local machine) as SYSTEM, this is a very privileged account similar to root on a UNIX machine ~ use with extreme caution.

Accept eula


When launched for the first time, PsExec will create the license registry key:

HKCU\Software\Sysinternals\PsExec\EulaAccepted=0x01


Psexec will swallow the first "-accepteula" on the commandline, no matter where it occurs, so when using psexec to run any other ps* utilities, you will have to pass "-accepteula" twice:


psexec -accepteula -s c:\utils\pslist.exe -accepteula


Surround any long filenames "with quotation marks"


Error codes returned by PsExec are specific to the applications you execute, not PsExec.

Internal commands


Internal commands (such as COPY, CD, DIR etc) are only available within the CMD shell. To run these commands from PsExec you must call CMD /C and then pass the commands as parameters - see the examples below.


Examples:


Launch an interactive command prompt on \\workstation64, the CMD prompt window will appear locally:


psexec \\workstation64 cmd


Execute a program that is already installed on the remote system:


psexec \\workstation64 "c:\Program Files\test.exe"


Connect to workstation64 and run IPCONFIG to display the remote PC's IP address:


psexec \\workstation64 ipconfig


Connect to workstation64 and list a directory:


psexec \\workstation64 -s cmd /c dir c:\work


Connect to workstation64 and copy a file from another server:


psexec \\workstation64 -s cmd /c copy \\server21\share45\file.ext c:\localpath


Execute IpConfig on the remote system, and display the output locally:


psexec \\workstation64 ipconfig /all


Copy the program test.exe to the remote system and execute it interactively, running under the account DannyGlover:


psexec \\workstation64 -c test.exe -u DannyGlover -p Pa55w0rd


Run Internet Explorer on the local machine but with limited-user privileges:


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


Run Regedit on the local machine with SYSTEM privileges:


psexec -s -i regedit.exe


From PowerShell, run a VBscript on a remote workstation and pass some parameters:


PS C:> $script='C:\Program Files\demo.vbs'

PS C:> $args = "some more text"

PS C:> psexec -s \\workstation64 c:\windows\system32\cscript.exe $script $args












本文转自leonardos51CTO博客,原文链接:http://blog.51cto.com/leomars/1900528 ,如需转载请自行联系原作者



相关文章
|
存储 网络协议 Linux
把Linux服务器做成一个下载器,实现远程下载
把Linux服务器做成一个下载器,实现远程下载
把Linux服务器做成一个下载器,实现远程下载
|
4月前
|
监控 网络安全 数据安全/隐私保护
局域网员工电脑监控软件远程命令执行代码详解
在企业网络管理中,为了确保员工的工作效率和网络安全,监控系统的使用成为一种必要的手段。本文将深入解析一种局域网员工电脑监控软件的远程命令执行代码,通过例子详细说明其实现原理。
261 0
|
10月前
|
移动开发 Ubuntu 网络协议
【服务器】iPad远程服务器进行开发(上)
【服务器】iPad远程服务器进行开发
199 0
|
10月前
|
网络协议 Ubuntu 网络安全
【服务器】iPad远程服务器进行开发(下)
【服务器】iPad远程服务器进行开发(下)
321 0
|
12月前
|
安全 数据安全/隐私保护 iOS开发
需要远程协助?可以先试试 macOS 自带的远程屏幕共享 | 一日一技
需要远程协助?可以先试试 macOS 自带的远程屏幕共享 | 一日一技
322 0
|
NoSQL 前端开发 Linux
【C++】使用VS2022开发可以在线远程编译部署的C++程序
c++类库源码以及其他有关资源。站点是英文的,英文不好的话可以谷歌浏览器在线翻译。http://www.cplusplus.com/
583 0
【C++】使用VS2022开发可以在线远程编译部署的C++程序
|
Ubuntu 网络安全 计算机视觉
树莓派开发笔记(四):更方便的开发,qt远程运行(主机qt开发一键远程运行到目标机上)
树莓派开发笔记(四):更方便的开发,qt远程运行(主机qt开发一键远程运行到目标机上)
树莓派开发笔记(四):更方便的开发,qt远程运行(主机qt开发一键远程运行到目标机上)