TCPサーバの接続情報と、サーバのプログラム script.py が与えられた。
script.py は、以下の処理をするものだった。
flag.txt の内容を読み込み、それをもとに整数mを生成するp, qとするmの257乗をp*qで割った余りを計算し、ctとする(p-1)*(q-1)における逆元dを求めるn, 257, ctを出力するsの入力を受け付けるdをsで割った余りを出力する
sとして1 << 139 = 696898287454081973172991196020261297061888を与えると、
この値は2の140乗未満になり、出力される余りはdの下位139ビットになる。
すると、dの下位ビットがp*qのビット数の1/4程度得られるので、
SageMathを使ってCoppersmith's Attackをやってみる - ももいろテクノロジー
を参考にdの値が復元できそうに思えた。
しかし、このページのプログラムをそのまま動かしてもdの値は得られなかった。
そこで、得られているdの値の上位に何ビットかを全探索で補うようにした。
Information to connect to a TCP server and a server program script.py were given.
What script.py does is:
flag.txt and generate an integer m based on that.p, q.m to the 257th power modulo p*q and name it ct.(p-1)*(q-1) and name it d.n, 257, ct.s which is not less than 1 and less than 2 to the 140th power.d modulo s.
Entering 1 << 139 = 696898287454081973172991196020261297061888 as s,
this value should be less than 2 to the 140th power and the remainder will be the least 139 bits of d.
This means that we can obtain the lower part of p and its length is about 1/4 of the bit length of p*q.
Referring to SageMathを使ってCoppersmith's Attackをやってみる - ももいろテクノロジー,
it seemed the value of d can be recovered.
However, the value of d wasn't found by simply running the program on the page.
Seeing this, I had it to add several bits to the top of the obtained part of d by brute-forcing.
Using the Shell in
I got this result after about 45 minutes:
得られたdの値を用い、以下のように復号を行った。
I decrypted the message with the obtained value of d in this way:
この復号結果に
I obtained the flag by applying "From Hex" on