Here is another great post from Doug Burks.
For the purposes of this blog post, “evil User Agents” could be truly
evil User Agents like “Bob’s Evil Clown C&C Agent” or they could
simply be outdated and vulnerable browser software like
“Firefox/2.0.0.20″.

Clown2.jpeg

Only from a cheese grater..

Proxy
If you already proxy your outbound HTTP traffic, then this a trivial
exercise of just parsing your existing proxy logs. This is left as an
exercise to the reader, but the command-line kung-fu at the bottom of
this blog post may help you get started. If you don’t already have a
proxy, read on for some other ideas.
WPAD
WPAD is Web Proxy Auto Discovery. By default, most browsers will
attempt to retrieve a proxy configuration file from a local WPAD
server. Even if you don’t have a proxy server, you can create a
“wpad” A record in your internal DNS and point it at a web server
where you can monitor the logs. You don’t have to add a proxy
configuration file to the web server, just let the clients request the
file and then query the web server logs for their User Agent strings.
This isn’t a 100% solution as some malware may not try to connect to
WPAD. [1] [2] httpry
If you can span or tap your outbound Internet traffic to a box running
the httpry utility [3], it will create logs very similar to a proxy
but without requiring any reconfiguration of your network or clients
[4] [5]. A recent update to Security Onion added httpry and
configured it to run on all monitored interfaces, so you can have full
IDS/NSM *and* searchable HTTP logs in one box [6].
httpry’s output format is configurable. If you want just the client
IP and User Agent, you can configure httpry to log just those fields.
If running httpry in Security Onion, it logs in the following format:
timestamp,source-ip,source-port,dest-ip,dest-port,method,host,request-uri,referer,user-agent
(for uploading into Sguil [7]). We can use our old friends cut, awk,
sort, and uniq to pare this down to just client IP and User Agent to
produce an actionable report:

cut -f2,10 /nsm/sensor_data/*/httpry/`date +%Y-%m-%d`.log | awk '$2 !=
"-"' | sort | uniq -c |sort -nr

Let’s break the command down:
cut -f2,10 /nsm/sensor_data/*/httpry/`date +%Y-%m-%d`.log
Security Onion stores its httpry logs in
/nsm/sensor_data/NAME_OF_SENSOR/httpry/YYYY-MM-DD.log (where
NAME_OF_SENSOR is the actual sensor name and YYYY-MM-DD is the actual
date). We can get today’s date in YYYY-MM-DD format using the
backticked command `date +%Y-%m-%d`. So the full command extracts
fields 2 and 10 from today’s log on all sensors on the box.
| awk ‘$2 != “-”‘
Take the output from the cut command and remove lines where the User
Agent field is just a hyphen.
| sort | uniq -c |sort -nr
Take the output from the awk command, sort the logs by IP address and
collapse them into unique entries (giving a count of each unique entry
at the beginning of the line), and then sort in reverse numerical
format. This puts our User Agents with the highest amount of traffic
on top.
Here’s some sample output:

 2701 192.0.2.2  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2)
AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
1024 192.0.2.8  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20
992 192.0.2.3  Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1
(KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
39 192.0.2.4  Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.2.23) Gecko/20110921 Ubuntu/10.04 (lucid) Firefox/3.6.23
78 192.0.2.4  Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1
(KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
11 192.0.2.5  Roku/DVP-3.0 (013.00E02227A)
5 192.0.2.4  Wget/1.12 (linux-gnu)
3 192.0.2.4  Bob's Evil Clown C&C Agent
2 192.0.2.4  curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7
OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15

On the second line of the output, we see that 192.0.2.8 is running the
vulnerable Firefox 2.0.0.20 browser. On the next to last line of the
output, we find Bob’s Evil Clown C&C Agent on 192.0.2.4.
[1] – http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol
[2] – http://support.microsoft.com/kb/934864
[3] – http://dumpsterventures.com/jason/httpry/
[4] – http://taosecurity.blogspot.com/2008/06/logging-web-traffic-with-httpry.html
[5] – http://isc.sans.edu/diary.html?storyid=9295
[6] – http://securityonion.blogspot.com/2011/09/security-onion-20110922-now-available.html
[7] – http://www.pintumbler.org/Code/hafs

About the author

Leave a Reply