sshbackdors-dumont2018

0001-01-01

The Dark Side of the ForSSHe - A landscape of OpenSSH backdoors

by Romain Dumont, Marc-Etienne M.Leveille, Hugo Porcher

ESET Research, December 2018

This is a paper about OpenSSH backdoors seen in the wild between 2015 and 2018.

https://www.welivesecurity.com/2018/12/05/dark-side-of-the-forsshe/

Notes
Linux Malware
The analysts talk about how it was hard for them to gather data due to telemetry limitations on their Linux systems
Windigo https://www.welivesecurity.com/2014/02/21/an-in-depth-analysis-of-linuxebury/
most observed sshd backdoors shared the same rough feature set
21 openssh malware families were observed, 12 of which were undocumented.
the ssh backdoor used by DarkLeech operatirs is the same one used by Carbanak
ssh backdoors used by both APT groups and ecrime
Eset discovered several C2 servers that had been running for years during this process
Families: Abafar, Alderaan, Anoat, Akiva, Ando, Atollon, Batuu, Bespin, Bonadan, Borleias, Chandrila, Crait, Coruscant, Endor, Jakku, Kamino, Kessel, Mimban, Onderon, Polis Massa, Quarren
Ebury
Ebury - openssh backdoor + credential stealer
Ebury runs a Perl script through ssh to perform reconniassance, wipe logs, detect honeypots, detect LD_PRELOAD, and ForceCommand OpenSSH option
Ebury enumerates Linux distribution and version
Ebury enumerates installed software
Ebury checks for other known OpenSSH backdoors
Ebury checks /usr/bin/ssh and /usr/sbin/sshd for byte patterns indicating other backdoors
this is a large amount of signatures for specific families as well as generic signatures to detect unknown strains
Ebury will steal credentials from other openssh backdoors
Ebury checks for rootkits by comparing /proc/modules and /sys/module
Ebury alters package manager metadata (debsums, rpm) to make it look legitimate
Ebury waits a few days before embedding after the recon script is ran
Ebury backdoor sends daily collections of credentials collected and data on how the system was ran (last command, .bash_history, …)
Eset researchers translated signatures from the recon script to YARA rules to help hunt.
some of the signatures were difficult to implement as YARA rules and had high percentage of false positive
signatures were iterated and made better over time.
Bonadan uses code from Onderon - lots of relationships like this observed
strings and code obfuscation
Some samples used UPX
XOR string encryption was the most common
several samples used stack strings to obfuscate strings
client-based malware hooked these functions: userauth_passwd, ssh_askpass, try_challenge_response_authentication, input_userauth_info_req, input_userauth_passwd_chagereq
in a few rare cases, load_identity_file steals passphrases from private keys
server-based malware hooked: auth_password, sshpam_respond, sys_auth_passwd, sshpam_auth_passwd, server_listen
almost every sample stored the credentials to a local file.
the path of the stolen credentials usually blended in with the filesystem
lots of code reuse with publicly-available PoCs
commonly found in /usr/include or /usr/share.
many logs have .h file extensions
/usr/lib with a .so extension
/usr/share/man with a .gz extension
tmp w various extensions
/usr/local/include with .h extension
many encrypted the file contents with simple methods: xor, not, sub w/ single byte key,
AES - Atollon malware
3DES - Bespin malware
RC4 - Crait malware
many log files shared the same formats:
“+user: %s +password: %s\n”
“+host: %s + +user: %s +password: %s\n”
“ssh: ~(av[%d]: %s\n”
“IN: %s at: %s | user: %s, pass: %s\n”
“user:password -> %s:%s\n”
“passwd from: %s \tuser: %s \tpass: %s \n”
“%s:%s\n”
9 out of the 21 backdoors observed exfiltrated credentials over the network in addition to saving to a file.
HTTP
Custom TCP protocol
Custom UDP protocol
used common ports such as 80, 443, 1194 (OpenVPN)
Kessel malware exfiltrated over DNS
some client backdoors used email using the mail command
most families added a hard-coded password to retain access
many were hard coded
some protected the password with crypt() or bcrypt()
some protected the password with md5
many backdoors tampered with sshd to allow root logons despite the configuration of sshd_config
auth_root_allowed
do_setusercontext
permanently_set_uid
getpwnamallow
userauth_finish
many had settings that turned off logging while the attacker’s account was logged in
this includes sshd logging and setting HISTFILE/HISTSIZE environment variables
hooked logging functions: do_log, record_login, record_logout, auth_log, login_write, do_pam_session,
sshpam_cleanup, sshpam_auth_passwd, log_facility_number, debug, verbose, logit, error, ssh_userauth2
Chandrila
Chandrila malware
logs passwords locally
“S%s %s: %s”
base64 encoded
sends over UDP port 32784
has two special passwords
if password 1 is found, it establishes a reverse shell to the IP address to the address appended to the password
if password 2 is found, it runs a command using the appended data
Bonadan malware
based on Onderon malware
includes a cryptocurrency miner
attempts to remove existing miners if they are present
writes miner payload to tmp.abc
has ability to execute bind shells, reverse shells, arbitrary commands, update c2 config remotely
Kessel
Kessel malware
most advanced observed by Eset
uses DNS protocol for c2
uses RC4 encryption
exfiltrates local username that it steals credentials from
Kamino
Kamino malware https://www.welivesecurity.com/2013/01/24/linux-sshdoor-a-backdoored-ssh-daemon-that-steals-passwords/
observed being used in conjuction with a malicious Apache module “DarkLeech”
backdoor is used by Carbanak/Anunak
appears to be motivated by financial gain
Honeypots
high interaction, low interaction
Mimban
Mimban malware
logon from Russia
unset HISTFILE
manually entered commands
Borleias
Borleias malware
used Tor
used credentials used by Mimban operators, alluding credentials were sold, given to, or collected from Mimban attackers
took a copy of the cron binary
used timestomping on trojanized binaries
used a bash script to collect data about the host
set HISTFILE to /dev/null
very careful operators; checked ps and logged in users often
dropped Crait backdoor
Mitigation suggestions
PermitRootLogin no
complex passwords
disable password authentication
protect sudo access
MFA: OATH toolkit, google-authenticator-libpam
verify package manager contents
look at libraries loaded by OpenSSH (Ebury altered legitimate libkeyustils.so)
Analyze outbound traffic