首页 > 其他分享 >BUUCTF SameMod

BUUCTF SameMod

时间:2022-11-13 14:33:33浏览次数:51  
标签:SameMod BUUCTF gmpy2 839 c2 c1 e1 e2

题目原型:

1 {6266565720726907265997241358331585417095726146341989755538017122981360742813498401533594757088796536341941659691259323065631249,773}
2 {6266565720726907265997241358331585417095726146341989755538017122981360742813498401533594757088796536341941659691259323065631249,839}
3 
4 message1=3453520592723443935451151545245025864232388871721682326408915024349804062041976702364728660682912396903968193981131553111537349
5 message2=5672818026816293344070119332536629619457163570036305296869053532293105379690793386019065754465292867769521736414170803238309535

 可以看到有两个不同的e和c,并且有相同的n,很明显是rsa的共模攻击

先验证e1,e2是否互质

1 import gmpy2
2 e1 = 773
3 e2 = 839
4 r = gmpy2.gcd(e1, e2)
5 print(r)

得到结果为1,则e1,e2互质

根据共模攻击原理,使得(c1^e1*c2^e2)%n==m

由代码实现便是

 1 import gmpy2
 2 
 3 e1=773
 4 e2=839
 5 
 6 n=6266565720726907265997241358331585417095726146341989755538017122981360742813498401533594757088796536341941659691259323065631249
 7 
 8 c1=3453520592723443935451151545245025864232388871721682326408915024349804062041976702364728660682912396903968193981131553111537349#c1
 9 c2=5672818026816293344070119332536629619457163570036305296869053532293105379690793386019065754465292867769521736414170803238309535#c2
10 
11 _,s1,s2=gmpy2.gcdext(e1,e2)
12 m=(pow(c1,s1,n)*pow(c2,s2,n))%n
13 print(gmpy2.gcd(e1,e2))
14 print(m)

得出m后继续转换,尝试了long_to_bytes转换却得到一行乱码,另外试图将其转换成16进制转换字符也不行,后来转换成ascii码变得到答案

 1 m=str(m)
 2 flag=''
 3 i=0
 4 while i<len(m):
 5     if m[i]=='1':
 6         flag+=chr(int(m[i:i+3]))
 7         i+=3
 8     else:
 9         flag+=chr(int(m[i:i+2]))
10         i+=2
11 print(flag)

最后得到flag:flag{whenwethinkitispossible}

标签:SameMod,BUUCTF,gmpy2,839,c2,c1,e1,e2
From: https://www.cnblogs.com/lgyj/p/16885181.html

相关文章

  • BUUCTF [ACTF新生赛2020]crypto-rsa3
    题目原型:1fromflagimportFLAG2fromCryptodome.Util.numberimport*3importgmpy24importrandom56e=655377p=getPrime(512)8q=int(gmpy......
  • BUUCTF [ACTF新生赛2020]SoulLike题解(非爆破)
    查壳发现无壳。   IDA检查main函数显然先检查了输入是否以actf{开头进入sub_83A无法进入 点不进去是因为IDA限制了解析函数的长度,可以修改IDA下cfg......
  • BUUCTF [强网杯 2019]随便注 1
    1.拿到题目,先输入一个1'试一下是否存在注入点报错error1064:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMariaDBserverve......
  • BUUCTF-PWN-第四页writep(32题)
    重感冒持续发热五天,拖到现在终于发第四页的题解了axb_2019_heap保护全开的菜单堆题但是存在格式化字符串漏洞add如果key=43,那么大小可以自定义,不然最小只能是......
  • [BUUCTF]第八天训练日志
    文章目录​​[RoarCTF2019]EasyJava​​​​[BUUCTF2018]OnlineTool​​​​[GYCTF2020]Blacklist​​​​[MRCTF2020]你传你......
  • [BUUCTF]第八天训练日记
    文章目录​​[ZJCTF2019]NiZhuanSiWei​​​​[CISCN2019华北赛区Day2Web1]HackWorld​​​​[网鼎杯2018]Fakebook​​​​[极客大挑战2019]HardSQL​​​​[GXYCTF......
  • [BUUCTF]第六天训练日志
    文章目录​​[SUCTF2019]EasyWeb​​​​[HFCTF2020]EasyLogin​​​​[CISCN2019华北赛区Day2Web1]HackWorld​​[SUCTF2019]EasyWeb做了一半做不动了,换个时间来,花费......
  • [BUUCTF]第七天训练日志
    [SUCTF2019]EasyWeb​​suctf2019​​​​bypassopen_basedir的新方法​​阿姨熄灯了睡觉......
  • [BUUCTF]第十二天训练日志
    文章目录​​[SWPU2019]Web1​​[SWPU2019]Web1首先注册一个​​admin​​​用户提示已经被注册,估计要伪造admin身份了,发布广告那一页​​<script>alert(1);</scirpt>​​......
  • [BUUCTF]第三天训练日志
    文章目录​​[GKCTF2020]EZ三剑客-EzWeb​​​​[FBCTF2019]RCEService​​​​[BSidesCF2019]Kookie​​​​[CISCN2019华北赛区Day1Web5]CyberPunk​​​​[极客大挑......