LoginSignup
1
0

More than 5 years have passed since last update.

picoCTF 2017 level1 write up

Last updated at Posted at 2018-06-27

picoCTF という初心者向けのCTFがあると聞いてやってみた。

全て英語だが、かなり親切なので感動している。

ガンガン解けるから楽しい。

MISC

Internet Kitties

I was told there was something at IP shell2017.picoctf.com with port 53382. How do I get there? Do I need a ship for the port?

IPとポート番号を与えられる。

nc コマンドでつないであげれば良い。

nc shell2017.picoctf.com 53382

Piazza

Have questions about pico? You can ask here. The access code is 31337.

まずPiazzaにアカウント登録

検索BOXで31337で検索したらpinned post を見ろって書いてるから、

検索結果の一番下を見たらPINNED っていうpostがあった。

Leaf of the Tree

We found this annoyingly named directory tree starting at /problems/f8fc794974ad619254d983bc423608c6. It would be pretty lame to type out all of those directory names but maybe there is something in there worth finding? And maybe we dont need to type out all those names...? Follow the trunk, using cat and ls!

タブ補完の話

cat /problems/f8fc794974ad619254d983bc423608c6 とshellに打って(エンターキーを押さずに)タブを2回押すとその下のディレクトリが表示される。

初めはtrunkというディレクトリが表示されるのでtと打ってタブで補完。

もう一度タブを2回押すとさらにディレクトリが表示される。

Follow the trunkという言葉に従い、trunkで始まるディレクトリを追っていけばflagファイルにたどり着くので、そこでコマンドを実行すれば良い

looooong

I heard you have some "delusions of grandeur" about your typing speed. How fast can you go at shell2017.picoctf.com:44909?

ncコマンドで接続する

nc shell2017.picoctf.com 44909

30秒以内にv を760回ってその後5を打て、と言われる。

To prove your skills, you must pass this test.                     
Please give me the 'v' character '760' times, followed by a single 
'5'.
To make things interesting, you have 30 seconds.                   
Input:

無理に決まってるので、コピペで貼り付ける。

ヒントでは、pythonを推奨しているので、pythonで以下の文を実行し、所望の文字列を出力させる。

print("v" * 760 + "5")

shellで以下のように実行する

python -c 'print("v" * 760 + "5")'

あるいは、pythonを起動して打ち込んでも良い

****@shell-web: python                                              
Python 2.7.9 (default, Jun 29 2016, 13:08:31)            
[GCC 4.9.2] on linux2                                    
Type "help", "copyright", "credits" or "license" for more
 information.                                            
>>> print("v" * 760 + "5")

この1行を書くのにモタモタしているとbashloop が終了して、次は他の文字を指定してくるので、そこだけ速くタイピングする必要あり。

Leaf of the Forest

We found an even bigger directory tree hiding a flag starting at /problems/df79496e08066eab7b27611c897c4151. It would be impossible to find the file named flag manually...

findコマンドの話。-nameオプションでファイル名で検索できる。

find /problems/df79496e08066eab7b27611c897c4151 -name flag

見つかったらcatコマンドで見つけておしまい。

WorldChat

We think someone is trying to transmit a flag over WorldChat. Unfortunately, there are so many other people talking that we can't really keep track of what is going on! Go see if you can find the messenger at shell2017.picoctf.com:14747. Remember to use Ctrl-C to cut the connection if it overwhelms you!

grepの話。

シェルでコマンドの出力をフィルターできる。

nc shell2017.picoctf.com 14747 でつなぐと、おびただしい数のメッセージがやりとりされている。

そのままでは見ていけないので、nc shell2017.picoctf.com 14747 | grep flag として、flag という文字列が含まれる行のみを抽出してあげれば、flagperson がflagを教えてくれる。

BINARY EXPLOITATION

Bash Loop

シェルの話。

cd /problems/995871fcb203d3e223e9e4aaa65e4053  すると、bashloopflag が置いてある。

flagcat しても権限がないと言われるので、bashloop を実行してみる。

./bashloop

What number am I thinking of? It is between 0 and 4096 と返ってくるので適当な数字を引数に与えてみる。

./bashloop 20

Nope. Pick another number between 0 and 4096 と返ってくるので、全ての値を試して、grep でflagを抽出する。

for((i=0;i<4096;i++))do                                                 
    ./bashloop $i                                                  
done | grep flag                                 

Just No

A program at /problems/f6ae7c5798439ab46292af914f47b170 has access to a flag but refuses to share it. Can you convince it otherwise?

/problems/f6ae7c5798439ab46292af914f47b170 にはflag, auth, justno, just no.c が置いてある。

