Showing posts with label fileless malware. Show all posts
Showing posts with label fileless malware. Show all posts

Saturday, 31 March 2018

Just another Malware Analysis Guide (6) - Walk Through It

Sample executable file for this guide can be found at here.

Static Analysis

Drag and drop EXE into PeStudio:

ws2_32.dll use for internet connection.


Check on the Imported Symbols, able to notice that the EXE file will perform file creation, write file, registry key creation and network connection.


Next will check on the strings. Under Unclassified, notice huge unknown strings in rdata section.


More suspicious strings are found such as unknown vbs script, base64 encoder strings and registry key.

Now let's use Strings from Sysinternals to dump the strings in the EXE file.


Notice that some strings are not found in PeStudio appeared. The IP addresses and wscript.exe /B.


Notice that the unknown long strings, let's try to decode it using base64. The decoded strings are VBS script. The script create Task Scheduler with PowerShell execution. PowerShell will obtain malicious PowerShell from new created registry.


Dynamic Analysis

Run the EXE in Sandoxie and BSA:
First try without internet connection, the EXE exit if there's no internet connection.



Run the EXE in Sandoxie and BSA with internet connection reveals the malicious activities of the EXE file.
It checks internet connection multiple times before perform more malicious activities.
First, it checks for internet connection to 172.217.31.46. If successful it will create a file name called "unknown.vbs" located at Documents folder.
Second, it checks for internet connection to 162.125.248.1 and 52.74.223.119. If successful it will execute VBS script using wscript.
Final, it executes cmd and create a Task Scheduler to execute PowerShell.



Get information about the IP addresses.




With the dynamic analysis information, we now know what is the activities will perform by the EXE.

Advanced Static Analysis

Open the EXE in x32dbg then press F9 to run single time on the EXE to directly takes us to the main function. After that find the string references on the current module.


Now let's follow the disassembler by right click on the IP address.


On the disassembler, right click or press G to view in graph mode.




Press O or right click to view in Overview mode.



Click on the CPU tab to move back into disassembler view. Perform analysis on the call instructions by follow in disassembler and graph view.




Spot the SHGetFolderPath API called. By checking on MSDN and googling around for the CSIDL, conclude that it is hex 0x5 CSIDL_PERSONAL that will point to current user document path.



Following the execute path in the graph, CreateFile and WriteFile API were called.


Return to disassembler view in CPU tab, insert comment by pressing ";". The edi contain the file name which is unknown.vbs.


Continue to WriteFile API called.


Return back to the main function by pressing "-" then move on to the next call instruction. In here the address is 0xFD1900. SHGetFolderPath appeared again with unknown.vbs. Suspecting it tries to get the unknown.vbs file path.


Return back to main function by pressing "-", notice that the compare instruction that will compare whether the unknown.vbs file existence. If file not found then quit.
If file exits, it will check for network connection to 162.125.2481 before proceed to a call function.

Inside 0xFD1720, there are two long unknown strings being push to the stack. We can follow the long unknown strings in dump.



Continue analysis, there is a call instruction to create a new registry key and data.


The following image is after finished analyzed the call instruction and included comments.




Advanced Dynamic Analysis

Set breakpoint using F2 to get a more detailed understand on what happened before and after the call instruction.


Press F9 to run once. Notice that the unknown.vbs script has created in My Documents folder.


Press F9 again. Notice that new registry key and data has been created.


Press F9 again. Notice that in the stack contained wscript.exe /B command.


Press F9 again. Notice that the unknown.vbs script location is push to the stack.


Press F9 again. Then follow dump in EAX before it push to the stack. It is a full command will executed by system during the next call instruction.


Set a breakpoint after the system call instruction. Notice that the VBS script create a new Task Scheduler. The Task Scheduler contain PowerShell execution.


Open registry editor and copy out the registry data. Perform a base64 decode for UUID. It is a RC4 algorithm that will decrypt the content in registry data UID.



