Pages

Saturday, September 21, 2024

Use of Tox protocol in malware

Intro

Note: For the samples mentioned in here, I haven't spent much time doing in-depth analysis so I'm not super confident in my analysis. I was not able to find any sandbox results showing the samples running and getting instructions. (also I'm on vacation. I just found this idea interesting and wanted to get this blog post pushed out)

This is me. I'm not a professional malware analyst or threat intel person: 

 

Every once in a while, someone publishes a new bot/backdoor that uses weird service or protocol to do c2 (command and control). For example, I saw someone doing c2 over reddit (there are several projects on github). 

I was thinking about a protocol I'd use that doesn't require me to have a public server then I remembered that I used Tox chat many years ago so I started looking into it. 

Tox can be used for chat, sharing files, audio, video, etc. You can also use Tox library to build your own client or apps too. You can find more info here: https://tox.chat/faq.html

You could potentially use Tox for C2, stealing files, etc...

I started looking into seeing if anyone was using Tox maliciously or in their malware.

Known activity

While researching, the first article I found was by Uptycs. They observed a cryptocurrency miner using Tox for C2. Screenshot below from Uptycs article. (https://www.uptycs.com/blog/threat-research-report-team/is-tox-the-new-cc-method-for-coinminers)

Next I started looking at github to see if there is anything interesting there. I found a project that uses Tox protocol for traffic tunneling. The project is called ToxTun. More info here: https://github.com/gjedeer/tuntox and here: https://hackaday.io/project/171834-wandboard-experiments/log/178822-tuntox-tunnel-tcp-connections-over-the-tox-protocol

ToxTun isn't necessarily malicious but it shows what you could do on top of Tox protocol.

Another github project I found is ToxNet ("Decentralised P2P botnet using toxcore."), This project actually does use tox for c2 and below is the screenshot provided by the author:


I don't believe I've seen anyone use ToxNet in the wild or have seen anyone write about it being used in the wild. The project can be found here: https://github.com/0x4meliorate/toxnet

I was not able to find any other write ups or projects that involve the use of Tox maliciously. It's possible that I didn't Google enough.

Interesting samples

Note: I decided to see if there are other samples I could find. I focused on Windows PE files. I have not looked at ELF files. The other issue when looking for samples is that people upload legitimate Tox clients (and related files) that run on various systems on VT (VirusTotal). For some of the samples that imported libtox library, VT sandbox results are not useful as the libraries were not on the sandbox when sample ran.


Sample 1 - "vivian":

To find samples, I looked at some of the Tox nodes on VirusTotal and looked at associated files that were marked as malicious.

One of the samples I found is 783c4a9cf616f01dbad0fc49bb49d61bb6f9fb95c1bcafacb9529198fc0b77a2. (https://www.virustotal.com/gui/file/783c4a9cf616f01dbad0fc49bb49d61bb6f9fb95c1bcafacb9529198fc0b77a2)

This file runs and drops another file and creates a service. The exe file that this sample drops seems to be the one that interacts with Tox. 

The behavior is documented on VT but also here: https://vms.drweb.com/virus/?i=24040707

The second sample I came across is 648ace599bcdea491322f08616d4be9b6949f1860282b60bd0e78b64d6c4507e (https://www.virustotal.com/gui/file/648ace599bcdea491322f08616d4be9b6949f1860282b60bd0e78b64d6c4507e) and while researching the first sample, I realized that they're similar. 

While running 783c4a9cf616f01dbad0fc49bb49d61bb6f9fb95c1bcafacb9529198fc0b77a2 in Triage (https://tria.ge/240920-y3p37swclc/behavioral1) I noticed that it dropped a file that's pretty much same size as the sample above. 

The drive.exe dropped is 83085d79329b4951cbefdc8bf9d6b4d04accf33c25a547511efeeab4cfe3d9f2, which I uploaded here: https://www.virustotal.com/gui/file/83085d79329b4951cbefdc8bf9d6b4d04accf33c25a547511efeeab4cfe3d9f2

Both 362KB are pretty much similar and mutexlunastring mutex is seen being used:


I started researching the mutex string and was not able to find any writeups mentioning it.

At this point, I started doing just basic static analysis. 

Quick strings review shows that you'd seen these kinds of commands in a backdoor/bot.  There are some references to Tox in the binary but dynamic analysis also shows connections to Tox nodes.

Based on the strings, I wrote a yara rule and looked at Hybrid Analysis for more samples. 

I found another sample, which was easier to analyze. It's dd2abd48e408d08f52300907a4a29783472bcdfc8e5b2954d3192dd717beeb40. https://www.virustotal.com/gui/file/dd2abd48e408d08f52300907a4a29783472bcdfc8e5b2954d3192dd717beeb40

Screenshot below shows some of the available commands:

 

lpStartAddress refers to the place where code for that specific command is. This for example is for sysinfo:


Sample 2 - "fffline": 

I decided to start looking for samples differently. I decided to look for binaries using libtox.

One of the samples I found is bb1468383e488f7e90c2900c9a7e65aae856d93cee75130effa300dc4dfec8b6 https://www.virustotal.com/gui/file/bb1468383e488f7e90c2900c9a7e65aae856d93cee75130effa300dc4dfec8b6

This was named bot.exe on VT and one of the AV's marked this as rev shell so it seemed interesting.

Tox library being used:

Strings look very interesting. I think fffline is supposed to be "offline".

 

It appears that Tox name is being set to Evil and status is being set to "hacking corps for money and for fun!":

This function is also interesting as it suggests command execution:

Sample 3:

The last sample I found while looking at samples importing libtox is this: d204f359b5c990575a2bf7a2babfe611997f985ef94bc39393aab955516382a5. https://www.virustotal.com/gui/file/d204f359b5c990575a2bf7a2babfe611997f985ef94bc39393aab955516382a5

This was interesting because it was uploaded as "windows_payload.exe" on VT and there is just one detection right now. 

Based on quick analysis of this sample, it might be taking commands and returning the output but I'm not 100% sure.

 

While reviewing this sample a bit more, I noticed that this sample and sample 2 have strings similar to Tox Echo Bot example. Maybe they partially used the Echo bot code.

References in the sample:

Echo bot example https://gist.github.com/nurupo/8c6c1d455b39b0830668 :

 

Detection

I don't think Tox will be used widespread because implementing it into malware is pain in the ass compared to currently existing solution for c2. I do think looking for use of Tox in malicious files might lead to finding interesting samples.

Yara can be used to find samples/do detection.

The rules I made are here: https://github.com/BoredHackerBlog/signatures/blob/main/yara/tox.yar  They're not the best rules but good enough for what I wanted to do.

You can use yara to look for the following things:

- Library imports (libtox, libtoxcore, other libraries/bindings (go, python, etc))

- Tox related function names from various libraries

- Node related info such as IP, domain names, or public keys

 

Network traffic analysis can be used for detecting Tox usage as well. 

There are some suricata rules here: https://rules.evebox.org/search?q=tox https://rules.evebox.org/search?q=tox.chat

There are Tox node lists that exist too. Looking for traffic to Tox node could be interesting. 

One of the other things to keep in mind is that a lot of the nodes seem to be using port 33445. 

Nodes:

https://nodes.tox.chat/

https://wiki.tox.chat/users/nodes


Finally, there will be false positives. As mentioned earlier, a lot of people have uploaded legitimate Tox clients or related files from various systems to VT. I'm sure there are people compiling their own clients as well, which sometimes get uploaded to VT. 

Maybe looking for Tox and other behavior or file properties is a better solution for reducing FPs.


End

For anyone interested, I'd recommend doing proper analysis and maybe also looking for Linux/ELF samples too. I have not looked at use of golang or python libraries yet either.

Wednesday, June 19, 2024

Progressive Web Apps (PWA) on Windows - forensics and detection of use

Introduction

Progressive Web app (PWA) is just a webapp that can be installed as an app on a system and runs in a browser when you open it from desktop or other places. Links under resources have more details/specifics. 


While on twitter, I saw a tweet from mr.d0x (who does great research and runs many useful projects) about using PWA for phishing.

Essentially, the user is made to install PWA app, once they install the app, the app pops up with phishing page. Since the attacker made the app, the attacker can control what the app UI looks like. In the phishing attack, the app has phishing page with URL bar deceptively showing official MS login URL. 

https://mrd0x.com/progressive-web-apps-pwa-phishing/


As someone who does blue team as a job 😢, I was thinking about how I'd go find PWA's being used in my environment. 

I'd like to start by looking at logs, such as process execution logs or file write logs, then start looking for what other artifacts are generated on disk, if logs aren't available and forensics being done. 

PWAs can be installed with multiple browsers. I will just focus on Chrome for now but research can be replicated with other browsers. 


Analysis

Since I don't have PWA app of my own to mess with, I just Googled for demo apps that I can try in a lab environment and Microsoft has a dedicated page for some demo apps. 

I loaded up one of the demo apps in Anyrun and Triage. The sandboxes provide enough info to then figure out what you'd look for in logs or on disk. 


App: https://microsoftedge.github.io/Demos/pwamp/

Reports:

https://app.any.run/tasks/6467ee70-96d3-41dd-8094-c1ec77ac4baa

https://tria.ge/240619-21m3lszgll/behavioral1


Initially, once the app is installed, the app opens up in a new window. There doesn't seem to be any specific process execution activity. 


A shortcut file is written to the Desktop for the app. 


Shortcut link opens the PWA in a very specific way, which is nice. With Chrome, chrome_proxy process is opened with --app-id and specific app id. 


That's not all, there is a secondary process spawned by Chrome_proxy. It's chrome, but with shortcut link file name and app id. 



There are also registry changes that happen around the installation process, specifically, Anyrun highlights creation of uninstallation entry. 

The uninstallation entry located at HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\9A3477235286E8A16E2ECE78681F58F7 contains the following:

link to icon file - C:\Users\admin\AppData\Local\Google\Chrome\User Data\Default\Web Applications\_crx_gpkmcolhnceikobakadkpfhphmboeeog\PWAmp music player.ico

uninstall string - "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory=Default --uninstall-app-id=gpkmcolhnceikobakadkpfhphmboeeog

Version

App display name - PWAMP MUSIC PLAYER

Install date

Publisher - GOOGLE\CHROME 



That's not all, there are more interesting registry changes that happen.

Location: HKEY_CLASSES_ROOT\Chrome.2257410145\Application & HKEY_CLASSES_ROOT\Chrome.1969634003\Application have more info about the app:

Chrome also makes some folders/files for the app.


Chrome makes app info available as well.



Chrome app service internals page has even more details


Preferences file in C:\Users\user\AppData\Local\Google\Chrome\User Data also has info about the app and the exact link. 


Logs

Process execution logs - 4688 or sysmon event id 1 should show the use of PWA apps. Execution of chrome_proxy and chrome with some of the parameters/args shown in the examples above is what I'd look for. 

File write - There are multiple file write events. Easiest things to look for is lnk file in Chrome Apps folder and creation of files in Web Applications folder in "AppData\Local\Google\Chrome\User Data\Default". 

You could look at .lnk file creation on Desktop by Chrome process too.

Registry changes - Sysmon has multiple events related to registry operations. Looking for uninstall entry and Chrome app creation like "HKEY_CLASSES_ROOT\Chrome.2257410145\Application" could be interesting.


File system/registry artifacts

If you don't have logs but still have disk access to do forensics, it should be pretty easy to grab and parse registry files to find the PWA app info in locations listed above. Same goes for files and folders created during PWA app installation. 

Chrome and Windows keeps timestamp info regarding installation in the logs/registry too which can be helpful in determining timeline.

As mentioned above, Preferences file has useful info as well.

Reviewing App_* files in C:\Users\user\AppData\Local\Google\Chrome\User Data\Default\Sessions\ might be useful too. 


Conclusion

PWA apps are legitimately used by many orgs and hunting across the env. or doing forensics won't always lead to anything interesting. 


I haven't done too much research but as far as I know, I haven't seen threat actors abuse PWA and I'm not sure if any will start.


There are for sure more spots where artifacts of PWA use can be found (storage, logs, sqlite files, etc) that I didn't find/dive into. Also, it's possible each browser behaves differently. 


Resources

https://en.wikipedia.org/wiki/Progressive_web_app

https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps

https://mrd0x.com/progressive-web-apps-pwa-phishing/

https://blog.nviso.eu/2020/01/16/deep-dive-into-the-security-of-progressive-web-apps/

https://learn.microsoft.com/en-us/microsoft-edge/progressive-web-apps-chromium/demo-pwas


Saturday, March 23, 2024

observed in the wild - batch obfuscation technique and an interesting way to run powershell code

Saw these two things in the wild while looking at some samples.


Batch Obfuscation

Malicious batch file was found and when opened in notepad/visual studio code, the code/text was not readable. The text was in another language.

When opening the file with hex editor or doing strings, batch commands were seen clearly. When the batch file was ran in command prompt, it worked just fine. The commands seen setting variables worked correctly. Only issue was that you couldn't easily read the file with visual studio.

When reviewing the obfuscated batch file in hex editor and comparing it to normal text file, the following bytes were seen in the front: fffe0d0a before normal ascii.

Turns out this isn't brand new. There is a blog by OneConsult discussing this technique:

https://www.oneconsult.com/en/blogs/dfir-analysts-diary/batch-file-obfuscation-incident/

Blog also points to https://github.com/SkyEmie/batch-obfuscator, which provides a tool.

Personally, I took the obfuscated batch file into hex editor and removed fffe0d0a from the front and opened it again in visual studio code and worked just fine.

I don't have a sample/hash I can link here right now. :-( 


Loading powershell code in a weird way

Another sample I was looking at ran powershell code with Get-Content and SubString. 

Sample is here: https://tria.ge/240307-fj3k3see34/behavioral1 

https://www.virustotal.com/gui/file/4490ebc3a2c6260e09ef8f4f71c08a7afc809630e56ec9e8e215a04935bb0394/behavior 

This is the interesting part:

"powershell" -windowstyle hidden "$Undgaaelsers=Get-Content 'C:\Users\Admin\AppData\Local\Butikstidens150\heluldent\retrtens\Befingringernes\Souchie\indlsninger\Casement.Sub';$Inferably=$Undgaaelsers.SubString(55257,3);.$Inferably($Undgaaelsers)"


1. Get-Content reads powershell text file into a variable, the file just has 1 long line, which includes comments and actual powershell code.
2. SubString is used to extract iex from the variable (the powershell text file)

Loading the substring part in python:

>>> psfile[55257:55260]
'iex'

3. IEX is used to run the variable (the powershell text file)

I thought it was an interesting way of doing things and this was the first time I've seen it done with Powershell.

If you're hunting, maybe look for command line containing Get-Content and SubString?