天天看點

遠端工具psexec

Windows Sysinternals工具下載下傳位址:

<a>用法: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]</a>

computer

訓示 PsExec 在指定的一台或多台計算機上運作應用程式。如果省略計算機名稱,則 PsExec 将在本地系統上運作應用程式;如果輸入計算機名稱“\\*”,則 PsExec 将在目前域中的所有計算機上運作應用程式。

@file

-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。

<a>編輯</a>

以下指令可在 \\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 &lt;[路徑]檔案名&gt;:拷貝檔案到遠端機器并運作(注意:運作結束後檔案會自動删除)

-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]] &lt;command&gt; &lt;options&gt;

它的參數隻有:

-u 後面跟使用者名 -p後面是跟密碼的,如果建立ipc連接配接後這兩個參數則不需要。(如果沒有-p參數,則輸入指令後會要求你輸入密碼)

它的command有:

query [服務名]:顯示某一服務的狀态,如不填服務名則顯示所有服務的狀态。

config &lt;服務名&gt;:顯示某一服務的配置。

start &lt;服務名&gt;:啟動某一服務。

stop &lt;服務名&gt;:停止某一服務。

testart &lt;服務名&gt;:停止某一服務并重新啟動它。

pause &lt;服務名&gt;:暫停某一服務。

cont &lt;服務名&gt;:恢複暫停的服務。

depend &lt;服務名&gt;:顯示某一服務依存關系。

find &lt;服務名&gt;:在網絡種搜尋指定的服務。

比如你想檢視在遠端機器上的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]] &lt;process name | process id&gt;

它有三個參數:

-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]]]

-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]

-s:是使用任務管理器模式實時檢視程序,可以按ESC鍵退出。

-r &lt;秒數&gt;:是和-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]]

它的參數有:

-c:關閉會話或檔案

比如我想看看遠端機器上的會話和被遠端使用者打開的檔案可以打:

psfile \\遠端機器ip

接着就會顯示

[33] C:\WINNT

  User:   ADMINISTRATOR

  Locks: 0

  Access: Read

[63] \PIPE\srvsvc

  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]

它的參數有

比如要看遠端機器上賬号名為abc的sid資訊可以打:

psgetsid \\遠端機器ip abc

(11)pskill

pskill是一個殺除程序的程式。

pskill [\\遠端機器ip [-u username] [-p password]] &lt;process name | process id&gt;

比如要殺除一個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] &lt;eventlog&gt; 

-u 後面跟使用者名 -p後面是跟密碼的,如果建立ipc連接配接後這兩個參數則不需要。

-c:顯示事件之後清理事件記錄

-l &lt;事件記錄檔案名&gt;:用于檢視事件記錄檔案

-n &lt;n&gt;:隻顯示最近的n條系統事件記錄。

-d &lt;n&gt;:隻顯示n天以前的系統事件記錄

-a mm/dd/yy:顯示mm/dd/yy以後的系統事件記錄

-b mm/dd/yy:顯示mm/dd/yy以前的系統事件記錄

-f &lt;事件類型&gt;:隻顯示指定的事件類型的系統事件記錄。

-x:顯示事件資料代碼

-r:從舊到新排列(如不加則預設是從新到舊排列)

-s:以一個事件為一行的格式顯示,中間預設以逗号格開各個資訊。

-t &lt;字元&gt;:這個參數和-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:

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:&gt; $script='C:\Program Files\demo.vbs'

PS C:&gt; $args = "some more text"

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

本文轉自leonardos51CTO部落格,原文連結:http://blog.51cto.com/leomars/1900528 ,如需轉載請自行聯系原作者

繼續閱讀