Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. 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
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

CSS and XSS in Melodious Harmony

Web application penetration testers, have you ever run into a situation where you can inject into the attribute of a tag and break out of the attribute, but not the tag?

For those who can only <script>alert('XSS')</script> this is a lost cause... BUT NOT FOR THE SASSY!

No, the sassy PenTester will just create a new attribute, specifically an event handler. An event handler attribute will launch some bit of JavaScript code when a certain event occurs. Some are more useful than others. If we're injecting into the "src" attribute of an "img" tag, we can point the image to a URL that doesn't actually exist, causing an error. Conveniently, in many browsers there exists an "onerror" attribute which runs its contents as a set of Javascript commands when loading the image produces an error. Here's an example of a string we could inject:

http://www.fail.nod/not_there.jpg" onerror="alert('XSS')

Win!

What if we have control over the contents of the "value" attribute of a text box? This is pretty common in search boxes that populate the search box of a search results page with the previous query entered, in case you need to make small changes, like correcting a typo. Normally we could use the following to pop an alert box:

"><script>alert('XSS')</script>

But for the sake of the point of this blog post in general, let's say that for some reason (perhaps an incomplete patch of this XSS flaw) the application filters angle brackets (< and >). Assuming we can't use alternate encodings or something of that ilk, this forces us to work with attributes instead. My favorite is "onmouseover", which triggers when a user moves their mouse over the element we have control over. The only problem is, what if we have a REALLY small text box off in a corner of the page that no one can see? This doesn't do us much good.

Here's where it gets fun, and where CSS comes into the picture.

With CSS, we can define the size and position of an element. Better yet, we can use the "style" attribute to define these properties inline. The following attack string will cause our text box to be the size of the entire page, and will pop an alert box when the user moves their cursor while it's over any part of the text box (which is conveniently gigantic).

" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px" onmouseover="alert('XSS')

And now, just for giggles, imagine that our quotes are being escaped with backslashes. This actually doesn't prevent us from breaking out of attributes, but it does make writing our payload a bit harder. Fortunately, if you can avoid using spaces in the values of attributes you don't need to delimit them with quotes. In terms of JavaScript, there are a few tricks to avoiding the use of quotes. My favorite is to define a regex, then take its "source" attribute, which is essentially just the raw pattern itself, represented as a string. For the string "intertubes", you could write the following:

/intertubes/.source

This can be used interchangeably with strings, so our attack string can look like this, with an extra junk parameter at the end, just to prevent the trailing quote from interfering...

" style=position:absolute;top:0px;left:0px;bottom:0px;right:0px onmouseover=alert(/SpiderLabs/.source) fakeattrib="

So what have we learned today? XSS flaws can be hard to patch correctly, and with the right tricks and a little sass, even difficult exploitation scenarios can be leveraged into reliable attacks. Always, always retest any supposedly fixed vulnerabilities to ensure that a proper fix is in place.

Latest SpiderLabs Blogs

Welcome to Adventures in Cybersecurity: The Defender Series

I’m happy to say I’m done chasing Microsoft certifications (AZ104/AZ500/SC100), and as a result, I’ve had the time to put some effort into a blog series that hopefully will entertain and inform you...

Read More

Trustwave SpiderLabs: Insights and Solutions to Defend Educational Institutions Against Cyber Threats

Security teams responsible for defending educational institutions at higher education and primary school levels often find themselves facing harsh lessons from threat actors who exploit the numerous...

Read More

Breakdown of Tycoon Phishing-as-a-Service System

Just weeks after Trustwave SpiderLabs reported on the Greatness phishing-as-a-service (PaaS) framework, SpiderLabs’ Email Security team is tracking another PaaS called Tycoon Group.

Read More