Notes - MCS
Analysis and Exploration of Vulnerabilities
Notes - MCS
Analysis and Exploration of Vulnerabilities
  • Analysis and Exploration of Vulnerabilities
  • Vulnerabilities
    • Vulnerabilities
      • CIA Triad
      • Vulnerability Sources
    • Vulnerability Tracking
    • Vulnerability Disclosure
  • Vulnerability Assessment of Networked Systems
    • Vulnerability Research
    • Vulnerability Assessment
    • Penetration Test
      • Scope
    • Types of Assessments
    • Vulnerability Management Life Cycle
  • Enumeration and Information Leakage
    • Network access
    • Information leakage
    • Errors
    • Web Sources and Support Files
    • Cookies
    • Ports
    • Banners
    • OS Fingerprinting
  • Injection
    • CWE-74
    • How it works
    • Common Pitfalls
    • CWE-89 SQL Injection
    • Using SQL
    • Things to consider
    • The NULL plate
    • SQLi types
    • SQL Injection - Avoiding
    • CWE-78 OS Command Injection
    • Command Override
    • Argument Exploitation
    • GTFOBins and LOLBAS
    • Environmental Variables
    • Parameter Expansion
    • Code Injection - CWE-94
    • Avoiding OS Injection
  • Broken Authentication
    • OWASP A2
    • HTTP Basics
    • HTTP Communication
    • Authentication
    • Authentication Flow State
    • Referer Header
    • SESSION ID
    • Cookies (RFC 6265)
    • JWT - JSON Web Tokens
  • XSS Cross Site Scripting
    • Prevalence and Detectability
    • Reflected XSS
    • Stored XSS
    • DOM XSS
    • Cross Site Request Forgery
    • Avoiding XSS
    • Same Origin Policy
  • Concurrency
    • Concurrency
    • CWE-361 - 7PK - Time and State
    • Basic Time Related CWEs
      • CWE-362 – Race Condition
    • Serializability
    • Database ACID characteristic
    • State Related CWEs
    • Basic Side Effects Related CWEs (Covert Channel)
    • Covert Timing Channel
    • Meltdown Type
  • Buffers
    • Buffer Overflow
    • Popularity decline
    • Potentially Vulnerable Software
    • Dominant prevalence
    • Vulnerabilities in languages (mostly C/C++)
    • Why? Memory Structure 101
    • CWE-120 Classic Overflow
      • Practical Examples
    • Stack Based Vulnerabilities
    • Stack Smashing
    • Countermeasures
    • ROP
Powered by GitBook
On this page
  • Examples
  • CVE-2014-6271 - Shellshock
  1. Injection

Environmental Variables

Command execution is affected by environmental variables.

  • They are not present in the command line executed, just exist in the current context.

In other words: commands process environmental variables.

  • Controlling environmental variables may provide control over a program.

Examples

The PATH variable contains a list of folders, which are searched when a command is issued.

If PATH=“/bin;/sbin;/usr/bin;/usr/sbin”, system(“ls”) will lead to bash searching for ls in those folders.

If an attacker controls PATH it may make an application call a different binary.

host:/sec$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
host:/sec$ ls -al
drwxr-xr-x 1 user user   4096 Nov 5 23:36 .
drwxrwxrwt 1 root root   4096 Nov 5 23:39 ..
-rwxr-xr-x 1 user user 455584 Nov 5 23:36 ls
host:/sec$ export PATH=/sec
host:/sec$ ls -la
Evil code here!

CVE-2014-6271 - Shellshock

Summary: Bash executes code present after the declaration of a function placed on an environmental variable

env ‘FUNCTION()=() { :; } echo “Bad code” ’

Will result in executing echo “Bad code”.

  • Issues seems to be innocuous as an attacker that calls env could call other command directly.

But... Some servers create env variables based on user content.

CGI: Common Gateway Interface.

  • Simple way of executing scripts that interact with clients through a web server

Operation:

  1. Server receives a request.

  2. Server creates environmental variables with the request content.

    1. URL parameters

    2. REQUEST body

    3. ALL HTTP HEADERS!

  3. Server executes the script.

    1. If script uses bash at any point (e.g. Perl script that uses system), environmental variables may be executed.

  4. Server returns the output to the client as the HTTP Response Body.

    1. There are ways of returning headers also.

User-Agent: () { :;}; echo "passwd: " $(</etc/passwd)

The User-Agent HTTP Header is converted into a ENV Variable.

Bash will execute the echo command with the content of the /etc/passwd file.

  • Output will be sent to clients as the response body.

Last updated 1 year ago