Unlocking LockScreen

2013-07-01

Walter (Tiezhu) Kong

Fortinet, Canada

Kyle Yang

Fortinet, Canada
Editor: Helen Martin

Abstract

During their analysis of LockScreen, Walter Kong and Kyle Yang found that this piece of malware uses more anti-debug tricks than a lot of other the malware. Here, they will detail the anti‑debug tricks before shedding light on the communication protocol and encryption algorithm between the bot and the C&C server.


LockScreen is characterized by a piece of malware that locks the victim’s screen, displays the logos of a police department or law enforcement agency and accuses the victim of having committed an offence. To unlock the computer, the victim is asked to pay a small fine through an electronic payment service such as Paysafecard, Ukash, etc. It may also impersonate an officially recognized organization in charge of collecting taxes or various fees, or even a fictitious organization that claims to be responsible for collecting such payments. Figure 1 shows an example.

Example of LockScreen.

Figure 1. Example of LockScreen.

During our analysis of LockScreen, we found that this piece of malware uses more anti-debug tricks than a lot of the malware we usually see. In this article, we will detail all the anti‑debug tricks before shedding light on the communication protocol and encryption algorithm between the bot and the C&C server.

Anti-debug tricks

1. Kernel API modification

The first anti-debug trick we faced was ‘kernel API modification’. In this case, LockScreen redirects its code flow by modifying the ZwClose API. First, it gets the ZwClose API by calling the GetProcAddress function, then it backs up the first five bytes of ZwClose to a specific location for future restoration. Finally, it adds an unconditional jump which leads the code flow back to itself. Figure 2 shows the ZwClose modification routine, and Figure 3 shows the modified ZwClose function.

ZwClose modification routine.

Figure 2. ZwClose modification routine.

(Click here for a larger view of Figure 2.)

Modified ZwClose API.

Figure 3. Modified ZwClose API.

After the modification, it calls the LocalFree API, which eventually calls the modified ZwClose API.

2. Debug port check via ZwQueryInformationProcess API

LockScreen will determine whether a debugger is attached to a process by calling the ZwQueryInformationProcess API with the ProcessInformationClass parameter set to 7 (ProcessDebugPort). This API will query the DebugPort field of the EPROCESS kernel structure. A non-zero value in the DebugPort field indicates that the process is being debugged.

Check debug port.

Figure 4. Check debug port.

3. Hide thread from debugger via ZwSetInformationThread API

The ZwSetInformationThread is usually used for setting a thread’s priority. However, it can be used to prevent a debugging event from sending from the kernel function bgkpSendApiMessage(). Figure 5 shows an example of such a technique.

Hide thread from debugger.

Figure 5. Hide thread from debugger.

In Figure 5, ThreadHideFromDebugger (0x11) is set to the ThreadInformationClass parameter when calling ZwSetInformationThread, which results in the ThreadHideFromDebugger setting the HideThreadFromDebugger field of the ETHREAD16 kernel structure. Therefore, the send event to the debugger function is never invoked.

4. Hide all via the SwitchDesktop API

Windows NT-based platforms support multiple desktops, and it is possible to select a different active desktop. LockScreen will create a desktop by calling CreateDesktop with GENERIC_ALL set to dwDesiresAccess. After that, it invokes the SwitchDesktop API (Figure 6), which results in the OS switching to a new desktop which is used for LockScreen to display the scam screen. It will hide the previously selected desktop, with no obvious way to switch back to the old one with our debugger on it.

SwitchDesktop.

Figure 6. SwitchDesktop.

Communication protocol and encryption algorithm

Injection

LockScreen first lands in the explorer.exe process via injection, then it injects its core code into the svchost.exe process. The injected code creates three threads which kill the taskmgr.exe process, create an autorun registry entry and copy the malware to a specific location. After that, it tries to use the SwitchDesktop API in a loop as a final barrier to the communication routine (see Figure 7).

SwitchDesktop loop.

Figure 7. SwitchDesktop loop.

Preparing communication data

To prepare the communication data, LockScreen first retrieves the computer name and turns it into a hash by using a custom algorithm. Then it gets the C:\ VolumeSerialNumber by calling the GetVolumeInformation API. Finally, it retrieves the OS minor version by calling the GetVersionEx API. All of the gathered information will form into the structure shown in Figure 8.

