繁体   English   中英

如何隐藏 tcp 端口监听器 powershell 脚本?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM