Port 53

明日のための技術メモ

picoCTF2018 miscellaneous WriteUP

せっかくCTF始めて楽しかったならpicoCTF2018もやってみたら?
とおすすめされたので、挑戦してみることにした。
ここではWarmUPとmiscellaneousを書く。

目次

General WarmUP

最初開いたらラボに横たわるロボットの画像が。
最初の問題を解いてロボットを動かしてくれ、とのこと。
本当にゲームっぽい。

General WarmUP1 (50pt)

問:あなたの成績を16進数で0x41という評価なら、ASCIIでは何になるか? 変換表を確認してフラグゲット。
picoCTF{A}

General WarmUP2 (50pt)

問:10進数27を2進数に変換すると? そのまんま素直に計算。
picoCTF{11011}

General WarmUP3 (50pt)

問:16進数0x3Dを10進数に変換すると? 同じくそのまんま素直に計算。
picoCTF{61}

miscellaneous

最初のWarmUPを解いたら解放された。これ以外にもおなじみの分野が解けるみたい。
miscellaneousとは、雑多な、の意味らしい。

Resources (50pt)

リンク先に行ってフラグを探してね、とあったので素直にブラウザで開く。
ページにそのまんまフラグが書いてあった。
picoCTF{xiexie_ni_lai_zheli}

grep 1 (75pt)

ファイルの中のフラグを探す問題。ファイルの種類を調べる

~/Downloads $ file file
file: ASCII text, with very long lines

lessで開いてpicoCTFで検索かけた。
picoCTF{grep_and_you_will_find_cdf2e7c2}

net cat (75pt)

netcatの使い方問題みたい。

~/Downloads $ nc 2018shell.picoctf.com 49387
That wasn't so hard was it?
picoCTF{NEtcat_iS_a_NEcESSiTy_8b6a1fbc}

strings (100pt)

stringsの使い方問題みたい。全部出すと長いのでgrepしてみた。

~/Downloads $ strings strings | grep picoCTF
picoCTF{sTrIngS_sAVeS_Time_d3ffa29c}

pipe (110pt)

pipeの使い方問題。ごめんstringsでやってたやつだった。

~/Downloads $ nc 2018shell.picoctf.com 2015 | grep picoCTF
picoCTF{almost_like_mario_8861411c}

grep 2 (125pt)

Gamesタブの横にShellタブがあるのでこれを使う。
ログインは自分のユーザとPW(記号があるとログインできない)でいける。

hoge@pico-2018-shell:/problems/grep-2_1_ef31faa711ad74321a7467978cb0ef3a/files$ls                          
files0  files1  files2  files3  files4  files5  files6  files7  files8  files9
hoge@pico-2018-shell:/problems/grep-2_1_ef31faa711ad74321a7467978cb0ef3a/files$ cd files0                  
hoge@pico-2018-shell:/problems/grep-2_1_ef31faa711ad74321a7467978cb0ef3a/files/files0$ ls                  
file0   file11  file14  file17  file2   file22  file25  file28  file4  file7                                    
file1   file12  file15  file18  file20  file23  file26  file29  file5  file8                                    
file10  file13  file16  file19  file21  file24  file27  file3   file6  file9   

うわぁ、やめてくれ...
これワンライナーで突破した人いるんだろうか。
地道にcdしてcatとgrepで探した。すぐ見つかったからましだけど。

hoge@pico-2018-shell:/problems/grep-2_1_ef31faa711ad74321a7467978cb0ef3a/files/files2$ cat file* | grep pic
oCTF                                                                                                            
picoCTF{grep_r_and_you_will_find_4baaece4}

Aca-Shell-A (150pt)

言われるがままにサーバへ接続する。
どうも時間制限があり、一定時間経つと接続が切れて最初からやり直しになる。

~/Downloads $ nc 2018shell.picoctf.com 33158
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!

色々と試してみたけど相対パスの書き方が使えないとか、
よく使うコマンドのオプションが使えないとかあった。
ということで偵察。

