Attack All Around

今やCTFと競プロばかりだが、トビタテ生のアメリカ留学やTOEFL奮闘記

Newark Academy CTF writeup

こんにちは!Ken.Sです!

 

昨日まで行われてたNACTFのwriteupを書いていきます!といっても、solves数多い問題しかやってないので参戦記の方が近いかもですが(笑)

 

www.nactf.com

 

 

 

 

結果

今回も個人で参加しました。存在自体に気付いたのが最終日だったので、ちゃんと考察しないといけない問題は解けなかったです。Crypto問題むずかった…。

f:id:partender810:20201105132334p:plain

総合結果

f:id:partender810:20201105132417p:plain

カテゴリー別

 

解説

問題が並んでた順です。解説と言いながら取り掛かったけど分からなかった問題も書いていきます。解けた方はご一報ください(笑)

 

Reverse Engineering

Generic Flag Checker® 1 75pt

Flag Checker Industries™ has released their new product, the Generic Flag Checker®! Aimed at being small, this hand-assembled executable checks your flag in only 8.5kB! Grab yours today!

ファイル:gfc1

 

解けている人多いし最初の問題だからRE初心者でもいけるだろうと、高を括ってやってみました。見事stringsでflagが出ました。

 

nactf{un10ck_th3_s3cr3t5_w1th1n_cJfnX3Ly4DxoWd5g}

 

Generic Flag Checker® 2 150pt

Flag Checker Industries™ is back with another new product, the Generic Flag Checker® Version 2℠! This time, the flag has got some foolproof math magic preventing pesky players from getting the flag so easily.
Hint : When static analysis fails, maybe you should turn to something else...

ファイル:gfc2

調子に乗って二問目。静的解析がダメなら実行だろうと動かしてみる。stringsでflagが書いてありそうな部分は見つけたけど、これgdbとかのデバッガー知らんとできないやつだ。断念。いつか勉強します。

 

 

General Skills

Survey 1pt

アンケートに答えるとflagがもらえます。解いている人少なかったのでみんな1点はいらないということかな。

nactf{survey_flag12f93}

 

Join the Discord 10pt

これもSurveyほどではないけど、みんな回答しているわけではなさそう。Discord内にflagが落ちてました。

nactf{n1c3_j0b_h4v3_fun}

 

Intro to Flags 10pt

NACTF flags are case-sensitive and should be inputted with the format nactf{...}

Practice entering your flag here: nactf{fl4gz_4_d4yz}

 

これはsolves数多かった。みんなアンケート答えるとか一手間かけての少ないポイントは眼中にないの?

nactf{fl4gz_4_d4yz}

 

Basics 30pt

Tiffany no longer communicates in normal text. Weird, I know. She randomly sent me this message: bmFjdGZ7YmE1MzVfYXIzX3N3MzN0fQ==

Can you figure out what it means?

 

やっと問題らしくなりました。末尾が=なのでbase64なのでしょう。久しぶりに使った気がする。

nactf{ba535_ar3_sw33t}

 

Grep 0 50pt
Sophia created this large, mysterious file. She might have said something about grap.. grapes? Find her flag!

ファイル:flag.zip -> flag.txt

 

テキストファイルは83MBと大きい。中は文章がめちゃくちゃありました。

問題名からgrepしてflagを持ってくればいいのでしょうが、メモ帳の検索機能で見つけたひねくれものは私です。

nactf{gr3p_1s_r3ally_c00l_54a65e7}

 

Numbers 50pt

What do the numbers mean?

ファイル:flag.txt

 

中にあった数字はいかにもASCII変換しろって数字。chrしてみたけど文章にならない…。

 

f:id:partender810:20201105134516p:plain

ASCII変換したのに

 

違うのか?と思ったけど最初の五文字を一つ前にするとnactfになることに気付く。全て-1してchrすればOK。

nactf{asc11_XB4RCR5}

 

Hashbrowns 50pt

MD made 5 hashbrowns this morning and forgot to add salt and pepper. He took a bite out of one of them and found a piece of paper with this written on it: 5af554431d976fdc57ea02908a8e0ce6.

 

