Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

If you read this blog, you might have seen my earlier post regarding my configurable SQL injection testbed, SQLol. It comes with challenges which I've seen some buzz about. In the latest version, there is a challenge involving use of the "LIKE" keyword and I'm just too jazzed about the attack vector that I had to share.

The LIKE keyword operates similarly to the equality operator "=". However, it also supports wildcards. The "%" wildcard matches zero or more characters, and the "_" keyword matches only one character. LIKE is commonly used in search pages like so:

select * from used_cars where make LIKE '%Toyota%'

This will return any rows from "used_cars" where "Toyota" appears anywhere in the "make" column. If we have control over what goes into the operand for the "LIKE" clause we can enumerate all the "make" values from the database through brute force if they are not shown to us directly. Imagine that this is used (erroneously) for a login prompt, using a query like this:

select * from users where username LIKE 'input_username' and password LIKE 'input_password'

If a user never uses wildcards, this operates as a normal login prompt. However, if we were to provide a username and password of "%", this will return all users from the database. Authentication bypass! Even worse, we can use this to enumerate all the usernames and passwords from the database, even if single quotes are filtered out, preventing us from breaking out of the string value and performing traditional SQL injection attacks.

First, we would enumerate all usernames. We start with character set reduction, by providing a password of "%" and a username of "%A%". This will tell us if there are any usernames which contain an upper-case A in the database. We can repeat this process with all other possible characters and know the character set used in all the usernames in the database. Next, we'll try each of these characters as the first character in the username and wildcard the rest.

Let's say we have a character set of "abfor".

We'll try:

a%

b%

f%

o%

r%

Let's say that on the requests using "f%" and "b%" we are logged in. This indicates that all usernames begin with either "f" or "b". We'll continue onward like this, brute forcing each character to determine the possible character set at each position until no requests are successful:

fa%

fb%

ff%

...

br%

Eventually, we learn all the usernames in this way. Next, we would enumerate all passwords and then attempt to log into each account with each password. Note that the process of enumerating all passwords would require us to make multiple login attempts with the username "%". Beware! If account lockout is enabled, we might also see LIKE in the query to set lockout status:

update users set locked_out=1 where username LIKE '%'

Imagine that phone call.

What's most interesting about this is that using parameterized queries, stored procedures, whitelisting, WAF etc. is not likely enough to prevent this! It's a plausible scenario that usernames could contain underscores, so even if the percent sign was not allowed, one could still perform the same attack by first enumerating lengths of items in the database using varying numbers of underscores and then performing a similar attack to the one described above. It just goes to show that you still need someone testing the application and you still need to be security conscious when writing code.

ABOUT TRUSTWAVE

Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo