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.

Senior SANS Instructor
GSE #15
Internet Storm Center Handler
Penetration Testing and Incident Response Consultant
Technical Advisor to DoD for The SANS Institute
Founding President of the Greater Augusta ISSA
Cofounder of BSidesAugusta Security Conference

FREQ SERVER - Tool and technique for detecting Malware Command and Control domains
DOMAIN_STATES - Tool for detecting "Baby Domains" used for phishing and Malware distribution
SRUM_DUMP - Forensics tool for extracting System Resource Utilization Monitoring artifacts
LIAM_NEESON - Proof of Concept Linux Hash Protection
HONEY_HASHES - Certainly Honey Tokens have been around since 2003 but I created a cool technique for creating fake SATs in memory that was turned into Dell Secure Works DCEPT framework.
VSSOWN - Tool & Technique for Using Microsoft Volume Shadow Copies for hiding malware and extracting artifacts
SDB Hacking - Using Application Compatibility in unexpected ways.
SET-KBLED - Utility for Managing Clevo and Sager Laptop LED Backlit Keyboards - Scapy based fragement reassembly engine - A password cracker for the EAP protocol

and more. Most of these tools are available on my github page. Follow me on twitter @markbaggett

First Stab at NSE Scripting

Over the weekend I decided to take my first look at the NMAP scripting engine.  I’ve read about it, but had not really tried it until now.  First, here is how to use the built in scripts.  First make sure you have the latest scripts.   Similar to NIKTO and other vulnerability scanning systems NMAP has the ability to update its detection scripts.   To update your scripts type this;

nmap --script-updatedb

This will download the latest .NSE scripts from the nmap site.   The scripts (by default) are located in /usr/local/share/nmap/scripts.  

Here is the list of scripts as of today:

You can run ALL of these scripts against a host like this…


Macintosh:scripts mark.baggett$ nmap localhost -n --script all           

Starting Nmap 4.65 ( ) at 2008-06-20 10:44 EDT

Interesting ports on


80/tcp open  http

|_ HTML title: Test Page for Apache Installation

Nmap done: 1 IP address (1 host up) scanned in 42.216 seconds


-n   : says do not do an DNS query

--script all : tells it to run all the scripts against the host


The scripts themselves tell nmap which ports they are applicable to.  So any scripts related to PORT 25 (smtp) will not run on a host unless port 25 is open for that host.

You can also pass a script CATEGORY and nmap will run all of the scripts in that category.   Categories include SAFE, DEMO, INTRUSIVE, DISCOVERY, VULERABILTY, VERSION and BACKDOOR


Nmap –sS –P0 –n –script INTRUSIVE, VULNERABILITY localhost

Will run all the scripts that have been classified by the script author as “INTRUSIVE” and run all of the scripts that have been categorized as VULNERABILTY against hosts which have the applicable ports open

You can get more information on a script by looking at its sourcce.  For example:

Cat /usr/local/share/nmap/scripts/robots.nse will show you the script that displays disallowed entries from the robots.txt file on web servers.

That’s all good, but I want to try my own scripts.    NMAP uses a LUA interpreter to process its scripts.   I’d never heard of LUA, but it looks pretty intuitive so I thought I’d give it a go.    I figured I’d write a script that would look for Apache servers with the USERDIR directory

 enabled, then brute force the usernames off of the system.  In writing it I found it was easier to use the LUA interpreter built into my Powerbook (as a result of the NMAP install??) rather than repeatedly running it through NMAP.  But since my scripts would use functions defined in nmap I needed to be in the /usr/local/share/nmap/nselib directory when I ran the script.  For example …

Macintosh:nselib mark.baggett$ pwd


Macintosh:nselib mark.baggett$ lua ~/HTTPApacheUsers2.txt

BUT there is one important thing to do when debugging your scripts using the LUA interpreter rather than running the code through nmap.   Nmap calls the following section of code when it determines the script needs to be run.  This is the MAIN function of your nmap script.  But LUA doesn’t have a concept of MAIN.   So for testing in LUA you will want to comment out the function header and footer with a double dash (--) and statically set the parameters to your function.  For example 


action = function(host, port)

-- do stuff here

return output


Becomes this:

--action = function(host, port)

host = BLA.Com

port = 90

-- do stuff here

-- return output


So after 3 hours of learning the nuances of LUA, I came up with the script below.  Recursive code isn’t the fastest way to do this, but the network I/O will be the real bottle neck.  To make it faster I’d need to parallelize the GET request and that would probably take a little more LUA experience.   To me it means the NSE is very powerful tool and could prove to be a viable alternative to Nessus in the future. 

Here is a sample run.   Now I can just give it an NSE extension and add it to my /usr/local/share/nmap/scripts directory!

Macintosh:scripts mark.baggett$ nmap localhost -p 80 -n --script ~/HTTPApacheUsers2.txt

Here is the script.   Adjust your CHARSET and MAXLENGTH as desired.





id = "HTTPApacheUsers.nse"

author = "Mark Baggett "

description = "Brute force usernames on Apache"

license = "Same as Nmap--See"

categories = {"intrusive", "discovery"}

runlevel = 1.0

portrule = shortport.port_or_service({80,443}, {"http","https"}

--charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-_"

charset = "abcdefghijklmnopqrstuvwxyz"

username = ''

maxlength = 3

local function replacechar( instring, pos, newchar)

        if pos == 1 then

                -- replace first character

                instring = newchar .. string.sub(instring,2)


                -- replace mid or end character

                instring = string.sub(instring,1, pos-1) .. newchar .. string.sub(instring,pos+1)


        return instring


local function IncUser(position) 

        local userchar = string.sub(username, position, position)

        if userchar == '' then 

                --the current character is Null add the first char from charset to the end

                username = string.sub(username, 1 ,position) .. string.sub(charset,1,1)

        elseif userchar == string.sub(charset,-1) then

                --Reset current char and Increment the next char

                username = replacechar(username, position, string.sub(charset,1,1)) 



                -- Just increment the current character

                curchar = string.find(charset, userchar)

                username = replacechar(username, position, string.sub(charset,curchar + 1,curchar+1))


        return username


action = function(host, port)

        local output = "No Root User Found"

        local answer = http.get( host, port, "/~root")

        --      print(answer.body)

        if answer.status == 403 then

          --  print("Root User Found.")

            output = "Root user found.  "

            while string.len(username) <= maxlength do


                tryme= "/~" .. username

                local answer = http.get( host, port, tryme)

--              print(answer.status)

                if answer.status == 403 then

                        output = output .. " User found " .. username .. "." 

     --   print(output)




        return output


Popular posts from this blog

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.

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.

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 …