まあMD5なのでしょう。なんかセキュリティ界隈でsalt and pepperって聞いたことあるな。最後の16進数はハッシュ値なのだろうけど、逆引きのように元の平文なんて分かるの?でもsolves数多いしポイントも低いから簡単なんじゃ?

と、50ptのくせに時間をめちゃくちゃ取られました。salt and pepperはパスワードをハッシュ化するときに必要なんですね。Adversarial Exampleでもそんな言葉あったような…。

ソルト (暗号) - Wikipedia

 

MD5はどうやらレインボーテーブル攻撃という、平文->ハッシュ値のセットをたくさん持っていると、ハッシュ値から平文を予測できてしまうという攻撃があるようです。上のソルトを入れると、この攻撃を受けにくくできるようです。

なんかそんなことやってくれるサイトやツールないかなと「MD5 逆変換」でググると、Hash Toolkit というのがあるみたいです。これの使い方が分からず苦労しましたが、もう一度ここに訪れるとあっさり解けました。なんだったんだろう。

 

https://hashtoolkit.com/decrypt-hash/?hash=5af554431d976fdc57ea02908a8e0ce6

 

nactf{secure_password}

 

Dr. J's Vegetable Factory #1 50pt

After years of collecting plush vegetable toys, Dr. J decided to take on his true passion: starting a vegetable factory. Dr. J is incredibly organized, so he likes all of his vegetables to be in the proper order. In fact, he built a robot "Turnipinator-1000" to alphabetize his vegetables for him! Unfortunately, Dr. J doesn't know what instructions to give Turnipinator-1000. Can you help him out?


nc challenges.ctfd.io 30267

Give instructions in the form of numbers separated by spaces. Entering the number x will swap the vegetable in position x with the vegetable in position x+1. Positions start at zero, not one. (Dr. J is a programmer after all.) For example, given the following vegetables: Avocado, Brocolli, Eggplant, Daikon Radish, Carrot, one possible solution is "3 2 3"

Avocado, Brocolli, Eggplant, Daikon Radish, Carrot

(swap 3 and 4)
Avocado, Brocolli, Eggplant, Carrot, Daikon Radish

(swap 2 and 3)
Avocado, Brocolli, Carrot, Eggplant, Daikon Radish

(swap 3 and 4)
Avocado, Brocolli, Carrot, Daikon Radish, Eggplant

Hint : Try sorting the vegetables by hand! For example: insertion sort.

 

まあ、アルファベット順に並び替えるだけです。ソートを多少知っていればそんなに問題ないです。これはsolver作らず手で解きました。3回正解するとflagが出ました。

nactf{1f_th3r3s_4_pr0b13m_13ttuce_kn0w_db4d736fd28f0ea39ec}

 

Arithmetic 150pt

Ian is exceptionally bad at arthimetic and needs some help on a problem: x + 2718281828 = 42. This should be simple... right?

nc challenges.ctfd.io 30165

Hint : What does uint32_t mean?

ファイル:arithmetic.c

 

x = 42 - 2718281828 ではないのか、と思ったら負の数はrejectされてしまいます。まあ、そうなればC言語だしオーバーフロー起こせばいいんですね。あとはそれ用にCプログラムを書けばいいです。

nactf{0verfl0w_1s_c00l_6e3bk1t5}

 

Dr. J's Vegetable Factory #2 150pt

Dr. J expanded his vegetable factory! Now he's got hundreds of vegetables. Same problem as last time: can you give Turnipinator-1000 the right instructions to sort Dr. J's vegetables?

nc challenges.ctfd.io 30267

Hint : It seems like there are too many vegetables to sort by hand this time. But not too many for a computer!

Check out the example script if you're unsure of how to connect to the server with code! example.py

 

#1の野菜数を多くしただけですね。100個あるのでプログラム組まないと死んでしまいます。

