たくみん成長日記

開発したアプリやプログラミングの備忘録を不定期に上げていきます。

picoCTF2018 WriteUp 100点以下編

こんちか! たくみんです。2018.09.28(金)から2018.10.12(金)まで行われたpicoCTFに挑戦してみました。競技に参加したのが10.08(月)から、10.09(火)だったので、実質5日間で競技に取り組みました。 最終結果が以下のようになります。この内、General Skillsの400点問題1問と、Web Exploitationの300点問題1問、400点問題1問は大会終了後に解いているので実際は6735点が最終結果となります。

f:id:takuminv:20181015013704p:plain:w500

ぼくもCTFのWriteUpをやってみたかったので、記事にしてみます。picoCTFは問題の数が多かったので、複数回にわけて行いたいと思います。 今回は、100点以下の問題全14問のWriteUpを行います。

Forensics Warmup 1 - Points: 50

問題文

Can you unzip this file for me and retreive the flag?

ヒント

Make sure to submit the flag as picoCTF{XXXXX}

解答

ファイルがDLできるようになっているので、DLしてみます。するとflag.zipというファイルがDLできるので、素直にunzipコマンドを実行してみましょう。

$ unzip flag.zip

すると、flag.jpgという画像ファイルが出現します。開いてみるとフラグ獲得!

flag

f:id:takuminv:20181015014625j:plain:w500

Forensics Warmup 2 - Points: 50

問題文

Hmm for some reason I can't open this PNG? Any ideas?

ヒント

How do operating systems know what kind of file it is? (It's not just the ending! Make sure to submit the flag as picoCTF{XXXXX}

解答

pngファイルが何故か開けないようです。Warmupなので、そこまで難しくはないはず。というわけでとりあえずfileコマンドを実行してみましょう。

$ file flag.png
flag.png: JPEG image data, JFIF standard 1.01, resolution (DPI), density 75x75, segment length 16, baseline, precision 8, 909x190, frames 3

いや、めっちゃJPEGやん!!PNGちゃうやん!!
というわけで、flag.pngをflag.jpgになおしてフラグ獲得!!

flag

f:id:takuminv:20181015015546j:plain:w500

General Warmup 1 - Points: 50

問題文

If I told you your grade was 0x41 in hexadecimal, what would it be in ASCII?

ヒント

Submit your answer in our competition's flag format. For example, if you answer was 'hello', you would submit 'picoCTF{hello}' as the flag.

解答

ASCIIコード上で、0x41は何だろう?という問題です。こんな時は、ASCll表の出番ですね。

f:id:takuminv:20181015020004p:plain:w500

はい、ASCll表をみると0x41Aになっていますね。なので、picoCTF{A}がフラグになります。

flag

picoCTF{A}

General Warmup 2 - Points: 50

問題文

Can you convert the number 27 (base 10) to binary (base 2)?

ヒント

Submit your answer in our competition's flag format. For example, if you answer was '11111', you would submit 'picoCTF{11111}' as the flag.

解答

10進数の27は2進数だとどうなりますか?という問題です。27は10進数に直すと61ですね。なので、picoCTF{61}がフラグになります。

flag

picoCTF{61}

General Warmup 3 - Points: 50

問題文

What is 0x3D (base 16) in decimal (base 10).

ヒント

Submit your answer in our competition's flag format. For example, if you answer was '22', you would submit 'picoCTF{22}' as the flag.

解答

16進数の3Dは10進数だとどうなりますか?という問題です。16進数の3Dは10進数に直すと61ですね。なので、picoCTF{61}がフラグになります。

flag

picoCTF{61}

Resources - Points: 50

問題文

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)

ヒント

なし

解答

リンク先のページからフラグを見つけろという問題です。おそらくHTMLのなかにあるのではないかと推測しました。 HTML内で、picoCTFと検索するとフラグ発見!!

f:id:takuminv:20181015021003p:plain:w500

flag

picoCTF{xiexie_ni_lai_zheli}

Reversing Warmup 1 - Points: 50

問題文

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?

ヒント

If you are searching online, it might be worth finding how to exeucte a program in command line.

解答

ファイルをDLすると、runというファイルがDLできます。拡張子が書かれていないのでなんのファイルかわかりません。こういう時は、fileコマンドですね。fileコマンドを実行してみましょう。

$ file run
run: 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]=3f4cbb89ad8989bad12dfa913e40072f3d21c96d, not stripped

実行結果から、ELFファイルだとわかりました。 実行ファイルから文字列を見つけるときは、とりあえずstringsコマンドを叩いてみましょう。

$ strings run | grep pico
picoCTF{welc0m3_t0_r3VeRs1nG}

ビンゴ!!!

flag

picoCTF{welc0m3_t0_r3VeRs1nG}

Reversing Warmup 2 - Points: 50

問題文

Can you decode the following string dGg0dF93NHNfczFtcEwz from base64 format to ASCII?

ヒント

Submit your answer in our competition's flag format. For example, if you answer was 'hello', you would submit 'picoCTF{hello}' as the flag.

解答

base64のdGg0dF93NHNfczFtcEwzという文字列をデコードしろという問題ですね。ググってみると、ブラウザ上でデコードしてくれるサイトがあるようなので、ぶち込みます。

www.convertstring.com すると、dGg0dF93NHNfczFtcEwz → th4t_w4s_s1mpL3
となるので、picoCTF{th4t_w4s_s1mpL3}がフラグですね。

flag

picoCTF{th4t_w4s_s1mpL3}

Crypto Warmup 1 - Points: 75

問題文

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?.

ヒント

Submit your answer in our competition's flag format. For example, if you answer was 'hello', you would submit 'picoCTF{HELLO}' as the flag. Please use all caps for the message.

