byt3bl33d3r / CrackMapExec

A swiss army knife for pentesting networks
BSD 2-Clause "Simplified" License
8.29k stars 1.64k forks source link

SSH: try upgrade to root using sudo #787

Closed saligrama closed 1 year ago

saligrama commented 1 year ago

Many SSH-supporting systems (e.g. Debian and Ubuntu based Linux distributions) do not have a root password set by default, nor do their default SSH configurations support logging in as root. However, we can still execute commands as root by using sudo, usually with the user password of the user we're logged into if it's a sudoer.

This PR adds support for testing if we can do the root upgrade with the user we logged in with, and if executing a command, prefixing that command with sudo to execute it as root if requested. Modes include --try-root-upgrade (execute with sudo if possible, but fall back to executing as user if not possible) and --force-root-upgrade (execute a command if we have root, don't execute at all otherwise).