SQL Injection – UNION attack, retrieving data from other tables | PortSwigger Lab Note #4

Published: (March 9, 2026 at 09:20 AM EDT)
1 min read
Source: Dev.to

Source: Dev.to

Target

Tools Used

  • Browser
  • Burp Suite

Vulnerability Summary

  • Type: SQL Injection
  • Description:
    To solve the lab, perform a SQL injection UNION attack that retrieves all usernames and passwords, and use the information to log in as the administrator user.

Steps to Exploit

  1. Using the technique mentioned in the previous note, determine the number of columns returned by the query and which columns contain text data. Verify that the query returns two columns, both of which contain text.

    Column enumeration result

  2. Inject the payload and obtain the password belonging to the administrator.

    Payload injection screenshot 1

    Payload injection screenshot 2

Remediation

  • Use parameterized queries / prepared statements.
  • Implement server‑side input validation.
  • Escape and sanitize user input.

Lessons Learned

When you have determined the number of columns returned by the original query and identified which columns can hold string data, you are in a position to retrieve interesting data.

0 views
Back to Blog

Related posts

Read more »