SHA1:
- 4af24c9f6815c8b0f5d0b44cc9040cdd7d828d96
It is a Trojan for Android whose examined sample looks as follows:
/data/system/.loki/loki32
The Trojan’s main purpose is to incorporate the liblokih.so library into the system_server process and execute commands using root privileges.
Along with the system, the loki32 process is launched and waits until the system is completely booted up. After that, the malicious application scans the /proc directory, which contains information about processes, state and configuration of the system and the kernel, and searches for a process whose value is set to "system_server" in the /proc/<pid>/cmdline file.
The Trojan then receives relative function addresses necessary for the injection:
libcAddr = getAddressFromMaps(v1, "/system/lib/libc.so");
linkerAddr = getAddressFromMaps(v0, "/system/bin/linker");
mallocAddr = (int)&malloc - libcAddr;
dlopenAddr = (int)&dlopen - linkerAddr;
dlcloseAddr = (int)&dlclose - linkerAddr;
dlsymAddr = (int)&dlsym - linkerAddr;
dlerrorAddr = (int)&dlerror – linkerAddr.
The getAddressFromMaps function parses the /proc/self/maps file, which contains a process memory map, and finds the first line that corresponds to the required library. It may look as follows:
40020000-40065000 r-xp 00000000 1f:00 363 /system/lib/libc.so
It extracts the first number from this line, and the injection procedure is then executed:
inject(ss_pid, "/data/system/.loki/liblokih.so", "load_loki", "");
This function receives the PID value of a process into which the injection will be performed, a path to a library that needs to be downloaded, and a name of a function in this library that needs to be executed. The injection procedure is carried out using the ptrace system call that is mainly implemented by debuggers. Once the process is “killed” with the help of the PTRACE_ATTACH function, the Trojan connects to it and can read and modify the state of its memory and registers. The PTRACE_GETREGS function helps the Trojan receive the registers values. Then, using PTRACE_SETREGS, the malicious program modifies them to perform the necessary function. After that, the process is started once again using PTRACE_CONT.
Moreover, if Android.Loki.3 gets root privileges, it can execute commands received from Android.Loki.1.origin and Android.Loki.2.origin. Thus, Android.Loki.3 is, in fact, a server that launches shell scripts—the Trojan receives a path to a script, which needs to be executed, via a local socket, and Android.Loki.3 launches this script.