[英]How to hide tcp port listener powershell script?
目標:運行 powershell 腳本而不顯示 window(如果它彈出幾秒鍾就可以了)。
問題:腳本tcplisten.ps1
僅在 window 顯示給用戶時才有效。 以下所有嘗試均無效。 因為當我運行netstat -ano -p tcp
時,端口9999
沒有在監聽。
tcplisten.ps1
$Listener = [System.Net.Sockets.TcpListener]9999;
$Listener.Start()
嘗試:
powershell.exe
powershell.exe -windowstyle hidden .\tcplisten.ps1
隱藏命令
powershell -windowstyle hidden -command $Listener = [System.Net.Sockets.TcpListener]9999; $Listener.Start()
-NoProfile -NonInteractive -ExecutionPolicy 繞過
powershell -NoP -NonI -W Hidden -Exec Bypass -Command
啟動過程
Start-Process powershell.exe -ArgumentList "-WindowsStyle hidden -file .\tcplisten.ps1"
vbs 腳本
使用此腳本創建 a.vbs 並運行它
command = "powershell.exe -nologo -command C:\Users\Utente\Desktop\tcplisten.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0
問:有解決辦法嗎? 我做錯了什么嗎?
試試這個 vbscript:
Option Explicit
Dim Ws,Port,StrCmd
Set Ws = WScript.CreateObject("WScript.Shell")
Port = 9999
REM We can run this script as admin or not
Call RunAsAdmin()
Call Start_TcpListener(Port)
REM We try to launch the default browser by opening this url with port
ws.Run """http://127.0.0.1:9999""",1,False
wscript.sleep 5000
REM Here just for checking if the port is open or not !
StrCmd = "CMD /K Title Checking Openning Port on "& Port & "& netstat -ano -p tcp | find "& chr(34) & Port & chr(34) &""
Ws.Run StrCmd,1,True
'------------------------------------------------------------------------------
Sub Start_TcpListener(Port)
Dim Ws,PS_CMD,shell
Set Ws = WScript.CreateObject("WScript.Shell")
PS_CMD = "$Listener = [System.Net.Sockets.TcpListener]"& Port &";" & vbCrLF &_
"$Listener.Start{(}{)}~cls~"
ws.run "Powershell",1,False
ws.AppActivate "PowerShell"
wscript.sleep 2000
Ws.sendkeys(PS_CMD)
wscript.sleep 2000
Set shell = CreateObject("Shell.Application")
Shell.MinimizeAll
End Sub
'------------------------------------------------------------------------------
Sub RunAsAdmin()
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, chr(34) & WScript.ScriptFullName & chr(34) & " /elevate", "", "runas", 1
WScript.Quit
End If
End Sub
'------------------------------------------------------------------------------
嘗試將其作為后台作業運行。 此命令在計算機而不是任何用戶上運行,因此在您注銷時它會繼續運行:
Invoke-Command -ComputerName $env:COMPUTERNAME -FilePath 'C:\Users\Utente\Desktop\tcplisten.ps1' -AsJob
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.