📝
Home
Pentesting
  • 📝Home
  • ⚒️PENTESTING
    • Foundational
      • Gaining Access
      • Session Hijacking
      • Buffer Overflows
        • Finding the Offset
        • Spiking
        • Fuzzing
      • Attack Basics
        • Brute Force Attacks
        • Credential Stuffing and Password Spraying
        • Netcat Shell Stabilization
        • Reverse Shells vs Bind Shells
        • Staged vs Non-Staged Payloads
      • Footprinting
    • Reconnaissance
      • Discovering Email Addresses
      • Hunting Subdomains
    • Scanning and Enumeration
      • Banner Grabbing
      • Enumerating HTTP and HTTPS
      • Enumerating SMB
      • Enumerating SSH
      • NetBIOS Enumeration
      • SNMP Enumeration
      • Sniffing
    • Privilege Escalation
      • 🐧Linux Privilege Escalation
      • 🪟Windows Privilege Escalation
        • Initial Enumeration
    • Defense Evasion
      • Hiding Files and Covering Tracks
      • Network Evasion
    • Attacking Services
      • Attacking Kerberos
      • Attacking VPNs
      • Denial of Service
      • Exploiting FTP
      • Exploiting NFS
      • Exploiting SMTP
      • Exploiting Telnet
    • Attacking Active Directory
      • Initial Attack Vectors
        • Gaining Shell Access
        • LLMNR Poisoning
        • SMB Relay
        • Passback Attacks
        • IPv6 Attacks
      • Post-Compromise Enumeration
        • Bloodhound
        • ldapdomaindump
        • PowerView
        • PlumHound
      • Post-Compromise Attacks
        • GPP Attacks
        • Print Nightmare
        • Token Impersonation using Incognito
        • URL File Attack
        • Pass Attacks
        • Kerberoasting
        • LNK File Attacks
        • Mimikatz
      • Post-Domain Compromise Attacks
        • Dumping the NTDS.dit
        • Golden Ticket Attacks
      • Post Exploitation
    • Toolkit
      • Burp Suite
        • Intruder
      • Hping
        • Crafting TCP and UDP Packets
      • Metasploit
        • Meterpreter
        • Shell Handler
        • Gather Information
        • Gaining Root
    • Web Application Hacking
      • Attack Methodology
      • Attacking Web Applications
      • Authentication Bypass
      • Cross-Site Scripting
      • Cross-Site Request Forgery
      • File Inclusion
      • Server-Side Request Forgery
      • Injection
        • Command Injection
        • LDAP Injection
        • SQL Injection
  • 👽MALWARE ANALYSIS
    • Malware Analysis Primer
    • Malware Types
      • Rootkits
      • Viruses
      • WannaCry
    • Analyzing Malicious Windows Programs
    • Static Analysis
      • Basic Static Techniques
      • Advanced Static Analysis
    • Reverse Engineering
      • Crash Course in x86 Disassembly
      • Recognizing Code in Assembly Language
    • Dynamic Analysis
    • Detecting Malware
      • Evasion Techniques
      • Detecting Mimikatz
      • Hunting Malware
      • Hunting Metasploit
      • Hunting Persistence
  • 🏹THREAT HUNTING
    • Foundational
      • ATT&CK Framework
      • CIA Triad
    • APTs
  • 🐍PROGRAMMING & SCRIPTING
    • Foundational
      • Computer Memory
    • C Programming
    • Assembly Language
      • Assembly File Structure
      • Debugging with gdb
    • Bash
    • Python
      • Foundational
        • Booleans and Operators
        • Comprehensions
        • Conditionals
        • Dictionaries
        • Exceptions and Error Handling
        • Functions
        • Lambdas
        • Lists
        • Loops
        • Modules
        • Numbers
        • Reading and Writing Files
        • Sets
        • Sockets
        • String Formatting
        • Tuples
        • User Input
        • Variables
      • Extending Python
        • Virtual Environments
        • Sys Module
        • Requests
        • pwntools
    • Regular Expressions
    • SQL
  • 🕵️DIGITAL FORENSICS
    • Anti-Forensic Techniques
    • 🪟Windows Security Internals
      • Windows Security Internals
        • Kernel
          • Security Reference Monitor (SRM)
          • Object Manager
            • System Calls
            • NTSTATUS Codes
            • Object Handles
            • Query and Set Information System Calls
          • The I/O Manager & The Process and Thread Manager
          • The Memory Manager
          • The Configuration Manager
  • 💼GRC (CISSP Notes)
    • Security Assessment and Testing
    • Security Governance Principles
    • Security Policies Standards and Procedures
    • Preventing and Responding to Incidents
    • Organizational Roles and Responsibilities
    • Organizational Processes
  • 📦Networking
    • Foundational
      • DHCP
      • DNS Basics
      • HTTP Protocol
      • IPSec
      • IPv6 Fundamentals
    • Wireless Technologies
      • 802.11
      • Bluetooth
      • Wireless Authentication
      • Wireless Encryption
