Courseiva
312-50Chapter 12 of 18Objective 7.2

Hacking Web Applications

Hacking web applications: the art of finding and exploiting weaknesses in websites and web-based software. For a Certified Ethical Hacker candidate, understanding these flaws is critical because web applications are the most common attack surface in modern networks — and the 312-50 exam devotes a heavy portion of questions to testing your ability to identify them.

12 min read
Advanced
Updated Jul 23, 2026
Editorial oversight: Johnson Ajibi· Security Systems Architect · MSc IT Security · IEEE Senior Member

A simple way to picture Hacking Web Applications

The BBQ Restaurant Order Mix-Up Analogy

Ever been to a BBQ restaurant where you order 'brisket with coleslaw and a side of pickles' from a waiter, but the kitchen sends out pork ribs with baked beans?

That’s what happens when a web application doesn’t properly check who’s asking for what. In a web app, every request is like an order form. The waiter (the server) takes your order from the menu (the website’s forms and buttons) and gives it to the kitchen (the database). Now, imagine a sneaky customer — a hacker — scribbling a secret instruction in the ‘special instructions’ box, like ‘add extra salt to the kitchen salt shaker.’ The waiter reads it, passes it along, and the kitchen follows the instruction because it never stops to ask ‘Who wrote this? Is this part of the order or a command to us?’

In web app hacking, the ‘extra salt’ is malicious code, like a SQL injection or a cross-site scripting (XSS) payload. The application treats the hacker’s input as if it were a legitimate part of the order, so the database or browser executes it. A real-world security fix would be like a chef checking every note to see if it’s a valid item on the menu — input validation and parameterised queries. If the kitchen says ‘We only cook menu items, not instructions to the cook,’ the mix-up never happens.

How It Actually Works

Web applications are programs that run inside a web browser — like your online banking portal, a social media feed, or an e-commerce store. They work by sending data from your browser (called the client) to a server, where the server processes the request and fetches or stores information in a database. The three main parts are the client (your browser), the server (the computer doing the thinking), and the database (the filing cabinet of data).

Attackers target the points where the client talks to the server, and where the server talks to the database. If the application trusts user input without verifying it, an attacker can trick it into doing things the developer never intended.

SQL Injection (SQLi) SQL stands for Structured Query Language — it’s the language used to talk to databases. A SQL injection happens when an attacker inserts malicious SQL commands into an input field (like a username box or search bar). If the application builds its database query by simply pasting the user’s input directly into the query string, the attacker can close the intended command and add their own. For example, a login form might check for a matching username and password with a query like: SELECT * FROM users WHERE username = 'admin' AND password = 'pass'. If an attacker types ' OR 1=1 -- into the password field, the query becomes: SELECT * FROM users WHERE username = 'admin' AND password = '' OR 1=1 —. The double-dash (--) comments out the rest, and 1=1 is always true, so the attacker gains access without a valid password.

Cross-Site Scripting (XSS) XSS is about injecting scripts (usually JavaScript) into a web page that other users will see. This happens when an application takes user input and displays it back without sanitising it. For instance, a comment box on a blog that lets you write '<script>alert('xss')</script>' — if the site shows your comment raw, every visitor’s browser will run that script. There are three types: stored XSS (the script is saved permanently on the server, like in a comment), reflected XSS (the script is reflected back in the immediate response, like a search result page), and DOM-based XSS (the vulnerability exists in the client-side JavaScript code itself). Attackers use XSS to steal cookies (which hold session IDs), redirect users to fake login pages, or deface websites.

Cross-Site Request Forgery (CSRF, pronounced ‘sea-surf’) CSRF tricks an authenticated user into performing actions they didn’t intend. Imagine you’re logged into your bank website. An attacker sends you a link (maybe in a forum or email) to a page with a hidden image tag that makes a request to your bank’s transfer money API. Because your browser holds a valid session cookie for the bank, the bank believes the request came from you. The result: money transferred to the attacker’s account without your knowledge. CSRF attacks exploit the fact that web applications often rely solely on cookies to authenticate requests, and the browser automatically attaches cookies to every request to that domain. The common defence is to include a unique, unpredictable token in each form (called a CSRF token) so the server can verify the request came from your browser, not a third-party page.