i番目に(アルファベット順で)小さいものをi番目にまでswapする形を取ります。初めにpythonのsortedでソートしたやつも持っておいて、それを0から順にindexで探せばOKです。一番小さいものが58番目にあれば、57 56 55 ... 1 0, で0番目まで来ます。二番目に小さいものが5番目にあれば、4 3 2 1で1番目まで来ます。これを記述するプログラムを組めばOKです。

nactf{d0n7_w0rry_p34_h4ppy_f27ae283dd72cb62f685}

 

Zip Madness 175pt

Evan is playing Among Us and just saw an imposter vent in front of him! Help him get to the emergency button by following the directions at each level.

ファイル:flag.zip

 

zipファイルを開くと1000left.zip, 1000right.zip, direction.txtの3つがあり、leftの方のサイズが大きいです。direction.txtを見ると"left"しか書いてなく、とりあえず1000left.zipを展開すると999left.zip, 999right.zip, direction.txtがあって…。これは途轍もないことだなと観念し、なんとかプログラムでLinuxのコマンド実行できないかと調べてました。そういえばPakenCTFでやったな。subprocessだ。

「unzip -o (階層)(左右).zip」を1000回実行すれば良さそうです。-oはoverwriteできるようなオプションです。階層はfor文で指定すれば良くて、左右はdirection.txtから読み取った方向を入れます。実行にはcallで行って、引数はリストで[unzip, -o, zipファイル名]とします。

nactf{1_h0pe_y0u_d1dnt_d0_th4t_by_h4nd_87ce45b0}

 

 

Dr. J's Vegetable Factory #3 175pt 104

Rahul hates vegetables. Rahul hates vegetables so much that he snuck into Dr. J's factory at night to sabotage Dr. J's vegetable production! He brought a sledgehammer and broke the wheels of Dr. J's robot! 😓 Now the robot is stuck in place, and instead of being able to swap any adjacent elements, it can only swap the elements in positions 0 and 1!

But Dr. J won't let this incident stop him from giving the people the vegetables they deserve! Dr. J is a problem solver 🧠. He organized his vegetables in a circle, and added a conveyor-belt that allows him shift the positions of the vegetables. He thinks that the conveyor belt should make it possible to sort his vegetables, but he's not 100% sure. Can you help him out?

nc challenges.ctfd.io 30267

Enter letters separated by spaces to sort Dr. J's vegetables. Entering "c" will activate the conveyor belt and shift all vegetables left one position. Entering "s" will swap the vegetable in position 0 with the vegetable in position 1.

 

cは野菜が左に一つずれ(一番左のは一番右に行く)、sは0,1番目をswapします。#2ではswapを好きなところでできたのに対し、#3では0,1番目しかできません。その代わりに野菜を一つずらすことができます。

 

解法としては、まず後ろからZの方からソートしていきます。

まず、sortedで先にソートしたのも持っておきます。一番後ろの野菜を0番目までに来るまでcを連打します(実際には変数mesに記憶させます)。0番目まで来たら[0:1]までソートしたこととします(swap一切してないけど)。

次に、後ろから二番目のを0番目まで持ってきます(c連打)。1番目が既にソートされているもの = 0番目にある野菜よりも後ろになるはずのものが来たらソートしたこととし、そうでないならsでswapします。三番目以降も同様に考えて行うと命令が完成します。

要はバブルソートですね。

nactf{1t_t4k35_tw0_t0_m4n90_8a51c7b47fbe227}

 

こういうプログラミング問題はやってて楽しいです(解けるかは別として)。

 

Grep 1 200pt

Elaine hid a REGULAR flag among more than 1,000,000 fake ones! The flag was an EXPRESSION of her love for nactf, so the first 10 characters after "nactf{" only have the characters 'n', 'a', 'c', and the last 14 characters only have the characters 'c', 't' and 'f'. There are 52 characters in total, including nactf{}.

ファイル:flag.zip -> flag.txt

txtファイルの中には"nactf{"から始まるflag候補が大量にあります。flagになるのは"nactf{"のあとに[n,a,c]のどれかが10個、任意の文字が21個、[c,t,f]のどれかが14個、"}"

です。これをコマンドで書けばOKです。

