« A Volatility Plugin Created for Detecting Malware Used in Targeted Attacks | Main R E C E N T Nov 19, 2015 Decrypting Strings in Emdivi A Volatility Plugin Created for Detecting Malware Used in Targeted Attacks Decrypting Strings in Emdivi Emdivi and the Rise of Targeted Attacks Hello, this is You ‘Tsuru’ Nakatsuru at Analysis Center. in Japan The 5th CERT-RO Annual International As introduced in the previous blog post, my colleagues presented on the attacks arising Conference in Bucharest and Latest in Japan at CODE BLUE 2015, entitled “Revealing the Attack Operations Targeting Cyber Security Trends in Romania Japan”. APCERT Annual General Meeting and Conference 2015 in Kuala Lumpur In this entry, I will introduce the details of an IDAPython script VPN Servers Altered by Attacker Leading “emdivi_string_decryptor.py”, which JPCERT/CC developed to analyse Emdivi, a remote to Scanbox, a Reconnaissance control malware. The script was also introduced in our presentation at CODE BLUE 2015. Framework Please utilize the script along with the codes, etc., that are already published on Enhanced Protected Mode in Internet JPCERT/CC’s GitHub account. JPCERTCC/aa-tools · GitHub https://github.com/JPCERTCC/aa-tools Encrypted Strings within Emdivi Emdivi encrypts strings such as URLs that they connect to and stores them in itself. Depending on the sample, encrypted strings are Base64-encoded and stored as in Figure 1, or in other cases, just saved in an encrypted binary format. Explorer PoisonIvy adapts to communicate through Authentication Proxies The 27th FIRST Annual Conference in Berlin Protected Mode in Internet Explorer C A T E G O #APCERT #FIRST #Incident management #JPCERT news #Threats #Trends in Japan #Tsubame #Vulnerabilities Africa India Indonesia Laos Mongolia Myanmar Pacific Islands Sri Lanka Thailand A C C E S S A Volatility Plugin Created for Detecting Figure 1: Encrypted strings encoded with Base64 Malware Used in Targeted Attacks In the incident analysis phase, these encrypted strings need to be decrypted in order to Emdivi and the Rise of Targeted Attacks in Japan identify information such as URLs that the malware connects to, etc. For this purpose, JPCERT/CC developed emdivi_string_decryptor.py. Analysis of a Recent PlugX Variant - “P2P PlugX” Analysis on Emdivi’s Decryption Process A New UAC Bypass Method that Dridex Uses Emdivi runs the following process in order to decrypt the strings in itself. Decrypting Strings in Emdivi The 5th CERT-RO Annual International Upon its startup, it calculates the key for decryption, based on the following string Conference in Bucharest and Latest information: The sample’s version strings Cyber Security Trends in Romania APCERT Annual General Meeting and Conference 2015 in Kuala Lumpur e.g. t17.08.26..3340.4444 Random long strings in the sample e.g. jp5cQEhSR7xMEdv1JOjh5eKGsMxSCAE5M57CijC8VgN1KMbBvP9 VPN Servers Altered by Attacker Leading to Scanbox, a Reconnaissance Framework PoisonIvy adapts to communicate through Authentication Proxies (Omitted hereafter) Fiddler Core's insecure Default flag may lead to Open Proxy Issue It then combines these strings with Base64 encode, MD5 hash value calculation and others to calculate the decryption key as in Figure 2. Depending on Emdivi’s version, it L I N K S sometimes combines addition and other arithmetic process for this calculation. JPCERT homepage Follow us @jpcert_en RSS feed Figure 2: Calculated decryption key Using the decryption key calculated here, Emdivi performs decryption just before it uses the strings. Processes related to the encryption are implemented as classes. Figure 3 shows information of those classes. Figure 3: Encryption related classes defined within Emdivi Many samples of Emdivi use XxTEA as in Figure 3, but we have confirmed that some versions use AES. Also, there are some versions that switch the encryption and decryption process, and we have seen that some use XxTEA encryption process for decryption. After analysing various samples of Emdivi, we were able to summarise the method for the decryption key calculation and the decryption process as in Chart 1 below. For details of the decryption key generation process, please refer to the source codes of emdivi_string_decryptor.py. Table 1: Decryption process for each Emdivi version t19 and t20 mid t17 versions Decryption process Method to calculate decryption key XxTEA XxTEA Encryption AES Encryption Decryption MD5 ( scanf( MD5 (base64 (ver)) "%x%x%x%x", [:24] + Inc_Add(ver17_key) MD5 (key_string)) ) Before Using emdivi_string_decryptor.py Since emdivi_string_decryptor.py is an IDAPython script, it requires disassembler IDA for execution. Also, the version string used when calculating the decryption key is required for string decryption. Before actually using the tool, you have to obtain the version string from the memory or communication data. If you are obtaining the string from the memory, execute Emdivi in an analysis environment and then search for the string in the memory by using debugger, etc. You do not have to worry about virtual environment detection, since the version string is generated before the detection process. If you are obtaining the version string from the communication data, you would need to decode that data. For decoding, you can use emdivi_postdata_decoder.py which is also made public together with emdivi_string_decryptor.py. Here below is what you will see when executing by giving the data you want to decode to emdivi_postdata_decoder.py’s argument. > python emdivi_postdata_decoder.py "r13ftV=C% 5DZ% 03k% 07% 06% 7Edkgd% 05% 19% 7Dq% 05% 05% 1E% 0D% 02% 0C;yhmsuRvo=% 00;date=- Contributor info A R C H I V November 2015 October 2015 September 2015 August 2015 July 2015 June 2015 May 2015 April 2015 March 2015 February 2015 More... C A T E G O #APCERT #FIRST #Incident management #JPCERT news #Threats #Trends in Japan #Tsubame #Vulnerabilities Africa India Indonesia t20 early and late versions Laos Mongolia Myanmar Pacific Islands Sri Lanka Inc_Add(ver17_key) Thailand b% 27f.4% 60% 25% 23% 3A% 24% 2C% 3A% 26% 22% 3A% 3A% 27% 27% 20% 24% 3A% 20% 20% 20% 20% 1Dh% 1DZ% 40.4% 22% 3A% 25% 3A% 23% 22% 24% 25% 1DO% 7Eu9% 5EDI% 1Dh% 1DYQY.4% 26% 24% 20% 2CY% 1Dh% 1DSY% 40% 3C- % 3D" [*] 3 field(s) found in postdata "r13ftV" -> "win7_32JP_SP1-IE11*968" "yhmsuRvo" -> "1" "date" -> "9v3r: t17.08.26..3340.4444 | NT: 6.1.7601 [ja-JP] | MEM: 2048M | GMT(9)" Please note that the version string included in the communication data may be different from the string required for the decryption. Therefore, we recommend obtaining the string from the memory. Executing emdivi_string_decryptor.py If you have obtained the version string, you are all set. Load the target Emdivi into IDA, and execute emdivi_string_decryptor.py. Then, it will process as follows: 1. Input version string 2. Calculate decryption key 3. Search for encrypted string 4. Decrypt string 5. Output results and insert comments in the corresponding section Upon execution of emdivi_string_decryptor.py, the following dialog box appears to input the version string. Figure 4: Dialog box to input version string After you input the version string, the tool will display the decrypted string in the console, and it will be inserted as a comment to where the encrypted string is stored. This is shown in Figure 5. Figure 5: Screenshot after executing emdivi_string_decryptor.py Now you can obtain various information including URLs that the malware connects to. Based on these and other related pieces of information, JPCERT/CC coordinates and handles incidents caused by attack operations involving Emdivi. In Summary We hope that the scripts that we made public will contribute in dealing with the attacks relating to Emdivi, and in improving malware analysis techniques. A blog entry by Kaspersky (see Reference) has revealed that a few versions of Emdivi use the infected users’ SID. Unfortunately, the current version of emdivi_string_decryptor.py is not yet adapted to input SID. Furthermore, it is possible that new versions of Emdivi with other encryption methods may emerge in the future. We welcome any pull requests on GitHub. Thanks for reading. -You Nakatsuru Reference New activity of The Blue Termite APT - Securelist https://securelist.com/blog/research/71876/new-activity-of-the-blue-termite- apt/ Posted on Nov 19, 2015 in #JPCERT news, #Threats, #Trends in Japan | Permalink