REVERSE ENGINEERING

Hex2Raw

This program requires some unprintable characters as input... But how do you print unprintable characters? CLI yourself to /problems/3ced8dfe6c77c63010c94a84656fa6ea and turn that Hex2Raw!

/problems/3ced8dfe6c77c63010c94a84656fa6ea/hex2raw を実行すると、1a558acddabd64bbccdd94903eafdf18 を raw formで渡してくれと言われる。

Give me this in raw form (0x41 -> 'A'):                           1a558acddabd64bbccdd94903eafdf18

echo -e を使えば16進数をraw form に変換できる。

echo -e '\x1a\x55\x8a\xcd\xda\xbd\x64\xbb\xcc\xdd\x94\x90\x3e\xaf\xdf\x18' | ./hex2raw

Python2 のdecode("hex") を使うのもあり。

python -c 'print("1a558acddabd64bbccdd94903eafdf18".decode("hex"))' | 
./hex2raw

WEB EXPLOITATION

What Is Web

Someone told me that some guy came up with the "World Wide Web", using "HTML" and "stuff". Can you help me figure out what that is? Website.

web問題。

とりあえずブラウザの Developer tool を開く。

ソースを見ると、以下のコメントがみれる。

<!-- Cool! Look at me! This is an HTML file. It describes what each page contains in a format your browser can understand. -->
<!-- The first part of the flag (there are 3 parts) is 72b28b258d2 -->
<!-- What other types of files are there in a webpage? -->

フラグが3つあって他のファイルといえば、CSSjs だろうとdeveloper toolsources タブを見ると、それぞれのファイルが見れ、フラグゲット。

Raw2Hex

This program just prints a flag in raw form. All we need to do is convert the output to hex and we have it! CLI yourself to /problems/45f3b0abcf176b7cf7c1536b28d05d72 and turn that Raw2Hex!

今度はraw formから16進に変換してくれ、とのこと。

これはxxd コマンドでできる。

raw2hex を実行するとThe flag is:v\h3- と返ってくるので、The flag is: の部分を削除してあげる必要がある。

これにはsed コマンドを使う。これは置換のコマンドでs/変更前の文字/変更後の文字/g のオプションを与える。

xxd はデフォルトではエディタのような出力を吐くので、16進のみを吐くように-ps オプションをつけて完成。

./raw2hex | sed 's/The flag is://g' | xxd -ps

CRYPTOGRAPHY

keyz

While webshells are nice, it'd be nice to be able to login directly. To do so, please add your own public key to ~/.ssh/authorized_keys, using the webshell. Make sure to copy it correctly! The key is in the ssh banner, displayed when you login remotely with ssh, to shell2017.picoctf.com

sshの話。

