Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
Get access to immediate incident response assistance.
Get access to immediate incident response assistance.
Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More
SOURCE Boston is coming up in April, and Mike Ryan and I are giving a presentation about making packet analysis easier for the masses. One of the challenges with building new protocol parsers for tools such as Ettercap and Wireshark is many of these parsers are written in C. C is very fast and powerful, however you run the risk of introducing vulnerabilities in the software. And, for folks who aren't fluent C programmers, building these parsers can be intimidating.
So, what are we going to do to change this? One of the pieces we've been working on is trying to merge Lua into Ettercap. We did a presentation at Derbycon last year about how we planned to do this, and now we have some practical uses. We're going to take a look at how to build easy to use scripts, similar to the Nmap NSE scripts, to allow manipulation and parsing of data that would otherwise require C code.
I wrote a quick example that we will examine in more detail during our presentation. The example focuses on tracking HTTP traffic on the network or in captures.
Why do we care about HTTP requests? On a penetration test, we may use a MitM attack to target groups of individuals and watch their requests in order to identify interesting targets for session theft or other attacks. Another good example of when this is useful is when looking at malware. We may want to determine what requests malware is making, where it's being redirected to, and even watch for beaconing requests.
It turns out, doing these things with existing tools can be pretty cumbersome. Right now, you could try to match requests and replies in tcp dump. But, if there are multiple simultaneous requests, it gets trickier. You can do the same thing in Wireshark and Tshark, but you have to do a lot of clicking around-- or write some lua tore-assemble the sessions and then track down the data.
Our solution adds a basic registry to Ettercap. So, you can store session data. To create a session we can do something like this:
-- Get session key for tracking req->reply pairs local session_id = http.session_id(p,hobj)
-- We have a session, lets get our registry space local reg = ettercap.reg.create_namespace(session_id)
Now, we have a local registry that is unique to our session.We can use this registry to store session data. One thing we may want to do is extract request data, and store it until the response comes in so we can match them up. To do something like this, we can parse the packet:
-- Parse the packet (p) and retrieve the http data
local hobj = http.parse_http(p)
If we are looking at a request, we want to store the request for retrieval in the registry for when we see the response:
if hobj.request then
reg.request = hobj
If we saw a response, then we just want to print it out:
-- Get the status code local code = hobj.status_code -- Build the request URL -- If we have a 2XX or 4XX or 5XX code, we won't need to log redirect -- so just log the request and code if code >= 200 and code < 300 or code >= 400 then ettercap.log("HTTP_REQ: %s:%d -> %s:%d %s %s %d (%s)\n", packet.dst_ip(p), packet.dst_port(p), packet.src_ip(p), packet.src_port(p), reg.request.verb ,reg.request.url , hobj.status_code, hobj.status_msg)
Dealing with the request and matching response is easy in this model. And we can easily add parsers for other types of traffic that aren't supported by Ettercap and Wireshark. When you put it all together, it gets very easy to track requests made by a browser in a MitM attack or from network capture files. Here's an example of how the initial requests from viewing Slashdot look, using our version of Ettercap with Lua modules enabled:
Note: we are printing both source and destination, the full request, status code, and in the case of a redirect, where the user was sent. This is just a brief example of the types of things that are going to be easy to build with this framework.
We will be releasing the source code for a patched Ettercap along with sample modules at SOURCE Boston.
If you're interesting in helping out or learning more, come see us and the other SpiderLabs folks at SOURCE Boston and chat with us about your ideas.
Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.
Copyright © 2024 Trustwave Holdings, Inc. All rights reserved.