1.报错信息

    1. root@kali:~/桌面/RSA/easy_rsa/rsatool# python rsatool.py -f PEM -o key.pem -n 13826123222358393307 -d 9793706120266356337
    2. Using (n, d) to initialise RSA instance
    3. n = 13826123222358393307 (0xbfe041d1197381db)
    4. e = 65537 (0x10001)
    5. d = 9793706120266356337 (0x87ea3bd3bd0b9671)
    6. p = 4184799299 (0xf96ef843)
    7. q = 3303891593 (0xc4ed6289)
    8. Saving PEM as key.pem
    9. Traceback (most recent call last):
    10. File "rsatool.py", line 164, in <module>
    11. data = rsa.to_pem()
    12. File "rsatool.py", line 98, in to_pem
    13. return (PEM_TEMPLATE % base64.encodestring(self.to_der()).decode()).encode()
    14. File "rsatool.py", line 107, in to_der
    15. seq.setComponentByPosition(len(seq), Integer(x))
    16. File "/usr/local/lib/python2.7/dist-packages/pyasn1/type/univ.py", line 2267, in __len__
    17. return len(self._componentValues)
    18. File "/usr/local/lib/python2.7/dist-packages/pyasn1/type/base.py", line 214, in plug
    19. raise error.PyAsn1Error('Attempted "%s" operation on ASN.1 schema object' % name)
    20. pyasn1.error.PyAsn1Error: Attempted "__len__" operation on ASN.1 schema object

    1.原因在于python 的pyasn1库版本过高,需要安装低版本的库

    1. python -m pip install pyasn1==0.4.5

    image.png
    2.尝试生成私钥

    1. python rsatool.py -f PEM -o key.pem -n 13826123222358393307 -d 9793706120266356337

    image.png

    1. python rsatool.py -o private.pem -e 65537 -p 275127860351348928173285174381581152299 -q 319576316814478949870590164193048041239

    image.png
    计算出私钥,拿去解密出明文:

    1. openssl rsautl -decrypt -in flag.enc -inkey private.pem

    image.png

    1. openssl rsa -pubin -text -modulus -in warmup -in pubkey.pem

    解密公钥文件,提取出N(即Modulus),E(即Exponent),N不长的话可以直接转10进制,太长用工具转换。