Basic computer information.

Figure 8. Basic computer information.

Next, it encrypts the above data using the RC4 algorithm with the result of the current time-stamp multiplied by 0x18D as the key (QWORD). After the encryption, it will prepend the key to the encrypted data.

Encrypted basic computer information.

Figure 9. Encrypted basic computer information.

Generate C&C URL

In order to generate the C&C server domain name and URL, it will decrypt data from a specific location in the sample using the following algorithm:

data = ((data & 0xFFFF0000) >> (key & 0xFFFF)) ^ (key & 0xFFFF) + ((data & 0xFFFF) >> (key & 0xFFFF - 1) ^ (key & 0xFFFF - 1)

After decryption, it shows the following data:

Decryption result.

Figure 10. Decryption result.

It will use the above results and the previously prepared encrypted data to generate the C&C URL via the custom algorithm shown in Figure 11.

C&C URL generation algorithm.

Figure 11. C&C URL generation algorithm.

The result of the generation is shown in Figure 12.

C&C URL.

Figure 12. C&C URL.

In this way, it hides the basic computer information within the C&C URL, which gives the C&C’s URL random characteristics and makes it hard to detect.

Response data from C&C server

After sending the information, the C&C server will send a big chunk of data back to the bot. First, let’s take a look at the header – which is shown in Figure 13.

Header of C&C response data.

Figure 13. Header of C&C response data.

After decryption with the RC4 key and data length specified in the header, it shows the data shown in Figure 14.

C&C response data (clear text).

Figure 14. C&C response data (clear text).

Note that if the DWORD (offset 0x0C) is 0x464C4553(SELF), it will quit. Only when the DWORD is 0x4b5000(PK) will it decompress the data and write it into 49 different local files which will be used to display the scam page.

In order to display the scam page, it still needs some other information, such as IP address, geo location, etc. This information is actually encrypted in another location of the response data, as shown in Figure 15.

Additional information (key and encrypted data).

Figure 15. Additional information (key and encrypted data).

After decryption, it shows:

Additional information (key and encrypted data).

Figure 16. Additional information (key and encrypted data).

It will use the above information to fill the scam page and display it as shown in Figure 1.

Conclusions

LockScreen implements many different anti-debug tricks; the purpose is obvious: to make debugging tougher. However, if we are aware of those tricks and can figure out a way to bypass them, the malware will have nowhere to hide.

twitter.png
fb.png
linkedin.png
hackernews.png
reddit.png

 

Latest articles:

Nexus Android banking botnet – compromising C&C panels and dissecting mobile AppInjects

Aditya Sood & Rohit Bansal provide details of a security vulnerability in the Nexus Android botnet C&C panel that was exploited to compromise the C&C panel in order to gather threat intelligence, and present a model of mobile AppInjects.

Cryptojacking on the fly: TeamTNT using NVIDIA drivers to mine cryptocurrency

TeamTNT is known for attacking insecure and vulnerable Kubernetes deployments in order to infiltrate organizations’ dedicated environments and transform them into attack launchpads. In this article Aditya Sood presents a new module introduced by…

Collector-stealer: a Russian origin credential and information extractor

Collector-stealer, a piece of malware of Russian origin, is heavily used on the Internet to exfiltrate sensitive data from end-user systems and store it in its C&C panels. In this article, researchers Aditya K Sood and Rohit Chaturvedi present a 360…

Fighting Fire with Fire

In 1989, Joe Wells encountered his first virus: Jerusalem. He disassembled the virus, and from that moment onward, was intrigued by the properties of these small pieces of self-replicating code. Joe Wells was an expert on computer viruses, was partly…

Run your malicious VBA macros anywhere!

Kurt Natvig wanted to understand whether it’s possible to recompile VBA macros to another language, which could then easily be ‘run’ on any gateway, thus revealing a sample’s true nature in a safe manner. In this article he explains how he recompiled…


Bulletin Archive

We have placed cookies on your device in order to improve the functionality of this site, as outlined in our cookies policy. However, you may delete and block all cookies from this site and your use of the site will be unaffected. By continuing to browse this site, you are agreeing to Virus Bulletin's use of data as outlined in our privacy policy.