eCPPTv3-PTP-Notes
HomeGitHubPortfolioTwitter/XMediumCont@ct
  • 📝eCPPT / PTP - Notes
    • eCPPTv3
      • 1️⃣1 - Resource Development & Initial Access
        • 1.1 - PowerShell for Pentesters
        • 1.2 - Client-Side Attacks
          • 1.2.1 - System/Host Based Attacks
            • 1.2.1.1 Windows Vulnerabilities
          • 1.2.2 - The Metasploit Framework (MSF)
            • 1.2.2.1 MSF Introduction
            • 1.2.2.2 Information Gathering & Enumeration
            • 1.2.2.3 Vulnerability Scanning
            • 1.2.2.4 Client-Side Attacks
            • 1.2.2.5 Post Exploitation
            • 1.2.2.6 Armitage
          • 1.2.3 Exploitation
          • 1.2.4 Social Engineering
      • 2️⃣2 - Web Application Penetration Testing
        • 2.1 - Web App Concepts
          • 2.1.1 HTTP/S Protocol
          • 2.1.2 Encoding
          • 2.1.3 Same Origin
          • 2.1.4 Cookies
          • 2.1.5 Session
          • 2.1.6 Web App Proxies
        • 2.2 - Information Gathering
          • 2.2.1 Gathering Information on Your Targets
          • 2.2.2 Infrastructure
          • 2.2.3 Fingerprinting Frameworks and Applications
          • 2.2.4 Fingerprinting Custom Applications
          • 2.2.5 Enumerating Resources
          • 2.2.6 Information Disclosure Through Misconfiguration
          • 2.2.7 Google Hacking
          • 2.2.8 Shodan HQ
        • 2.3 - Cross Site Scripting
          • 2.3.1 XSS Anatomy
          • 2.3.2 Reflected XSS
          • 2.3.3 Stored XSS
          • 2.3.4 DOM-Based XSS
          • 2.3.5 Identifying & Exploiting XSS with XSSer
        • 2.4 - SQL Injection
          • 2.4.1 Introduction to SQL Injection
          • 2.4.2 Finding SQL Injection
          • 2.4.3 Exploiting In-Band SQL Injection
          • 2.4.4 Exploiting Error-Based SQL Injection
          • 2.4.5 Exploiting Blind SQL Injection
          • 2.4.6 SQLMap
          • 2.4.7 Mitigation Strategies
          • 2.4.8 From SQLi to Server Takeover
        • 2.5 - Other Common Web Attacks
          • 2.5.1 Session Attacks
          • 2.5.2 CSRF
          • 2.5.3 File and Resource Attacks
      • 3️⃣3 - Network Security
        • 3.1 Network Based Attacks
        • 3.2 Linux Vulnerabilities
        • 3.3 - Exploitation
          • 3.3.1 Linux Exploitation
      • 4️⃣4 - Exploit Development
        • 4.1 Architecture Foundamentals
        • 4.2 Assemblers and Tools
        • 4.3 Buffer Overflow
        • 4.4 Cryptography
        • 4.5 Malware
        • 4.6 Shellcoding
      • 5️⃣5 - Post-Exploitation
        • 5.1 Linux Post-Exploitation
        • 5.2 - Linux Privilege Escalation
          • 5.2.1 Kernel Exploitation
          • 5.2.2 SUID Exploitation
          • 5.2.3 CronJobs
        • 5.3 - Post Expolitation / Pivoting
          • 5.3.1 Pivoting Guidelines
          • 5.3.2 Pivoting Example (3 Targets)
      • 6️⃣6 - ​Red Teaming
        • 6.1 - Active Directory Penetration Testing
          • 6.1.1 Introduction to Active Directory (AD)
            • 6.1.1.1 Users, Groups & Computers
            • 6.1.1.2 Organizational Units (OUs)
            • 6.1.1.3 Trees, Forest & Trust
          • 6.1.2 AD Authentication
          • 6.1.3 AD Penetration Testing Methodology
        • 6.1.4 AD Enumeration
        • 6.1.5 AD Privilege Escalation
        • 6.1.6 AD Lateral Movement
        • 6.1.7 AD Persistence
        • 6.2 - Command & Control (C2/C&C)
    • eCPPTv2
      • 1️⃣1 - ​System Security
        • 1.1 Architecture Foundamentals
        • 1.2 Assemblers and Tools
        • 1.3 Buffer Overflow
        • 1.4 Cryptography
        • 1.5 Malware
        • 1.6 Shellcoding
      • 2️⃣2 - Network Security
        • 2.1 System/Host Based Attacks
          • 2.1.1 Windows Vulnerabilities
        • 2.2 Network Based Attacks
        • 2.3 The Metasploit Framework (MSF)
          • MSF Introduction
          • Information Gathering & Enumeration
          • Vulnerability Scanning
          • Client-Side Attacks
          • Post Exploitation
          • Armitage
        • 2.4 Exploitation
        • 2.5 - Post Expolitation / Pivoting
          • 2.5.1 Pivoting Guidelines
          • 2.5.2 Pivoting Example (3 Targets)
        • 2.6 Social Engineering
      • 3️⃣3 - PowerShell for PT
        • 3.1 PowerShell
      • 4️⃣4 - Linux Exploitation
        • 4.1 Linux Vulnerabilities
        • 4.2 Linux Exploitation
        • 4.3 Linux Post-Exploitation
        • 4.4 Linux Privilege Escalation
          • 4.4.1 Kernel Exploitation
          • 4.4.2 SUID Exploitation
          • 4.4.3 CronJobs
      • 5️⃣5 - Web App Security
        • 5.1 - Web App Concepts
          • 5.1.1 HTTP/S Protocol
          • 5.1.2 Encoding
          • 5.1.3 Same Origin
          • 5.1.4 Cookies
          • 5.1.5 Session
          • 5.1.6 Web App Proxies
        • 5.2 - Information Gathering
          • 5.2.1 Gathering Information on Your Targets
          • 5.2.2 Infrastructure
          • 5.2.3 Fingerprinting Frameworks and Applications
          • 5.2.4 Fingerprinting Custom Applications
          • 5.2.5 Enumerating Resources
          • 5.2.6 Information Disclosure Through Misconfiguration
          • 5.2.7 Google Hacking
          • 5.2.8 Shodan HQ
        • 5.3 - Cross Site Scripting
          • 5.3.1 XSS Anatomy
          • 5.3.2 Reflected XSS
          • 5.3.3 Stored XSS
          • 5.3.4 DOM-Based XSS
          • 5.3.5 Identifying & Exploiting XSS with XSSer
        • 5.4 - SQL Injection
          • 5.4.1 Introduction to SQL Injection
          • 5.4.2 Finding SQL Injection
          • 5.4.3 Exploiting In-Band SQL Injection
          • 5.4.4 Exploiting Error-Based SQL Injection
          • 5.4.5 Exploiting Blind SQL Injection
          • 5.4.6 SQLMap
          • 5.4.7 Mitigation Strategies
          • 5.4.8 From SQLi to Server Takeover
        • 5.5 - Other Common Web Attacks
          • 5.5.1 Session Attacks
          • 5.5.2 CSRF
      • 6️⃣6 - ​Wi-Fi Security
        • 6.1 Traffic Analysis
      • 7️⃣7 - ​Metasploit & Ruby
        • 7.1 Metasploit
      • 📄Report
        • How to write a PT Report
  • 🛣️RoadMap & My Experience
  • 📔eCPPT Cheat Sheet
