今天看啥  ›  专栏  ›  sunnnnnnnnnny

psexec的使用

sunnnnnnnnnny  · 简书  ·  · 2020-11-18 13:17

psexe简介

本资料来自官网

介绍

psexe是一种轻量级的远程连接工具,可远程执行命令
基于IPC共享,所以要目标打开445端口
下载地址 https://download.sysinternals.com/files/PSTools.zip
ps工具包中还有这些工具

◆PsExec - 远程执行进程
◆PsFile - 显示远程打开的文件
◆PsGetSid - 显示计算机或用户的 SID
◆PsKill - 按名称或进程 ID 终止进程
◆PsInfo - 列出有关系统的信息
◆PsList - 列出有关进程的详细信息
◆PsLoggedOn - 查看在本地通过资源共享(包含所有资源)登录的用户
◆PsLogList - 转储事件日志记录
◆PsPasswd - 更改帐户密码
◆PsService - 查看和控制服务
◆PsShutdown - 关闭并重新启动(可选)计算机
◆PsSuspend - 暂停进程

安装

下载解压,在目录下运行cmd,在命令行中使用

使用方法

Usage: psexec [\computer[,computer2[,...] | @file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c executable [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
选项

-a 指定程序在哪个CPU上运行 比如-a 2,4 在2号和4号CPU运行程序
-c 将本地的可执行文件拷贝到远程主机上运行,若忽略该选项,程序必须在远程主机上
-d 无需等待程序结束(非交互式)
-e 不加载指定用户配置
-f 拷贝指定的文件,即便文件已经存在
-i 指定远程桌面会话,若不指定,将以console模式运行
-h If the target system is Vista or higher, has the process run with the account's elevated token, if available
-l 限定指定的用户运行程序
-n 指定连接远程主机的timout时间 单位为s
-p  指定密码,若忽略该选择,登陆过程中会提示输入密码
-r  指定远程服务名称
-s 在远程主机上以system账户来运行程序 
-u 登陆用户名
-v 拷贝指定的文件,当当前文件比远程主机上的文件新的时候拷贝
-w 指定程序的工作目录
-x 显示winlogon界面 (local system only)
-priority 指定运行程序的优先级 -low, -belownormal, -abovenormal, -high or -realtime 
computer 指定运行程序的主机名 不指定的话在本地系统中运行, 若指定为\\*,将在当前域的所有主机上运行
@file 指定文件,为主机列表,psexec将在所有这些主机上运行程序 
cmd 要运行的程序的名称
arguments 参数,文件路径必须是绝对路径
-accepteula 不显示license dialog

psexec \\marklap"c:\long name app.exe"

Enter 在远程主机运行
Ctrl+C 终止远程程序
若不指定用户名,将以上下文中的用户名登陆,但是不能访问网络资源
当需要访问网络资源时,需要提供合法的符合Domain\User语法的用户名
传输的密码和执行的命名加密传输
psexec会返回执行的错误

例子

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"


实验

环境搭建

  • 本地win10 psexec.exe 开启了主机发现功能
  • 远程win7 64位 开启了主机发现和共享功能 有个管理员账户WLJ
    远程主机需要进行如下配置
以管理员权限运行cmd,执行命令
net share ipc$
net share admin$
要在psexec中使用本地管理员账户需要修改注册表
在注册表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System中添加LocalAccountTokenFilterPolicy 值为1,类型为DWORD

参考
https://blog.51cto.com/babyfenei/1741291
https://blog.csdn.net/weixin_34174322/article/details/92117768

测试


使用IP地址登陆
psexec \\192.168.31.210 -u WLJ -p 123456 cmd
也可以使用主机名登陆
psexec \\WLJ-VM-WIN7-X64 -u WLJ -p 123456 cmd
退出后再登陆可以不需要用户名和密码,默认使用上下文中的登陆信息

psexec \\WLJ-VM-WIN7-X64 ipconfig /all

参考资料

https://docs.microsoft.com/zh-cn/sysinternals/downloads/psexec




原文地址:访问原文地址
快照地址: 访问文章快照