A new version of Jsunpack-n was posted recently and i have finally got around to installing it. There are some very cool new features such as

1) improved URL tracking using ‘urlattr’ class and urls dictionary
1a) new command line option -g, to create a URL graph (only when pcap contains 10 or fewer URL requests)

2) bug fixes for stream reassembly and pdf parsing
2a) stream reassembly now handles all streams when processing a pcap file, regardless of whether the nids state is in end_states
4) detection of NOP sled shellcode and performance improvements in shellcode processing (this was one of the performance bottlenecks)
5) new output format with ./files/ directory or -d OUTDIR command line option
6) CVE references are available in the ‘rules’ file but are temporarily unavailable in alerts

One of the major differences is this release is dependent on Yara.. Before you attempt to install Yara make sure you install PCRE by running the following command

apt-get install libpcre3 libpcre3-dev

Now download the following files

1) http://yara-project.googlecode.com/files/yara-1.2.1.tar.gz
2) http://yara-project.googlecode.com/files/yara-python-1.2.1.tar.gz

For yara-python-1.2.1.tar.gz you can build by running the following commands

$ tar xzvf yara-python-1.2.0.tar.gz
$ cd yara-python-1.2.0
$ python setup.py build
$ sudo python setup.py install

And then for yara-1.2.1.tar.gz simply run

$ tar xzvf yara-1.2.1.tar.gz
$ cd yara-1.2.1
$ sudo ./configure; make; make install

Next run the following commands

$ sudo echo “/usr/local/lib” >> /etc/ld.so.conf
$ sudo ldconfig

I then ran jsunpack-n against one the sample .pcap files with the new -g option to generate an image file however immediately received the following error

sudo ./jsunpack-n.py sample-http-exploit.pcap -g url
Traceback (most recent call last):
File “./jsunpack-n.py”, line 1030, in
main()
File “./jsunpack-n.py”, line 1026, in main
graph(file, js.urls, options.graphfile)
File “./jsunpack-n.py”, line 924, in graph
import yapgvb
ImportError: No module named yapgvb

The error is from a missing python module which can easily be installed by running the following command.

apt-get install python-yapgvb

Now that everything is working I scraped MalwareURL.com for the most recently IPs/Domains associated with Exploits by using the following command.

links2 -dump http://www.malwareurl.com/search.php?domain=\&s=exploits\&match=0\&rp=100\&urls=on\&redirs=on\&ip=on\&reverse=on\&as=on | awk ‘{print $1}’ | sed ‘s/|//’ | egrep “[A-Za-z0-9\/]” | awk ‘{print “http://”$1}’ >> t3stURLS.txt

The result of the command stores a list of URLs into a file called t3stURLS.txt while running jsunpack-n in the background we can use wget to loop through the file t3stURLS.txt and download the content to see what gets picked up and decoded.

wget -i t3stURLS.txt -T 1 -t 3

Below is a small sample of the Jsunpack Output that was generated.

*Caution Malicious URLS*

[suspicious:5] 55x5h.2288.org/fkzd/2.htm
[impact=5] DecodedIframe  detected <iframe
[info] [iframe http] http://wm.7udij.cn/x87/xx.html
[info] [script http] http://js.tongji.linezing.com/1240663/tongji.js
[suspicious:5] wm.7udij.cn/x87/xx.html
[impact=5] DecodedIframe  detected <iframe
[info] [iframe .] wm.7udij.cn/x87/Td14.htm
[info] [iframe .] wm.7udij.cn/x87/yt.htm
[info] [iframe .] wm.7udij.cn/x87/td09.htm
[info] [iframe .] wm.7udij.cn/x87/yut.htm
[suspicious:5] 44x5h.2288.org/fkzd/2.htm
[impact=5] DecodedIframe  detected <iframe
[info] [iframe http] http://wm.7udij.cn/x87/xx.html
[info] [script http] http://js.tongji.linezing.com/1240663/tongji.js
[suspicious:5] wm.6bief.cn/x3/xx.html
[impact=5] DecodedIframe  detected <iframe
[info] [iframe .] wm.6bief.cn/x3/Td14.htm
[info] [iframe .] wm.6bief.cn/x3/yt.htm
[info] [iframe .] wm.6bief.cn/x3/td09.htm
[info] [iframe .] wm.6bief.cn/x3/yut.htm

[suspicious:5] 55x5h.2288.org/fkzd/2.htm
[impact=5] DecodedIframe  detected <iframe
[info] [iframe http] http://wm.7udij.cn/x87/xx.html
[info] [script http] http://js.tongji.linezing.com/1240663/tongji.js
[suspicious:5] wm.7udij.cn/x87/xx.html
[impact=5] DecodedIframe  detected <iframe
[info] [iframe .] wm.7udij.cn/x87/Td14.htm
[info] [iframe .] wm.7udij.cn/x87/yt.htm
[info] [iframe .] wm.7udij.cn/x87/td09.htm
[info] [iframe .] wm.7udij.cn/x87/yut.htm
[suspicious:5] 44x5h.2288.org/fkzd/2.htm
[impact=5] DecodedIframe  detected <iframe
[info] [iframe http] http://wm.7udij.cn/x87/xx.html
[info] [script http] http://js.tongji.linezing.com/1240663/tongji.js
[suspicious:5] wm.6bief.cn/x3/xx.html
[impact=5] DecodedIframe  detected <iframe
[info] [iframe .] wm.6bief.cn/x3/Td14.htm
[info] [iframe .] wm.6bief.cn/x3/yt.htm
[info] [iframe .] wm.6bief.cn/x3/td09.htm
[info] [iframe .] wm.6bief.cn/x3/yut.h

As you can see from the output above jsunpack-n was able to decode the obfuscated JavaScript and output the Iframes that were buried within. Because I am using Wget the Iframes are not followed so this test only touches on some of the functionality jsunpack-n provides. Originally I believe jsunpack-n was developed to act as an IDS application however it can also be used for research purposes.

The New file directory now organizes the decodings by MD5 and also saves the executables.
decoding_048c802efcc40b164a42cf29c95ad9e13cf28995
decoding_742d479309d69fd4bc7353647cc66f5cc9418bf9
decoding_d6641a882f77807034ff0a1f5530b1b781ee1019
original_86c2d76a7ba524487ab518c7fae29dcc60c6fc54
decoding_17278448f71fbb774fd420d6bb6dc9f1bf1d8689
decoding_75d715bee572a79d9fba6bae2fff79cf2cb1620d
decoding_f867d1bc0da9a69c286131639f474a5c2521f46d

This tool has come along way and has become one of my favorite. Many thanks to the author for sharing with everyone in the community.