Powered by GitBook
On this page
  • Linux Privilege Escalation
  • Tools
  • LinEnum
  • LinPeas
  • Bashark
  • Linux Exploit Suggester
  • Linux Persistence
  • Dumping & Cracking Hashes
  • ​Pivoting​
  • Clearing Tracks
  • Cheatsheets for Pentesting
  1. eCPPT / PTP - Notes
  2. eCPPTv3
  3. 5 - Post-Exploitation

5.2 - Linux Privilege Escalation

Previous5.1 Linux Post-ExploitationNext5.2.1 Kernel Exploitation

Linux Privilege Escalation

While the web vulnerabilities are typically always the same, when it comes to privilege escalation, it’s hard to make a complete list of all the possible ways in which one can elevate its privileges. It all depends on the specific configuration of the remote machine. Having said that, there are still common attacks that deserve to be studied. Some (not all) of these tehcniques are listed below:

  • PATH exploitation

  • ()

  • ()

  • wildcard expansion

Tools

As we have seen, there are tools that help us in this process:

LinEnum

Privesc vulnerabilities can be identified automatically using the tool.

  • The below labs will focus on manual Linux Privilege Escalation techniques, instead

  • Linux file Permissions are important

🔬 Check

The following command will look for files (and not symlinks etc) which is world writable.

find / -not -type l -perm -o+w
find / -user root -perm -4000 -exec ls -ldb {} \; #or this

if we don't find nothing of anomaly, we can try to find misconfigured sudo. Check the current sudo capabilities.

sudo -l
(root) NOPASSWD: /usr/bin/man #user has root permissions for man app

The man entry depicts that the man command can be run using sudo without providing any password. Run it and launch /bin/bash from it.

sudo man ls
!/bin/bash

After this, escalated to root user is successful.

if file /etc/shadow is world writable, we can read its contents.

ls -l /etc/shadow
cat /etc/shadow

If root password isn't set. We can adding a known password in shadow file, one can escalate to root. Use openssl to generate a password entry.

openssl passwd -1 -salt abc password #setting new psw

LinPeas

Bashark

It's another automatic tool to do identify vulnerabilities in Linux.

Linux Exploit Suggester

Linux Persistence

❗ Persistence techniques and methods usually require administrative access and must follow the rules of engagement agree with the customer.

Persistence Techniques - MITRE ATT&CK

Linux Server SSH service is typically enabled and an attacker can take advantage of it.

  • If password login is disabled and key-based authentication is enabled, the attacker can copy a user's SSH private key and use it for future access.

