I'm not sure I fully understood you, but I'll give it a try anyway.
The following instructions will explain how to achieve something like this:|
radare2 comes with its own webserver. Although at first, it might seems like an overkill, its actually quite useful, especially when you want to debug embedded systems, or simply to execute commands from a remote terminal.
Simply launch the web server with
=h <port> and connect to it with any HTTP client.
You can print the help for this command by using
|Usage: =[hH] [...] # http server
| http server:
| =h port listen for http connections (r2 -qc=H /bin/ls)
| =h- stop background webserver
| =h-- stop foreground webserver
| =h* restart current webserver
| =h& port start http server in background
| =H port launch browser and listen for http
| =H& port launch browser and listen for http in background
So let's use a oneliner command to spawn a radare2 web server with a session to our beloved
$ r2 -c=h /bin/ls
Starting http server...
r2 -C http://localhost:9090/cmd/
Good, now that we have an HTTP server running with an open session, let's connect to it.
You can do this with
$ curl http://127.0.0.1:9090/cmd/?EHello,World!
| _| | |
| O O < Hello,World! |
| | | | |
|| | / `--------------'
You can even do this from your favorite browser:
Although it's cool, it isn't helping you -- you asked for a solution using r2pipe. Well... there is!
What is r2pipe?
The r2pipe APIs are based on a single r2 primitive found behind
r_core_cmd_str() which is a function that accepts a string parameter
describing the r2 command to run and returns a string with the result.
Source: r2pipe repository
As you probably know, using python, you can just do
import r2pipe and
r2pipe.open("/bin/ls") to open a radare2 session with "/bin/ls". Did you know that you can connect with r2pipe to a remote web server? Yup.
Let's write a quick script to do so:
print("[+] Connecting with python r2pipe")
r2_remote = r2pipe.open("http://127.0.0.1:9090")
command = "?E Welcome from server!"
while command != "stop":
command = raw_input("r2cmd > ")
Save the script to
poc.py on you drive.
Now let's run
r2 -c=h /bin/ls in one terminal and
python poc.py in another one:
Yes, radare2 can also print QR codes.