首页 > 其他分享 >Crypto|[AFCTF2018]可怜的RSA

Crypto|[AFCTF2018]可怜的RSA

时间:2023-05-06 14:33:51浏览次数:57  
标签:AFCTF2018 Crypto RSA flag ----- key import

public.key

-----BEGIN PUBLIC KEY-----
MIIBJDANBgkqhkiG9w0BAQEFAAOCAREAMIIBDAKCAQMlsYv184kJfRcjeGa7Uc/4
3pIkU3SevEA7CZXJfA44bUbBYcrf93xphg2uR5HCFM+Eh6qqnybpIKl3g0kGA4rv
tcMIJ9/PP8npdpVE+U4Hzf4IcgOaOmJiEWZ4smH7LWudMlOekqFTs2dWKbqzlC59
NeMPfu9avxxQ15fQzIjhvcz9GhLqb373XDcn298ueA80KK6Pek+3qJ8YSjZQMrFT
+EJehFdQ6yt6vALcFc4CB1B6qVCGO7hICngCjdYpeZRNbGM/r6ED5Nsozof1oMbt
Si8mZEJ/Vlx3gathkUVtlxx/+jlScjdM7AFV5fkRidt0LkwosDoPoRz/sDFz0qTM
5q5TAgMBAAE=
-----END PUBLIC KEY-----

flag.enc

GVd1d3viIXFfcHapEYuo5fAvIiUS83adrtMW/MgPwxVBSl46joFCQ1plcnlDGfL19K/3PvChV6n5QGohzfVyz2Z5GdTlaknxvHDUGf5HCukokyPwK/1EYU7NzrhGE7J5jPdi0Aj7xi/Odxy0hGMgpaBLd/nL3N8O6i9pc4Gg3O8soOlciBG/6/xdfN3SzSStMYIN8nfZZMSq3xDDvz4YB7TcTBh4ik4wYhuC77gmT+HWOv5gLTNQ3EkZs5N3EAopy11zHNYU80yv1jtFGcluNPyXYttU5qU33jcp0Wuznac+t+AZHeSQy5vk8DyWorSGMiS+J4KNqSVlDs12EqXEqqJ0uA==

读取public.key

读取public.key获取e和n

from Crypto.PublicKey import RSA
with open("pubckey.pem","rb") as f:
    key = RSA.import_key(f.read())
    print('n = %d' % key.n)
    print('e = %d' % key.e)

n = 79832181757332818552764610761349592984614744432279135328398999801627880283610900361281249973175805069916210179560506497075132524902086881120372213626641879468491936860976686933630869673826972619938321951599146744807653301076026577949579618331502776303983485566046485431039541708467141408260220098592761245010678592347501894176269580510459729633673468068467144199744563731826362102608811033400887813754780282628099443490170016087838606998017490456601315802448567772411623826281747245660954245413781519794295336197555688543537992197142258053220453757666537840276416475602759374950715283890232230741542737319569819793988431443
e = 65537

也可使用在线工具读取

分解n

使用factordb分解n

p = 3133337
q = 25478326064937419292200172136399497719081842914528228316455906211693118321971399936004729134841162974144246271486439695786036588117424611881955950996219646807378822278285638261582099108339438949573034101215141156156408742843820048066830863814362379885720395082318462850002901605689761876319151147352730090957556940842144299887394678743607766937828094478336401159449035878306853716216548374273462386508307367713112073004011383418967894930554067582453248981022011922883374442736848045920676341361871231787163441467533076890081721882179369168787287724769642665399992556052144845878600126283968890273067575342061776244939

解析明文

查看flag.enc可以发现密文是经过base64加密的,需要base64解码才能解析

from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from base64 import b64decode
import libnum

n = 79832181757332818552764610761349592984614744432279135328398999801627880283610900361281249973175805069916210179560506497075132524902086881120372213626641879468491936860976686933630869673826972619938321951599146744807653301076026577949579618331502776303983485566046485431039541708467141408260220098592761245010678592347501894176269580510459729633673468068467144199744563731826362102608811033400887813754780282628099443490170016087838606998017490456601315802448567772411623826281747245660954245413781519794295336197555688543537992197142258053220453757666537840276416475602759374950715283890232230741542737319569819793988431443
e = 65537
p = 3133337
q = 25478326064937419292200172136399497719081842914528228316455906211693118321971399936004729134841162974144246271486439695786036588117424611881955950996219646807378822278285638261582099108339438949573034101215141156156408742843820048066830863814362379885720395082318462850002901605689761876319151147352730090957556940842144299887394678743607766937828094478336401159449035878306853716216548374273462386508307367713112073004011383418967894930554067582453248981022011922883374442736848045920676341361871231787163441467533076890081721882179369168787287724769642665399992556052144845878600126283968890273067575342061776244939
d = libnum.invmod(e, (p-1)*(q-1))

