Cатсн²² (in)sесuяitу / ChrisJohnRiley

Because we're damned if we do, and we're damned if we don't!

[SecTorCA] Reverse Engineering a Web Application – for fun, behavior & WAF Detection

Reverse Engineering a Web Application

For fun, behavior & WAF Detection

by Rodrigo “Sp0oKeR” Montoro (Sucuri Security)

Abstract

Screening HTTP traffic can be something really tricky and attacks to applications are becoming increasingly complex day by day. By analyzing thousands upon thousands of infections, we noticed that regular blacklisting is increasingly failing so we started research on a new approach to mitigate the problem. We started with reverse engineering the most popular CMS applications such as Joomla, vBulletin and WordPress, which led to us to creating a way to detect attackers based on whitelist protection in combination with behavior analysis.  Integrating traffic analysis with log correlation has resulted in more than 2500 websites now being protected, generating 2 to 3 million alerts daily with a low false positive rate. In this presentation we will share some of our research, our results and how we have maintained WAF (Web Application Firewall) using very low CPU processes and high detection rates.

Presenation is based on WordPress / NGINX, but concepts can be applied to any Wed Application / CMS technologies. The goal of this talk to better protect CMSs, with better performance (less rules is better), but also protect against new vulnerabilities as they are released/discovered.

Introduction

By reverse engineering common CMSs (in this case WordPress) it is possible to better understand how they work.

WAF Detection (breakdown):

  • Traffic Analysis
  • Application Structural Analysis
  • Behavior

Detection steps

Reverse Engineering Traffic

As we’re taking about web applications we’re mostly talking about HTTP here. By breakdown down the traffic into specific categories it’s possible to better understand the traffic. We include such as IP source in this section.

Crawling the application

Various ways to crawl the application from a blackbox perspective (Burp Suite for example). From a whitebox rerspective there are various other options.

Looking at requests

By looking at the parameters used by the applications it’s possible to identify parts where an application is only sending numbers or letters as part of the parameter. For example, a name field should not contain numbers. However this could be problematic if you don’t consider edge case situations, like names with special characters.

Looking at the common headers, it’s easy to identify headers values that must fall within specific whitelists. E.g. HTTP/1.0 or HTTP/1.1. Anything else is either corrupted data or somebody fiddling with the date being sent.

With wordpress.com, the response contains an x-hacker header saying “if you should read this you should apply for a job…”

Brute-force attacks are on the rise, so if you can, compare users passwords against a list of the top X passwords and inform the user that it’s weak.

Malicious user-agent strings tend to be shorter than legitimate user agent strings. They also tend to send more complete request headers (often over 8 headers). Also, you don’t see normal browsers sending HTTP/1.0 requests anymore. Drop these simple things. Checking that all expected parameters are sent is also important. A lot of attackers only send the parameters they need, and ignore the others. This can be checked easily enough.

A regular user is also not going to request a whole load of pages that result in a 404. If there are a lot of request that end in a 404, this looks more like a attack than a normal users traffic.

Detection

Using a PCAP of real traffic and simple regex matching, it’s possible to test your logic to list what requests would normally be dropped BEFORE implementing something as a rule. You can then tweak the matching logic before going live.

NGINX is meant to be quick, so doesn’t allow IF ELSE, only IF statements.

e.g.

if ($request_method != <something>){
     return <status_code>
}

WordPress has a lot of files (check the tarball for a full list). So we can slim that down a bit by removing things like initial config and setup files. Administration (/wp-admin) console is also something that can either by disabled or restricted to specific source addresses (think 2FA). Core files (wp-includes) are not meant to be externally accessible, same with uploaded content (wp-content). WordPress also has an XML-RPC interface that allows somebody to perform specific actions (e.g. ping-backs, comments, user-auth, …). Redirecting them to a honeypot might be an option for you.

<ifModule mod_alias.c>
     Redirect 301 /xmlrpc.php
     http://honeypot.address
</ifModule>

Lots of brute-forces seen from June 2014 using the xmlrpc.php. Similar rise in traffic seen in the use of xmlrpc.php as a DDoS tool in March 2014. By looking at the logs it’s easy to see spikes where there may be new attacks or new methods being tried out.

