• 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

In partnership with

🎯 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'='1

Time-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" --dump

That'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.1

What you enter:

192.168.1.1; ls -la

What gets executed:

ping 192.168.1.1; ls -la

The 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 output

  • command β€” Command substitution

  • $(command) β€” Command substitution

Windows:

  • & β€” Chain commands

  • && β€” Execute if first succeeds

  • | β€” Pipe output

  • || β€” Execute if first fails

Test payload:

127.0.0.1; whoami

If you see a username in the response, you're executing commands.

Step 3: Common Injection Patterns

Basic chaining:

; ls
; cat /etc/passwd
; whoami

Time-based confirmation:

; sleep 10
; ping -c 10 127.0.0.1

If 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:

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

  1. Set up a lab environment β€” Use DVWA (Damn Vulnerable Web App) or PortSwigger's free labs

  2. Test SQL injection manually β€” Try bypassing a login with ' OR '1'='1

  3. Run SQLmap β€” Automate an attack on a practice target

  4. Find command injection β€” Test a ping tool with ; whoami

  5. Read 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 Matters

Did You Enjoy This Week’s Offensive Tutorial?

Login or Subscribe to participate in polls.

β€” Zwire ✌️

P.S. Got questions? Reply to this email. I read everything.

Reply

or to participate.