Powered by GitBook
On this page
  • What is Command Injection?
  • Discovering Command Injection
  • Exploiting Command Injection
  • Useful Payloads
  • Remediating Command Injection
  1. PENTESTING
  2. Web Application Hacking
  3. Injection

Command Injection

What is Command Injection?

  • The abuse of an application's behavior to execute commands on the operating system, using the same privileges that the application on a device is running with

  • Also known as a "Remote Code Execution (RCE)" because an attacker can trick the application into executing a series of payloads that they provide, without direct access to the machine itself

  • Webserver will process this code and execute it under the privileges and access controls of the user who is running the application

Discovering Command Injection

  • The vulnerability exists because applications often use functions in programming languages use functions to pass data to and to make system calls on the OS

Exploiting Command Injection

  • Applications that use user input to populate system commands with data can often be combined in unintended behavior

  • Can be detected in one of two ways:

  1. Blind command injection

  • This type of injection is where there is no direct output from the application when testing payloads.

  • You will have to investigate the behaviors of this application to determine whether or not your payload was successful.

  • Another method of detecting blind command injection is by forcing some output.

  • This can be done by using redirection operators such as >

  1. Verbose command injection

  • The direct feedback from the application once you have tested a payload.

  • The web application will output the username on the page directly.

Useful Payloads

Linux

Payload

Description

whoami

See what user the application is running under.

ls

List the contents of the current directory. You may be able to find files such as configuration files, environment files (tokens and application keys), and many more valuable things.

ping

This command will invoke the application to hang. This will be useful in testing an application for blind command injection.

sleep

This is another useful payload in testing an application for blind command injection, where the machine does not have ping installed.

nc

Netcat can be used to spawn reverse shell onto the vulnerable application. You can use this foothold to navigate around the target machine for other services, files, or potential means of escalating privileges.

Windows

Payload

Description

whoami

See what user the application is running under.

dir

List the contents of the current directory. You may find files such as configuration files, environment files (tokens and application keys), and many more valuable things.

ping

This command will invoke the application to hang. This will be useful in testing an application for blind command injection.

timeout

This command will also invoke the application to hang. Useful for testing an application for blind command injection if the ping command is not installed.

Remediating Command Injection

  • Vulnerable Functions

    • Attempt minimal use of potentially dangerous functions or libraries that interact with the operating system to execute commands via shell, these include:

      • Exec

      • Passthru

      • System

    • Any application that uses these functions without proper checks will be vulnerable to command injection.

  • Input sanitization

    • Sanitizing input from a user that an application uses is a great way to prevent command injection

    • This is a process of specifying the formats or types of data that a user can submit

  • Bypassing Filters

    • Applications employ filtering and sanitizing data that is taken from a user's input.

    • Filters will restrict you to specific payloads; however, we can abuse the logic behind an application to bypass these filters

PreviousInjectionNextLDAP Injection

Last updated 1 year ago

⚒️