~/$ pwd
/home/l33th4x0r/~/$ ls
blackmail
executables
passwords
photos
secret
~/$ cd secret
Now we are cookin'! Take a look around there and tell me what you find!
~/secret$ ls -l 
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  86 Jul  1  2018 intel_1
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2 100 Jul  1  2018 intel_2
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  95 Jul  1  2018 intel_3
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  40 Jul  1  2018 intel_4
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  85 Jul  1  2018 intel_5
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  44 Jul  1  2018 profile_ahqueith5aekongieP4ahzugi
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  44 Jul  1  2018 profile_ahShaighaxahMooshuP1johgo
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  90 Jul  1  2018 profile_aik4hah9ilie9foru0Phoaph0
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  95 Jul  1  2018 profile_AipieG5Ua9aewei5ieSoh7aph
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  30 Jul  1  2018 profile_bah9Ech9oa4xaicohphahfaiG
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  34 Jul  1  2018 profile_ie7sheiP7su2At2ahw6iRikoe
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  75 Jul  1  2018 profile_of0Nee4laith8odaeLachoonu
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  34 Jul  1  2018 profile_poh9eij4Choophaweiwev6eev
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  89 Jul  1  2018 profile_poo3ipohGohThi9Cohverai7e
-rw-r--r-- 1 aca-shell-a_2 aca-shell-a_2  50 Jul  1  2018 profile_Xei2uu5suwangohceedaifohs

この後、intelとつくファイルを全部消すように言われる

Sabatoge them! Get rid of all their intel files!
~/secret$ rm intel*
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!
~/secret$ 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!

言われるがままにecho 'Drop it in!'を打ってみる。 怪しいスクリプトの実行権限がついていた。最初偵察したときは権限なかったのに。

