radare2/man/rarun2.1
pancake 62c2128b6f
Better use of the R_SOCKET_PROTO_DEFAULT and add _NONE (#17644)
* Better use of the R_SOCKET_PROTO_DEFAULT and add _NONE ##http

* Fix regressions in: r2 -C and =+ ##r2pipe

Introduced in 04edfa82c1

* Implement sleep command ##shell

* Add tests for the webserver and remoting

* Implement daemon directive in rarun2, fix http test ##rarun2

* Fix socket timeout on Windows (patch by @GustavoLCR) ##socket

* Missing http.root is not a reason to not start the webserver ##http

* Fix r2 -C, =!=0, replace curl with r2 in the webserver test ##http

* Honor anal.in/from/to in aae, optimize db/formats/mach0/thumb ##anal

* Bug fixes and performance improvements

Co-authored-by: pancake <pancake@nopcode.org>
2020-09-25 19:51:23 +08:00

173 lines
4.8 KiB
Groff

.Dd Feb 3, 2017
.Dt RARUN2 1
.Sh NAME
.Nm rarun2
.Nd radare2 utility to run programs in exotic environments
.Sh SYNOPSIS
.Nm rarun2
.Op [directives]
.Op [script.rr2]
.Op [--] [program] [args]
.Sh DESCRIPTION
This program is used as a launcher for running programs with different environment, arguments, permissions, directories and overridden default filedescriptors.
.Pp
rarun2 -t will show the terminal name and wait for a connection from another process. try rarun2 stdio=<ttypath> program=/bin/sh
.Pp
The program just accepts a single argument which is the filename of the configuration file to run the program.
.Pp
It is useful when you have to run a program using long arguments or pass long data to stdin or things like that usually required for exploiting crackmes :)
.Sh DIRECTIVES
.Pp
The rr2 (rarun2) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'.
.Bl -tag -width Fl
.It Ar arg[0-N]
set value for argument N passed to the program
.It Ar aslr
enable or disable ASLR
.It Ar bits
set 32 or 64 bit (if the architecture supports it)
.It Ar chdir
change directory before executing the program
.It Ar chroot
run the program in chroot. requires some previous setup
.It Ar clearenv
unset the whole environment
.It Ar core
set no limit the core file size
.It Ar connect
connect stdin/stdout/stderr to a socket
.It Ar pty
use a pty for connection over socket (with connect/listen)
.It Ar envfile
set a file with lines like `var=value` to be used as env
.It Ar fork
used with the listen option, allow to spawn a different process for each connection. Ignored when debugging.
.It Ar input
set string to be passed to the program via stdin
.It Ar libpath
override path where the dynamic loader will look for shared libraries
.It Ar listen
bound stdin/stdout/stderr to a listening socket
.It Ar maxstack
set the maximum size for the stack
.It Ar maxproc
set the maximum number of processes
.It Ar maxfd
set the maximum number of file descriptors
.It Ar nice
set the niceness level of the process
.It Ar preload
preload a library (not supported on Windows, only linux,osx,bsd)
.It Ar daemon
Set to false by default, otherwise it will run the program in background, detached from the terminal.
.It Ar program
path to program to be executed
.It Ar execve
use execve instead of posix_spawn (osx tricks)
.It Ar runlib
path to the library to be executed
.It Ar runlib.fcn
function name to call from runlib library
.It Ar r2preload
preload with libr2, kill -USR1 to get an r2 shell or -USR2 to spawn a webserver in a thread
.It Ar r2preweb
run the webserver in a thread just at starting the r2preload
.It Ar setenv
set value for given environment variable
.It Ar setegid
set effective process group id
.It Ar seteuid
set effective process uid
.It Ar setgid
set process group id
.It Ar setuid
set process uid
.It Ar sleep
sleep for the given amount of seconds
.It Ar stdin
select file to read data from stdin
.It Ar stdout
select file to replace stdout file descriptor
.It Ar system
execute the given command
.It Ar timeout
set a timeout
.It Ar timeoutsig
signal to use when killing the child because the timeout happens
.It Ar unsetenv
unset one environment variable
.El
.Sh VALUE PREFIXES
Every value in this configuration file can contain a special
.Pp
.Bl -tag -width Fl
.It Ar @filename
Slurp contents of file and put them inside the key
.It Ar "text"
Escape characters useful for hex chars
.It Ar 'string'
Escape characters useful for hex chars
.It Ar !cmd
Run command to store the output in the variable
.It Ar :102030
Parse hexpair string and store it in the variable
.It Ar :!cmd
Parse hexpair string from output of command and store it in the variable
.It Ar %1234
Parses the input string and returns it as integer
.El
.Sh EXAMPLES
Sample rarun2 script
.Pp
$ cat foo.rr2
#!/usr/bin/rarun2
program=./pp400
arg0=10
stdin=foo.txt
chdir=/tmp
clearenv=true
setenv=EGG=eggsy
setenv=NOFUN=nogames
unsetenv=NOFUN
# EGG will be the only env variable
#chroot=.
./foo.rr2
.Pp
Connecting a program to a socket
.Pp
$ nc \-l 9999
$ rarun2 program=/bin/ls connect=localhost:9999
.Pp
Debugging a program redirecting io to another terminal
.Pp
## open a new terminal and type 'tty' to get
$ tty ; clear ; sleep 999999
/dev/ttyS010
## in another terminal run r2
$ r2 \-r foo.rr2 -d ls
$ cat foo.rr2
#!/usr/bin/rarun2
stdio=/dev/ttys010
## Or you can use -R to set a key=value
r2 \-R stdio=/dev/ttys010 -d ls
.Pp
You can also use the -- flag to specify program and arguments in a more natural way:
.Pp
$ rarun2 timeout=2 -- sleep 4
.Pp
Run a library function
.Pp
$ rarun2 runlib=/lib/libc-2.25.so runlib.fcn=system arg1="ls /"
.Sh SEE ALSO
.Pp
.Xr radare2(1) ,
.Xr rahash2(1) ,
.Xr rafind2(1) ,
.Xr rabin2(1) ,
.Xr radiff2(1) ,
.Xr ragg2(1) ,
.Xr rasm2(1) ,
.Sh AUTHORS
.Pp
Written by pancake <pancake@nopcode.org>