Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Trustwave Unveils New Offerings to Maximize Value of Microsoft Security Investments. Learn More

Services
Capture
Managed Detection & Response

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

twi-managed-portal-color
Co-Managed SOC (SIEM)

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

twi-briefcase-color-svg
Advisory & Diagnostics

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

tw-laptop-data
Penetration Testing

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

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

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

tw-officer
Digital Forensics & Incident Response

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

tw-network
Firewall & Technology Management

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

Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
Microsoft Exchange Server Attacks
Stay protected against emerging threats
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
SpiderLabs Blog

LIKE, omg!

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.

Latest SpiderLabs Blogs

Clockwork Blue: Automating Security Defenses with SOAR and AI

It’s impractical to operate security operations alone, using manual human processes. Finding opportunities to automate SecOps is an underlying foundation of Zero Trust and an essential architecture...

Read More

Professional Services Sector Under Attack - Trustwave SpiderLabs Report 2024

Recent research by Trustwave SpiderLabs, detailed in their newly published report "2024 Professional Services Threat Landscape: Trustwave Threat Intelligence Briefing and Mitigation Strategies,"...

Read More

Atlas Oil: The Consequences of a Ransomware Attack

Overview Atlas Oil, a major player in the oil and fuel distribution industry, fell victim to a ransomware attack orchestrated by the Black Basta group. This attack not only compromised sensitive...

Read More