cat flag.txt | grep -E "nactf{[n,a,c]{10}.{21}[c,t,f]{14}}"

nactf{caancanccnxfynhtjlgllctekilyagxctftcffcfcctft}

 

(実は正規表現を調べるのが面倒でpythonで書きました)(そのあと勉強した)

 

World Trip 300pt

Will has been travelling the world! Here's a list of the coordinates of the places he's been to. There might be a secret message hidden in the first letter of all of the countries.

Note: The flag is all uppercase without spaces or "_"

Hint : This would be really tedious to do by hand...

Hint : The last part of the flag is just random characters and is not supposed to make sense

ファイル:enc.txt

 

enc.txtには座標(緯度経度)が194個入ってて、その座標の国名の頭文字を並べてnactf{}で括ればいいようです。

座標から国を特定するのってどうするんだ…。とりあえず、enc[0]を調べてみるとItalyに旅行できました。194個ってことは全部の国に行けるのかな?(194ヶ国は違いました。世界の国は196ヶ国、国連加盟国は193ヶ国、バカがバレる)

 

 

そういえばcurlコマンドでURL指定で情報持って来れるなぁ、とgooglemapのURLをぶったたくといっぱい情報が来ました。まず、日本語だとgrepしにくいので英語に変換します(URLの最後に?hl=en)。あとはgrepsedの駆使とbashでやりました。og:descriptionって単語をgrepするとItalyが含む列を持ってこれます。あとはsolverに書いておきます。Githubを見てください。

得られた文字列をtxtファイルに書き込んでいったのですが、192行でした…。2個抜けてる…。それを探すのに30分近くかかった…。

 

 

次は、国名は-2番目にあるのでそれを引っ張ってこうと思ったら「Dominican Republic」のように国名が一単語ではないやつがいくつかあって、それを直すのに時間がかかりました(一番最後の","の次という選び方をすればよかった)。

それを直すのにtxtファイル見直したら、South Pacific Ocean と Lake Kivuがありました。Lake Kivuはともかく海はどこの国でもないやろ!!ちゃんと調べたらトンガという世界で三番目に小さい国でした。Lake Kivuはちゃんと地図を見ずwikiの情報でコンゴだと思ってたらincorrect。座標で検索するとルワンダ寄りでした…。ただそれでもincorrect。DiscordでAdminに聞きまくってました。

 

 

結局、(一番最後の","の次という選び方をすればよかった)が重要でした = 二単語のやつを一つ直し忘れてた!!! めっちゃ時間かかったし、何よりしょうもないミスを直せばcorrectというのも悔しい…。

英語名知らない国もあったし、そもそも聞いたことない国もありました。ちなみに被っている国がいくつかあったので193ヶ国すら巡れなかったです…。

ちなみに、引っ張ってきたのはここの情報のようです。

f:id:partender810:20201105220804p:plain

一つ下の情報だと、Lake kivuとかの場合も地名が書いてあった

 

nactf{IHOPEYOUENJOYEDGOINGONTHATREALLYLONGGLOBALTOURIBOFAIQFUSETZOROPZNQTLENFLFSEMOGMHDBEEIZOIUOCGSLCDYMQYIRLBZKNHHFGBPDIVNBUQQYPDCQIAVDYTRFOCESEQUOUUMSKYJOVKVJGMRGNATNIRESHRKHCEDHHZYQRZVOGCHSBAYUBTRU}

 

Dr. J's Vegetable Factory #4 350pt

Thanks to you solving Dr. J's conveyor belt conundrum, Dr. J's vegetable factory is up and running once again. But this time, Juliet breaks into the factory to finish what Rahul started. For some reason, she doesn't break Turnipinator-1000 completely. First, she spins Turnipinator-1000 in a random direction. Then, she pulls the arms of Turnipinator-1000 a random distance apart so it can no longer swap adjacent elements! Now, it can only swap the vegetable in position x with the vegetable in position y!

Initially, Dr. J is very sad. 😥 Even with the conveyor belt, he doesn't think he can sort his vegetables anymore. But then, Dr. J has a brilliant revelation! 💡 He scribbles on scratch paper for a few minutes, then he gets up and removes a few of the vegetables from the conveyor belt.

