[LitCTF 2023]easy_math (中级)

源代码:

from Crypto.Util.number import *
from secret import flag

m = bytes_to_long(flag)
e = 65537
p = getPrime(512)
q = getPrime(128)
n = p*q
hint = p**3-q**5
c = pow(m,e,n)
print(f'n = {n}')
print(f'c = {c}')
print(f'hint = {hint}')
'''
n = 2230791374046346835775433548641067593691369485828070649075162141394476183565187654365131822111419512477883295758461313983481545182887415447403634720326639070667688614534290859200753589300443797
c = 2168563038335029902089976057856861885635845445863841607485310134441400500612435296818745930370268060353437465666224400129105788787423156958336380480503762222278722770240792709450637433509537280
hint = 392490868359411675557103683163021977774935163924606169241731307258226973701652855448542714274348304997416149742779376023311152228735117186027560227613656229190807480010615064372521942836446425717660375242197759811804760170129768647414717571386950790115746414735411766002368288743086845078803312201707960465419405926186622999423245762570917629351110970429987377475979058821154568001902541710817731089463915930932142007312230897818177067675996751110894377356758932
'''

攻击代码:

import gmpy2
import sympy as sp
from Crypto.Util.number import long_to_bytes

# 定义符号变量p,q
p, q = sp.symbols('p q')

# 定义方程组
y1 = 392490868359411675557103683163021977774935163924606169241731307258226973701652855448542714274348304997416149742779376023311152228735117186027560227613656229190807480010615064372521942836446425717660375242197759811804760170129768647414717571386950790115746414735411766002368288743086845078803312201707960465419405926186622999423245762570917629351110970429987377475979058821154568001902541710817731089463915930932142007312230897818177067675996751110894377356758932
y2 = 2230791374046346835775433548641067593691369485828070649075162141394476183565187654365131822111419512477883295758461313983481545182887415447403634720326639070667688614534290859200753589300443797
eq1 = p**3 - q**5 - y1
eq2 = p * q - y2

# 求解方程组
sol = sp.solve((eq1, eq2), (p, q))
print(sol)

# 解题
e = 65537
n = 2230791374046346835775433548641067593691369485828070649075162141394476183565187654365131822111419512477883295758461313983481545182887415447403634720326639070667688614534290859200753589300443797
c = 2168563038335029902089976057856861885635845445863841607485310134441400500612435296818745930370268060353437465666224400129105788787423156958336380480503762222278722770240792709450637433509537280
p = 7321664971326604351487965655099805117568571010588695608389113791312918573783115429227542573780838065461696504325762281209452761930184231131129306271846427
q = 304683618109085947723284393392507415311
d = gmpy2.invert(e, (p - 1) * (q - 1))
m = pow(c, d, n)
print(long_to_bytes(m))

flag为:

NSSCTF{f9fab7522253e44b48824e914d0801ba}

相关推荐
H轨迹H2 天前
BUUCTF-Web方向16-20wp
网络安全·渗透测试·ctf·buuctf
Мартин.2 天前
[Meachines] [Easy] Horizontall Strapi RCE+KTOR-HTTP扫描+Laravel Monolog 权限提升
网络协议·http·laravel·ctf
lally.5 天前
web信息泄露 ctfshow-web入门web1-web10
web·ctf·信息泄露
希望奇迹很安静8 天前
CTFSHOW-WEB入门-PHP特性109-115
开发语言·前端·web安全·php·ctf·新手
0DayHP10 天前
[HCTF 2018]WarmUp
ctf
Мартин.11 天前
[Meachines] [Easy] Soccer Tiny 2.4.3-RCE+WS-SQLI+Doas权限提升+dstat权限提升
ctf
希望奇迹很安静17 天前
CTFSHOW-WEB入门-PHP特性89-100
学习·web安全·php·ctf
希望奇迹很安静22 天前
CTFSHOW-WEB入门-命令执行29-32
前端·web安全·ctf
希望奇迹很安静1 个月前
CTFSHOW-WEB入门-文件包含78-81
学习·web安全·ctf
H轨迹H1 个月前
BUUCTF刷题-Web方向1~5wp
网络安全·渗透测试·ctf·buuctf·web漏洞