解答

table.txtというファイルが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

はい、これはシーザー暗号の上位互換である、ヴィジュネル暗号ですね。鍵の文字によって、ずらす回数が変化するやつです。 Rubyでヴィジュネル暗号を復号するスクリプトを作成しました。(ネットに復号するサイトがあることに後で気づきました…)

strs = "llkjmlmpadkkc"
keys = "thisisalilkey"


strs.each_char.with_index do |str,index| 

  str_ord = str.ord - "a".ord
  key_ord = keys[index].ord - "a".ord
  
  print((((((str_ord + 26) - key_ord) % 26) + "a".ord).chr).upcase)
  
  
end

実行した結果がこちらになります。

$ ruby answer.rb 
SECRETMESSAGE

SECRETMESSAGEなんて完全にフラグっぽいですね。よってフラグはpicoCTF{SECRETMESSAGE}になります。

これは余談ですが、渡された文を平文と鍵の2つだと勘違いしていて、50分位まちがったスクリプトを作り続けていました…

flag

picoCTF{SECRETMESSAGE}

Crypto Warmup 2 - Points: 75

問題文

Cryptography doesn't have to be complicated, have you ever heard of something called rot13? cvpbPGS{guvf_vf_pelcgb!}

ヒント

This can be solved online if you don't want to do it by hand!

解答

で、でた~ROT13奴~。はい、シーザー暗号ですね。ROT13は13文字ずつずらせということです。以下のサイトに暗号をぶち込みました。

ango.satoru.net するとcvpbPGS{guvf_vf_pelcgb!} → picoCTF{this_is_crypto!}になりました。 シーザー暗号の前に、ヴィジュネル暗号が来るのは何故なんでしょう。

flag

picoCTF{this_is_crypto!}

grep 1 - Points: 75

問題文

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.

ヒント

grep tutorial

解答

問題名からして、grepを使ってみよー的な問題だと思われます。 ファイルをDLします。また拡張子がないのでfileコマンド実行

$ file file
file: ASCII text, with very long lines

ASCllということはstringsコマンドでフラグが見つかるかもしれません。やってみます。

$ strings file | grep pico
picoCTF{grep_and_you_will_find_42783683}

フラグ獲得!!
ちなみにcatコマンドでも獲得できます。

flag

picoCTF{grep_and_you_will_find_42783683}

net cat - Points: 75

問題文

Using netcat (nc) will be a necessity throughout your adventure. Can you connect to 2018shell3.picoctf.com at port 36356 to get the flag?

ヒント

nc tutorial

解答

これも問題名からして、ncを使ってみよー的な問題だと思われます。 2018shell3.picoctf.comの36356番ポートに接続しろとのこと。

$ nc 2018shell3.picoctf.com 36356
That wasn't so hard was it?
picoCTF{NEtcat_iS_a_NEcESSiTy_9454f3e0}

フラグ獲得!!

flag

picoCTF{NEtcat_iS_a_NEcESSiTy_9454f3e0}

HEEEEEEERE'S Johnny! - Points: 100

問題文

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 2018shell3.picoctf.com 35225. Files can be found here: passwd shadow.

ヒント

If at first you don't succeed, try, try again. And again. And again. If you're not careful these kind of problems can really "rockyou".

解答

passwdとshadowの2つのファイルをDLできます。 psswdとshadowの内容は以下の通りです。

passwd

root:x:0:0:root:/root:/bin/bash
shadow

root:$6$L0grUkkk$H8JS0BBMMpGj8qqVpdvkOoBumhqhP5l2RYyOb/0aNhhgjtoEN4pJW3LVXIl93qieXao/G14AsjstVjJYxBmaz0:17770:0:99999:7:::

passwdを見ると、rootユーザが存在しており、パスワードは、shadowの方にハッシュ化して保存されているようですね。 ググってみると、ハッシュ化されたパスワードを推測するツールにJohn the Ripperがあるようです。 John the Ripperを用いて、ハッシュ化されたパスワードを推測します。

https://www.openwall.com/john/

$ john --show shadow    
root:superman:17770:0:99999:7:::

1 password hash cracked, 0 left

これにより、rootユーザのパスワードはsupermanだと判明しました。この情報を用いて、フラグを獲得しましょう。

$ nc 2018shell3.picoctf.com 35225
Username: root
Password: superman
picoCTF{J0hn_1$_R1pp3d_99c35524}

フラグもjohnとなっているので、John the Ripperを使うことが想定されているようです。

flag

picoCTF{J0hn_1$_R1pp3d_99c35524}

strings - Points: 100

問題文

Can you find the flag in this file without actually running it? You can also find the file in /problems/strings_4_40d221755b4a0b134c2a7a2e825ef95f on the shell server.

ヒント

stringsコマンドのドキュメントページヘのリンク

解答

これもstringsコマンド使ってみよー問題です。今までの問題ですでに使ってしまっていますが、やってみましょう。 stringsというファイルがDLできます。またまた拡張子がないので、とりあえずfileコマンド実行。

$ file strings 
strings: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e5ca61b750713b9161da547bc8ba99efc6e976be, not stripped

はい、ELFファイルですね。stringsコマンドを使う問題なので、stringsコマンドを実行してみます。grepでpicoで絞り込むとおそらくフラグにヒットすると思います。

$ strings strings| grep pico
picoCTF{sTrIngS_sAVeS_Time_d3ffa29c}

やったね。

flag

picoCTF{sTrIngS_sAVeS_Time_d3ffa29c}

おわりに

picoCTFはかなり初心者向けだと感じました。100点以下の問題であれば、linux触りたての人でも解けるのではないでしょうか。 次は、問題数的に、101~199点の問題のWriteUpになると思います。 ではでは。