Proudly, he declares, "Dr. J's Vegetable Factory is back in business!"

nc challenges.ctfd.io 30267

Same instructions as in part #3. Enter letters separated by spaces to sort Dr. J's vegetables. Entering "c" will activate the conveyor belt and shift all vegetables left one position. Entering "s" will swap the vegetable in position x with the vegetable in position y. (x and y will be given.)

何してくれてんねん!!!!

 

#3では0,1番目をswapできたのに今度はx,y番目となりました。先程は隣りあった野菜をswapできたのに、離れた場所でのswapだとソート済みな部分も壊してしまう可能性があります。最初はそこに気付かず、なぜできないんだ、(自分のソート後の結果を見て)なぜこんなぐちゃぐちゃになっているんだ、となってました。

 

 

結果、Flagは得られなかったのですがソートはなんとかできました。恐らく命令が長すぎて実行時間がかかりダメだと判定されたのだと思います。以下、私なりの解法です。

  1. sortedを利用し、得られた野菜をソートした結果(以後vとする)を持っておく
  2. x,yについて、x > yなら、x,yの値を入れ替える(計算しやすくするため)
  3. p = 野菜の個数-2を初期値として、v[p]を何回swapすればv[p+1]の一つ左にいくか、与えられた野菜の配列(以後gとする)から計算する。v[p],v[p+1]のindexをs,tとすると、s+(y-x)*(swap_count) = t-1 mod 野菜の個数の式が成り立ち、(y-x)は一回のswapで移動する長さであり(野菜の個数)とは互いに素になる(そうでないとそもそもソートできない)。なので(swap_count) = (t - 1 - s)*(y-x)^-1 mod 野菜の個数と求まった。
  4. swapした際にソート済みの部分を壊してしまったらその野菜をFirst in Last outのキューで格納。そうすると、元に戻すために各野菜1回のswapで済む。First in First outだと、swap回数が増えてしまう。
  5. 野菜を一つ左にスライドするcについては、1回ずつ行うのではなく任意の回数一気にできるよう関数を作っておく

 

これで、ソートは上手くいくのですが命令長が800万ほどとなりそれがflagが出ない原因のようです。手元でやればすぐ終わるのですが…。解けた方はご一報を(solves数少なかったけど…)

 

 

Cryptography

Caesar's Challenge 25pt

Zabelo wrote this message on a note he passed to me. anpgs{q3p1cu3e1at_e0px5!} He also told me his favorite number was 13. What could this mean?

13が好きだとは珍しいですが、人それぞれですからね。rot13でしょう。

nactf{d3c1ph3r1ng_r0ck5!}

 

YAMS 100pt

Instead of turnips, Yavan loves YAMS. Day and night, he sings about YAMS, dreams about YAMS and runs to the store to catch the newest released batch of YAMS. Hes cryptic too. I wonder what this could mean.

Uexummq lm Vuycnqjc. Hqjc ie qmud xjas: fycfx{waY5_sp3_Y0yEw_w9vU91}

Hint : I can't believe he also eats them with vinaigrette!

 

fycxfがnactfになるんだろうな、3文字目がc->cだからなんかあるのかなと考えてたらヒントを見逃してて「ああVigenereか」と。久しぶりでした。

ヴィジュネル暗号 - Wikipedia

keyがVigenereには必要ですが、c->cがあるのでAが入っている & a->yがあるからYがある、つまりyaと続くkeyがある。はい、問題名がkeyですね。

nactf{yaM5_ar3_Y0mMy_w9jC91}

 

Error 0 150pt

Rahul has been trying to send a message to me through a really noisy communication channel. Repeating the message 101 times should do the trick!

ファイル:enc.txt

最後まで解けなかった…。中は01だけで記述されてて、長さが23432でした。今23432と書いてて101の倍数じゃん!ってなってます。長さが8の倍数だから、長さ8毎持って来てASCII変換したら最初にnactf(aはホモグリフでaの上になんかついてるやつ)となり、ここからなんか行けるか…と思ったけど、時間切れ。23432 = 232*101 を気付いた今もいい案は思いつかず…。101が二進数かなとも思いましたが、5をどうしていいか分からず。

 

