とっても遅ればせながら、2018年度の picoCTF をやってみているので write-up。
リアルタイムで開催されている事自体は知っていたものの、学生さんしか参加できないと思ってスルーしていました。社会人でも参加できるようですので、気になった方いらっしゃいましたら是非!
TOPはこんな感じでかっこいい!
flag形式は picoCTF{***}
。
webブラウザさえあれば、shellサーバーがwebブラウザから操作できるようになってるのが学生向けなのかとても良い!環境用意できない人もいますもんね、きっと。
私が参加した時点で、Scoreボードに存在するチームは 23,819。すごいですねー!
この記事では、150pt問題までを。150ptまでを全部解いた時点で 5,501 位。まだまだだ。assembly-0 で躓いて暫く塩漬けになっていたものの、それ以外の問題はサクサク解けて楽しい。
IT/Linuxの知識の基本を問う問題も多く、Linux入門・情報系入門としてもよさそう。
学生の頃であっていればなぁ、とか、せめてCTF始める時にこれを最初にやりたかったなぁとか思ったりもするけれど、言ってもしょうがないので、CTF始めたい人や情報系が気になる学生さん、就職・転職先でLinux知識が必要になった社会人etc...に紹介していくことにする!
150ptまで解くと、5000位台になった。
ここまでくらいの問題なら、全問大量にwrite-upが落ちていそうですが、自分のメモも兼ねて書いておきます。
[Forensics] Warmup 1 (50pt)
Can you unzip this file for me and retreive the flag?
zipファイルをDLし、これをunzipするだけ。 flag.jpgの画像が出てきて、ここにflagの書かれた画像が入っている。
[Forensics] Warmup 2 (50pt)
Hmm for some reason I can't open this PNG? Any ideas?
まって、普通にMacで開けてしまった。まぁいいか。深追いはしない。
[General] Warmup 1 (50pt)
If I told you your grade was 0x41 in hexadecimal, what would it be in ASCII?
ソラで出てこなかった。ググった。反省。
flag: picoCTF{A}
[General] Warmup 2 (50pt)
Can you convert the number 27 (base 10) to binary (base 2)?
10進→2進の変換
flag: picoCTF{11011}
[General] Warmup 3 (50pt)
What is 0x3D (base 16) in decimal (base 10).
16進→10進の変換
flag: picoCTF{61}
[Resources] (50pt)
We put together a bunch of resources to help you out on our website! If you go over there, you might even find a flag! https://picoctf.com/resources (link)
リンク先のページに旗が落ちてる。
flag: picoCTF{xiexie_ni_lai_zheli}
[Reversing] Warmup 1 (50pt)
Throughout your journey you will have to run many programs. Can you navigate to /problems/reversing-warmup-1_1_b416a2d0694c871d8728d8268d84ac5c on the shell server and run this program to retreive the flag?
picoCTFではオンラインshellが用意されているので、オンラインshellのページに行きます。shell serverにログインして、上記指定のpathにアクセスし、そこにある run ファイルを実行します。
flag: picoCTF{welc0m3_t0_r3VeRs1nG}
[Reversing] Warmup 2 (50pt)
Can you decode the following string dGg0dF93NHNfczFtcEwz from base64 format to ASCII?
base64 -> ascii オンラインサイトでも変換できる。 flag: picoCTF{th4t_w4s_s1mpL3}
[Crypto] Warmup 1 (75pt)
Crpyto can often be done by hand, here's a message you got from a friend, llkjmlmpadkkc with the key of thisisalilkey. Can you use this table to solve it?.
it のリンクから、下記tableをDLすることができます。
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z +---------------------------------------------------- A | A B C D E F G H I J K L M N O P Q R S T U V W X Y Z B | B C D E F G H I J K L M N O P Q R S T U V W X Y Z A C | C D E F G H I J K L M N O P Q R S T U V W X Y Z A B D | D E F G H I J K L M N O P Q R S T U V W X Y Z A B C E | E F G H I J K L M N O P Q R S T U V W X Y Z A B C D F | F G H I J K L M N O P Q R S T U V W X Y Z A B C D E G | G H I J K L M N O P Q R S T U V W X Y Z A B C D E F H | H I J K L M N O P Q R S T U V W X Y Z A B C D E F G I | I J K L M N O P Q R S T U V W X Y Z A B C D E F G H J | J K L M N O P Q R S T U V W X Y Z A B C D E F G H I K | K L M N O P Q R S T U V W X Y Z A B C D E F G H I J L | L M N O P Q R S T U V W X Y Z A B C D E F G H I J K M | M N O P Q R S T U V W X Y Z A B C D E F G H I J K L N | N O P Q R S T U V W X Y Z A B C D E F G H I J K L M O | O P Q R S T U V W X Y Z A B C D E F G H I J K L M N P | P Q R S T U V W X Y Z A B C D E F G H I J K L M N O Q | Q R S T U V W X Y Z A B C D E F G H I J K L M N O P R | R S T U V W X Y Z A B C D E F G H I J K L M N O P Q S | S T U V W X Y Z A B C D E F G H I J K L M N O P Q R T | T U V W X Y Z A B C D E F G H I J K L M N O P Q R S U | U V W X Y Z A B C D E F G H I J K L M N O P Q R S T V | V W X Y Z A B C D E F G H I J K L M N O P Q R S T U W | W X Y Z A B C D E F G H I J K L M N O P Q R S T U V X | X Y Z A B C D E F G H I J K L M N O P Q R S T U V W Y | Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Z | Z A B C D E F G H I J K L M N O P Q R S T U V W X Y
メッセージ(crypted)が llkjmlmpadkkc
, 鍵が thisisalilkey
とのことなので、1文字目の平文は T
の列で L
が現れる行を探すと、 S
の行が L
になっているので、1文字目の元のメッセージ(平文)は S
。
手で解ける問題もあるぜ、とのことだったので、頑張って手で解いた。
picoCTF{SECRETMESSAGE}
[Crypto] Warmup 2 (75pt)
Cryptography doesn't have to be complicated, have you ever heard of something called rot13? cvpbPGS{guvf_vf_pelcgb!}
rot13の問題。下記スクリプトを実行。
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import string data = "cvpbPGS{guvf_vf_pelcgb!}" output = "" alphabet = list(string.ascii_lowercase) def rot13(c): return alphabet[(alphabet.index(c) + 13) % 26] def rot13_robust(c): if c.isdigit(): return c if c.isupper(): return rot13(c.lower()).upper() if c.islower(): return rot13(c) else: return c for c in data: output += rot13_robust(c) print(output)
flag: picoCTF{this_is_crypto!}
[General] grep 1 (75pt)
Can you find the flag in file? This would be really obnoxious to look through by hand, see if you can find a faster way. You can also find the file in /problems/grep-1_2_ee2b29d2f2b29c65db957609a3543418 on the shell server.
fileをDLすると16kbのファイルが。
$ file file file: ASCII text, with very long lines
file
コマンドで確認すると very long linesらしい。問題タイトル通りgrepで探すことに。
$ grep "picoCTF{" file picoCTF{grep_and_you_will_find_42783683}
[General] netcat 1 (75pt)
Using netcat (nc) will be a necessity throughout your adventure. Can you connect to 2018shell.picoctf.com at port 22847 to get the flag?
netcatコマンドの使い方わかる?問題。
$ nc 2018shell.picoctf.com 22847 That wasn't so hard was it? picoCTF{NEtcat_iS_a_NEcESSiTy_69222dcc}
[Crypto] HEEEEEEERE'S Johnny! (100pt)
Okay, so we found some important looking files on a linux computer. Maybe they can be used to get a password to the process. Connect with nc 2018shell.picoctf.com 42165. Files can be found here: passwd shadow.
linkから passwd
ファイルと shadow
ファイルが落とせる。
passwd
root:x:0:0:root:/root:/bin/bash
shadow
root:$6$HRMJoyGA$26FIgg6CU0bGUOfqFB0Qo9AE2LRZxG8N3H.3BK8t49wGlYbkFbxVFtGOZqVIq3qQ6k0oetDbn2aVzdhuVQ6US.:17770:0:99999:7:::
shadowファイルについて、ザクッとした知識しかなかったので調べてみると、とても丁寧な解説がありました。
ひつまぶし食べたい: /etc/shadowについて勉強してみた
ということで
- ログインユーザー名: root
- パスワードのハッシュ化方式: SHA-512
- Salt: HRMJoyGA
- ハッシュ化済みのパスワード: 26FIgg6CU0bGUOfqFB0Qo9AE2LRZxG8N3H.3BK8t49wGlYbkFbxVFtGOZqVIq3qQ6k0oetDbn2aVzdhuVQ6US.
となります。
shadowファイルの解析には John the Ripper が有名なので、こちらをinstallして実行してみました。
macに直接 John the Ripper をソースダウンロード→コンパイルの手順で入れましたが、いろいろ躓いた。
基本的にはこちらを参照しつつ、openssl系のエラーが出た時はこちらも参照しつつ。
以下、Johnが入ったあとの解析。
$ ~/tools/john_the_ripper/run/unshadow passwd shadow > passfile $ ~/tools/john_the_ripper/run/john passfile Warning: detected hash type "sha512crypt", but the string is also recognized as "sha512crypt-opencl" Use the "--format=sha512crypt-opencl" option to force loading these as that type instead Warning: hash encoding string length 98, type id $6 appears to be unsupported on this system; will not load such hashes. Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 64/64 OpenSSL]) Press 'q' or Ctrl-C to abort, almost any other key for status hellokitty (root) 1g 0:00:00:15 DONE 2/3 (2019-02-09 00:52) 0.06578g/s 192.4p/s 192.4c/s 192.4C/s hellokitty Use the "--show" option to display all of the cracked passwords reliably Session completed
このまま picoCTF{hellokity}
で投げるとエラー。じゃなくて、指定されたサーバーに接続し、今回パスワードが取れた root ユーザーで上記のpasswordを使ってログインする。
$ nc 2018shell.picoctf.com 42165 Username: root Password: hellokitty picoCTF{J0hn_1$_R1pp3d_5f9a67aa}
個人的には今までコンパイルエラーなどなどで入れられていなかった John the Ripper がmacにinstallできて感激!
[General] strings (100pt)
Can you find the flag in this file without actually running it? You can also find the file in /problems/strings_2_b7404a3aee308619cb2ba79677989960 on the shell server.
いきなりgrepしようとすると
$ grep "picoCTF{" strings Binary file strings matches
と怒られるので、一旦 strings
コマンドで文字列のみ抽出してから grep。
$ strings strings | grep "picoCTF{" ascii.txt picoCTF{sTrIngS_sAVeS_Time_3f712a28}
[General] pipe (110pt)
During your adventure, you will likely encounter a situation where you need to process data that you receive over the network rather than through a file. Can you find a way to save the output from this program and search for the flag? Connect with 2018shell.picoctf.com 48696.
あれ、pipeコマンド前の問題で使ってしもうた。
指定されたホストにncで接続すると、だーーーーーっとデータが流れてきます。こんな感じ。
Unfortunately this is also not a flag This is not a flag This is not a flag This is not a flag I'm sorry you're going to have to look at another line I'm sorry you're going to have to look at another line This is not a flag I'm sorry you're going to have to look at another line This is not a flag I'm sorry you're going to have to look at another line I'm sorry you're going to have to look at another line This is not a flag Unfortunately this is also not a flag Unfortunately this is also not a flag
全部「この行はフラグじゃないよ、ごめん」的な。多分低確率でflagが流れてきてるんだろうと予想して、nc
コマンドで取ってきたデータに対してgrepをかける。
$ nc 2018shell.picoctf.com 48696 | grep "picoCTF{" picoCTF{almost_like_mario_f617d1d7}
このメッセージの意味が気になるところ・・・?
[Web] Inspect Me (125pt)
Inpect this code! http://2018shell.picoctf.com:28831 (link)
リンク先に飛んでソースを表示してみると、コメントで下記の行が。
<!-- I learned HTML! Here's part 1/3 of the flag: picoCTF{ur_4_real_1nspe -->
うーん、1/3ということなので、あと2個ありそうなんだけどソース上にはないなぁ。
These are the web skills I've been practicing: * HTML * CSS * JS (JavaScript)
ということなので、あと2つはCSSとJSっぽいぞと。よくソースを見てみると、cssとjsのリンク先が mycss.css
と myjs.js
になっていて怪しい。お手製のやつだ。
htmlソース上で既にリンクになっているので、それぞれリンクから飛ぶと、下記メッセージにのココリのフラグ部分が。
/* I learned CSS! Here's part 2/3 of the flag: ct0r_g4dget_b4887011} */
/* I learned JavaScript! Here's part 3/3 of the flag: */
つなげるとflagに。
flag: picoCTF{ur_4_real_1nspect0r_g4dget_b4887011}
3番目いらんかったやん…。
[General] grep 2 (125pt)
This one is a little bit harder. Can you find the flag in /problems/grep-2_1_ef31faa711ad74321a7467978cb0ef3a/files on the shell server? Remember, grep is your friend.
web shellで指定されたフォルダにアクセス。下記コマンドで発見。
$ grep "picoCTF{" ./files*/* ./files4/file20:picoCTF{grep_r_and_you_will_find_4baaece4}
[General] Aca-Shell-A (150pt)
It's never a bad idea to brush up on those linux skills or even learn some new ones before you set off on this adventure! Connect with nc 2018shell.picoctf.com 27833.
問題文の通り、ncコマンドで接続してみた。
$ nc 2018shell.picoctf.com 27833 Sweet! We have gotten access into the system but we aren't root. It's some sort of restricted shell! I can't see what you are typing but I can see your output. I'll be here to help you along. If you need help, type "echo 'Help Me!'" and I'll see what I can do There is not much time left!
こんな文言が。とりあえず助けを求めてみる。
~/$ echo 'Help Me!' Help Me! You got this! Have you looked for any directories?
とりあえずディレクトリ構成でも確認してみる。
find
も grep
も file
も less
も効かない。本当に制限されたshell環境である。 ls
コマンドで状況確認。
$ ls blackmail executables passwords photos secret
secret
以外は何もなし。secret ディレクトリはこんな感じ。
$ cd secret Now we are cookin'! Take a look around there and tell me what you find! ~/secret$ ls intel_1 intel_2 intel_3 intel_4 intel_5 profile_ahqueith5aekongieP4ahzugi profile_ahShaighaxahMooshuP1johgo profile_aik4hah9ilie9foru0Phoaph0 profile_AipieG5Ua9aewei5ieSoh7aph profile_bah9Ech9oa4xaicohphahfaiG profile_ie7sheiP7su2At2ahw6iRikoe profile_of0Nee4laith8odaeLachoonu profile_poh9eij4Choophaweiwev6eev profile_poo3ipohGohThi9Cohverai7e profile_Xei2uu5suwangohceedaifohs Sabatoge them! Get rid of all their intel files!
cat
commandが効いたので、一つづつ覗いてみるもよくわからない文字列ばかり。
get rid of らしいので、intel_*ファイルを一つ消してみる。
$ rm intel_1 Nice! Once they are all gone, I think I can drop you a file of an exploit! Just type "echo 'Drop it in!' " and we can give it a whirl!
言われたとおりに打ってみます。
$ echo 'Drop it in!' Drop it in! I placed a file in the executables folder as it looks like the only place we can execute from! Run the script I wrote to have a little more impact on the system!
executeファイルが生成されたっぽいので、行って実行してみます。
$ cd ../executalbes ~/executables$ ls dontLookHere ~/executables$ ./dontLookHere fc38 f138 894b 06df 6f59 b0c5 b85f bdf4 b0b6 e333 051d 5029 c0b8 8af2 e89a 6ca2 9428 f690 1184 61a9 1804 b678 9c1a cee3 352b 3d37 29f2 eb9c 0abc ea24 695a 6415 9cb9 8c79 7f6f 4316 e8af 11b9 b8a1 0607 0fe9 a69e 8ed8 6bc9 db2e 10de 4ca9 4a8d f5a9 37bf ~~(略)~~ Looking through the text above, I think I have found the password. I am just having trouble with a username. Oh drats! They are onto us! We could get kicked out soon! Quick! Print the username to the screen so we can close are backdoor and log into the account directly! You have to find another way other than echo!
ブワーッと意味不明な文字列が出力されたあと、次の司令が。自分のusernameを入れればいいが、echoは使えないとのこと。ならばusernameを返してくれるコマンドを入れてみる。
~/executables$ whoami l33th4x0r Perfect! One second! Okay, I think I have got what we are looking for. I just need to to copy the file to a place we can read. Try copying the file called TopSecret in tmp directory into the passwords folder.
コピーコマンドを使えば良いっぽい。
$ cp /tmp/TopSecret ../passwords/ Server shutdown in 10 seconds... Quick! go read the file before we lose our connection!
まじか!10秒しか無いのか!と焦りつつコピーしたファイルを開く。
$ cat ../passwords/TopSecret Major General John M. Schofield's graduation address to the graduating class of 1879 at West Point is as follows: The discipline which makes the soldiers of a free country reliable in battle is not to be gained by harsh or tyrannical treatment.On the contrary, such treatment is far more likely to destroy than to make an army.It is possible to impart instruction and give commands in such a manner and such a tone of voice as to inspire in the soldier no feeling butan intense desire to obey, while the opposite manner and tone of voice cannot fail to excite strong resentment and a desire to disobey.The one mode or other of dealing with subordinates springs from a corresponding spirit in the breast of the commander.He who feels the respect which is due to others, cannot fail to inspire in them respect for himself, while he who feels,and hence manifests disrespect towards others, especially his subordinates, cannot fail to inspire hatred against himself. picoCTF{CrUsHeD_It_17ab99f5}
英文の理解が一番難しかった…。時間内には終わらなかったので何度かチャレンジ。
[Web] Client Side is Still Bad (150pt)
I forgot my password again, but this time there doesn't seem to be a reset, can you help me? http://2018shell.picoctf.com:55790 (link)
ソース見たらめっちゃ書いてあった。
<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>
flag: picoCTF{client_is_bad_3bd366}
最近認証の判定ロジックが配布する方のjsに書いてあって話題になっていましたが、それのひどいやつですね。
[Forensics] Desrouleaux (150pt)
Our network administrator is having some trouble handling the tickets for all of of our incidents. Can you help him out by answering all the questions? Connect with nc 2018shell.picoctf.com 40952. incidents.json
incidents.json に書かれた内容を集計したりするだけ。
$ nc 2018shell.picoctf.com 40952 You'll need to consult the file `incidents.json` to answer the following questions. What is the most common source IP address? If there is more than one IP address that is the most common, you may give any of the most common ones. 138.77.123.109 Correct! How many unique destination IP addresses were targeted by the source IP address 138.77.123.109? 3 Correct! What is the number of unique destination ips a file is sent, on average? Needs to be correct to 2 decimal places. 1.25 Correct! Great job. You've earned the flag: picoCTF{J4y_s0n_d3rUUUULo_b6cacd6c}
[Web] Logon (150pt)
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. http://2018shell.picoctf.com:5477 (link)
SQL injection を疑って admin' --
をuserに入れてみたが、こんなページが。
どうやら SQL injection に引っかかったわけではなく、単に "admin" 意外のuserを入れるとこうなるらしい。admin 意外はpasswordはチェックしていません、と。
もう少しサイトの状態を見てみると、ログインに成功・失敗したときにcookieに保存されているのがわかる。このとき、admin フィールドがFalseになっているので、これをTrueに書き換えてリロードするとflagが出現。
picoCTF{l0g1ns_ar3nt_r34l_aaaaa17a}
[Forengics] Reading Between the Eyes (150pt)
Stego-Saurus hid a message for you in this image, can you retreive it?
おや!ステゴザウルスと言っているけど、これはステガノ?来た?
そして落としたimageはステゴザウルスではなく犬。ハスキー犬。
タイトルが Reading Between the Eyes
なので、犬の目の間に何かがあるのか?
Exifをざっと確認しても特に何もなさそうだったので、Hintを確認。
Maybe you can find an online decoder?
うん?decoder?ちょっと調べてみるとこんなサイトが!
ここで該当のイメージをアップして decode したら、flagが出てきました。
ちょっと納得行かない気もするけどまぁよし。ステガノはあまり追ってもしょうがない気がする。サイトだけ覚えておこう。
[Forengics] Recovering From the Snap (150pt)
There used to be a bunch of animals here, what did Dr. Xernon do to them?
とりあえずなんかこの落ちてきたファイル、fileコマンドで見てもようわからんかったので
$ file animals.dd animals.dd: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 20480 (volumes <=32 MB), Media descriptor 0xf8, sectors/FAT 20, sectors/track 32, heads 64, serial number 0x9b664dde, unlabeled, FAT (16 bit)
foremost を mac に入れて分解させてみた。
$ foremost animals.dd foremost: /usr/local/etc/foremost.conf: No such file or directory Processing: animals.dd |*|
そしたら沢山jpeg画像が掘り出されて、その中の一つにflagが書いてありましたとさ。
$ ls 00000077.jpg 00002277.jpg 00003541.jpg 00005093.jpg 00001313.jpg 00003041.jpg 00004173.jpg 00005861.jpg
picoCTF{th3_5n4p_happ3n3d}
[Forengics] admin panel (150pt)
We captured some traffic logging into the admin panel, can you find the password?
リンク先から、data.pcap がDLできます。
wiresharkで開きます。packetの通信が全部で78行なので、すべての通信を見ていれば何かしら出てきそうですが、HTTP/1.0 200 OK のL74 の通信をちょっと見て これは書き出したほうが早そうだと思い、File > Export Objects > HTTP... で SaveAllします。いくつかファイルができているので、grepでフラグを探すもよし、adminワードで引っ掛けるもよし。
login(2) のファイルに
user=admin&password=picoCTF{n0ts3cur3_9feedfbc}
とありました。
[Reversing] assembly-0 (150pt)
What does asm0(0x2a,0x4f) return? Submit the flag as a hexadecimal value (starting with '0x'). NOTE: Your submission for this question will NOT be in the normal flag format. Source located in the directory at /problems/assembly-0_3_b7d6c21be1cefd3e53335a66e7815307.
Source の部分がリンクになっていたので落とすと、下記内容のファイル。
intro_asm_rev.S
.intel_syntax noprefix .bits 32 .global asm0 asm0: push ebp mov ebp,esp mov eax,DWORD PTR [ebp+0x8] mov ebx,DWORD PTR [ebp+0xc] mov eax,ebx mov esp,ebp pop ebp ret
これに asm0(0x2a,0x4f)
を突っ込んだときの返却値を回答するみたいですね。flagの形式はpicoCTF{***} ではないみたいです。
さっっっぱりわからなかったところに、ちょうどkaitoさんの記事が出たので、これとトリコロールな猫さんのEBP,ESPの解説を読みながら解いてみました。
push ebp # ebp(ベースポインタ)をmainが使用しているスタック領域の一番上に移動 mov ebp,esp # esp(スタックポインタ)をebpに追従 mov eax,DWORD PTR [ebp+0x8] # eax に 入力値 0x2a を代入 mov ebx,DWORD PTR [ebp+0xc] # ebx に 入力値 0x4f を代入 mov eax,ebx # eaxにebxの値(0x4f)を代入 mov esp,ebp # ebpをespに追従 pop ebp # ebpをmainに戻す ret # 戻り値はeax
ということで、答えは 0x4f。
[Binary] buffer overflow 0 (150pt)
Let's start off simple, can you overflow the right buffer in this program to get the flag? You can also find it in /problems/buffer-overflow-0_4_ab1efebbee9446039487c64b88d38631 on the shell server. Source.
donwloadした vuln
ファイルも詳細を見てみます。
$ file vuln vuln: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e1e24cdf757acbd04d095e531a40d044abed7e82, not stripped
Linux上か、picoCTFのshellで実行するべし。sourceもみてみます。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <signal.h> #define FLAGSIZE_MAX 64 char flag[FLAGSIZE_MAX]; void sigsegv_handler(int sig) { fprintf(stderr, "%s\n", flag); fflush(stderr); exit(1); } void vuln(char *input){ char buf[16]; strcpy(buf, input); } int main(int argc, char **argv){ FILE *f = fopen("flag.txt","r"); if (f == NULL) { printf("Flag File is Missing. Problem is Misconfigured, please contact an Admin if you are running this on the shell server.\n"); exit(0); } fgets(flag,FLAGSIZE_MAX,f); signal(SIGSEGV, sigsegv_handler); gid_t gid = getegid(); setresgid(gid, gid, gid); if (argc > 1) { vuln(argv[1]); printf("Thanks! Received: %s", argv[1]); } else printf("This program takes 1 argument.\n"); return 0; }
flag.txtを読み出して flag
変数に格納。
※なので flag.txt がおいてある picoCTF のshellで実行する必要がある。ちなみに、picoCTF shell に置かれている flag.txt は当然ながら、permissionが許可されておらず直接はのぞけない。
sigsegv_handler 関数がcallされれば、flagの内容を吐き出してくれる。
その先(L35)で呼ばれているvuln関数が、実行引数の argv[1] を buf[16] で確保した領域にコピーしようとしているので、ここでオーバーフローさせれば、signalが発動、flagの中身が表示されます。
なので、長めの入力を与えればOK
$ ./vuln aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa picoCTF{ov3rfl0ws_ar3nt_that_bad_b49d36d2}
[Crypto] caesar cipher 1 (150pt)
This is one of the older ciphers in the books, can you decrypt the message? You can find the ciphertext in /problems/caesar-cipher-1_2_73ab1c3e92ea50396ad143ca48039b86 on the shell server.
ciphertextは picoCTF{payzgmuujurjigkygxiovnkxlcgihubb}
あれ、もうフラグの形じゃん、ということで一旦入れてみる。。。やっぱこのままじゃだめか。
タイトルが ceaser cipher なので、シーザー暗号なんでしょう。いつもならフラグフォーマットの picoCTF
部分で法則を発見するのですが、今回はカッコの中だけが暗号文っぽいのであまり情報がない…。
ということで、ずらす文字数はたかだか26通り、全部出してみて意味のある文字列になることを祈って、全通り出力してみる。
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import string cipher = "payzgmuujurjigkygxiovnkxlcgihubb" alphabet = list(string.ascii_lowercase) def ceaser(shift, c): return alphabet[(alphabet.index(c) + shift) % 26] for shift in range(26): plain = "" for c in cipher: plain += ceaser(shift, c) print(plain)
実行結果
$ python solve.py payzgmuujurjigkygxiovnkxlcgihubb qbzahnvvkvskjhlzhyjpwolymdhjivcc rcabiowwlwtlkimaizkqxpmzneikjwdd sdbcjpxxmxumljnbjalryqnaofjlkxee tecdkqyynyvnmkockbmszrobpgkmlyff ufdelrzzozwonlpdlcntaspcqhlnmzgg vgefmsaapaxpomqemdoubtqdrimonahh whfgntbbqbyqpnrfnepvcuresjnpobii xighouccrczrqosgofqwdvsftkoqpcjj yjhipvddsdasrpthpgrxewtgulprqdkk zkijqweetebtsquiqhsyfxuhvmqsrell aljkrxffufcutrvjritzgyviwnrtsfmm bmklsyggvgdvuswksjuahzwjxosutgnn cnlmtzhhwhewvtxltkvbiaxkyptvuhoo domnuaiixifxwuymulwcjbylzquwvipp epnovbjjyjgyxvznvmxdkczmarvxwjqq fqopwckkzkhzywaownyeldanbswyxkrr grpqxdllaliazxbpxozfmeboctxzylss hsqryemmbmjbaycqypagnfcpduyazmtt itrszfnncnkcbzdrzqbhogdqevzbanuu justagoodoldcaesarcipherfwacbovv kvtubhppepmedbftbsdjqifsgxbdcpww lwuvciqqfqnfecguctekrjgthycedqxx mxvwdjrrgrogfdhvduflskhuizdferyy nywxeksshsphgeiwevgmtlivjaegfszz ozxyflttitqihfjxfwhnumjwkbfhgtaa
これが一番それっぽいぞ。ということで、flagは picoCTF{justagoodoldcaesarcipherfwacbovv}
[General] environ (150pt)
Sometimes you have to configure environment variables before executing a program. Can you find the flag we've hidden in an environment variable on the shell server?
picoCTF shell serverのenvironmentにflagがあるっぽいので、shell serverで確認。
$ export ~~中略~~ declare -x FLAG="Finding the flag wont be that easy..." declare -x PICOCTF_FLAG="Nice try... Keep looking!" declare -x SECRET_FLAG="picoCTF{eNv1r0nM3nT_v4r14Bl3_fL4g_3758492}" ~~中略~~
他にもややこしいのがありましたが、flagの形式を満たしている3つめのが答え。
[Crypto] hertz (150pt)
Here's another simple cipher for you where we made a bunch of substitutions. Can you decrypt it? Connect with nc 2018shell.picoctf.com 43324.
指定のurlにアクセスしてみるとこんな文字列が。
$ nc 2018shell.picoctf.com 43324 ------------------------------------------------------------------------------- yhisgtlp rfgf kp zhng mats - pnwplklnlkhi_ykxrfgp_tgf_phaotwaf_wuxtuftmyk ------------------------------------------------------------------------------- pltlfaz, xanvx wnyb vnaaksti ytvf mghv lrf pltkgrfte, wftgkis t whua hm atlrfg hi urkyr t vkgghg tie t gtchg atz yghppfe. t zfaahu egfppkisshui, niskgeafe, utp pnpltkife sfilaz wfrkie rkv hi lrf vkae vhgikis tkg. rf rfae lrf whua tahml tie kilhife: -kilghkwh te taltgf efk. rtalfe, rf xffgfe ehui lrf etgb ukiekis pltkgp tie ytaafe hnl yhtgpfaz: -yhvf nx, bkiyr! yhvf nx, zhn mftgmna qfpnkl! phafviaz rf ytvf mhgutge tie vhnilfe lrf ghnie snigfpl. rf mtyfe twhnl tie wafppfe sgtofaz lrgkyf lrf lhufg, lrf pngghniekis atie tie lrf tutbkis vhniltkip. lrfi, ytlyrkis pksrl hm plfxrfi efetanp, rf wfil lhutgep rkv tie vtef gtxke yghppfp ki lrf tkg, sngsakis ki rkp lrghtl tie prtbkis rkp rfte. plfxrfi efetanp, ekpxaftpfe tie paffxz, aftife rkp tgvp hi lrf lhx hm lrf pltkgytpf tie ahhbfe yhaeaz tl lrf prtbkis sngsakis mtyf lrtl wafppfe rkv, fjnkif ki klp afislr, tie tl lrf aksrl nilhipngfe rtkg, sgtkife tie rnfe akbf xtaf htb. wnyb vnaaksti xffxfe ti kipltil niefg lrf vkgghg tie lrfi yhofgfe lrf whua pvtglaz. -wtyb lh wtggtybp! rf ptke plfgiaz. rf teefe ki t xgftyrfgp lhif: -mhg lrkp, h eftgaz wfahofe, kp lrf sfinkif yrgkplkif: whez tie phna tie wahhe tie hnip. pahu vnpky, xaftpf. prnl zhng fzfp, sfilp. hif vhvfil. t akllaf lghnwaf twhnl lrhpf urklf yhgxnpyafp. pkafiyf, taa. rf xffgfe pkefutzp nx tie stof t ahis pahu urkplaf hm ytaa, lrfi xtnpfe turkaf ki gtxl tllfilkhi, rkp fofi urklf lfflr sakplfikis rfgf tie lrfgf uklr shae xhkilp. yrgzphplhvhp. luh plghis prgkaa urkplafp tipufgfe lrghnsr lrf ytav. -lrtibp, hae yrtx, rf ygkfe wgkpbaz. lrtl ukaa eh ikyfaz. puklyr hmm lrf ynggfil, ukaa zhn? rf pbkxxfe hmm lrf snigfpl tie ahhbfe sgtofaz tl rkp utlyrfg, stlrfgkis twhnl rkp afsp lrf ahhpf mhaep hm rkp shui. lrf xanvx prtehufe mtyf tie pnaafi hota qhua gfytaafe t xgfatlf, xtlghi hm tglp ki lrf vkeeaf tsfp. t xaftptil pvkaf wghbf jnkflaz hofg rkp akxp.
長い。そして何もわからない。
が、単語の区切りがあったりするみたいなので、換字式暗号化なと当たりをつけて念力で解く。こういうのは好きだ。
まずは文字の出現頻度を計測してみる。
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import string import pprint data = "pltlfaz, xanvx wnyb vnaaksti ytvf mghv lrf pltkgrfte, wftgkis t whua hm atlrfg hi urkyr t vkgghg tie t gtchg atz yghppfe. t zfaahu egfppkisshui, niskgeafe, utp pnpltkife sfilaz wfrkie rkv hi lrf vkae vhgikis tkg. rf rfae lrf whua tahml tie kilhife::: phafviaz rf ytvf mhgutge tie vhnilfe lrf ghnie snigfpl. rf mtyfe twhnl tie wafppfe sgtofaz lrgkyf lrf lhufg, lrf pngghniekis atie tie lrf tutbkis vhniltkip. lrfi, ytlyrkis pksrl hm plfxrfi efetanp, rf wfil lhutgep rkv tie vtef gtxke yghppfp ki lrf tkg, sngsakis ki rkp lrghtl tie prtbkis rkp rfte. plfxrfi efetanp, ekpxaftpfe tie paffxz, aftife rkp tgvp hi lrf lhx hm lrf pltkgytpf tie ahhbfe yhaeaz tl lrf prtbkis sngsakis mtyf lrtl wafppfe rkv, fjnkif ki klp afislr, tie tl lrf aksrl nilhipngfe rtkg, sgtkife tie rnfe akbf xtaf htb.::: rf pbkxxfe hmm lrf snigfpl tie ahhbfe sgtofaz tl rkp utlyrfg, stlrfgkis twhnl rkp afsp lrf ahhpf mhaep hm rkp shui. lrf xanvx prtehufe mtyf tie pnaafi hota qhua gfytaafe t xgfatlf, xtlghi hm tglp ki lrf vkeeaf tsfp. t xaftptil pvkaf wghbf jnkflaz hofg rkp akxp." alphabet = list(string.ascii_lowercase) def make_histgram(sentence): histgram = {} for a in alphabet: histgram[a] = 0 for c in sentence: if c.isupper(): histgram[c.lower()] += 1 if c.islower(): histgram[c] += 1 pprint.pprint(sorted(histgram.items(), key=lambda x: x[1])) make_histgram(data)
出力結果
$ python hertz.py [('d', 0), ('c', 1), ('q', 1), ('j', 2), ('o', 4), ('b', 10), ('z', 10), ('w', 11), ('m', 14), ('u', 14), ('y', 16), ('x', 17), ('v', 19), ('n', 25), ('s', 31), ('g', 45), ('h', 50), ('a', 53), ('k', 53), ('e', 55), ('p', 55), ('r', 55), ('l', 59), ('i', 63), ('t', 80), ('f', 97)]
頻度分析のこの表(wikipedia)) を参考に、当たりをつけて換算してみる。以下、作成した変換テーブル。変換後が大文字。
また、一文字単語に t
があったので、こちらは A
だと予想をつける。
更に、頻出する3文字の単語は THE
のことが多いので、 lrf
-> ``THE。
QVXZ
f -> E t -> A i -> N l -> T r -> H p -> S e -> D k -> I a -> L h -> O g -> R s -> G z -> Y m -> F v -> M n -> U u -> W y -> C w -> B c -> Z x -> P b -> K q -> J o -> V
これを当てはめると、全文は以下のように。
------------------------------------------------------------------------------- CONGRATS HERE IS YOUR FLAG - SUBSTITUTION_CIPHERS_ARE_SOLVABLE_BWPAWEAFCI ------------------------------------------------------------------------------- STATELY, PLUMP BUCK MULLIGAN CAME FROM THE STAIRHEAD, BEARING A BOWL OF LATHER ON WHICH A MIRROR AND A RAZOR LAY CROSSED. A YELLOW DRESSINGGOWN, UNGIRDLED, WAS SUSTAINED GENTLY BEHIND HIM ON THE MILD MORNING AIR. HE HELD THE BOWL ALOFT AND INTONED: -INTROIBO AD ALTARE DEI. HALTED, HE PEERED DOWN THE DARK WINDING STAIRS AND CALLED OUT COARSELY: -COME UP, KINCH! COME UP, YOU FEARFUL JESUIT! SOLEMNLY HE CAME FORWARD AND MOUNTED THE ROUND GUNREST. HE FACED ABOUT AND BLESSED GRAVELY THRICE THE TOWER, THE SURROUNDING LAND AND THE AWAKING MOUNTAINS. THEN, CATCHING SIGHT OF STEPHEN DEDALUS, HE BENT TOWARDS HIM AND MADE RAPID CROSSES IN THE AIR, GURGLING IN HIS THROAT AND SHAKING HIS HEAD. STEPHEN DEDALUS, DISPLEASED AND SLEEPY, LEANED HIS ARMS ON THE TOP OF THE STAIRCASE AND LOOKED COLDLY AT THE SHAKING GURGLING FACE THAT BLESSED HIM, EjUINE IN ITS LENGTH, AND AT THE LIGHT UNTONSURED HAIR, GRAINED AND HUED LIKE PALE OAK. BUCK MULLIGAN PEEPED AN INSTANT UNDER THE MIRROR AND THEN COVERED THE BOWL SMARTLY. -BACK TO BARRACKS! HE SAID STERNLY. HE ADDED IN A PREACHERS TONE: -FOR THIS, O DEARLY BELOVED, IS THE GENUINE CHRISTINE: BODY AND SOUL AND BLOOD AND OUNS. SLOW MUSIC, PLEASE. SHUT YOUR EYES, GENTS. ONE MOMENT. A LITTLE TROUBLE ABOUT THOSE WHITE CORPUSCLES. SILENCE, ALL. HE PEERED SIDEWAYS UP AND GAVE A LONG SLOW WHISTLE OF CALL, THEN PAUSED AWHILE IN RAPT ATTENTION, HIS EVEN WHITE TEETH GLISTENING HERE AND THERE WITH GOLD POINTS. CHRYSOSTOMOS. TWO STRONG SHRILL WHISTLES ANSWERED THROUGH THE CALM. -THANKS, OLD CHAP, HE CRIED BRISKLY. THAT WILL DO NICELY. SWITCH OFF THE CURRENT, WILL YOU? HE SKIPPED OFF THE GUNREST AND LOOKED GRAVELY AT HIS WATCHER, GATHERING ABOUT HIS LEGS THE LOOSE FOLDS OF HIS GOWN. THE PLUMP SHADOWED FACE AND SULLEN OVAL JOWL RECALLED A PRELATE, PATRON OF ARTS IN THE MIDDLE AGES. A PLEASANT SMILE BROKE jUIETLY OVER HIS LIPS.
ということで、最初の行のflag部分を小文字に変換すればOK
[Forengics] hex editor (150pt)
This cat has a secret to teach you. You can also find the file in /problems/hex-editor_4_0a7282b29fa47d68c3e2917a5a0d726b on the shell server.
cat のリンク部分から、ハロウィン仕様の黒猫ちゃんの画像が。詳細を確認してみる。
$ file hex_editor.jpg hex_editor.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 631x1024, frames 3
タイトルが hex editor なので、とりあえずバイナリエディタで開いてみる。
と、最終行にflagが。ちなみに、 strings
コマンドでも良かった。
$ strings hex_editor.jpg (~~中略~~) Your flag is: "picoCTF{and_thats_how_u_edit_hex_kittos_dF817ec5}"
[General] ssh-keyz (150pt)
As nice as it is to use our webshell, sometimes its helpful to connect directly to our machine. To do so, please add your own public key to ~/.ssh/authorized_keys, using the webshell. The flag is in the ssh banner which will be displayed when you login remotely with ssh to with your username.
まずはlocal machineで鍵ペアの作成
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/***/.ssh/id_rsa): -> authorized_keys Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/***/.ssh/authorized_keys. Your public key has been saved in /home/***/.ssh/authorized_keys.pub.
picoCTFの Web Shell で、指定のフォルダを作成&移動、上記で作成した公開鍵をコピペ。
$ mkdir ~/.ssh $ cd ~/.ssh $ vi authorized_keys.pub # ここで中身の貼り付け
作ってみたは良いが、flagは何処?ということで問題文を読むと、どうやらsshでリモートログインしたときに表示されるとのこと。
$ ssh -i ~/.ssh/authorized_keys 2018shell4.picoctf.com picoCTF{who_n33ds_p4ssw0rds_38dj21}