- Zero-Day Wire
- Posts
- Break the Web (Week 4): SQL & Command Injection
Break the Web (Week 4): SQL & Command Injection
SQL & Command Injection Exploitation: Step-by-Step Tutorial with SQLmap, Burp Suite & Payload Testing
π― Week 4: Injection (SQL & Command)
Break the Web: Part 4 of 8
Welcome back to Offensive Tuesday.
Hey π
Last week you broke access control. You changed IDs in URLs, accessed other users' data, and escalated to admin. If you missed it, catch up here π week 1, week 2, week 3
This week? We're injecting malicious code into applications.
Here's the brutal truth β your input is code. Every form field, every URL parameter, every search box is a potential command line.
If the app doesn't validate what you type? You're not just a user anymore. You're executing commands on their server.
You type '; DROP TABLE users;-- into a login form. Their database gets wiped.
You enter ; ls -la into a search box. You're browsing their server files.
This is SQL Injection and Command Injection β the attacks that have compromised millions of systems and leaked billions of records.
Today you're learning how to weaponize input fields.
Let's inject some chaos. π
πͺ§Want your brand on a billboard? This is how to do it in less than 48 hours . . .
Run ads IRL with AdQuick
With AdQuick, you can now easily plan, deploy and measure campaigns just as easily as digital ads, making them a no-brainer to add to your teamβs toolbox.
You can learn more at www.AdQuick.com
π§ What is Injection?
Injection happens when untrusted data gets interpreted as code.
Think about it:
You fill out a form
The app takes your input
Puts it directly into a database query or system command
Executes it without checking
You just hijacked their execution flow.
Two main types we're covering today:
SQL Injection β Injecting database commands
Command Injection β Injecting operating system commands
Both follow the same principle: break out of the data context and execute code.
π SQL Injection Explained
SQL Injection lets you talk directly to the database by manipulating queries.
Normal query behind a login form:
SELECT * FROM users WHERE username='john' AND password='pass123'
The app expects you to type a username and password. But what if you type something the developer didn't expect?
What you enter:
admin' OR '1'='1
What the query becomes:
SELECT * FROM users WHERE username='admin' OR '1'='1' AND password='...'
Result: '1'='1' is always true. You just bypassed authentication.
That's SQL injection in 30 seconds.
π§ The SQL Injection Attack Process
Step 1: Find Injectable Parameters
Look for anywhere the app accepts input:
Login forms (username, password)
Search boxes
Contact forms
URL parameters (
?id=5,?search=laptop)Cookies
HTTP headers
Your job: Find where user input touches a database.
Step 2: Test for Vulnerabilities
Drop these payloads into input fields:
Single quote test:
'If you see a database error (like "SQL syntax error"), it's vulnerable.
OR-based test:
' OR '1'='1Time-based test (if errors are hidden):
' OR SLEEP(5)--If the page takes 5 seconds to load, the database executed your command.
Pro tip: Start simple. One character at a time. If ' breaks the page, you're in business.
Step 3: Understand the Injection Types
Error-Based SQLi β Database errors leak information
Union-Based SQLi β Combine your query with the original using UNION
Blind SQLi β No errors shown, but you can still extract data using true/false questions
Time-Based Blind SQLi β Use delays to confirm queries worked
You don't need to memorize these. Tools will handle it. But understanding helps you recognize what's happening.
Step 4: Extract Data
Once you confirm injection works, you can:
Find database names:
' UNION SELECT schema_name FROM information_schema.schemata--Find table names:
' UNION SELECT table_name FROM information_schema.tables--Find column names:
' UNION SELECT column_name FROM information_schema.columns WHERE table_name='users'--Dump data:
' UNION SELECT username, password FROM users--But honestly? You'll use tools for this. Manual extraction takes forever.
Step 5: Automate with SQLmap
SQLmap is the industry standard. It automates everything.
Basic test:
sqlmap -u "http://target.com/page?id=1"Dump entire database:
sqlmap -u "http://target.com/page?id=1" --dumpThat's it. SQLmap handles detection, exploitation, and data extraction automatically.
β‘ Command Injection Explained
Command injection lets you execute operating system commands on the server.
Normal behavior:
App takes your input (like an IP address) and runs:
ping 192.168.1.1What you enter:
192.168.1.1; ls -laWhat gets executed:
ping 192.168.1.1; ls -laThe semicolon ends the first command. Your command runs next.
Result: You just listed their server files.
π§ The Command Injection Attack Process
Step 1: Find Command Execution Points
Look for features that might execute system commands:
Ping tools
DNS lookup tools
File converters
Image processors
System diagnostics
Anything that interacts with the OS
Step 2: Test for Command Injection
Use command separators to chain commands:
Linux/Unix:
;β Execute next command&&β Execute if first succeeds||β Execute if first fails|β Pipe outputcommandβ Command substitution$(command)β Command substitution
Windows:
&β Chain commands&&β Execute if first succeeds|β Pipe output||β Execute if first fails
Test payload:
127.0.0.1; whoamiIf you see a username in the response, you're executing commands.
Step 3: Common Injection Patterns
Basic chaining:
; ls
; cat /etc/passwd
; whoamiTime-based confirmation:
; sleep 10
; ping -c 10 127.0.0.1If the page delays, injection works even if you don't see output.
Output redirection:
; ls > /var/www/html/output.txt Then visit http://target.com/output.txt to see results.
Step 4: Escalate Access
Once you confirm command injection:
Reverse shell β Get interactive access to their server
Download tools β Pull exploitation frameworks
Establish persistence β Create backdoors
Pivot internally β Attack other systems on their network
But we're not covering that depth here. This is about finding the vulnerability, not post-exploitation (that's a whole other series).
π‘οΈ Why These Work
Both attacks exploit the same flaw: mixing data with code.
The app treats your input as trusted data, but you're writing code. No separation = game over.
Developers forget:
Input can contain special characters
Strings can break out of quotes
Users are adversaries, not friends
Your advantage: apps that trust user input are everywhere.
π οΈ Tool List
SQL Injection:
SQLmap β The king of automated SQLi β Download here
Burp Suite β Manual testing with Repeater β Download here
NoSQLMap β For NoSQL injection β Download here
Command Injection:
Commix β Automated command injection tool β Download here
Burp Suite β Manual testing
OWASP ZAP β Free alternative to Burp β Download here
Wordlists & Payloads:
PayloadsAllTheThings β Massive injection cheat sheet β Get it here
SecLists β Fuzzing wordlists β Download here
Learning Labs:
PortSwigger SQL Injection Labs β Free hands-on practice β Start here
HackTheBox β Real vulnerable machines β Join here
TryHackMe SQL Injection Room β Guided learning β Try it
π Learning Resources
Deep Dives:
OWASP Injection Guide β Complete reference β Read here
PortSwigger SQL Injection Cheat Sheet β All payloads in one place β Get it
PentesterLab SQL Injection Exercises β Hands-on training β Start here
Bug Bounty Reports:
HackerOne SQL Injection Reports β Real-world examples β Browse reports
Bugcrowd Command Injection Write-ups β Learn from hunters β Read write-ups
Books:
The Web Application Hacker's Handbook β Chapter 9 covers injection in depth
SQL Injection Attacks and Defense by Justin Clarke β The bible
π― What to Practice This Week
Set up a lab environment β Use DVWA (Damn Vulnerable Web App) or PortSwigger's free labs
Test SQL injection manually β Try bypassing a login with
' OR '1'='1Run SQLmap β Automate an attack on a practice target
Find command injection β Test a ping tool with
; whoamiRead real bug bounty reports β See how pros find and exploit injection
Don't attack real systems without permission. That's illegal. Use practice labs.
That's Week 4. π
Tomorrow (Wednesday): How to defend against injection attacks and write secure code.
Next Tuesday: Cross-Site Scripting (XSS) β we're injecting JavaScript into browsers and hijacking sessions.
See you then.
Your Feedback MattersDid You Enjoy This Weekβs Offensive Tutorial? |
β Zwire βοΈ
P.S. Got questions? Reply to this email. I read everything.


Reply