Hunting The Malicious JavaScript

Systems that perform sandbox analysis have a very important role in identifying and taking necessary precautions for cyber-attacks that are made against corporations directly or indirectly. Alerts that arise from these systems are examined by corporate CIRT’s (Cyber Incident Response Team) and this can sometimes lead to interesting security incidents.

Sometimes it proves difficult and time consuming for security specialists to find the harmful JavaScript code that creates suspecious activities and trigger the alarms that are on these systems or on suspecious network traffic packages (PCAP). One of the primary reasons for this is that, harmful JavaScript codes are mostly hidden (encoded) in HTTP traffic. This is why, opening a PCAP file with Wireshark tool and searching for the eval() function which is commonly found in hidden JavaScript codes is nothing but a waste of time.

In the previous months, I examined an alert from a system that performs sandbox analysis and found out that Hurriyet Hackathon’s website was hacked and the visitors were directed to the following domain name: uitbracht.kateandoliverswedding.co.uk

Malicious JavaScript Hunting

Hackathon (also known as hack day, hackfest or codefest) is where attendants including computer programmers, graphics designers, interface designers and project leaders intensely compete against other teams to develop software projects. (Reference: Wikipedia)

Malicious JavaScript Hunting

Like I said above, since it is time consuming task to search for the harmful JavaScript code inside the PCAP file with Wireshark, I started to think of ways to automate this process.

I thought it would be semi useful if I prepared a tool with Python programming language and let it open the PCAP file with Scapy, analyze the HTTP traffic, find and run the JavaScript code between script tags and then locate the eval() function. The obstacle I would encounter was how to run the JavaScript code with Python. Not so long after, I decided to run the JavaScript code revealed by Python through a headless browser named PhantomJS which doesn’t have a graphical user interface.

After a short amount of time, a tool which I named JavaScript Eval Finder came up. When you provide a PCAP file to this tool, it copies the HTML files that include the script tags into the javascripts folder. After that with the JavaScript Extractor Tool which works with Phantomjs, sends out an alarm when it encounters the eval() function in the hidden JavaScript code, and then the same tool adds the identified JavaScript codes as a comment into the headers of the previously added HTML files.

After I decoded and inspected the JavaScript code with JavaScript Eval Finder, I found out that it was a different version of the exploit kit called Angler which I analyzed it before.

Malicious JavaScript Hunting
Malicious JavaScript Hunting

After I replaced the encoded JavaScript code hidden in the HTML file with the decoded JavaScript code, I analyzed it with Firebug addon on the Firefox internet browser, then I was able to confirm that it was the same code that directed the visitors to http://uitbracht.kateandoliverswedding.co.uk/topic/18572-indivisible-arriver-existences-faroff-prepositions-sunburn-crushing-hittable/

Malicious JavaScript Hunting
Malicious JavaScript Hunting

You can download the JavaScript Eval Finder and JavaScript Extractor tools which I believe, they would be beneficial for CIRT members as one package from here.

Hope to see you on the next post, have a secure day.

P.S: This post also includes the solution of the 5th Pi Hediyem Var security game ;)

Original Article: Zararlı JavaScript Avı
Translated to English by: Hüseyin Fatih Akar | Twitter: @thehakar)

image_pdfShow this post in PDF formatimage_printPrint this page
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

e-Devlet Hacklendi mi?

If you are looking for an English version of this article, please visit here. Öncelikle yazının sonunda söyleyeceğimi başta söyleyeyim, “Hayır, hack-len-me-di!” Peki bu durumda vatandaş olarak rahat bir nefes alabilir misiniz ? Maalesef hayır. Bunun sebebini de yazının devamında okuyabilirsiniz. Zaman zaman hortlayan “e-Devlet Hacklendi!”, “e-Devlet verileri çalındı!”, “85…
Read More
Read More

WhatsApp Dolandırıcıları

If you are looking for an English version of this article, please visit here. Başlangıç Son günlerde hemen hemen WhatsApp uygulaması kullanan herkesi rahatsız eden yabancı cep telefonu numaralarından gelen çağrılardan, mesajlardan ben de yakın zamanda nasibimi aldım ve tabii ki diğer dolandırıcılıklarla ilgili yazılarımda (Kripto Para Dolandırıcıları, LinkedIn Dolandırıcıları,…
Read More
Read More

LinkedIn Dolandırıcıları

If you are looking for an English version of this article, please visit here. Uzun yıllardan beri sosyal ağları ve medyayı etkin kullanan bir siber güvenlik araştırmacısı olarak bağlantılarım arasında yer alanlarınız özellikle hafta içi LinkedIn ve Twitter üzerinden okuduğum ve beğendiğim siber güvenlik makalelerini, haberleri paylaştıklarımı farkediyorlardır. Twitter hesabımın…
Read More
Read More

e-Devlet Hesaplarımızı Nasıl Hackliyorlar?

If you are looking for an English version of this article, please visit here. Başlangıç 25 Ekim 2023 günü saat 11:46’da e-Devlet uygulamasından ve e-posta adresime gelen uyarılardan e-Devlet Kapısı hesabıma üst üste birden fazla defa yanlış parola ile giriş yapılmaya çalışıldığı için hesabımın bir saatliğine geçici olarak kullanıma kapatıldığını…
Read More