|
| 1 | +\newpage |
| 2 | + |
| 3 | +# State of the art |
| 4 | + |
| 5 | +In this part, we will dive into the concept of evasion. Malware authors are |
| 6 | +ahead of the analyst and it is a lead they have to maintain. To this end, they |
| 7 | +deploy more and more techniques to make harder the analysis and comprehension |
| 8 | +of their code. Against static analysis they use obfuscation, encryption and |
| 9 | +such, as for dynamic ones they use evasion. |
| 10 | + |
| 11 | +The concept of evasion refers to all the techniques used by a malware to hide |
| 12 | +its behaviour according to its environment. For instance, if a malware detects |
| 13 | +a sandbox (from an analyst or an antivirus), it will make low profile to so as |
| 14 | +not to arouse suspicion. One of the most known example of this is the Red Pill |
| 15 | +demonstration (reference to the legendary film *The Matrix*) presented by |
| 16 | +Joanna Rutkowska in 2004 – just two years before she presents the Blue |
| 17 | +Pill attack which is a type of *hyperjacking*. |
| 18 | + |
| 19 | +Red Pill is a small piece of code written in C that checks the address of the |
| 20 | +*Interrupt Descriptor Table* (IDT). The address of this table has to be |
| 21 | +modified by the hypervisor to avoid memory conflicts. Therefore, there is a |
| 22 | +correlation between the address being superior to `0xD0` and the fact of being |
| 23 | +executed in a virtual machines. This technique is however less efficient on |
| 24 | +today's systems as those filter the access to certain zones of the memory, such |
| 25 | +as the DTI. It still works on *QEMU* though. |
| 26 | + |
| 27 | +```c |
| 28 | +int swallow_redpill () |
| 29 | +{ |
| 30 | + unsigned char m[2+4], rpill[] = "\x0f\x01\x0d\x00\x00\x00\x00\xc3"; |
| 31 | + *((unsigned*)&rpill[3]) = (unsigned)m; |
| 32 | + ((void(*)())&rpill)(); |
| 33 | + return (m[5]>0xd0) ? 1 : 0; |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## Linux techniques |
| 38 | + |
| 39 | +### The DMI table |
| 40 | + |
| 41 | +DMI stands for *Desktop Management Interface*. It is a standard developed in |
| 42 | +the 90' with de goal of uniforming the tracking of the components in a computer |
| 43 | +and abstracting them from the softwares supposed to run them. Parsing this |
| 44 | +table can reveal practical information on the hardware used by the operating |
| 45 | +system and possibly detect the presence of names specific to virtualized |
| 46 | +environment, such as *vbox*, *virtualbox*, *oracle*, *qemu*, *kvm* and so on. |
| 47 | + |
| 48 | +### Linux kernel's hypervisor detection |
| 49 | + |
| 50 | +Linux's kernel comes with an hypervisor detection feature that can be used to |
| 51 | +identify a potential hypervisor below the operating system. Based on this, we |
| 52 | +easily can listen for the kernel event to see if an hypervisor has been |
| 53 | +detected by the kernel: |
| 54 | + |
| 55 | +```c |
| 56 | +static inline const struct hypervisor_x86 * __init |
| 57 | +detect_hypervisor_vendor(void) |
| 58 | +{ |
| 59 | + const struct hypervisor_x86 *h = NULL, * const *p; |
| 60 | + uint32_t pri, max_pri = 0; |
| 61 | + |
| 62 | + for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) { |
| 63 | + if (unlikely(nopv) && !(*p)->ignore_nopv) |
| 64 | + continue; |
| 65 | + |
| 66 | + pri = (*p)->detect(); |
| 67 | + if (pri > max_pri) { |
| 68 | + max_pri = pri; |
| 69 | + h = *p; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + if (h) |
| 74 | + // this line prints the hypervisor in the `/dev/kmsg` file |
| 75 | + pr_info("Hypervisor detected: %s\n", h->name); |
| 76 | + |
| 77 | + return h; |
| 78 | +} |
| 79 | +``` |
| 80 | +
|
| 81 | +### Checking Linux's pseudo-filesystems |
| 82 | +
|
| 83 | +Linux provides a lot of information via a certain type of files (mostly in |
| 84 | +`/proc`) that are generated at boot and modified during runtime. A lot of |
| 85 | +binaries use this directory like `ps`, `uname`, `lspci` and so on. These |
| 86 | +information are really helpful when trying to identify wether or not you are |
| 87 | +in a virtualized environment, like UML for instance. UML refers to the |
| 88 | +aforementioned way of executing a Linux kernel in user-space. This can easily |
| 89 | +be verified by looking for the string "User Mode Linux" in the file |
| 90 | +`/proc/cpuinfo` which describes the CPU of the machine. |
| 91 | +
|
| 92 | +In the same way, a lot of these virtual *files* can provide information on the |
| 93 | +environment, including – but not limited to – `/proc/sysinfo` (in |
| 94 | +which some distribution expose data about virtual machines), |
| 95 | +`/proc/device-tree` (that lists the devices on the machine), `/proc/xen` (a |
| 96 | +file created by the *Xen Server*) or `/proc/modules` (that contains information |
| 97 | +about the loaded kernel modules, modules that are used by hypervisors to |
| 98 | +optimize the guests). |
| 99 | +
|
| 100 | +Like *procfs* (mounted in `/proc`), *sysfs* can be useful. Its role is to |
| 101 | +provide to the user an access to the devices and their drivers. The file |
| 102 | +`/sys/hypervisor/type`, for instance, is sometimes used to store information |
| 103 | +about the hypervisor Linux is running on. |
| 104 | +
|
| 105 | +
|
| 106 | +## Windows |
| 107 | +
|
| 108 | +<!-- TODO --> |
0 commit comments