To secure things further, deny specific filetypes in directories where you may have user content or data (e.g. uploads, logs, …).

Mitigating the attack surface

Turn off the machine and remove the network cable –> Not really an option

OSSEC for real-time monitoring.

Monitor specific locations for alteration or addition of files to ensure you get visibility on the web application.

Threshold ideas

Too many 404s –> somebody searching the web app

GET/POST per time for same IP source –> automated user hitting the site (not a normal user)

File specific: Set files on Linux as immutable (lsattr)

Statistical data

Useful for counter intelligence and to find behaviors, new trends and alerts.

Instead of blocking “user-agent: ABCD”, think about blocking connections from user-agents with < 19 bytes (maybe a few false positives, but less specific).

GEO-IP Blocking –> based on top countries, you could block specific countries if you don’t have business reasons to allow traffic from them. This may change week by week however.

Methods –> If your application only allows GET/POST, then drop everything else

HTTP Version –> If you only accept HTTP/1.1, then drop 1.0 and all malformed versions (stats from Sucuri show 1 mill hits a week dropped by this rule alone)

Conclusions

This is a constant process, not set it and forget it.

Challenges:

  • Developers
  • plug-ins
  • Bad Code
  • languages

Next steps:

  • Integration with SCAP
  • open source PCAP parser tool
  • build rule-set for CMSs under OWASP banner

 

Links:

[Guest Post] A first-timers view of the “Hacker Summer Camp”

As many people are aware, the big „Hacker Summer Camp“ took again place in Las Vegas this August. This get-together describes the occasion of Black Hat, for the Business sponsored InfoSec employee, BSides Las Vegas, for the techies, and DEF CON, which apparently became object of both type of folks already years ago, and many more little side conventions.

As these types of conferences are usually a big chance to meet all of the friends that you don’t see the rest of the year, attending many talks is never a goal. Especially not, as these days most of the talks are recorded. As for the full lists of recordings, please check the following links:

The DEF CON 22 Talks will be published by the speakers on YouTube, or can be bought, some of the slides are also already available here: https://www.DEF CON.org/html/links/dc-archives/dc-22-archive.html

The Black Hat Talks will show up here: https://www.youtube.com/user/BlackHatOfficialYT

Over the last few weeks already many Blogposts arose that listed personal favorite talks and what the learnings are. For such a reference, check out other European sites like http://www.scip.ch/?labs.20140819 in German or http://blog.csnc.ch/2014/08/blackhat-and-def-con-usa-2014/ in English.

The big topics this year were infections over USB and wireless transmission of signals like the ones that can be read with a HackRF. One topic that isn’t completely over yet, is hacking of Point of Sale devices. Although they are usually very specific by the country the research originates, and therefore can’t be applied to every vendor or product. They are still interesting though and give new hints on what to consider when securing such an infrastructure.

As an outlook we were informed at the Closing Ceremony of DEF CON, that the next year DEF CON will be hold at the Paris and Bally’s. With DEF CON becoming not only bigger in numbers of attendees, but also space, and seeing the changes that just happened to the German Chaos Communication Congress, I personally like the change. More space can give more ways to be creative.

The CCC has become a very colorful but dizzying experience, which makes it hard for new people to find navigation or orientation in. But CCC, early on, started having villages where like minded people and friends have a “public” space where they can be found and present their stuff. The concept becomes very visible at the hacker camps, where usually even more equipment is brought in and spaces are decorated with lots of creativity and love. DEF CON has also started with the villages, by having for example, Hardware, Social Engineering and Wireless villages. This concept of organized interest groups can be quite a help, if an event becomes too big. I personally also wouldn’t mind seeing more talks in villages, which have smaller audiences but also give the speaker more chance to interact and talk, learn and share information. I always feel sorry for speakers who prepare a talk and only get to hold it once. Presenting a talk several times with slight variations, depending on the target audience, might improve the rate of knowledge exchange and therefore be beneficial for both sides. The big talks still should be held in big rooms of course, but information overflow has become such a big topic, that the concept of split, addressed information might help. If there were more spaces like DEF CON SkyTalks, the chance exists that the quality of the presented information would also improve again.

- Des

