Ethical › Module 15 › Lesson 1
Why String-Built SQL Breaks
The query becomes attacker-controlled text. Mechanism, not a cheat sheet of unions.
Visual · string_built_sql_break
Concatenating a user string into SQL turns data into syntax. Parameterized queries keep structure and values apart. That split is the fix. Not a UNION cookbook.
Opening
SQL injection is not a magic password. It is a query the app wrote as text, then let a stranger finish the sentence.
Module 14 treated a web app as input, auth, session, and access control under written scope. This module names one failure of that input path: the application builds a database statement by gluing strings together, so a value that should have been a product SKU, a search term, or a username is parsed as SQL grammar. In Cyberlium wording, SQL injection (SQLi) is that grammar break — untrusted text becoming part of the command. The database engine is not “hacked.” It is obedient. It runs the statement it received. This lesson is ORIGINAL Cyberlium teaching mapped to the CEH v13 SQL-injection domain — not official EC-Council training, not a certification, not exam dumps, and completing it does not grant CEH. You will not fire live SQLi at a shop, a classmate’s API, or a random internet form. You will not collect a UNION SELECT cheat sheet. You will not point sqlmap at strangers. Topic 10 (Web Security / OWASP) goes deeper in Cyberlium labs on apps YOU own. Here the skill is the mechanism: concatenating versus parameterized. The parameterized version is the homework. Next lesson is literacy for reading a report (blind vs in-band) — still not exploit steps.
1. The query is a program. Concatenation lets input become syntax
A SQL statement is a tiny program: keywords (SELECT, WHERE), identifiers (table and column names), operators, and literals (the quoted strings and numbers that are data). When an app does sku = request value; sql = "SELECT name FROM catalog_items WHERE sku = '" + sku + "'", it is compiling that program at runtime by pasting bytes from the network into the source. If those bytes stay inside the quoted literal, the engine treats them as a SKU. If those bytes include a quote, a comment marker, or extra clauses, the parser may close the literal early and read the rest as SQL. That is the whole mechanism. No special hat. No cert acronym. A string builder that mixed code and data.
Login forms get the famous stories because a broken WHERE clause can skip a password check. Search boxes, sort parameters, cookie values, JSON fields, and HTTP headers can reach SQL the same way. The channel does not matter. The glue does. Module 1 still owns the permission line: a public website is someone else’s computer. “I was practicing CEH Module 15” is not a defense. Skill does not create consent. This path forbids probing random sites, even with a “harmless” quote in a search box. Recognition of concatenating code you wrote — or a fictional snippet in this course — is in scope. Changing someone else’s query with injected syntax is not.
Command guide
Query is a program — WHAT/WHY (concat lets input become syntax)
═══ INSTALL ═══
Linux (Debian/Ubuntu):
Command — copy this
sudo apt install sqlmap sudo apt install python3
macOS:
Command — copy this
brew install sqlmap brew install python3
Windows:
Command — copy this
pip install sqlmap
Download https://python.org/downloads/
═══ COMMANDS ═══
Command — copy this
python3 - << 'PY'
sku = 'WIDGET' # data only
unsafe_shape = "SELECT name FROM catalog_items WHERE sku = '" + sku + "'"
print('glued_shape', unsafe_shape)
print('problem: if sku were syntax, the parser would read it as SQL')
print('REFUSE: live SQLi, UNION cheat sheet, sqlmap')
PY2. Concatenating versus parameterized: the contrast is the lesson; the placeholder is the homework
A parameterized query (prepared statement) sends the SQL structure with placeholders and sends the values on a separate bind channel. The engine substitutes data into those slots without re-parsing it as keywords. A quote in the SKU stays a quote inside a value. It does not close a string literal in the statement text. That split — structure in the query string, values in the parameter tuple — is THE fix this module exists to install in your hands. Filters, WAFs, and “escape the quotes yourself” are not the fix. Topic 10 will drill prevention on local labs. Lesson 3 names ORM pitfalls and least privilege. Lesson 4 is the rewrite lab. This lesson only needs you to see both shapes side by side and to treat the parameterized shape as what you will write.
The code block below is fictional catalog lookup, not a users table and not a password dump recipe. The unsafe function concatenates. The safe function uses sqlite3 placeholders. Copy the safe shape into your notes in YOUR words. Do not “improve” the unsafe function with extra clauses. Do not point either function at a hosted database you do not own. A local file under cyberlium-lab is the only database this module will ever ask you to touch, and that touch is Lesson 4. If a blog titled with a cert acronym pastes UNION SELECT username, password FROM users as homework, that blog is not this course.
Command guide
Parameterized contrast — WHAT/WHY (placeholder is homework)
═══ INSTALL ═══
Linux (Debian/Ubuntu):
Command — copy this
sudo apt install python3
macOS:
Command — copy this
brew install python3
Windows: Download https://python.org/downloads/
═══ COMMANDS ═══
Command — copy this
python3 - << 'PY'
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE catalog_items(sku TEXT, name TEXT)')
conn.execute('INSERT INTO catalog_items VALUES (?,?)', ('WIDGET','Demo'))
rows = conn.execute('SELECT name FROM catalog_items WHERE sku = ?', ('WIDGET',)).fetchall()
print('safe_rows', rows)
print('homework_shape: SQL with ? plus execute(sql, (value,))')
PY3. Why a quote changes grammar — named, not a payload pack
SQL string literals are delimited. Concatenation puts your delimiter in the same buffer as the caller’s bytes. If the caller supplies a delimiter, the parser’s idea of where the literal ends can move. Everything after that point is syntax: operators, keywords, another clause. Defenders need that sentence so they can read a finding. They do not need a catalog of clause recipes. This course will not paste a UNION SELECT cheat sheet, will not walk boolean-blind character loops, and will not give sqlmap flags aimed at a host. Those are how people turn literacy into unauthorized access and call it a lab. The repair does not depend on which clause arrived. The repair is: stop compiling SQL from untrusted text.
Useful failure: you feel this lesson is “too small” because you did not make a page dump rows. That feeling is how people leave mechanism and enter live SQLi against others. The skill is stopping at the grammar story and at the parameterized contrast. Verbose database errors in a browser are a symptom you may see named in a report (in-band / error-based) — Lesson 2. They are not a reason to trigger errors on a stranger’s site. If you cannot name the host as a system you own or a written RoE target, you do not send it a quote, a comment, or a tool.
4. What you record: mechanism, the safe shape, refuse lines — not a union notebook
A string-SQL note is boring on purpose. Date (UTC). Mechanism in your words: concatenating untrusted input into SQL lets that input become syntax. Contrast: parameterized queries bind values separately. Homework: the placeholder shape (sqlite3 ? plus a tuple) written so you could explain it to a teammate. Ethics: no live SQLi against others; no UNION SELECT cheat sheet; no sqlmap against strangers; Topic 10 goes deeper on authorized local labs. Legal: original Cyberlium teaching mapped to the CEH v13 SQL-injection domain — not official EC-Council training, not a cert, not exam dumps. Path: $HOME/cyberlium-lab/sqli-string-notes.txt, chmod 600. Empty files fail. Files that list target URLs you do not own fail even if you “only planned.” World-readable 777 fails.
Do not paste production connection strings, live passwords, or other people’s query logs into the notes. Do not add a second host because loopback and fiction felt later. Module 14 already said bug bounty is only in play if you actually read that program’s policy; the default for this course is YOUR app or a local demo. This module is stricter on SQLi: Lesson 4 rewrites a fictional snippet against a sqlite file YOU create. It does not authorize a hunt across the internet.
5. Wrong vs right: UNION / sqlmap against strangers vs mechanism plus the parameterized homework
Worked failure — same word “SQL injection,” opposite blast radius. Right never needs a foreign database to prove the grammar story.
Wrong
Paste a UNION SELECT cheat sheet and fire it at a shop, a classmate API, or a random form. Run sqlmap against strangers. Probe production with a quote “just to see.” Save world-readable notes with victim URLs. Call this official EC-Council training. This path is not a cert and does not give you that hunt.
Right
Name concatenation as the mechanism. Treat parameterized queries as THE fix and as this lesson’s homework shape. Lock sqli-string-notes.txt under $HOME/cyberlium-lab, chmod 600. No live SQLi against others. Topic 10 goes deeper in Cyberlium labs. Next: Blind vs In-band as Defender Literacy — report words, not exploit steps.
6. Hands-on: lock sqli-string-notes.txt — mechanism and the placeholder shape
On a computer you own, create cyberlium-lab if needed. Fill the notes in YOUR words. The checker only reads YOUR file. chmod 600. Do not add a foreign URL because the file felt short. Windows without chmod: WSL/Git Bash, or restrict the files in your profile. The code contrast is inspect-and-copy for the safe shape — not a scanner, not sqlmap, not a live foreign DB.
Mission: sqli-string-notes.txt in cyberlium-lab (mode 600)
1) In your own words, define the mechanism (concatenated SQL lets input become syntax) and write the parameterized homework shape (placeholder + bind). 2) Fill $HOME/cyberlium-lab/sqli-string-notes.txt; run the checker; chmod 600. 3) Ethics: parameterized queries are THE fix. No live SQLi against others. No UNION cheat sheet. No sqlmap against strangers. Topic 10 goes deeper. This is not official EC-Council training.
Stuck? Ask Cyberlium AI Mentor
If “CEH Module 15 means I should UNION SELECT a live site so it feels real” still feels true, ask for a hint — not a payload pack. Try: "Hint only: why concatenating SQL lets untrusted text become syntax, why the parameterized sqlite3 ? plus tuple is THE fix and this lesson’s homework, why Topic 10 goes deeper, why sqli-string-notes.txt lives at $HOME/cyberlium-lab chmod 600, and why this is not official EC-Council training?" You still fill the file. No sqlmap. No foreign DB.
You now treat string-built SQL as a program the caller can finish, and you treat parameterized queries as the homework fix — not a UNION notebook, not sqlmap, not a random-site probe. Notes are locked in cyberlium-lab. This is original Cyberlium material covering the same domain as CEH v13 SQL injection, not official training and not an exam dump. Next — Blind vs In-band as Defender Literacy — names what a report means. Topic 10 still goes deeper. You still do not fire SQLi at others.
Knowledge Check
APPLY: A classmate wants to paste a UNION SELECT list into a shop search “because CEH Module 15 is SQL injection.” What is the mechanism, and what do you do?
Multiple choice
Knowledge Check
APPLY: True or False: Because this module maps to a CEH v13 domain, you may run sqlmap against random forms, and “I was practicing” covers it.
True or False
Knowledge Check
APPLY: You are filling sqli-string-notes.txt. Which pairing matches the lesson and hygiene?
Multiple choice
Knowledge Check
APPLY: curl of http://192.168.0.1/ shows a home router login (TP-Link / Netgear / Huawei / "Router Admin"). Is that DEMO in scope as a hacking target?
Multiple choice