~/secret$ cd
~/$ cd executables
~/executables$ ls
dontLookHere
~/executables$ ./dontLookHere
 8e3e 5ba1 c413 0d5a 9bc2 d21d 5def 2852 f5f9 ae59 6462 3915 bb04 55a6 7569 49b3 c055 38fb e6fe b763 3b3b c0f6 c4a1 3781 39c2
 f1dd 4d6a 2c7c 587e 3cbd a0a9 f282 d7da 6b6d 412e 6a79 e4dd 5de7 23c0 b87a 8d54 04e9 725e cc7f f399 e80a dd65 055f e11a 97f2
 d6c8 7d5d b922 70c8 e641 fe4c 7915 2fdd f882 9f77 7059 45c2 173b b36e cd6e 24e4 6d80 9961 8e66 7a90 8e6e a837 ec5e 6d7c 9fb1
 0186 4308 a215 4d81 e7ca 1868 9834 4d82 5982 70a7 f575 c7e7 fdbb fd90 d2b5 b157 2082 d6f6 fe7a cb7b ff62 958b c11e 2854 c92a
 7937 10e2 1098 c2c6 0228 f7bb a0ca 57f6 9ca2 d1c9 ed7d 3bc1 c067 b1ee a0ff 9fbf 4f54 1fcc 5f9c 4ee5 87c8 053c 5919 5825 53ea
 f00e 9222 0529 e9ee 0d39 5ad4 a0b8 9491 1186 d3e1 42c2 7871 6f6e 81f5 f435 5086 8d82 e56f 5f64 d9b2 c4e5 a505 10db beb7 9807
 473d 7475 1a4b 9b7e cc82 3af0 f75a b58e 3c32 a4a7 3512 c7f3 7603 f506 0a28 68cc 0002 a278 a152 3da0 3d15 b5b0 0acc 811c b5cd
 f4be 2674 5bc6 a085 d5c5 871a 5421 81d6 6ee6 49a2 95a6 f6e3 62ac 706f ce56 b05c 10b4 4135 b679 3d91 86e9 d913 762c 4a1d 413d
 fa60 6f86 da1a 655d 43c1 4f3b 1184 cb95 2788 de62 4699 a30d d0d3 de8b 7868 cbc5 ceec fd78 b62e e87d 27e2 fbe5 be7f 1689 66d2
 9b5e 41fd 36a9 1c69 4861 8c29 cae9 60ae e6dd c28d 4f3f 2e5f 5ec5 c41f 6a6c f15a 90fd 5414 60ba e784 0ab5 068c dc6d 772c b6f2
 5a9d e2ec 5f8b d2b8 8cf4 6810 24b8 dc60 b70f e867 8bf3 4ac9 7d81 ba11 d03a 7fd5 1673 0ee7 9869 ce0a c693 7acd 23a8 b851 688b
 a791 b3d2 11dd d7e0 f049 ef2a b66c b856 b17f 1836 1948 bc16 d8f3 b158 74df 942d c874 cd78 fc1a 4849 81ed 30e4 a23c eb7c 0714
 8c68 b371 391d 3a68 ec4b 015a d0e7 e29c 0c0d 06c0 16ed 3379 516c 1168 519d e673 6322 c233 b415 870c c3d6 6803 a2ec db17 1a93
 6d50 7f69 9e71 9302 d42f 0f61 fa36 1fe2 2fc3 0e79 ba92 9c02 bd59 6ade 240a fe0e eeae ed41 0739 12ad de15 c5f9 b10a 25d9 a845
 0066 3ef2 7593 12a9 a458 dd97 9252 16c3 1657 fdbb 05d3 4fed de73 b71e f49d bdf0 6e62 bb6b 5284 f5c9 da04 983d 4513 e89d 834e
 deb9 737b 7c7a 222d a70b 0efb 0ddb be1f 7d54 a253 b3f8 725a bb1d 3dfb 3899 ec29 341b be0e 3456 e259 cbe2 6151 1987 d7d7 41ca
 c602 988e 8ef6 222a e942 bc8c ba65 7239 3375 e3c6 a2e9 6cd7 9f85 af6c 90d7 d793 0efe 6b99 47f8 d7b1 83c5 d32c 772a 669a 34fa
 d7fd 6a8e 7d3d ef9d 1382 1d03 c805 041a 3594 13ac bca1 2ef2 ea4e 506f aa60 52d7 8a7f 3039 4834 0d9c 191e 8203 e0d5 e670 8ae4
 84bb dbd5 ff70 2207 8a43 ac03 d061 d7b4 885a 30fb bd7b 5338 e7a3 3500 abda 093d 8004 f9ae fed6 763d 892d 0ae2 e445 9752 8bef
 42c3 2c33 1c51 8062 dc85 6eb8 7bec af72 0e49 1bd7 0477 8d67 c7e9 c36c fbf3 7fb5 21cb 1419 fa0c d3be c13c f8a7 2abe 8f6a 2a52
 4948 7717 a386 229d f276 c4ac fe61 6cef 0a1a ea0c 3a63 a389 45ad 03c2 b0d8 2b6a 6ee1 3460 9286 a745 0a40 25f5 5668 1cb9 c6a9
 6f59 4848 d2f8 9349 d318 d7f4 58ce b0e8 74bb 337a 7370 c0ea 0f8f 0640 47b3 4e35 5a44 a7de 4bdf 15f7 48b0 48a4 0ca5 77fe 75be
 322d 308a 6c99 1706 c4f5 4362 1978 256d 2232 c707 e4f3 d142 1249 d426 3f06 9146 cc41 0303 8a67 4271 b962 7aad e8c5 88bb ac8d
 9f61 d626 2cdf 5b6d d0ec a47f 05ff 75a0 dcc8 d1f1 fd5f 9fce 2406 113c e48d d5bb 39c4 c73b c4ca 3ca4 8be8 15ee 9289 d208 9520
 c5c7 75bc 2113 ae27 0e55 658b 015d a6b8 a3d4 41d9 f121 700e 63bc 2a8f c78d 1acc 2e07 1e88 3065 e483 f9fc 672f 682c 1bf4 79b8
 b6df faf4 fdcc f430 3a42 902f 4db0 6c82 d45d fab9 1a99 ee23 7dd8 b9cd e3a9 1d66 c0cd b1df 0cdb 9f95 0322 a1f9 7af6 fc76 c4d4
 658f d52f da6a 98ba e354 b22c 859b 0a52 9ca0 0d81 c63d 4826 db2b cecf 8dc0 0be0 f336 9b2a ef3f d4e1 efc9 8b99 b1ca 4120 518b
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!
~/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.

怪しいスクリプトを実行後、ユーザ名を表示させる。
その後、指定されたファイルをpasswordsディレクトリへコピーする。

~/executables$ cd
~/$ cd passwords
~/passwords$ cp /tmp/TopSecret passwords
Server shutdown in 10 seconds...
Quick! go read the file before we lose our connection!
~/passwords$ cat 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_9edaa84a}