Last Hacker Standing… Episode IV: The Last Hope

Just when you thought it was safe to go back into the water…LastHackerStanding_singleFace

With the untimely demise of the Network Security Podcast, Martin McKeay (along with Dave Lewis and myself) decided it was time for something new.

In the inaugural podcast, we talk news (straight up, with a twist), alongside our wonderful guest Katie Moussouris from Hacker One.

 

 

We’ve tried to add a twist to the usual podcast style of news and interviews… so feedback on the first part of episode IV is always gratefully received!

Lookout for part II dropping in a few weeks…

Links:

My picks for the coming conpocalypse

25C7DBB7FDEE98EB339313F2B55B68D5Yeah, yeah… I know. I’ve been slacking on my blog for the past few months (in-fact I think this post has been sitting in my drafts folder for about 2 months). Still, the wheels of life must go on, and the last post (although tongue firmly in cheek), was a bit depressing. So, with as little fan-fare as possible, I thought I’d give you my picks for the up-coming conpocalypse (AKA #HackerSummerCamp, AKA “That thing in Vegas”).

This year I’m volunteering at BSidesLV so won’t have much time at all to visit Blackhat. This might not be such a bad thing though… I think Blackhat and me need some time apart to see if we miss each other. Times move on, and I’m not sure I feel the same way about Blackhat as it feels about me… it’s not me… it’s you. Sorry Blackhat! Maybe I’ll pop over and see if it feels all funky or not! Who knows…

BSidesLV

This years BSidesLV is looking great… and I’m not just saying that because some of my favourite people in the world are running and helping shape it (you know who you are ;). Alongside all the hallway track stuff that’s much talked about, and working a couple of morning shifts as a room host (still not sure what this means… guess a mix of stand-up comedy routine and crowd control!) I’ve got a couple of talks on my radar to attend!

Tuesday 10:00 – 11:00 Opening Keynote — Beyond Good and Evil: Towards Effective Security

Tuesday 16:00 – 17:00 Anatomy of memory scraping, credit card stealing POS malware

Wednesday 17:00 – 18:00 We Hacked the Gibson! Now what?

Wednesday 18:00 – 18:45 Closing Keynote –> It’s A S3kr37
 

On the Wednesday I’ve booked in to play around in the RFID Hacking workshop… maybe I can finally pot this Proxmark3 I’ve had on my desk for about 3 years to some good use ;)

I was really hoping to attend @HackerHuntress‘ Hacking the Hustle Hands-On, Infosec Resume and Career Strategies workshop… however I’m volunteering at that time. So hopefully she’ll still be around to chat to for the remainder of the conference!

If you’re around at BSidesLV, make sure to pop into the “i am the cavalry” area to see what those crazy kids are up to!

DEF CON

By this time of the week everybody is pretty much dead… along with the inevitable mass of people and agoraphobia kicking in! So consider these as my dream picks if I can get into the room ;)

Don’t forget to check out the DEF CON SkyTalks (https://skytalks.info/) as well… these talks aren’t recorded usually, so it’s be there, or be ²!

Friday 12:00 – 12:30 From root to SPECIAL: Pwning IBM Mainframes

Friday 12:30 – 13:00 The $env:PATH less Traveled is Full of Easy Privilege Escalation Vulns

Friday 14:00 – 16:00 DefCon Comedy Jam Part VII, Is This The One With The Whales?

Saturday 10:00 – 11:00 Screw Becoming A Pentester – When I Grow Up I Want To Be A Bug Bounty Hunter!

Saturday 14:00 – 15:00 NinjaTV – Increasing Your Smart TV’s IQ Without Bricking It

Saturday 15:00 – 16:00 Advanced Red Teaming: All Your Badges Are Belong To Us

Sunday 14:00 – 15:00 Android Hacker Protection Level 0

… that’s a lot, and I don’t expect to hit them all! Hallways con and other events will keep me from that. Still, those are my picks for the Summercon marathon!

Hope to see you there… below photos can be used to identify me throughout the conference (depending on the day)

Easy Identification pictures…

8bit_startDay 1 8bit_mediumDay 2 – 3 8bit_endDay 4+
Follow

Get every new post delivered to your Inbox.

Join 129 other followers