key_info = RSA.construct((n, e, d, p, q))
key = RSA.importKey(key_info.exportKey())
key = PKCS1_OAEP.new(key)
f = open('flag.enc', 'r').read()
c = b64decode(f)
flag = key.decrypt(c)
print(flag)
b'afctf{R54_|5_$0_B0rin9}'

标签:AFCTF2018,Crypto,RSA,flag,-----,key,import
From: https://www.cnblogs.com/scarecr0w7/p/17377216.html

相关文章

  • [Pix2Pix] Image-to-Image Translation with Conditional Adversarial NetWorks
    paper:https://arxiv.org/pdf/1611.07004.pdf[CVPR2017]code:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pixhttps://phillipi.github.io/pix2pix/[official]数据组织:需要成对图像这是加利福利亚大学在CVPR2017上发表的一篇论文,讲的是如何用条件生成对抗......
  • cryptohack wp day(3)
    第二节模运算----第一题(GCD)在做这道题前,了解下欧几里得算法:欧几里得算法,也叫辗转相除法,用于求解两个非负整数a和b的最大公约数(GreatestCommonDivisor,GCD),即能够同时整除它们的最大正整数。算法的基本思想是,通过不断求解a和b的余数的最大公约数,最终可以得到a和b的最大公约......
  • 使用Angular Universal时的重要注意事项
    介绍尽管AngularUniversal项目的目标是能够在服务器上无缝渲染Angular应用程序,但您应该考虑一些不一致之处。首先,服务器和浏览器环境之间存在明显的差异。在服务器上渲染时,应用程序处于短暂或“快照”状态。应用程序被完全渲染一次,返回完整的HTML,而整个过程中的产生的状态被销毁......
  • cryptohack wp day (2)
    接着昨天的题目第五题看题目,一道简单的xor题,就是将“label中每个字符与13进行异或处理”,直接上代码:s="label"result=""foriins:result+=chr(ord(i)^13)print(result)或者按照题目所说,用pwntools库中的xor函数来进行异或操作,具体操作如下:frompwnimportxor......
  • h5 js RSA加密解密和AES加密解密
    一.RSA加密需要的js,点击下面链接可复制jsencrypt.js二.AES加密需要的js,点击下面链接可复制crypto-js.js三.加密方式1.单独使用RSA加密;(不推荐,加密后数据太大了)2.单独使用AES加密;(不推荐,安全性不好)3.RSA加密和AES加密混合使用;使用AES加密需要传的参数,使用RSA加密......
  • Robust Deep Reinforcement Learning against Adversarial Perturbations on State Ob
    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布!NeurIPS2020 ......
  • RSA(共模、低指数、素数分解、模不互质)
    buuctf:rsa3题目c1=22322035275663237041646893770451933509324701913484303338076210603542612758956262869640822486470121149424485571361007421293675516338822195280313794991136048140918842471219840263536338886250492682739436410013436651161720725855484866690084......
  • cryptohack wp day(1)
    就从头开始吧第一题(ASCII)一道简单的ASCII码转换,直接用题目的提示代码解就行了ascii=[99,114,121,112,116,111,123,65,83,67,73,73,95,112,114,49,110,116,52,98,108,51,125]flag=""foriinascii:flag+=chr(i)print(flag)第二题(Hex)......
  • NC53370 Forsaken的三维数点
    题目链接题目题目描述​Forsaken现在在一个三维空间中,空间中每个点都可以用\((x,y,z)\)表示。突然,三维空间的主人出现了,如果Forsaken想要继续在三维空间中呆下去,他就必须回答三维空间主人的问题。​主人会在空间中坐标为\((x,y,z)\)处加一点能量值,当他加了一......
  • 论文解读《Interpolated Adversarial Training: Achieving robust neural networks wi
    论文信息论文标题:InterpolatedAdversarialTraining:Achievingrobustneuralnetworkswithoutsacrificingtoomuchaccuracy论文作者:AlexLambVikasVermaKenjiKawaguchiAlexanderMatyaskoSavyaKhoslaJuhoKannalaYoshuaBengio论文来源:2022NeuralNetworks论文地址:dow......