Authentication Flaws Authentication flaws are weaknesses in the process of verifying who a user is. This includes poor password policies (like allowing ‘password123’), weak session management (like using predictable session IDs), insecure password recovery flows (where the answer to a security question is easily guessed), and failure to implement multi-factor authentication (MFA). Attackers exploit these by brute-forcing passwords, capturing session tokens through network sniffing or XSS, or simply guessing weak credentials. The exam often tests your ability to pick out which scenario describes a broken authentication mechanism versus a CSRF or XSS attack.

Why do these vulnerabilities exist? Often because developers prioritise speed over security, don’t validate inputs, or rely on outdated coding practices. The OWASP Top 10 is a published list of the most critical web application security risks, published by the Open Web Application Security Project — it’s essential reading for CEH candidates, as the exam references it directly.

Each of these attacks can be prevented by specific countermeasures: parameterised queries (for SQLi), output encoding (for XSS), anti-CSRF tokens, and strong authentication mechanisms like MFA and secure session handling. As an ethical hacker, you need to test for each of these flaws using both automated scanners and manual techniques, then report them so they can be fixed.

This diagram shows how attackers inject SQLi into the server, XSS into the client, and CSRF through the client's own requests.

Walk-Through

1

Reconnaissance and Mapping

Identify all input points in the web application: forms, URL parameters, headers, cookies, and API endpoints. Use a browser developer tools or a proxy like Burp Suite to capture every request the application makes.

2

Automated Vulnerability Scanning

Run a web vulnerability scanner such as OWASP ZAP or Nikto to automatically send attack payloads and flag potential vulnerabilities like SQL injection, XSS, and CSRF.

3

Manual SQL Injection Testing

Confirm SQLi by injecting single quotes, logical operators (like 'OR 1=1'), and time-delay commands. Use error messages or timing differences to determine if the database is responding to injected commands.

4

Cross-Site Scripting Verification

Insert a harmless script payload like '<script>alert(1)</script>' into input fields. Check if the script executes in the browser when the page is loaded — this confirms an XSS vulnerability and informs whether it is stored or reflected.

5

CSRF and Authentication Testing

Create a proof-of-concept HTML page that automatically submits a request to a state-changing endpoint (like a password change). If the action executes without a token, CSRF is confirmed. For authentication, attempt brute-force logins with common passwords and analyse the password reset workflow for weaknesses.

What This Looks Like on the Job

An IT security professional, often called a penetration tester or ethical hacker, systematically tests web applications for these vulnerabilities. Here’s a concrete scenario:

You’re hired by ‘BookStore Online’, a company that sells books through a web application. Your job: find vulnerabilities before a real attacker does.

Step 1: Reconnaissance. You start by mapping out the application — you visit every page, fill out every form, and note every place where the application accepts user input: search bars, login fields, feedback forms, profile update pages, and the ‘forgot password’ flow.