Copy the decoded PowerShell script to PowerShell ISE then edit the scrip to output the decrypted content inside registry data UID to a file.



Decode the PowerShell, it shows that it will connect back to C&C server at 34.211.199.148.



End of Just another Malware Analysis Guide (6) - Walk Through It

Friday, 16 February 2018

Just another Malware Analysis Guide (4) - Fileless Malware (PowerShell)

Let's take a look on most common arguments used by malicious PowerShell scripts (sources: Palo Alto).


====(NoProfile) Prevents from loading profile scripts====
-nop
-NoP
-noprofile
-NoProfile
-noP

====(NonInteractive) Prevent create prompt====
-noni
-NonI
-noninteractive
-NonInteractive
-nonI

====(WindowStyle Hidden) Prevent Windows Display====
-window hidden
-W Hidden
-w hidden
-windowstyle hidden
-win hidden
-WindowStyle Hidden
-win Hidden
-wind hidden
-WindowStyle hidden
-WindowStyle hiddeN
-windows hidden
-Win Hidden
-win hid
-Window hidden
-Wind Hidden
-Win hidden

====(EncodedCommand) Decode base64 encoded strings====
-enc
-Enc
-EncodedCommand
-encodedcommand
-encodedCommand
-ec
-en
-ENC

====Execution Policy Bypass====
-ep bypass
-exec bypass
-executionpolicy bypass
-Exec Bypass
-ExecutionPolicy ByPass
-ExecutionPolicy bypass
-Exec ByPass
-ExecutionPolicy Bypass
-ExecuTionPolicy ByPasS
-exe byPass
-ep Bypass
-ExecutionPolicy BypasS
-Exe ByPass

====(NoLogo) Hides the copyright banner====
-Nol
-NoL
-nologo
-nol


Tools that could help during static and dynamic analysis:
  1. Windows PowerShell ISE
    • Debugger for PowerShell script
  2. Wireshark
    • Capture network traffic
  3. Sysmon
    • Advanced system monitor tool
  4. Sysmon Configuration File (using SwiftOnSecurity)
    • Configuration file for Sysmon
  5. Process Monitor
    • Capture details running processes
  6. Windows Event Logs
    • Event logs for Windows
First example for the PowerShell script can be found at here.

Static Analysis

Malicious Powershell script at Notepad++:


Open Powershell ISE:
Start > Type "powershell" > Right click Windows PowerShell ISE > Run as Administrator
*Note* Need to set Set-ExecutionPolicy Bypass




Copy the highlighted base64 encoded strings and perform decoding:



It is binary file. Refer back to the PowerShell , notice that it is compressed by GZIP.
Let PowerShell ISE decode the base64 strings and decompress the GZIP for us.
Edit the PowerShell and paste it into PowerShell ISE as below. (There is two quotes '' change it to single quote ')


Write the decoded and decompressed malicious script into a text file using Write-Output then hit F5 to Run.


Below is the malicious script will download a text file from Dropbox and


Open the Dropbox content at Browser. Notice that it is another malicious script with base64 encoded.



Copy the encoded strings then decode it at ConEMU. Notice it connects back to malicious C2 server. It is malicious script generated by Empire.


Dynamic Analysis 


 Open Windows PowerShell ISE.
 


The malicious PowerShell script.


Open Wireshark.


Run CMD as Administrator.


Install Sysmon Configuration File.


Open Windows Event Viewer.


Notice the Sysmon in Event Viewer.


Copy the PowerShell script in purple highlighted into PowerShell ISE.



Start capture the network traffic in Wireshark.


Clear Sysmon Event Logs.


Run the PowerShell ISE by hitting F5.



Notice the network traffic in Wireshark contain Dropbox and C2 server.



Notice the logs captured in Sysmon contain PowerShell process and network connection.




Save the Wireshark traffic and Sysmon Logs then revert the virtual machine.

End of Just another Malware Analysis Guide (4) - Fileless Malware (PowerShell)