Oligar's Tricky RSA 175pt

The crypto master Oligar just sent this file with three numbers. What do they mean?

ファイル:rsa.txt

やっとRSA問題。NをFactorDBにぶん投げて素因数分解可能。終了

nactf{sn3aky_c1ph3r}

 

Random Number Generator 250pt

Dr. J created a fast pseudorandom number generator (prng) to randomly assign pairs for the upcoming group test. Austin really wants to know the pairs ahead of time... can you help him and predict the next output of Dr. J's prng?

nc challenges.ctfd.io 30264

heck out the hint for "Dr. J's Vegetable Factory #2 🥕" to see an example of how to connect to the server with code.

ファイル:rand0.py

seedを上手く使えば、randintの結果を予測出来てflagが手に入るんだな、でもどうしたらいいの?で時間切れ。こういうのをスッと解けないとcrypto得意なんて言えないな(笑)

 

Forensics

Gummies 50pt

Kylie is obsessed with gummies. With her collection of miscellaneous gummy bears, she took this incredible picture which is now her phone's wallpaper. Can you find her flag?

ファイル:gummy.png

Steganographyってやつですかね。PNGのヘッダーもちゃんとしてるし他に何したらいいの?状態。ただ、このサイトでpngファイルと同じ画像を発見。なんだったんだろう。

unsplash.com

 

Meta-morphosis 75pt

Mikey really likes Metamorphosis by Franz Kafka, so much so that he sent this meme to the class.

ファイル:meme-3.jpg

また同じ部類かな、ととりあえずstringsしてみました。あ、flagだ。

nactf{m3ta_m3ta_m3ta_d3f4j}

 

 

Web

Inspect 50pt

Lola's new to website-building. Having just learned HTML and CSS, she built this site and embedded some dark secrets. I wonder where I could find them.

http:/inspect.challenges.nactf.com/

とりあえずF12。あ、flagだ。

f:id:partender810:20201105231525p:plain

右下にホラ

nactf{1nspect1ng_sp13s_4_lyf3}

 

Missing Image 75pt

Max has been trying to add a picture to his first website. He uploaded the image to the server, but unfortunately, the image doesn't seem to be loading. I think he might be looking in the wrong subdomain...

https://hidden.challenges.nactf.com/

URLにアクセスすると、真緑な画面。F12で覗いてみると、画像(http://challenges.nactf.com/flag.png)が出てこないとのこと。サブドメインが違うということで、アクセスURLと同じようにhiddenを付けてみる。はい出た。

https://hidden.challenges.nactf.com/flag.png

nactf{h1dd3n_1mag3s}

 

Forms 125pt

Skywalker has created 1000 login forms and only managed to make one of them work. Find the right one and login! He also went a bit crazy with the colors for some reason.

https://forms.challenges.nactf.com/

1000個のログインフォームの内一つは本物。とりあえずF12でソースを見てみましょう。10000行を超えるソースですが、1つのフォームに対して10行近くあってそれが1000個あります。その下に行くとログインできそうな関数がありました。

f:id:partender810:20201105232513p:plain

この関数を呼んでるフォームを探そう

f:id:partender810:20201105232714p:plain

Ctrl+F でverifyとすると…

Form 673にUser:admin, pass:password123でログインするとflagが出ます。

nactf{cl13n75_ar3_3v11}

 

Calculator 150pt

Kevin has created a cool calculator that can perform almost any mathematical operation! It seems that he might have done this the lazy way though... He's also hidden a flag variable somewhere in the code.

https://calculator.challenges.nactf.com/

なんか裏で計算してるんだな、変な命令流せばなんかflag出るのかってF12で覗いたけど分からず…。ソースにあんま書いてない?とか思ったけどもうよく分からない、無理。

 

 

例によって、問題やsolverはGithubに載せてます!

github.com

 

それでは!

 

See you next time!