Step 2: Automated scanning. You run a web vulnerability scanner (like OWASP ZAP or Burp Suite) that sends thousands of attack payloads to each input point. The scanner flags a potential SQL injection on the product search page — when you enter a single quote ('), the application returns a database error message. That error tells you the application is vulnerable.

Step 3: Manual exploitation. You confirm the SQLi by entering a payload that causes a time delay (like 'waitfor delay '0:0:5' -- on SQL Server). The site slows down by exactly five seconds — confirmed. You now extract data from the database, starting with a simple statement to list the current database name and then enumerate tables. Within an hour, you find a table called ‘users’ containing admin credentials stored in plain text.

Step 4: XSS discovery. While testing the feedback form, you submit '<script>alert('xss')</script>’. When you visit the page that displays feedback (as an admin would), a pop-up appears with ‘xss’. This is a stored XSS vulnerability — an attacker could send a payload that steals the admin’s session cookie and redirect it to an attacker-controlled server.

Step 5: CSRF test. You identify the ‘change email address’ endpoint. You create a simple HTML page with a form that automatically submits to that endpoint. You load the page in a browser where you’re still logged in as a test user — the email changes without any user interaction. You report this as a CSRF flaw.

Step 6: Authentication analysis. You brute-force the login page using a wordlist of common passwords and find that three accounts have the password ‘123456’. The password reset flow emails a reset link to the registered email, but it doesn’t invalidate old sessions — an attacker who gains access to a user’s email inbox can reset the password and hijack the account.

By the end of the engagement, you produce a report listing each vulnerability, its severity, step-by-step reproduction steps, and recommended fixes. The developer team then patches the SQL injection by using parameterised queries, sanitises output to fix XSS, adds CSRF tokens to every state-changing form, and enforces a strict password policy. The professional’s role is to think like an attacker — anticipate every trick — to protect the business from real-world breaches.

How 312-50 Actually Tests This

The 312-50 exam tests your ability to identify, classify, and understand the mechanics of web application attacks. Here’s exactly what you need to know:

SQL Injection tactics: You must be able to recognise the difference between error-based, union-based, blind SQLi, and time-based blind SQLi. Exam questions often present a short scenario (e.g., “A tester uses ‘AND 1=1’ and ‘AND 1=2’ — what type of SQLi?”) and you need to pick the correct type. The classic trap: confusing blind SQLi with union-based SQLi. Remember: blind SQLi doesn’t show data, but you infer it from true/false responses; union-based SQLi displays data in the response.

XSS variants: You will be asked to differentiate stored, reflected, and DOM-based XSS. A common exam trick is to describe a vulnerability that appears to be reflected but is actually caused by client-side JavaScript — that’s DOM-based. Memorise the key phrase: server-side vs client-side. Stored and reflected are server-side; DOM-based is client-side.

CSRF mechanism: The exam loves asking how CSRF differs from XSS. XSS exploits the trust a user has in a website (the site runs the attacker’s script), while CSRF exploits the trust a website has in the user’s browser (the site processes the request automatically). Questions may give you a scenario where a user clicks a link and an action occurs — you need to know that’s CSRF if no script executes on the target site.

Authentication flaws: Pay special attention to session management. Traps include: a session ID that doesn’t expire, predictable session IDs (like sequential numbers), and passwords stored in plaintext. The exam expects you to identify these as broken authentication.

OWASP Top 10: Many questions reference the OWASP Top 10 list (e.g., “Which OWASP category does this vulnerability belong to?”). The 2021 version includes ‘Broken Access Control’, ‘Cryptographic Failures’, ‘Injection’, ‘Insecure Design’, ‘Security Misconfiguration’, ‘Vulnerable and Outdated Components’, ‘Identification and Authentication Failures’, ‘Software and Data Integrity Failures’, ‘Security Logging and Monitoring Failures’, and ‘Server-Side Request Forgery’. Know which of these maps to SQLi (Injection), XSS (Injection), and broken auth (Identification and Authentication Failures).

Correct answer pattern: When a question describes a web application attack, first identify the type of vulnerability (SQLi, XSS, CSRF, or authentication flaw). Then match it to the correct defence: parameterised queries for SQLi, input validation/output encoding for XSS, anti-CSRF tokens for CSRF, and multi-factor authentication for auth flaws. The exam almost always asks: “Which of the following is the most effective countermeasure?” Choose the defence that directly prevents the attack, not a general best practice like ‘encrypt all traffic’ (which helps but is not a direct fix).

Key Takeaways

SQL injection tricks the database into executing unintended commands by injecting malicious SQL through user input fields.

Cross-site scripting (XSS) lets an attacker execute scripts in a victim’s browser by reflecting or storing untrusted input without sanitisation.

Cross-site request forgery (CSRF) forces an authenticated user to perform unintended actions by sending requests from a third-party site.

Broken authentication includes weak passwords, predictable session IDs, and insecure password recovery mechanisms that attackers can exploit.

Parameterised queries prevent SQL injection by separating SQL code from user input, making it impossible to alter the query structure.

Output encoding and input validation are primary defences against XSS, ensuring that user input is treated as data, not executable code.

Anti-CSRF tokens embedded in forms verify that requests originate from the legitimate application, not malicious third-party sites.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

SQL Injection (SQLi)

Targets the database by injecting SQL commands

Exploits server-side input validation gaps

Uses characters like quotes, dashes, and semicolons

Cross-Site Scripting (XSS)

Targets the user's browser by injecting scripts

Exploits client-side output rendering

Uses angle brackets and script tags

Stored XSS

Malicious script is saved permanently on the server

Affects every user who visits the infected page

Example: a comment with a script that runs for all viewers

Reflected XSS

Script is reflected back in the immediate server response

Affects only the user who clicks the crafted link

Example: a search results page that echoes the search term

Cross-Site Request Forgery (CSRF)

Does not require a script to run on the target site

Exploits the trust the server has in the user's browser

Prevented by adding anti-CSRF tokens

Cross-Site Scripting (XSS)

Requires a script to execute in the user's browser

Exploits the trust the user has in the target site

Prevented by input validation and output encoding

Broken Authentication

Weak password policies or flawed login logic

Attackers can brute-force passwords or guess reset answers

Countermeasure: enforce strong passwords and MFA

Session Hijacking

Stealing an existing valid session ID

Attackers can use network sniffing or XSS to capture cookies

Countermeasure: use secure cookie flags and short session lifetimes

Watch Out for These

Mistake

SQL injection only works if the database returns an error message.

Correct

Blind SQL injection works even when no errors are displayed — the attacker infers data from true/false responses or time delays.

Many beginners think visible error messages are necessary, but the CEH exam tests blind SQLi techniques heavily.

Mistake

Cross-site scripting (XSS) and cross-site request forgery (CSRF) are the same thing because both involve injecting something.

Correct

XSS runs scripts in the victim’s browser; CSRF tricks the browser into sending authenticated requests without running scripts on the target site.

The terms sound similar and both involve a victim’s browser, so students lump them together. The exam tests the difference directly.

Mistake

If a site uses HTTPS, it is immune to web application attacks like SQL injection and XSS.

Correct

HTTPS only encrypts data in transit; it does not protect against input validation flaws or injection attacks on the server side.

People associate HTTPS with ‘security’ and incorrectly assume it covers all vulnerabilities.

Mistake

DOM-based XSS is exactly the same as reflected XSS.

Correct

Reflected XSS is processed on the server side, while DOM-based XSS occurs entirely in the client-side JavaScript without involving the server’s response.

Both appear in the browser’s URL, leading beginners to conflate them. The exam includes questions that hinge on this distinction.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between SQL injection and cross-site scripting?

SQL injection targets the database by injecting commands into SQL queries, while cross-site scripting (XSS) targets users by injecting scripts into web pages that execute in their browsers.

Can a firewall stop web application attacks like XSS?

A web application firewall (WAF) can filter some malicious payloads, but it is not foolproof — attackers can bypass WAF rules with encoding or obfuscation. The best defence is secure coding practices like input validation and output encoding.

What is a CSRF token and why do I need it?

A CSRF token is a unique, unpredictable value embedded in every form on a website. The server checks it when processing state-changing requests to ensure the request came from the real site, not a third-party page — preventing cross-site request forgery.

Is stored XSS more dangerous than reflected XSS?

Yes, because stored XSS saves the malicious script on the server (e.g., in a comment) and infects every user who visits that page, while reflected XSS only affects the single user who clicks a crafted link.

How do I test for SQL injection without causing damage?

Use a testing environment or a non-production copy of the application. Start with a benign payload like a single quote (') to see if an error appears, then use a time-based payload like 'waitfor delay' to confirm, all in a safe, controlled setting.

What is blind SQL injection?

Blind SQL injection occurs when an attacker cannot see database errors or data directly but can still extract information by asking the database true/false questions and observing the application’s response (e.g., different page content or timing delays).

Terms Worth Knowing

Keep going

You've finished Hacking Web Applications. Continue through the 312-50 study guide to build a complete picture of the exam.

Done with this chapter?