The Archaeologologogology #2 – the romantic view as seen through the winlogon.exe’s window…

November 27, 2016 in Archaeology, Reversing

Every once in a while people report that they suspect their systems to be infected. This is because they discover their winlogon.exe uses a very unusual, and definitely suspicious icon – the one with a the Moon, and the stars:

winlogonYou won’t see this on Windows 8 or 10 anymore, but if you look at the resources of winlogon.exe you can still find the icon there:

winlogon10Looking for the code referring to ID 14 inside the Windows 10 winlogon.exe doesn’t show any immediate results. We can try to do the same with winlogon.exe from Windows 7 – one of the OSs on which the icon is still visible directly in the Windows Explorer pane. I couldn’t find the code either, but I noted that this time the icon was listed under a different ID (notably, Windows XP lists it under the very same ID):

winlogon7First, let’s try to explain why the icon is no longer visible inside the Windows Explorer on Windows 10&8.

When Explorer chooses the icon to show for a given executable it enumerates the resources inside the file and searches for the first one that is defined as RT_GROUP_ICON (which is a bit like a set of icons – the good ol’ Resource Hacker shows it under the “Icon Group” branch). As a side note, the most typical way RT_GROUP_ICON lists are defined makes the very first icon we see on the list of icons inside Resource Hacker the one that is used by Windows Explorer.

Let’s have a look at the winlogon.exe icon groups from Windows 7.

winlogon10-iconsThe first one is ‘IDD_APPLICAITON_ICO’.

(As a side note, you have probably noticed the typo i.e. ‘applicaiton’ vs. ‘application’ in the ‘IDD_APPLICAITON_ICO’ ID name. It is actually quite an important mistake and I will explain why later on)

On Windows 7 it is slightly different:

winlogon7_iconsRight, so it’s ‘IDD_SHUTDOWN_BITMAP’, and the only icon in this set is… the Moon&the stars.

Going a bit further back, the Windows XP doesn’t use the name, but the number 4:

winlogonxpSo, we see the icon on Windows XP and 7, because it’s the very first RT_GROUP_ICON listed.

One mystery solved.

Let’s come back to the resource names we came across inside winlogon.exe from Windows 10. The name of the ‘IDD_SHUTDOWN_BITMAP’ may look familiar – if you take another look at that window (see below) you will notice that the developers inserted ‘IDD_APPLICAITON_ICO’ right above the ‘IDD_SHUTDOWN_BITMAP’ group – we can also confirm the latter is the very same icon group as in Windows 7 and on Windows XP:

winlogon10-icons2So, it’s obviously a cosmetic change intended to replace the romantic icon with a boring default application image in the newer versions of Windows.

If we take yet another look at the Icon Groups above, there is one more detail that is quite striking. There are 2 groups that use names (prefix ‘IDD_’) and 2 that use numbers.

Was it intentional?

I don’t think so.

The way Resource compiler works is that when the resource files (files with the extension .rc /which I believe are still used to build the ‘old’ executables even on Windows 10/) are compiled, the parser is looking for definitions of resource IDs which other resources may later refer to. Typical way to use the ID names is by using the approach shown below.

Inside the header file (resource.h) you write something along these lines:

#define IDD_SHUTDOWN_BITMAP 4

and later, you can refer to this resource by using the defined name (inside the .rc file):

IDD_SHUTDOWN_BITMAP ICON "moonstars.ico"

The funny side-effect (a bug/feature?) of the resource compiler is that it does not complain when it comes across a resource name that has not been defined earlier. In such cases it will blindly assume that it is… a string (a text). The root cause for this is that resource ID can be both numbers, and strings, so the arbitrary decision by the Resource Compiler to treat all unknown resource names as strings creates situations we see demonstrated on the above screenshots. Note that I intentionally chose to define IDD_SHUTDOWN_BITMAP as 4 (#define IDD_SHUTDOWN_BITMAP 4) to bring your attention to the difference between Windows XP (Icon group is number 4) and Windows 7 (icon group is a textual name ‘IDD_SHUTDOWN_BITMAP’).

The winlogon developer most likely modified the source code and removed a number of things between XP, Vista and 7, but failed to remove:

  • the icon itself
  • the group icon resource
  • and even if these 2 were meant to stay, the dev most likely removed the ‘IDD_SHUTDOWN_BITMAP’ declaration from the header file – this made the resource compiler incorporate the actual constant name into the compiled resource!

And this is where I can come back to the typo I mentioned earlier & why is it important. What I believe happened is that the dev declared:

#define IDD_APPLICATION_ICO <some number>

inside the header file, but then inside the .rc file referred to the name making a typo :

IDD_APPLICAITON_ICO ICON "moonstars.ico"

Resource Compiler couldn’t find the declaration of IDD_APPLICAITON_ICO and decided to treat it as a string.

So, it’s an unintentional data leakage in both cases as we learn about constants used in the source code 🙂

Finally, it’s time to reveal what was the purpose of the romantic icon…

Luckily, this is actually quite simple: by checking what other stuff can be found inside resources of winlogon.exe from XP, we can discover this dialog box definition:

winlogonxp_dialogand which Resource Hacker allows us to preview as:

winlogonxp_dialog2This is a dialog box that would pop up on ancient versions of Windows NT (before APM became a standard?) – luckily someone made a youtube video how it looks like so you can confirm it yourself.

The code referring to it is still partially present inside the winlogon.exe from Windows XP, but the dialog template is not really used after being loaded.

The described typos, partially removed code, and the ancient artifacts still present in Windows 10 should be a good excuse for anyone interested in reversing and forensics to explore the system internals more – fundamentally, reversing is reading other peoples’ code and bugs are a norm & knowing how tools that build programs work allow us to better understand the root cause of some of these mistakes.

3M samples – random stats

November 26, 2016 in Clustering, Malware Analysis, Visualisation

It’s been a while since I published some stats on a substantial corpora of samples, so here’s a quickie – re-visiting the compilation timestamp.

Three things to note:

  • these stats are biased (I don’t have all the malware under the Sun)
  • many samples in 2015-2016 show traces of compilation tampering so compilation timestamp is no longer reliable
  • many malware samples are Delphi samples and their timestamps are wrong

Still… quasi-scientific pictures are always nice to look at 😉

  • 3M samples, excluding non-sensical timestamps (I may investigate that spike in July 2015 one day):

3m

  • 3M samples, compilation time by the day of the month (end of the month = time to wrap it up and procrastinate):
    3m_dayofthemonth
  • 3M samples, compilation time by the day of the week (weekends are defo a thing for everyone):
    3m_dayoftheweek
  • 3M samples, compilation time by the hour (Europe is a malware cradle, apparently):
    3m_hour
  • 3M samples, compilation time by the hour:minute (I have no idea what it shows):
    3m_hour_minute_condensed