Attack All Around

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

ractf 2020 Write up

 皆さん、こんにちは! Ken.Sです!

 

今回はCTFのWrite upを書いていこうと思います!

 

Mysterious Masquerading Message

エスパーしなければ解けない問題なのに100ptと得点が低かったので印象的でした。

 

与えられたファイルは、id_rsaとquestion.txtの二つで、question.txtは与えたファイルはssh秘密鍵っぽいけど本物ではなさそうと書いてあります。

 

ではid_rsaを見てみましょう。ssh秘密鍵とrot13で「good luck」となる文字列と8bitがたくさん…。ssh秘密鍵の末尾「=」なのでbase64なのかなとエスパー。見事念が通じました。

If you are reading this, then you probably figured out that it wasn\'t actually an SSH key but a disguise. So you have made it this far and for that I say well done. It wasn\'t very hard, that I know, but nevertheless you have still made it here so congrats. Now you are probably reading this and thinking about annoying the person who made this, and you want to read the whole thing to check for clues, but you cant find any. You are starting to get frustrated at the person who made this as they still haven\'t mentioned anything to do with the challenge, except "well done you have got this far". You start slamming desks, and soon the monitor will follow. You are wondering where this is going and realising it\'s coming to the end of the paragraph, and you might not have seen anything. I have given you some things, although you will need something else as well good luck. \n696e656564746f6f70656e6c6f636b73\n696e697469616c69736174696f6e3132

 

バカにされました…。見落としてる箇所があるかもよ、と言いつつ最後の二つの数字が気になるところです。とりあえずlong_to_bytesしてみます。

f:id:partender810:20200715225444p:plain

実行結果

またしても勘が冴えてました。ヒントも無いので見つけるのに時間がかかりました。一つ目の"i need to open locks" から、鍵つまりKEYを連想します。もう一つがinitialisationであることからブロック暗号AESをエスパーします。

 

KEYとivが見つかったのですが、暗号文は何でしょう。そこでid_rsaにあった8bitの数値がたくさんあったのを使います。10進数にするとなんとなくASCIIっぽいなぁと。文字にしてみると[0-9,a-f]という16進数みたいな結果が出ました。はいまたエスパー。

90988c9befe5ea3f5a91effe03060a8714dfc20088415570b394ce9cd32be718

 

これが平文なのでしょう。あとはAESのCBCモードで実行すればFLAGが手に入ります。

f:id:partender810:20200715230222p:plain

solver.py

ractf{3Asy_F1aG_0n_aEs_rAcTf}

 

Really Secret Algorithm

さっきのMMMが100ptでこの問題が300ptなのは納得できないほど、この問題の方が楽でした。

 

与えられたsecret.pyとquestion.txtを見てみると、どうやらsecret.pyの出力結果がquestion.txtのようです。key, e_str, ctが出力されています。

 

e_strはbase85encodeされているのでdecodeしてあげると65537といつもの公開鍵が出てきました。

 

RSA秘密鍵dを求めるために必要なp,qはバイト列にされ、1byteずつsとxorしkeyにappendされています。keyが既知であり、sも値が変化していますが初期値は0で以降はkey[i+1]であることが分かります。key[x]とsをxorすればコード内のi,jつまりp,qの1byteに該当します。i,jを求めbytearrayにappendすればp,qのバイト列になります。

 

p,qをbytes_to_longしそれらが素数であれば上手くいってます。あとはいつものRSAと一緒でdを求めて復号すると

ractf{DoY0uLik3MyW4lrus35}

 

f:id:partender810:20200715231538p:plain

solver.py

 

key, ctは見切れてますが、question.txtから引用しています。

 

 

今回はこの2問のWrite upを書いてみました。これが自分の本職というか分野ですという紹介でした(笑)

 

それでは!

 

See you next time!