SHARE
TWEET

SapphireMushroom_2

a guest Jul 12th, 2018 431 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Details Concerning Sapphire Mushroom (APT-C-21) Attack Infrastructure Uncovered
  2.  
  3. Background
  4. 360 Security released it's first report on July 5, 2018 concerning an advanced organization that has targeted my country's government, military, research community, and financial sector for almost 8 years, starting in 2011, with attacks meant for advanced espionage. Sapphire Mushroom (APT-C-12) activities have actually increased in recent months. This article is to serve as a supplement to uncover details surrounding the attack infrastructure used by Sapphire Mushroom. We hope that the security community can understand every piece of the attacker's methodology and share blue team details together in order to face this nation-state level threat.
  5.  
  6. Spearphishing emails
  7. After April of 2018, 360 Monitoring and Response Center and 360 Threat Intelligence Center observed a focused spearphishing attack campaign in which the attackers tricked users into opening the attached LNK PowerShell script that uploaded sensitive user information and files and installed a malicious backdoor for continued access and control over the user's computer.The attack methodology actually uses a pretty novel approach to using LNK files, using AWS S3 and cloud infrastructure communication protocols to exfiltrate sensitive user information. Here, we will go into more detail concerning this attack methodology.
  8.  
  9. 360 Threat Intelligence Center has confirmed multiple external phishing emails that, in part, came from the email address baoaostaff[@]163[.]com. The emails appear as if they're an invitation coming from the staff of the Baoao Forum for Asia.
  10.  
  11. (Picture of phishing email depicts a general invitation, saying "Respected [name], thank you very much for participating in this year's Baoao Forum for Asia discussion, attached is a thank you letter that we hope you will read. Thank you for your continued support" followed by a traditional Chinese closing that doesn't translate well. Notably, the Chinese appears native, to the point of being appropriately formal for the context of the counterfeited correspondence.)
  12.  
  13. Attached is a RAR file uploaded to the 163 cloud storage service, which we consider to be the malicious payload.
  14.  
  15. (Pictured is the inside of the archive file containing a file named "Public Sentiment Surrounding Internet Governance Survey.")
  16.  
  17. If the user clicks the LNK shortcut, it will execute the PowerShell script, gather and upload sensitive user information, and install the backdoor to offer continued access to the victim's computer.
  18.  
  19.  
  20. Dropper
  21. Inside of the attached archive file, there is an LNK file named "Public Sentiment Surrounding Internet Governance survey." Observing the properties of this particular file (Pictured) there is no indication of the target of this LNK file, but using a disassembler, we can see it has PowerShell executable headers and settings meant to hide details about the file.
  22.  
  23. Analyzing the LNK file, some important functions emerge that reveal the malicious intentions of the payload, including: LinkTargetIDList, COMMAND_LINE_ARGUMENTS, and EnvironmentVariableDataBlock.
  24.  
  25. LinkTargetIDList is an array that specifies a link's target. Regarding the malicious samples, putting all of the LIST elements together forms the real malicious target using a debugger:
  26.  
  27. CLSID_MyComputer\C:\Windowss\system32\windOW~1\V1.0\POwersHELl.exe
  28.  
  29. COMMAND_LINE_ARGUMENTS discerns the target program's arguments. The parameters in the sample are passed to PowerShell to be executed, but because they contain characters that can't be displayed in Unicode, the code won't be displayed when viewing the 'Properties' of the file.
  30.  
  31. Setting the EnvironmentVariableDataBlock will cause the target to be set to the corresponding value, but it should be noted that it doesn't work for the actual program call. Finally, Shell32.dll starts PowerShell by parsing the StringTargetIDList array.
  32.  
  33. Powershell Payload
  34. Decrypting the powershell payload
  35.  
  36. The following PowerShell function will decrypt the payload:
  37.  
  38. (Code Snippet)
  39.  
  40. The PowerShell script lies at the very end of the LNK file:
  41.  
  42. (Disassembler Snippet)
  43.  
  44. This portion of the LNK file is Base64 encoded, and after decoding it takes the form of [compressed package+PowerShell script].
  45.  
  46. The decrypted PowerShell script begins by executing the function ps_start.
  47.  
  48. ps_start
  49. ps_start is used to decrypt the rest of the functions and decompress the corresponding package, which contains the information stealing modules. The script is decoded using [convert]::frombase64string((gc $a|select -l 2|select -f 1))); and Base64 is again used to decrypt the compressed package file, while rundll32 is used to load beoql.g. The backdoor file (load function being DllRegister), and a PowerShell script are passed as a parameter. The PowerShell is named ps_loader:
  50.  
  51. (Code snippet)
  52.  
  53. The compressed package contains the DLL backdoor named beoql.g, a legitimate decompression program named Rar.exe, and a legitimate DOC file that was used as the lure for the user.
  54.  
  55. (Picture of the files)
  56.  
  57. The script will then try to reach out to 3 IP addresses that act as C&C servers:
  58. 159.65.127.93
  59.  
  60. 139.59.238.1
  61.  
  62. 138.197.142.236
  63.  
  64. (Code snippet)
  65.  
  66. If it succeeds in connecting to a C2 server, it will then use the command line to gather core system information:
  67.  
  68. (List of well-known command line functions)
  69.  
  70. After gathering the system information, the script uses Rar.exe to create a compressed file named start.rar and then uses RSA encryption using a random string shown below to encrypt it.
  71.  
  72. The random string will then be used as the RAR encryption password and is saved in the id.rar file, and uses the pv9 function to upload to the attacker's cloud infrastructure.
  73.  
  74. (Code snippet)
  75.  
  76. The script then searches the system for files created within the past 180 days with designated suffixes (jpg,txt,eml,doc,xls,ppt,pdf,wps,wpp,et) and continues to use Rar.exe to compress the files using the random string to encrypt the files.
  77.  
  78. (Code snippet)
  79.  
  80. The script then uses the pv9 function to upload the RAR files using the AWS S3 protocol to the attacker's cloud-based infrastructure located at 0123[.]nyc3[.]digitaloceanspaces[.]com. The program contains the ACCESS_KEY and SECRET_KEY that are expected to be required by Amazon's S3 protocol.
  81.  
  82. (Code Snippet)
  83.  
  84. (Explanation of Amazon S3 service)
  85.  
  86. The purpose of this function is to add some header values that use AWS s3 V4 signing algorithms, which look like this:
  87.  
  88. (Displayed Header info)
  89.  
  90. The highlighted functions encapsulate the request and finalize the final upload, where ul3 encapsulates the uploaded file request headers and ig3 finishes the upload. The request headers created by ul3 are stored as $9, while another important variable, Signature, is created by the a53 and e77 function. $9 is encapsulated into $g, which is the final request. The whole thing looks like this:
  91.  
  92. (Code snippet)
  93.  
  94. The final upload looks like this:
  95.  
  96. (Code snippet)
  97.  
  98. ps_loader
  99. After downloading the DLL backdoor, the ps_start function will then choose a C2 server among the 3 IP addresses and download another PowerShell script, here called ps_loader.
  100.  
  101. (Code snippet)
  102.  
  103. ps_loader will first generate the us and Cookie fields for the request, and as you can see the response is just a series of decimal numbers.
  104.  
  105. (Screenshot of request and response)
  106.  
  107. The data is then decrypted by sj8 using the string 'whatthefuckareyoudoing.'
  108.  
  109. (Lol)
  110. (Code snippet)
  111.  
  112. The decrypted program is also a PowerShell backdoor, here named ps_backdoor, which invokes the function ROAGC:
  113.  
  114. (Code snippet)
  115.  
  116. ps_backdoor
  117. The ps_backdoor script is a PowerShell backdoor whose primary function (ROAGC) has the following parameters:
  118.  
  119. 1) Interval - here, 10.
  120. 2) ID - here, zhengyi5
  121. 3) IP/Port - a size 2 tuple
  122. 4) KEY - encryption key
  123. 5) MAC - mac address
  124.  
  125. (Code snippet)
  126.  
  127. These are the backdoor's commands:
  128.  
  129. rs - runs a CMD command
  130. up - upload file
  131. dw - download file
  132.  
  133. Aside from basic windows CMD commands, the backdoor also supports the following Linux commands:
  134.  
  135. ls/dir - display directory information
  136. mv/move/copy/cp/rm/del/rmdir - move files
  137. cd - change directory
  138. lpconfig/ifconfig - networking information
  139. ps/tasklist - display running processes
  140. whoami/getuid - display user information
  141. rteboot/restart - restarts machine
  142.  
  143. (Code snippet)
  144.  
  145. The upload/download functionality uses AES encryption, where the KEY is located in ps_loader and is Dqd6lfRDcXK2KxIFDqU1S/MMyxGJ7qPIwM/xZe0R6Ps=:
  146.  
  147. (Code snippet)
  148.  
  149. Persistence
  150. ps_start uses Rundll32.exe to run the decompressed beoql.g backdoor, which is the persistent backdoor module that uses ps_loader and the LNK file to maintain persistence. Below are details included in the beowl.g DLL:
  151.  
  152. (Details)
  153.  
  154. The following are the real purposes of the data included in the DLL:
  155.  
  156. DllEntry - used to start PowerShell
  157. DllRegister - saves the incoming PowerShell script and calls DllEntry to start PowerShell, calls DllInstall to generate and start the BAT script to modify the system LNK file.
  158. DllInstall - generates and starts the BAT script that alters the LNK file
  159. DllCanUnload - ?
  160. DllSetClassObject - Used by the BAT script to alter the LNK file
  161. DllUnsetClassObject - restores the LNK file
  162. DllCopyClassObject - used by the BAT script to copy the LNK file to a temporary directory
  163. DllEntryPoint - entry point for the DLL
  164.  
  165. ps_start also invokes the DllRegister field using the ps_loader script as a parameter and save ps_loader as the encrypted beoql.g.ini. It will then invoke the DllEntry and fun_Callinstall.
  166.  
  167. (Code snippet)
  168.  
  169. You can see the encrypted beoql.g.ini PowerShell script below
  170.  
  171. (WinHex dump of beoql.g.ini)
  172.  
  173. When DllEntry is invoked, it will first use CMD commands to delete relevant Jinshan security modules.
  174.  
  175. (Code snippet)
  176.  
  177. It will then use the CreateProcess function to invoke the ps_loader script:
  178.  
  179. (Code snippet)
  180.  
  181. When fun_Callinstall decrypts the relevant encrypted strings, they are used by Rundll32.exe to runn DllInstall.
  182.  
  183. (Code snippet)
  184.  
  185. (Code snippet)
  186.  
  187. The DllInstall function will first traverse multiple directories looking for LNK files.
  188.  
  189. (code snippet)
  190.  
  191. It then creates nview32_update.bat script and runs it:
  192.  
  193. (code snippet)
  194.  
  195. After nview32_update.bat runs, it will detect and delete certain WPS modules and then begins to modify the LNK files it found before:
  196.  
  197. It first uses DllCopyClassObject to copy the LNK to a temporary directory, then uses the DllSetClassObject to modify the LNK file in the %temp% directory. Finally, it writes the modified LNK file back to the original location:
  198.  
  199. (Code snippet)
  200.  
  201. DllSetClassObject uses the fun_Changelnk function to modify the LNK file:
  202.  
  203. (Code snippet)
  204.  
  205. The modified LNK file is broken up by multiple exclamation marks:
  206.  
  207. (Code snippet)
  208.  
  209. The specific purpose is as follows: the LNK shortcut file is altered to run the DllEntry function in the DLL using Rundll32.exe. The main purpose of the function is to run the ps_loader script by hijacking the LNK shortcut file in order to maintain persistence:
  210.  
  211. (Code snippet)
  212.  
  213. The methodology of the attack
  214.  
  215. (The picture, thankfully already translated, depicts the attack cycle)
  216.  
  217. Targeting information
  218. Attack timing
  219. The IPs were primarily used in April and May of this year, exactly corresponding to the samples we captured as well. This is indicative of the incredibly focused nature of the attacks.
  220.  
  221. Targets
  222. By simulating some of the attacker's infrastructure, we were able to gain metrics on what was being stolen, such as computer name and time of attack. The data indicates that the victims number in the hundreds.
  223.  
  224. Conclusion
  225. (Not going to directly translate, basically pontification about how awesome their TIP is, how they do more than just browsing twitter and blogs to gather intelligence, and that their TIP already has early warning monitoring for this APT)
  226.  
  227. IOCs
  228.  
  229. (UNREDACTED IOCs FROM A CHINESE INFOSEC COMPANY???????)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top