[GKCTF2021]RRRRSA
[GKCTF2021]RRRRSA
题目
from Crypto.Util.number import *
from gmpy2 import gcd
flag = b'xxxxxxxxxxxxx'
p = getPrime(512)
q = getPrime(512)
m = bytes_to_long(flag)
n = p*q
e = 65537
c = pow(m,e,n)
print('c={}'.format(c))
p1 = getPrime(512)
q1 = getPrime(512)
n1 = p1*q1
e1 = 65537
assert gcd(e1,(p1-1)*(q1-1)) == 1
c1 = pow(p,e1,n1)
print('n1={}'.format(n1))
print('c1={}'.format(c1))
hint1 = pow(2020 * p1 + q1, 202020, n1)
hint2 = pow(2021 * p1 + 212121, q1, n1)
print('hint1={}'.format(hint1))
print('hint2={}'.format(hint2))
p2 = getPrime(512)
q2 = getPrime(512)
n2 = p2*q2
e2 = 65537
assert gcd(e1,(p2-1)*(q2-1)) == 1
c2 = pow(q,e2,n2)
hint3 = pow(2020 * p2 + 2021 * q2, 202020, n2)
hint4 = pow(2021 * p2 + 2020 * q2, 212121, n2)
print('n2={}'.format(n2))
print('c2={}'.format(c2))
print('hint3={}'.format(hint3))
print('hint4={}'.format(hint4))
分析
不是非常常规的rsa,我们先看看四个提示:
hint1 = pow(2020 * p1 + q1, 202020, n1)=\((2020 * p1 + q1)^{202020}mod\;n1\)
hint2 = pow(2021 * p1 + 212121, q1, n1)=\((2021 * p1 + 212121)^{q1}mod\;n1\)
hint3 = pow(2020 * p2 + 2021 * q2, 202020, n2)=\((2020 * p2 + 2021 * q2)^{202020}mod\;n2\)
hint4 = pow(2021 * p2 + 2020 * q2, 212121, n2)=\((2021 * p2 + 2020 * q2)^{212121}mod\;n2\)
像hint1这样式子,我们可以用二项式定理进行一个化简。
(觉得typora写公式好麻烦干脆手写的屑↓
pq都出来之后就可以常规做题了。
from gmpy2 import gcd
from Crypto.Util.number import *
import gmpy2
c=13492392717469817866883431475453770951837476241371989714683737558395769731416522300851917887957945766132864151382877462142018129852703437240533684604508379950293643294877725773675505912622208813435625177696614781601216465807569201380151669942605208425645258372134465547452376467465833013387018542999562042758
n1=75003557379080252219517825998990183226659117019770735080523409561757225883651040882547519748107588719498261922816865626714101556207649929655822889945870341168644508079317582220034374613066751916750036253423990673764234066999306874078424803774652754587494762629397701664706287999727238636073466137405374927829
c1=68111901092027813007099627893896838517426971082877204047110404787823279211508183783468891474661365139933325981191524511345219830693064573462115529345012970089065201176142417462299650761299758078141504126185921304526414911455395289228444974516503526507906721378965227166653195076209418852399008741560796631569
hint1=23552090716381769484990784116875558895715552896983313406764042416318710076256166472426553520240265023978449945974218435787929202289208329156594838420190890104226497263852461928474756025539394996288951828172126419569993301524866753797584032740426259804002564701319538183190684075289055345581960776903740881951
hint2=52723229698530767897979433914470831153268827008372307239630387100752226850798023362444499211944996778363894528759290565718266340188582253307004810850030833752132728256929572703630431232622151200855160886614350000115704689605102500273815157636476901150408355565958834764444192860513855376978491299658773170270
n2=114535923043375970380117920548097404729043079895540320742847840364455024050473125998926311644172960176471193602850427607899191810616953021324742137492746159921284982146320175356395325890407704697018412456350862990849606200323084717352630282539156670636025924425865741196506478163922312894384285889848355244489
c2=67054203666901691181215262587447180910225473339143260100831118313521471029889304176235434129632237116993910316978096018724911531011857469325115308802162172965564951703583450817489247675458024801774590728726471567407812572210421642171456850352167810755440990035255967091145950569246426544351461548548423025004
hint3=25590923416756813543880554963887576960707333607377889401033718419301278802157204881039116350321872162118977797069089653428121479486603744700519830597186045931412652681572060953439655868476311798368015878628002547540835719870081007505735499581449077950263721606955524302365518362434928190394924399683131242077
hint4=104100726926923869566862741238876132366916970864374562947844669556403268955625670105641264367038885706425427864941392601593437305258297198111819227915453081797889565662276003122901139755153002219126366611021736066016741562232998047253335141676203376521742965365133597943669838076210444485458296240951668402513
e=65537
q1 = gcd(n1,pow(hint2-212121,202020,n1)*pow(2020,202020,n1)-hint1*pow(2021,202020,n1))
p1 = n1//q1
q2 = gcd(n2,pow(hint3,212121,n2)*pow(2021,202020*212121,n2)-pow(hint4,202020,n2)*pow(2020,202020*212121,n2))
p2 = n2//q2
d2 = gmpy2.invert(e,(q2-1)*(p2-1))
q = pow(c2,d2,n2)
d1 = gmpy2.invert(e,(q1-1)*(p1-1))
p = pow(c1,d1,n1)
d = gmpy2.invert(e,(q-1)*(p-1))
m = pow(c,d,p*q)
print(long_to_bytes(m))
总结
学了很多新东西。感觉非常奇妙,繁琐分析的最后是简短的一行表达式,有种新年第一天穿着新……(下略)
1)拿到两个式子后,先把括号去掉,然后把等号右边的常数项去掉
2)得到两个只含p和q的式子,凑一下,使两个式子的p(或q)的指数和系数相同
3)将两个式子相加或相减消掉p,剩下的式子里的未知数应该只有q。再将结果与n求解最大公因数,进而求出q。
[GKCTF2021]RRRRSA的更多相关文章
- GKCTF2021 MISC
1.签到 当时没签上┭┮﹏┭┮: 追踪http流,发现依次执行[ls][ls/][whoami] 发现存在[fl4g],同时发现破解的规则为hex decode->base64 decode-& ...
- GKCTF 2021 Reverse Writeup
前言 GKCTF 2021所以题目均以开源,下面所说的一切思路可以自行通过源码对比IDA进行验证. Github项目地址:https://github.com/w4nd3r-0/GKCTF2021 出 ...
- 协议层安全相关《http请求走私与CTF利用》
0x00 前言 最近刷题的时候多次遇到HTTP请求走私相关的题目,但之前都没怎么接触到相关的知识点,只是在GKCTF2021--hackme中使用到了 CVE-2019-20372(Nginx< ...
随机推荐
- OpenJudge 1.8.11 图像旋转
11:图像旋转 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个n行m列的黑白图像,将它顺时针旋转90度后输出. 输入 第一行包含两个整数n和m,表示图像包含像素点的行数和列数. ...
- C# 正则表达式常用的符号和模式解析
〇.正则表达式的基本语法符号 若只简单匹配固定字符串,则无需任何修饰符,例如:需要匹配字符串 77,则可直接写:new Regex("77"). 下边例举一下常用的符号:(知道下面 ...
- CH392/CH395常见问题解决方法指南
CH395 问题 1: CH395 初始化失败.解答: 1.首先检查"check_exist"命令,正常情况下 CH395 会将该命令的输入值按位取反后输出,若该命令不正常,则说明 ...
- Spark详解(08) - Spark(3.0)内核解析和源码欣赏
Spark详解(08) - Spark(3.0)内核解析和源码欣赏 源码全流程 Spark提交流程(YarnCluster) Spark通讯架构 Spark任务划分 Task任务调度 Shuffle原 ...
- Spark详解(07) - SparkStreaming
Spark详解(07) - SparkStreaming SparkStreaming概述 Spark Streaming用于流式数据的处理. Spark Streaming支持的数据输入源很多,例如 ...
- Python自动化结算工资和统计报表|编程一对一教学微信:Jiabcdefh
实例需求说明 你好,我是悦创. 博客首发:https://bornforthis.cn/column/pyauto/auto_base07.html 学习了 Excel 文件的写入.读取和追加内容,那 ...
- day05-Vue02
Vue02 7.修饰符 7.1基本说明 修饰符(Modifiers)是以.指明的后缀,指出某个指令以特殊方式绑定 官方文档:修饰符 Vue中的修饰符有: 事件修饰符 按键修饰符 系统修饰符 事件修饰符 ...
- pip19.2.3升级到20.3.3版本升级失败问题
2021-01-06 macOS版本:11.1 安装pip: sudo easy_install pip 话不多说,直接上问题 一行命令搞定 终端:sudo pip install --upg ...
- Nacos服务注册原理分析
在分布式服务中,原来的单体服务会被拆分成一个个微服务,服务注册实例到注册中心,服务消费者通过注册中心获取实例列表,直接请求调用服务. 服务是如何注册到注册中心,服务如果挂了,服务是如何检测?带着这些问 ...
- KingbaseES libstdc++.so.6/ version 'CXXABI_1.3.8'问题处理
ERROR:libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ...) 此文是以 CentOS Linux 7 (AltArc ...