Facebook CTF 2019 Writeup

この大会は2019/6/1 9:00(JST)~2019/6/3 9:00(JST)に開催されました。
今回もチームで参戦。結果は2380点で1734チーム中73位でした。
自分で解けた問題をWriteupとして書いておきます。

irc (misc)

freenodeで#fbctf-2019チャネルに入る。

09:14 *topic : CTF has started. Event ends June 3rd 00:00:00 UTC. fb{move_fast_and_hack_things}
fb{move_fast_and_hack_things}

easter egg (misc)

https://www.fbctf.com/careersのHTMLソースを見ると、HTMLタグの間に1文字ずつフラグの断片が入っている。

fb{we're_hiring}

keybaseish (crypto)

login画面やregister画面そのものには特に何も情報はない。次にlogin画面にリンクされているパスワードリカバリ画面を開く。
f:id:satou-y:20190608082742p:plain
ここではアクセスするたびに変わるpin番号が書いてあり、signature生成のスクリプトへのリンクがある。
スクリプトhttp://challenges.fbctf.com:8080/downloadは以下のようになっている。

from Crypto.PublicKey import RSA
from Crypto import Random

def print_twitter(sig):
    sig_str = str(sig)
    n = (len(sig_str) / 255) + 1
    chunks, chunk_size = len(sig_str), int(len(sig_str)/n) + 1
    tweets = [ sig_str[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
    print("Please post these signature strings as public twitter posts from your accout:")
    for ndx in range(len(tweets)):
        print ('  "PRF{}/{}:{}"'.format(ndx+1, len(tweets), tweets[ndx]))

def main():
    rng = Random.new().read
    print('Enter challenge pin from site: ')
    pin = input()
    print('Signing "{}" with a new RSA key....'.format(pin))
    RSAkey = RSA.generate(1024, rng)
    signature = RSAkey.sign(int(pin), rng)
    key_params = RSAkey.__getstate__()
    print_twitter(signature[0])
    print('\\n\\nPlease input your public key on the web form:')
    print('  "{}:{}"'.format(key_params['e'], key_params['n']))
    print('\\n\\n')

if __name__ == '__main__':
    main()

スクリプトRSAの通常の署名アルゴリズムになっていて、以下の式が成り立つ。

pow(signature, e, n) == pin

またパスワードリカバリ画面には、管理者のアカウントの情報として、以下のURLが記載されている。

https://twitter.com/baseishcoinfou1

ここにアクセスすると、signatureに関する情報が記載されている。
f:id:satou-y:20190608083033p:plain
スクリプトからsignatureは分断されているだけということがわかるので、1/2に書かれている数値と2/2に書かれている数値を結合したものがsignatureになる。
あとはeを適当に決めて、nを算出してe:nの形式にできれば、フラグにつながる情報が得られる。pinには900194が表示されたので、それを前提にスクリプトを組む。

sig1 = '43522081190908620239526125376626925272670879862906206214798620592212761409287968319160030205818706732092664958217053982767385296720310547463903001181881966'
sig2 = '554081621263332073144333148831108871059921677679366681345909190184917461295644569942753755984548017839561073991169528773602380297241266112083733072690367'
sig = int(sig1 + sig2)

e = 5
pin = 900194

n = pow(sig, e) - pin

print str(e) + ':' + str(n)

実行結果は以下の通り。

5:156152259934610603327242777109298638373934572320003018946780705593035129444427250712903196953268692654576940252842426080729553952653677882004392693966587497895771126063209172520687408155983845138814448218643812756870429001677159139697312185528286445629870220439486395991895413533025617686453330864683812555753179156400433858871091471963735884941049381029699284926525734780530683371637232542486580601832498002442370205259218637335066255536340402863614960635863279257288993952331758568563539255171752333659803630559976542479997459049186400474006649599261061239561731085004017823362429679461455596473090496147014713630612514413037251048846131962952608974559597665037989589516588758915639505296076818565509671460227096392858914958248349719519761080165615153613390888909577250254133864459387364823840496709605537195438529272540877498372727188018102166924786597538072319044503910010189326796934513137869684765977644563798377464844285519970335294217160696344254550102370879793030817756422968722131250375494110628633064924047523515038128770714301615363185342011455425978139447595336835379107137242896370138133354739730815895341370949542102301040465958437918589288157598747503502123011375289921007339937318514618737528870366815796019608309972031321180211231027906387141262192775078672105433479871010768651433527003348326639168952600370384527925162635252188830536959099871687232387447443824170080109823399109258223217519865552564954330502656132579024379460503613264612232039663908389480448494284442261160415871697947245392343456421606992172540056413

ハンドルネームはtwitterのハンドルネームを指定して、このスクリプトの実行結果を公開鍵として指定する。

twitter handle: baseishcoinfou1
public key: スクリプト実行結果

送信すると、画面遷移し、以下の情報が表示された。

Temporary Password
Account @admin Recovered:

Use this password to login: RWTFK1Z3zx5dsBV

login画面で以下を指定して送信すると、フラグが表示された。

Twitter handle: baseishcoinfou1
Password: RWTFK1Z3zx5dsBV

f:id:satou-y:20190608083320p:plain

flag{6F4EF3C06D00C14731B424069225CC6CAE96CD869E03C1B45A5D94A08F679DA2}