PsExec用法及遠程操控執行腳本舉例

PsExec用法及遠程操控執行腳本舉例

一、 簡介

PsExec是一種輕量級的telnet替代品,可以在其他系統上執行進程,完成控制檯應用程序的完全交互,而無需手動安裝客戶端軟件。PsExec強大的用途是在遠程系統上啓動交互式命令提示,遠程啓動執行包括IpConfig等cmd命令,故能夠遠程啓動服務器上程序、腳本等。

二、 環境配置

2.1 安裝PsTools

安裝PsTools到執行遠程命令的本地環境,安裝過程非常簡單,只需要下載壓縮包,解壓,配置本地環境即可,如果不配置本地環境,可以直接在解壓文件夾中執行cmd或PowerShell打開
Download:下載PSTools
配置本地環境變量或解壓壓縮包,在壓縮包下按住Shift鼠標右擊,打開命令窗口,下圖表示安裝成功。
在這裏插入圖片描述

2.2 配置執行環境

配置PsExec命令執行遠程服務器文件替換腳本的執行環境,以下配置是針對於執行遠程服務器進行文件替換,拷貝的腳本操作,若無該需求,可以嘗試忽略。
1.進入遠程服務器打開控制檯cmd,輸入 net share ipc$
在這裏插入圖片描述
2.繼續輸入 net share admin$
在這裏插入圖片描述

三、 PsExec使用說明

用法:
psexec [\ computer [,computer2 [,…] | @file ]] [ - u user [-p psswd] [ - ns] [ - r servicename] [ - h] [ - l] [ - s | -e] [ - x] [ - i [session]] [ -c executable [-f | -v]] [ - w directory] [ - d] [ - ] [ - an,n,…] cmd [arguments]
參數說明:

參數 描述
-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 executable to the remote system for execution. If you omit this option the application must be in the system path on the remote system.
-d Don’t wait for process to terminate (non-interactive).
-e Does not load the specified account’s profile.
-f Copy the specified program 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.
-h If the target system is Vista or higher, has the process run with the account’s elevated token, if available.
-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.
-r Specifies the name of the remote service to create or interact with.
-s Run the 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 remote computer).
-x Display the UI on the Winlogon secure 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.
computer Direct PsExec to run the application on the remote computer or computers specified. If you omit the computer name, PsExec runs the application on the local system, and if you specify a wildcard (\*), PsExec runs the command on all computers in the current domain.
@file PsExec will execute the command on each of the computers listed in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.

中文對照

參數 描述
-a 應用程序可以使用逗號運行的單獨處理器,其中1是編號最小的CPU。例,如要在CPU 2和CPU 4上運行應用程序,輸入:“ - a 2,4”
-c 將指定的可執行文件複製到遠程系統以供執行。如果省略此選項,則應用程序必須位於遠程系統上的系統路徑中。
-d 不必等待進程終止(非交互式)。
-e 不加載指定帳戶的配置文件。
-f 即使遠程系統上已存在該文件,也要複製指定的程序。
-i 運行該程序,使其與遠程系統上指定會話的桌面交互。如果未指定會話,則進程將在控制檯會話中運行。
-h 如果目標系統是Vista或更高版本,則使用帳戶的提升令牌(如果可用)運行該流程。
-l 以受限用戶身份運行進程(剝離Administrators組並僅允許分配給Users組的權限)。在Windows Vista上,該過程以低完整性運行。
-n 指定連接到遠程計算機的超時秒數。
-p 指定用戶名的可選密碼。如果省略此項,系統將提示您輸入隱藏密碼。
-r 指定要創建或與之交互的遠程服務的名稱。
-s 在系統帳戶中運行遠程進程。
-u 指定登錄到遠程計算機的可選用戶名。
-v 僅當指定文件的版本號較高或比遠程系統上的版本更新時才複製該文件。
-w 設置進程的工作目錄(相對於遠程計算機)。
-x 在Winlogon安全桌面上顯示UI(僅限本地系統)。
-priority 指定-low,-belownormal,-abovenormal,-high或-realtime以不同的優先級運行進程。使用-background在Vista上以低內存和I / O優先級運行。
computer 直接PsExec在指定的遠程計算機或計算機上運行應用程序。如果省略計算機名稱,PsExec將在本地系統上運行該應用程序,如果指定通配符(\ *),PsExec將在當前域中的所有計算機上運行該命令。
@file PsExec將在文件中列出的每臺計算機上執行該命令。
cmd 要執行的應用程序的名稱。
arguments 要傳遞的參數(請注意,文件路徑必須是目標系統上的絕對路徑)。
-accepteula 該標誌禁止顯示許可證對話框。

四、 應用舉例

1.遠程操控執行腳本

PsExec \\遠程服務器IP -u 登錄名 -p 密碼 -d -i 0 "腳本路徑\本地文件替換腳本.bat"

關於文件替換腳本的創建可以參考這裏:window下本地、遠端文件替換腳本bat及舉例
2.官網例子
(1)以下命令在\ marklap上啓動交互式命令提示符:

psexec \\ marklap cmd

(2)此命令使用/ all開關在遠程系統上執行IpConfig,並在本地顯示結果輸出:

psexec \\ marklap ipconfig / all

(3)此命令將程序test.exe複製到遠程系統並以交互方式執行它:

psexec \\ marklap -c test.exe

(4)指定已安裝在遠程系統上的程序的完整路徑(如果它不在系統的路徑上):

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

(5)在系統帳戶中以交互方式運行Regedit以查看SAM和SECURITY密鑰的內容::

psexec -i -d -sc:\ windows \ regedit.exe

(6)要使用受限用戶權限運行Internet Explorer,請使用以下命令:

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

參考

以上爲個人整理總結的知識,如有遺漏或錯誤歡迎留言指出、點評,如要引用,請寫引用說明,謝謝。
[1]: https://docs.microsoft.com/zh-cn/sysinternals/downloads/psexec

發佈了44 篇原創文章 · 獲贊 9 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章