code hacking, zen coding

NDH2k12 Public Wargame – RSA Writeup

Simple RSA:

$ cat john.pub
----- BEGIN PUBLIC KEY -----
KG4gPSAxNTQ5Mzg4MzAyOTk5NTE5LCBlID0gMTAxKQ==
-----  END PUBLIC KEY  -----
francois@squeeze:~/ndh2012/public/rsa$ echo -n "KG4gPSAxNTQ5Mzg4MzAyOTk5NTE5LCBlID0gMTAxKQ==" | base64 -d
(n = 1549388302999519, e = 101)

e = 101
n = 1549388302999519

Factorize n -> n = p * q -> 1549388302999519 = 31834349 * 48670331

$ python
>>> import librsa
>>> e = 101
>>> p = 31834349
>>> q = 48670331
>>> d = librsa.genPrivKey(e, p, q)
+ + +
>>> d
1165876286233741L

$ cat john.key
----- BEGIN PRIVATE KEY -----
KG4gPSAxNTQ5Mzg4MzAyOTk5NTE5LCBkID0gMTE2NTg3NjI4NjIzMzc0MSkK
-----  END PRIVATE KEY  -----
$ echo -n "KG4gPSAxNTQ5Mzg4MzAyOTk5NTE5LCBkID0gMTE2NTg3NjI4NjIzMzc0MSkK" | base64 -d
(n = 1549388302999519, d = 1165876286233741)

$ python decrypt.py john.key flag.asc
francois@squeeze:~/ndh2012/public/rsa$ cat flag
   _________
 _|      ___|_
|  ___  |   | |   HZV
| |___| |___| |
|_           _|   challenge by benjamin
  |  _   _  |
  |_| |_| |_|     c9132f892055ea81fd91a9ed0e54a859
Share