原题连接:https://ctf.njupt.edu.cn/545.html
    直接上脚本,反正原理也不懂

    1. from pwn import *
    2. from Crypto.Util.number import *
    3. from gmssl import func, sm2
    4. import server
    5. r = remote("129.211.59.129", 20001)
    6. # context.log_level = 'debug'
    7. pk = int(r.recvline().split(b":")[1].decode(), 16)
    8. pks = int(r.recvline().split(b":")[1].decode(), 16)
    9. log.info(f"pk: {pk}")
    10. log.info(f"pks: {pks}")
    11. backdoor = b'0'*128 + b'1'
    12. r.sendlineafter(b"op: ", b"sign")
    13. r.sendlineafter(b"backdoor:", backdoor)
    14. sks = int(r.recvline(), 16)
    15. n = 115792089210356248756420345214020892766061623724957744567843809356293439045923
    16. # pks = (sk + 1) * sks ^ -1
    17. sk = inverse(pks * sks, n) - 1
    18. log.info(f"sk: {sk}")
    19. data = b'Hello, Welcome to ISCC2021!'
    20. e = int(data.hex(), 16)
    21. k = 2
    22. tsm2 = server.TSM2('0xdeadbeaf')
    23. P1_P2 = tsm2._kg(k, server.G)
    24. R = int(P1_P2[:64], 16) + e
    25. s = inverse(1+sk, n) * (k - R*sk) % n
    26. r.sendlineafter(b"op: ", b"verify")
    27. r.sendlineafter(b"msg:", data)
    28. r.sendlineafter(b"sign:", hex(R)[2:].zfill(64) + hex(s)[2:].zfill(64))
    29. r.interactive()

    拿到flag
    变异的SM2 - 图1