Linux Cron is a service that repeatedly runs Cron jobs that can be used for command execution at a fixed interval and ensure persistent access to the target system.

Dumping & Cracking Hashes

📝 Check the already covered Credential Dumping theory here:

After the dumping process, hashes can be cracked using:

The best thing to do in privilege escalation optical is migration of lsass process, because at difference between explorer.exe, it permits to upgrade sessions at 64 bit and access to lsass process cache.

After migration to lsass process, we can use utility as hashdump.

It will display a dump list of accounts and their hashes (usually NTLM hashes).

Of course, we can store it a file hashes.txt.

We can also load kiwi module, that's a module implementation of Mimikats for Meterpreter.

Now, using tools how John The Ripper, we can crack NTLM Hashes.

john --list=formats | grep NT
john --format=NT hashes.txt If we don't specify word list, John will use default word list, but we can use custom word list as rockyou.
gzip -d /usr/share/wordlists/rockyou.txt.gz
john --format=NT hashes.txt --wordlist=/usr/share/wordlists/rockyou.txt

​In alternative we can use hashcat.

hashcat --elp
hashcat -a 3 -m 1000 hashes.txt --wordlist /usr/share/wordlists/rockyou.txt #-a 3 (attack-mode brute-force), -m 1000 (NTLM)

When we gaining credentials, we can use psex python script, msf module or RDP (default port 3389) by xfreerdp.

xfreerdp /u:user /p:psw /v:IP

It's a very good method to access and maintaining legitimate persistence.

🗒️ Pivoting is a post exploitation technique of using a compromised host, a foothold / plant, to attack other systems on its private internal network.

  • Once gained access to the first target host, a forwarded port can be used to exploit other hosts on a private network unreachable from the attacker machine.

🗒️ Port Forwarding consists of rerouting/redirecting traffic from a target system's particular port to an attacker system's specific port.

  • The service will be remotely available to the attacker system

Clearing Tracks

According to the rules of engagement, the pentester may be required to clear any changes that have been made to the target systems as a result of the exploitation and post-exploitation stages.A good practice is to store all artifacts payloads, scripts and binaries in these folders:

  • Windows - C:\Temp

  • Linux - /tmp

Metasploit Framework generates and stores a lot of artifacts on the target. Some modules provides removal resource scripts.

Windows

  • Delete the Windows Event Log can be a good post-exploitation clearing technique.

    • ❗ Avoid it during a regular Penetration Test, because data inside the Win Event Log is important to the customer.

Metasploit e.g.cd C:\\mkdir Tempcd Temp# Upload exploit into this C:\Temp directory

  • Use the Cleanup RC File

# Cleanup Meterpreter RC File:cat /root/.msf4/logs/persistence/ATTACKDEFENSE_20230429.0454/ATTACKDEFENSE_20230429.0454.rcbackgroundsessions 1resource /root/.msf4/logs/persistence/ATTACKDEFENSE_20230429.1019/ATTACKDEFENSE_20230429.1019.rc# Clear Windows Event Log from the Meterpreter session# An attacker could potentially do thisclearev

Linux

cd /tmp# Upload exploit into this /tmp directory

  • bash history logs the activity and the used commands

  • To clear the bash history

history -c

  • ~/.bash_history file content can be deleted too

cat /dev/null > ~/.bash_history

  • When using Metasploit Framework exploits, proceed manually to clear artifacts from the /tmp directory or other used directories.

Cheatsheets for Pentesting

​​

​

LinPEAS is a script that search for possible paths to escalate privileges on Linux/Unix*/MacOS hosts. The checks are explained on

In addition to the last tool, help us to suggest potential exploits.

​Of course we need to launch it on victim machine downloading it or transferring there (E.g. using a python )

🔬 Check the ​

​​

​​

​ -

​ -

🔬 Check the ​

​​

🔬 Check the ​

📝
5️⃣
Kernel exploitation
SUID binaries exploitations
https://gtfobins.github.io/
Weak file permissions
cronjob enumeration
https://github.com/DominicBreuker/pspy
sudo -l exploitation
LinEnum
Linux Privesc Labs
Linux Post Exploitation - Metasploit
book.hacktricks.xyz
Linux Exploit Suggester
SimpleHTTPServer
Linux Persistence Labs
Windows Credential Dumping
Linux Credential Dumping
Cracking Hashes Labs here
Pivoting
Pivoting Lab here
Windows Privilege Escalation Cheatsheet
CRTP (Active Directory Notes) Cheatsheet
John The Ripper
Hashcat
PEASS-ng/linPEAS at master · carlospolop/PEASS-ngGitHub
https://github.com/redcode-labs/Bashark/blob/master/bashark.sh
GitHub - The-Z-Labs/linux-exploit-suggester: Linux privilege escalation auditing toolGitHub
linux-exploit-suggester | Kali Linux ToolsKali Linux
Logo
Logo
Logo
Cheatsheet​
Cheatsheet