This new Linux script from THC will encrypt and obfuscate any executable or script to hide from on-disk detection. I'm going to show you how to detect it with command line tools in this thread.

github.com/hackerschoice/…Image
First, it only encrypts the binary at rest on disk. It is not encrypting the running process. This will evade legacy file scanning with YARA, etc. that is unreliable on Linux and I don't recommend using. The running process has no encryption so that is our detection target.
I encrypted a netcat binary. See the directory of encrypted and unencrypted binaries? Notice the size, and also notice I gzipped the binaries. Encrypted binaries do not compress well. This is a cheap "is this encrypted or not" check. Image
Running netcat as a listener we see it running here in the process listing. Again, once running the encrypted protection is gone and we will focus our efforts there. Image
We'll got to /proc/PID directory and do a quick investigation. A simple 'ls' directory listing gives us our first clue with the weird link of the exe to memfd:. Binaries should not be running out of a memfd: socket unless they are hiding. Image
Since the running binary is not encrypted, we'll grab it from memory so we can analyze it off the host at our leisure. This is very easy even if in a memfd socket:

cp /proc/PID/exe /tmp/malicious.bin Image
Inspect the file descriptors of a suspicious process by going to /proc/PID/fd.

With the fileless memfd attacks, the file descriptors will tell you what kind of file is being stored. A binary (ELF) file in a memfd: socket is bad news. Image
Image
We can see also if it's network enabled even if hiding this kind of thing in system tools like netstat/ss by looking at the /proc/PID/stack. The accept() call references are a dead giveaway it's likely a backdoor/server. Image
lsof -p PID shows a condensed snapshot that may also be useful. Image
The encrypted file can also be found if you check for high entropy scripts/binaries hanging around. We have a free tool to help with this called sandfly-entropyscan.

github.com/sandflysecurit…Image
The attack generates many alerts in @SandflySecurity as a process running from a memfd socket is virtually always malicious. Here's some of what we find if this tool is being used. Image
Image
Image
Image
Overall, a neat tool to protect a payload on disk from traditional file scanning detection, but exposed once running.

• • •

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

Keep Current with Craig Rowland - Agentless Linux Security

Craig Rowland - Agentless Linux Security 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 @CraigHRowland

Aug 14
@Phrack had a great article on leaked North Korean APT operations, including a Linux stealth rootkit with backdoor. I took a look at this backdoor and and wanted to share detection tips. Full article at the end of this thread. Image
Image
First, this rootkit is based on the khook library. This is a common rootkit base that allows full stealth for processes, network connections, files, etc. This is what @SandflySecurity sees when the rootkit is active. It's only stealthy if you aren't looking! Image
Like many LKM rootkits, it will be extremely fragile and needs to be built for the victim kernel version. When installed the first thing it does is drop persistence files and insert the module to hide them and itself. Here are some files in /etc and /lib it hides. Image
Image
Read 19 tweets
Aug 9
Since I apparently have so many safe fans, let's talk about my favorite safe type: Mosler Round Doors. They are absolute tanks with interesting features. Image
Image
Mosler made excellent vaults and safes of superior security and design. The round doors are my favorite as they are the absolute strongest design. The door rotates and locks into lugs when you turn the T handle. The bolts just keep the door from spinning unlocked. Image
Here we see the open door. The strength comes from the lugs. The door lugs you see here close into the frame. When you spin the handle the entire door rotates and the door lug slips in behind the frame lugs. Image
Read 11 tweets
Aug 9
I recommend placing a 24/7 monitored smoke alarm above your safe. Cutting tools make a lot of smoke and this would set off the alarm and get help dispatched while scaring off attackers. Here is a thread of burglarized safe photos I've seen or were taken by others with advice. Image
ISM Jeweler's safe on display floor of safe company. Attacked with oxyfuel torch. This is Hollywood tier non-sense and would never work on this type of safe. Image
Image
Image
Image
Photo someone took of an attempted peeling attack. Safe peeling is old school method of prying at a corner to separate layers and peel the safe open. Mainly a risk to fire safes and junk gun safes which are NOT burglary safes. Image
Read 10 tweets
Jun 23
The SCTP protocol on Linux provides a reliable and stealthy way to access Linux. In this thread I'm going to demonstrate a simple SCTP backdoor and how it can be missed by security teams. Then I'll show you how to look for this kind of activity. Image
SCTP is a protocol mainly used for telcos. It provides reliable transport like TCP, but is not TCP. Be aware that network monitoring may not be paying close attention to SCTP and packet filters can be mis-configured to not block it.
The main thing to know is that SCTP is enabled on heaps of Linux systems but it's rarely used. So if you see it being used, and you are not a telco, you need to be paying attention.
Read 12 tweets
Jun 15
The /proc/net/packet file on Linux shows you all open raw sockets that are grabbing network traffic. I'm going to show you what is in this file and provide a script that lists all processes sniffing traffic to help find malicious sniffers. Image
Image
The /proc/net directory contains files that shows protocol use on Linux. The /proc/net/packet file shows you all open raw/packet sockets which means the process is sniffing traffic. The file shows you open inodes and who owns them, but doesn't list the process doing the deed. Image
This file is stiched together with tools like lsof to show process data, but it can be useful to do it yourself or with a simple script to make sure you are getting the data directly and avoiding processes that may manipulate lsof, netstat, or ss output to hide.
Read 9 tweets
Jul 29, 2024
It is a total myth that you need agents on Linux to find attackers. It can all be done in user space and there is no reason to risk system stability doing kernel telemetry science projects across your org. Thread...
First, people think attackers always deploy stealth rootkits on Linux, but this is absolutely not the case. Most attacks are plainly obvious, but many are not found because nobody is looking. Kernel monitoring offers no advantage in finding typical attack patterns.
However, even the stealthiest of Linux stealth rootkits eventually does something to get caught. I've never seen a stealth rootkit in the wild that was perfect, and most of them horribly break things. Detecting rootkits does not require kernel kung-fu.
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!

:(