Try   HackMD

TSG CTF 2020 Modulus Amittendus Writeup

Problem

The flag encrypted with RSA and its public key are given.

But we are given

d instead of
N
, by bug. Additionally, the coefficient
c=q1modp
is leaked.

The problem is to restore the plaintext from these information.

Solution

First, we have to restore

φ(N)=(p1)(q1).

From

ed=1modφ(N), for some integer
k>0
,
ed1=kφ(N)
holds true. Then from
d<φ(N)
, we can observe
k<e=65537
and we can brute-force the
k
which satisfies that condition. Now we got
φ(N)
.

Let's think about

φ(N)modp. Here:

φ(N)=(p1)(q1)=p(q1)q+1

and then,

φ(N)1=qmodp

and if we multiply both sides by

c=q1modp,

(φ(N)1)c=qq1modp(φ(N)1)c+1=0modp

can be obtained. So

(φ(N)1)c+1 is a multiple of
p
. We can calculate this and put it as
m
.

By the way, from Euler's theorem in number theory, the following holds for any integer

a that is prime to
N
and each other.

aφ(N)=1modN

In particular, since

N is a multiple of
p
,
aφ(N)1
will also become a multiple of
p
.

Now if we calculate the following:

aφ(N)1modm

the result will be also a multiple of

p since the modulo and the original number is a mulitple of
p
.

In this formula we can get a multiple of

p as many as we like, by changing the value of
a
. So we can obtain
p
by getting GCD of these values.

From

φ(N),p we can get
q
, so all the information needed to decrypt RSA is given. Then we can get the flag.

Appendix

By the way, after we got

m it seems we can obtain
q
by not using Euler's theorem and by using Coppersmith's Attack on the formula:

cq=1modp

But this must be impossible. The following is the proof.

With Coppersmith's Attack, the condition required to get the solution

(x1,,xn) of n-variable non-identical linear equations

a1x1+a2x2++anxnCmodp

from

N, a multiple of
p
and
pNβ
, the lower boundary
p
and
xiXi
, the upper boundary of
x
is

1logNi=1nlogXi1(1β)n+1n(n+1)(1n1β)(1β)

In our situation

n=1, so by sorting out the formula we get

logX1logNβ2

Then we can evaluate that

cp,φ(N)p2, and we get
mp3
. Then if we put
N=m
, the lower boundary of
p
is:

pN1/3

and we can assume

β1/3.

And from

X1=q,Nq3:

logX1logN13

Considering the above, the above condition will become

13(13)2

which is clearly not satisfied even after considering the error.