Skip to main content

Welcome to Mark Baggett - In Depth Defense

I am the course Author of SANS SEC573 Automating Information Security with Python. Check back frequently for updated tools and articles related to course material.


I recently had the no so pleasurable task of dissecting an 0wn3d host to determine what happened.  The attacker did the system owner a favor and tagged the site with a defacement image making detection pretty easy.  The image appeared in small title frame on the top of the page.   My initial guess was they had a directory traversal vulnerability in the image upload engine and some weak permissions on a folder structure.   We took a look at the date/time of the defaced pic and it showed the image had change the previous evening.    "find / -mtime 0" showed a few other files that had changed around the same time.   One of them was a new PHP file.   vi revealed it was a variant of the c99 PHP Shell.    So we go to the apache logs and find the attackers IP and try to figure out how he got in.     There are two interesting entries:

[14/Aug/2008:22:18:42 - - [14/Aug/2008:22:18:42 -0400] "POST /index.php?option=com_user&task=completereset HTTP/1.1" 301 -
[14/Aug/2008:22:18:44 - - [14/Aug/2008:22:18:44 -0400] "GET /administrator/ HTTP/1.1" 200 4121

A check for recent vendor patches lead us to this..

This is a very interesting vulnerability.   Its a SQL injection vulnerability in the password reset function.   The code that actually resets the password is this..

$db->setQuery('SELECT id FROM #__users WHERE block = 0 AND activation = '.$db->Quote($token));

Token is  supposed to a verification code that is sent to your email address when you request a password reset.   BUT if you just say your token is an ampersand then the SQL statement looks like this...

SELECT id FROM jos_users WHERE block = 0 AND activation = ''

Which select the first account in the database (ADMINISTRATOR) for a password reset.   The next screen that appears is where your prompted for a new admin password.    Sorry Dude,  Your website was 0wn3d by a single character.

Once the attacker had admin access, he added his own php code (c99 shell) and had full access to the apache instance (as the apache user).     So why only a small image in a small frame when he had access to SO much more?    Who knows.   Perhaps good fortune.    Perhaps they caught it early.   The attack certainly did not require much work.   Just about anyone could pull it off.   Maybe he didn't know what he was doing, but my guess is there were a TON of websites  out there that required his attention.   The PUBLIC disclosure of the PHP vulnerability was about 48 hours old at the time.    48 hours isn't enough time to move through most change control processes.   There were probably many more fish to fry.

If you haven't patched.   Go ahead and do it and save yourself some heartache.



Popular posts from this blog

Awesome Keyboard Tricks - Clevo/Sager Backlight control from Powershell

I'm back on Windows.   After 8 years on a Macintosh I just couldn't go another day with ONLY 16GB of RAM.   I priced it out and for the cost of a top of the line MacBook I could get a tricked out PC with 32GB of ram and 2.5 TB or hard drive space (1.5 of it being SSD).   So I made the switch.  To get a top performing laptop I ended up buying a gaming machine from   The model is Sager NP9752 (Clevo P750ZM).    I have to say I like it quite a bit.    One of the features I was curious about was the "Programmable backlit keyboard".   With it you can set your keyboard backlight to various colors and light movement patterns.    Now, when I hear "programmable" I think APIs.   I was a little disappointed to find out there weren't any documented APIs that I could use to control the keyboard.    Your only choice is to use their built in tool to configure the lights on the keyboard.   That stinks.  I want to be able to change key colors automatically …

SRUM-DUMP and SRUM_DUMP_CSV Ported to Python 3

SRUM_DUMP and SRUM_DUMP_CSV have been ported to Python3 and are available for download from the PYTHON3 branch of my github page.

In moving to Python3 I also updated the modules that I depend upon to parse and create XLSX files and access the ESE database that contains the SRUM data.  I hope that this will fix the issue that some users have experienced with SRUDB.dat files that create very large spreadsheets.  If it does not please let me know and continue to use SRUM_DUMP_CSV.EXE to avoid the XLSX problem.

In moving to Python3 you will find the process to be faster.

If you would like to run the tools from source instructions for doing so are in the README on the github page.

Three Free Python apps to improve your defenses and incident response

I did a SANS Webcast on a couple of tools I developed to use automation to enhance your network defenses and incident response capability.    If you missed it you can check it out here:

Use Python and Scapy to Easily Do Full Duplex Stream Reassembly!

Check out this blog on how to get scapy to do full packet reassembly in just a few lines of Python code.

New tool

I read an article on Fireeye's website the other day where they used Machine Learning to eliminate a lot of the noise that comes out of tools like strings.  It's pretty interesting and looks like it would save me some time when looking through malware.

I wondered how effective scores would be in helping to eliminate the noise.  45 minutes and 29 lines of Python code later I have something that looks like it works.  Check out

Before here is the output of strings on a piece of malware:

student@573:~/freq$ strings -n 6 malware.exe | head -n 20
!This program cannot be run in DOS mode.
|$ H;_
|$ AVH

After the useful stings quickly bubble to the top.  Its not perfect but th…