ざっくり言うとsshはあるPC(ホスト)から他のPC(リモート)を操作するためのもの(https://wa3.i-3-i.info/word11722.html) で、安全な通信を行うために、公開鍵暗号という暗号を用いる。

公開鍵暗号のためには公開鍵と秘密鍵を作成し、ホストは秘密鍵を持ち、リモートに公開鍵を渡すことで通信を行う。

webshellは使いやすいけど、自分のPCから繋げられたらいいよねってことで、公開鍵を作って自分nのPCからssh接続して見ましょう、という問題。

ここなどに従って鍵を作成すると、~/.ssh に秘密鍵がid_rsa, 公開鍵がid_rsa.pub という名前で出来上がる。

この公開鍵をリモートのPCの~/.sshauthorized_keys という名前で置いてあげれば、ssh接続できる。

まずはローカルの~/.ssh/id_rsa.pub の中身をコピーして、webshellでvim などを開いて貼り付け、名前をauthorized_keysとして保存してあげれば良い。

あとは、ローカルからssh shell2017.picoctf.com で接続すれば、flagが手に入る。

Substitute

A wizard (he seemed kinda odd...) handed me this. Can you figure out what it says?

暗号文がいかにも英語っぽいので、換字式暗号のソルバーに流すと解いてくれる。

THEとかFLAGとか明らかにあっていそうなところをキーとして与えると、? になるところもちゃんと解いてくれる。

Hash101

Prove your knowledge of hashes and claim a flag as your prize! Connect to the service at shell2017.picoctf.com:17428

hashの話、と言いながら、最初はエンコーディングの話。

個人的に勝手に崇めてるblack catさんのまとめ に掲載の、以下のコマンドを使えば良い。


文字列⇔16進数表現⇔2進数表現

文字列→16進数表現

echo "ABC"|xxd -ps

文字列→2進数表現

echo "ABC"|xxd -b

16進数表現→文字列

echo 4142434445464748 | xxd -ps -r

16進数表現→2進数表現

echo 4142434445 | xxd -ps -r|xxd -b

2進数表現→16進数表現

echo "obase=16; ibase=2; 010000010100001001000011010001000100010100001010" | bc

2進数表現→文字列

echo "obase=16; ibase=2; 010000010100001001000011010001000100010100001010" | bc|xxd -ps -r

Level1

-------- LEVEL 1: Text = just 1's and 0's --------                
All text can be represented by numbers. To see how different lette
rs translate to numbers, go to http://www.asciitable.com/         

TO UNLOCK NEXT LEVEL, give me the ASCII representation of 01110000
0111011101101110011010010110111001100111

2進数を文字列に変換してくれ、とのこと

文字列は何種類かパターンがある模様。

先のリストより、

echo "obase=16; ibase=2; 011100000111011101101110011010010110111001100111" | bc|xxd -ps -r

level 2

------ LEVEL 2: Numbers can be base ANYTHING -----                
Numbers can be represented many ways. A popular way to represent c
omputer data is in base 16 or 'hex' since it lines up with bytes v
ery well (2 hex characters = 8 binary bits). Other formats include
 base64, binary, and just regular base10 (decimal)! In a way, that
 ascii chart represents a system where all text can be seen as "ba
se128" (not including the Extended ASCII codes)                   

TO UNLOCK NEXT LEVEL, give me the text you just decoded, pwning, a
s its hex equivalent, and then the decimal equivalent of that hex 
number ("foo" -> 666f6f -> 6713199)

今度は16進数と10進数に変換してくれ、とのこと

まずは16進。大文字になっているとincorrectと言われるので、A~Eはa~eに変換してあげる。

echo "obase=16; ibase=2; 011100000111011101101110011010010110111001100111" | bc

10進数はリストには乗っていないが、obase=10 としてあげれば良い。

echo "obase=10; ibase=2; 011100000111011101101110011010010110111001100111" | bc

level3

----------- LEVEL 3: Hashing Function ------------                
A Hashing Function intakes any data of any size and irreversibly t
ransforms it to a fixed length number. For example, a simple Hashi
ng Function could be to add up the sum of all the values of all th
e bytes in the data and get the remainder after dividing by 16 (mo
dulus 16)                                                         

TO UNLOCK NEXT LEVEL, give me a string that will result in a 3 aft
er being transformed with the mentioned example hashing fun

要するに、文字列のASCIIコードを全て足し合わせて、16進表記で1の位が3になれば良い(16で割ってあまりが3)

A がASCIIコードで41となるので、AAA (41 + 41 + 41 = c3) やC (43)と打てば1の位が3なのでOK

level4

--------------- LEVEL 4: Real Hash ---------------      
A real Hashing Function is used for many things. This ca
n include checking to ensure a file has not been changed
 (its hash value would change if any part of it is chang
ed). An important use of hashes is for storing passwords
 because a Hashing Function cannot be reversed to find t
he initial data. Therefore if someone steals the hashes,
 they must try many different inputs to see if they can 
"crack" it to find what password yields the same hash. N
ormally, this is too much work (if the password is long 
enough). But many times, people's passwords are easy to 
guess... Brute forcing this hash yourself is not a good 
idea, but there is a strong possibility that, if the pas
sword is weak, this hash has been cracked by someone bef
ore. Try looking for websites that have stored already c
racked hashes.                                          

TO CLAIM YOUR PRIZE, give me the string password that wi
ll result in this MD5 hash (MD5, like most hashes, are r
epresented as hex digits):                              
699c0be567e2cbc16214dc4bc531cf4d

長々とhashについて語ってくれている。

ある文字列のMD5でのハッシュ値が699c0be567e2cbc16214dc4bc531cf4d となっているので、元の文字列を求めてくれ、と言われている。

本来ハッシュ関数は元の文字列が求められないものであるが、MD5はネット上にデコードのツールがゴロゴロ転がっている。

ここ などを使えば良い。

computeAES

You found this clue laying around. Can you decrypt it?

AES暗号 がお題。

有名な暗号は大体ネット上にツールが転がっている。例えばここ

今回は、keyとtextがbase64 でencodeされているので、まずそこを復号してあげる。

base64はshellで以下のようにエンコード/デコードできる。-necho による改行をなくすため。

# エンコード
echo -n "hello" | base64    # "aGVsbG8="
# デコード
echo -n "aGVsbG8=" | base64 -d # "hello"

今回は、16進数に変換する必要があるので、さっき出てきたxxd -ps を使ってあげる。

echo -n "R9TacKHy6cf1AZho/nwWWYaNzP5GfltKE5yW+kwRYe0LY+PdGk1hfoanS/iVZ7z1" | base64 -d | xxd -ps

echo -n "azdvtH4bvfdS/mryKLTNqQ==" | base64 -d | xxd -ps

これによって得られた16進の文字列を、http://aes.online-domain-tools.com/ に突っ込んであげれば良い。

AES暗号の鍵長は128,192,256があり、今回は16進数で32文字=256なので、256を指定する。

computeRSA

RSA encryption/decryption is based on a formula that anyone can find and use, as long as they know the values to plug in. Given the encrypted number 150815, d = 1941, and N = 435979, what is the decrypted number?

RSA暗号。ヒントの通り、秘密鍵n, d が分かっていれば

(平文) = (暗号文)^d % n となる。

bc コマンドを使えばこんな感じ。

echo "150815^1941%435979" | bc

pythonならこんな。

python -c "print(150815**1941%435979)"

FORENSICS

forensics というよりnetworkって感じだ。

Digital Camouflage

We need to gain access to some routers. Let's try and see if we can find the password in the captured network data: data.pcap.

pcapファイルの問題。wireshark を使う。

httpのようなので、とりあえずファイル -> オブジェクトをエクスポート でファイルを取り出してみる。

すると、main.htmluserid=mathewsr&pswrd=aHJLUVNTTFd2Rw%3D%3D と記載されており、パスワードがわかる。

が、ヒントに乗っているようにこのパスワードは暗号化されているようだ。

URL感が半端ないので、ひとまずURLエンコード を疑ってみる。

URLエンコードのツールは本当にネット上に転がっているので、ぶち込む。こことか

結果としてaHJLUVNTTFd2Rw== という文字列が出てくるので、これはもうbase64 にしか見えない。

末尾が= だったらもう大体base64

というわけでデコードしてフラグゲット。

echo "aHJLUVNTTFd2Rw==" -n | base64 -d

Special Agent User

We can get into the Administrator's computer with a browser exploit. But first, we need to figure out what browser they're using. Perhaps this information is located in a network packet capture we took: data.pcap. Enter the browser and version as "BrowserName BrowserVersion". NOTE: We're just looking for up to 3 levels of subversions for the browser version (ie. Version 1.2.3 for Version 1.2.3.4) and ignore any 0th subversions (ie. 1.2 for 1.2.0)

pcapファイルからUser-Agent をみて、ブラウザの種類とバージョンを答えてくれ、という問題。

ヒントでは、User-Agentの解析サイトを教えてくれている。日本語 のサイトもある。

肝心のUser-Agentは、pcapファイルの90番目のパケットに書いてある。

HTTPの通信を追っていけば見つかるはず。

右クリックで追跡 してもいいし、パケットを選択して下画面の Hypertext Transfer Protocol の詳細を開いてみても良い。

一番最後の Safari かと一瞬考えるが、これは互換がある、という情報らしい。

MASTER CHALLENGE

Lazy Dev

I really need to login to this website, but the developer hasn't implemented login yet. Can you help?

これもweb問題

問題ページに行くと、Enter the password と表示されており、適当なpasswordで送信するとNah, that's not it と返って来る。

先のweb問題のように、ソースを見て見ると、client.js というファイルでログインの認証を行っているようだ。

しかし、validate 関数は常にfalse を返すようになっている。

//Validate the password. TBD!
function validate(pword){
  //TODO: Implement me
  return false;
}

つまり、ここで返る値をtrue にすれば良さそうだ。

validate 関数は、process_password 関数で呼び出され、その返り値はres に代入されている。

//Called when the user submits the password
function process_password(){
  var pword = document.getElementById("password").value;
  var res = validate(pword);
  var server_res = make_ajax_req(res);
}

つまり、var res = validate(pword); の行の実行後に、res の値をtrue に書き換え、 var server_res = make_ajax_req(res); を実行させれば勝ちである。

Developer tool では、デバッグ機能がついており、javascriptの実行を途中で止めたり、consoleから変数の値を確認できたりする。参考:https://ics.media/entry/11735

ここで、変数の値を確認するだけでなく、変更することもできるのである。

今回の場合は、ソースコードの行番号の26をクリックしてブレークポイントを仕掛けた状態でパスワードを送信する。

すると、var res = validate(pword); の行が実行された状態で止まってくれるので、下のconsole に console.log(res)とすることで、res の値が分かる。

ここでres = true とすればres の値を書き換えることができ、Resume ボタンを押すとフラグを手に入れることができる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0