最後の最後まで焦らせてくるので心臓に悪い。
指定されたファイルを開いてフラグゲット。

environ (150pt)

envコマンドの使い方問題。素直に打ってみる。

hoge@pico-2018-shell:~$ env                                                                                
SECRET_FLAG=picoCTF{eNv1r0nM3nT_v4r14Bl3_fL4g_3758492}                                                          
FLAG=Finding the flag wont be that easy...    

あっさりフラグが見つかった。

ssh-keyz (150pt)

picoCTFのシェルサーバにローカル端末からsshできるようにしましょう、
という問題。CTFというより環境構築のための問題っぽい気がする。
ローカル側でssh-keygenし、生成した公開鍵をpicoCTFのシェルサーバへコピペ。
ここを参考にした。
ローカル端末からsshするとフラグが見える。

~/Downloads $ ssh -i ~/.ssh/authorized_keys hoge@2018shell4.picoctf.com
Warning: Identity file /Users/pcname/.ssh/authorized_keys not accessible: No such file or directory.
picoCTF{who_n33ds_p4ssw0rds_38dj21}
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-1083-aws x86_64)

what base is this? (200pt)

指示通りサーバへ接続すると、30秒以内に基数変換してASCIIデコードする問題が。
コードを書いてターミナルを開いて待機。

~ $ nc 2018shell.picoctf.com 64706
We are going to start at the very beginning and make sure you understand how data is stored.
doctor
Please give me the 01100100 01101111 01100011 01110100 01101111 01110010 as a word.
To make things interesting, you have 30 seconds.
Input:
doctor
Please give me the 73746f7665 as a word.
Input:
stove
Please give me the  164 151 155 145 as a word.
Input:
time
You got it! You're super quick!
Flag: picoCTF{delusions_about_finding_values_5b21aa05}

you can't see me (200pt)

問題のシェルサーバにファイルがあるので探す。
ls -laじゃないとまずファイル名が出てこない。
そしてファイル名が.なので、ただじゃ開かない。
*を使って他のディレクトリ含め釣ることにした。

hoge@pico-2018-shell:/problems/you-can-t-see-me_3_1a39ec6c80b3f3a18610074f68acfe69$ ls -la
total 60
drwxr-xr-x   2 root       root        4096 Mar 25 19:57 .
-rw-rw-r--   1 hacksports hacksports    57 Mar 25 19:57 .  
drwxr-x--x 556 root       root       53248 Mar 25 19:58 ..
hoge@pico-2018-shell:/problems/you-can-t-see-me_3_1a39ec6c80b3f3a18610074f68acfe69$ cat .*
cat: .: Is a directory
picoCTF{j0hn_c3na_paparapaaaaaaa_paparapaaaaaa_cf5156ef}
cat: ..: Permission denied

absolutely relative (250pt)

問題文にあるディレクトリを見てみると、権限の関係でソースコードの編集はできなさそう。 また、ソースコードの中でこれとは別にpermission.txtが必要になることが分かった。

hoge@pico-2018-shell:/problems/absolutely-relative_3_c1a43555f1585c98aab8d5d2c7f0f9cc$ ll
total 76
drwxr-xr-x   2 root       root                   4096 Mar 25 19:11 ./
drwxr-x--x 556 root       root                  53248 Mar 25 19:58 ../
-rwxr-sr-x   1 hacksports absolutely-relative_3  8984 Mar 25 19:11 absolutely-relative*
-rw-rw-r--   1 hacksports hacksports              796 Mar 25 19:11 absolutely-relative.c
-r--r-----   1 hacksports absolutely-relative_3    37 Mar 25 19:11 flag.txt

ここにファイルを置くこともできないので、自分のホームディレクトリにpermission.txtを作成。
ソースコード30行目でこのファイルとconst char* yesを比較しているので、中身はyesと書いておく。

hoge@pico-2018-shell:~$ ls
permission.txt
hoge@pico-2018-shell:~$ cat permission.txt 
yes
hoge@pico-2018-shell:~$ /problems/absolutely-relative_3_c1a43555f1585c98aab8d5d2c7f0f9cc/absolutely-relative
You have the write permissions.
picoCTF{3v3r1ng_1$_r3l3t1v3_6193e4db}