qzm:Buuctf RSA 题目总结

1.RSA

题目:

在一次RSA密钥对生成中,假设p=473398607161,q=4511491,e=17

求解出d作为flga提交

首先:

学习RSAtool2的使用:

1.Number Base 设置为十进制

2.注意:Public Exponent这里要使用16进制的数,如果公钥e=17的话,就应该填入十六进制的11

3.给出p,q,e的话直接填入,再点击Calc.D,获得d

4.给出的是n和e的话,输入n和e,点击Factor N(分解),得到p,q,再重复第3步就能得到d了

解答:

注意e填进去是16进制,需要将17转hex得到11再填进去

2.rsarsa

题目:

Math is cool! Use the RSA algorithm to decode the secret message, c, p, q, and e are parameters for the RSA algorithm.

 

 

p =  9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483

q =  11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407

e =  65537

c =  83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034

 

Use RSA to find the secret message

解答:

类型:n+e+c+p+q= m

工具中的e65537要转成十六进制10001

然后再用python函数pow()即可求出flag

M = pow(C,d,n)    #快速求幂取模运算

print(M)

直接脚本跑:使用n+e+c+p+q= m脚本

3.RSA1

题目:

p = 8637633767257008567099653486541091171320491509433615447539162437911244175885667806398411790524083553445158113502227745206205327690939504032994699902053229

q = 12640674973996472769176047937170883420927050821480010581593137135372473880595613737337630629752577346147039284030082593490776630572584959954205336880228469

dp = 6500795702216834621109042351193261530650043841056252930930949663358625016881832840728066026150264693076109354874099841380454881716097778307268116910582929

dq = 783472263673553449019532580386470672380574033551303889137911760438881683674556098098256795673512201963002175438762767516968043599582527539160811120550041

c = 24722305403887382073567316467649080662631552905960229399079107995602154418176056335800638887527614164073530437657085079676157350205351945222989351316076486573599576041978339872265925062764318536089007310270278526159678937431903862892400747915525118983959970607934142974736675784325993445942031372107342103852

解答:

https://blog.csdn.net/MikeCoke/article/details/105959599

类型:dp+dq+p+q+c = m  已知dp dq泄露

使用脚本dp+dq+p+q+c = m

hex to text转文本

noxCTF{W31c0m3_70_Ch1n470wn}

flag{W31c0m3_70_Ch1n470wn}

4.RSA3

题目:

c1=22322035275663237041646893770451933509324701913484303338076210603542612758956262869640822486470121149424485571361007421293675516338822195280313794991136048140918842471219840263536338886250492682739436410013436651161720725855484866690084788721349555662019879081501113222996123305533009325964377798892703161521852805956811219563883312896330156298621674684353919547558127920925706842808914762199011054955816534977675267395009575347820387073483928425066536361482774892370969520740304287456555508933372782327506569010772537497541764311429052216291198932092617792645253901478910801592878203564861118912045464959832566051361

n=22708078815885011462462049064339185898712439277226831073457888403129378547350292420267016551819052430779004755846649044001024141485283286483130702616057274698473611149508798869706347501931583117632710700787228016480127677393649929530416598686027354216422565934459015161927613607902831542857977859612596282353679327773303727004407262197231586324599181983572622404590354084541788062262164510140605868122410388090174420147752408554129789760902300898046273909007852818474030770699647647363015102118956737673941354217692696044969695308506436573142565573487583507037356944848039864382339216266670673567488871508925311154801

e1=11187289

c2=18702010045187015556548691642394982835669262147230212731309938675226458555210425972429418449273410535387985931036711854265623905066805665751803269106880746769003478900791099590239513925449748814075904017471585572848473556490565450062664706449128415834787961947266259789785962922238701134079720414228414066193071495304612341052987455615930023536823801499269773357186087452747500840640419365011554421183037505653461286732740983702740822671148045619497667184586123657285604061875653909567822328914065337797733444640351518775487649819978262363617265797982843179630888729407238496650987720428708217115257989007867331698397

e2=9647291

解答:

类型:共模n攻击

使用脚本gongmo.py

5.RSA2

题目:

e = 65537

n = 248254007851526241177721526698901802985832766176221609612258877371620580060433101538328030305219918697643619814200930679612109885533801335348445023751670478437073055544724280684733298051599167660303645183146161497485358633681492129668802402065797789905550489547645118787266601929429724133167768465309665906113

dp = 905074498052346904643025132879518330691925174573054004621877253318682675055421970943552016695528560364834446303196939207056642927148093290374440210503657

c = 140423670976252696807533673586209400575664282100684119784203527124521188996403826597436883766041879067494280957410201958935737360380801845453829293997433414188838725751796261702622028587211560353362847191060306578510511380965162133472698713063592621028959167072781482562673683090590521214218071160287665180751

解答:

类型:dp+n+e+c = m  dp泄露

RSA各题型脚本\dp+n+e+c = m

6.RSA

题目:

解答:

RSA

类型:n+e+c+p+q= m + 公钥提取

在线从rsa公钥中提取N和E: https://blog.csdn.net/weixin42135087/article/details/10544686

离线脚本:

7.RSAROLL

题目:

{920139713,19}

 

704796792

752211152

274704164

18414022

368270835

483295235

263072905

459788476

483295235

459788476

663551792

475206804

459788476

428313374

475206804

459788476

425392137

704796792

458265677

341524652

483295235

534149509

425392137

428313374

425392137

341524652

458265677

263072905

483295235

828509797

341524652

425392137

475206804

428313374

483295235

475206804

459788476

306220148

RSA roll!roll!roll!

Only number and a-z

(don't use editor

which MS provide)

解答:

RSAROLL

类型:n+e+c+p+q= m +  n分解

8.Dangerous RSA

题目:

#n:  0x52d483c27cd806550fbe0e37a61af2e7cf5e0efb723dfc81174c918a27627779b21fa3c851e9e94188eaee3d5cd6f752406a43fbecb53e80836ff1e185d3ccd7782ea846c2e91a7b0808986666e0bdadbfb7bdd65670a589a4d2478e9adcafe97c6ee23614bcb2ecc23580f4d2e3cc1ecfec25c50da4bc754dde6c8bfd8d1fc16956c74d8e9196046a01dc9f3024e11461c294f29d7421140732fedacac97b8fe50999117d27943c953f18c4ff4f8c258d839764078d4b6ef6e8591e0ff5563b31a39e6374d0d41c8c46921c25e5904a817ef8e39e5c9b71225a83269693e0b7e3218fc5e5a1e8412ba16e588b3d6ac536dce39fcdfce81eec79979ea6872793L

#e:  0x3

#c:0x10652cdfaa6b63f6d7bd1109da08181e500e5643f5b240a9024bfa84d5f2cac9310562978347bb232d63e7289283871efab83d84ff5a7b64a94a79d34cfbd4ef121723ba1f663e514f83f6f01492b4e13e1bb4296d96ea5a353d3bf2edd2f449c03c4a3e995237985a596908adc741f32365

so,how to get the message?

解答:

类型:低加密指数攻击 e很小  n很大又不好分解

脚本:RSA各题型脚本\e=2-低加密指数攻击\低加密指数攻击.py

b'flag{25df8caf006ee5db94d48144c33b2c3b}'

 

9.[HDCTF2019]basic rsa

题目:

import gmpy2

from Crypto.Util.number import *

from binascii import a2b_hex,b2a_hex

flag = "*****************"

p = 262248800182277040650192055439906580479

q = 262854994239322828547925595487519915551

e = 65533

n = p*q

c = pow(int(b2a_hex(flag),16),e,n)

print c

# 27565231154623519221597938803435789010285480123476977081867877272451638645710

解答:

类型:n+e+c+p+q= m

注释中就是该脚本生成的c

使用脚本RSA各题型脚本\n+e+c+p+q= m

 

10.Rsa2

题目:

N = 101991809777553253470276751399264740131157682329252673501792154507006158434432009141995367241962525705950046253400188884658262496534706438791515071885860897552736656899566915731297225817250639873643376310103992170646906557242832893914902053581087502512787303322747780420210884852166586717636559058152544979471

e = 46731919563265721307105180410302518676676135509737992912625092976849075262192092549323082367518264378630543338219025744820916471913696072050291990620486581719410354385121760761374229374847695148230596005409978383369740305816082770283909611956355972181848077519920922059268376958811713365106925235218265173085

import hashlib

flag = "flag{" + hashlib.md5(hex(d)).hexdigest() + "}"

解答:

rsa2

类型:低解密指数攻击 e过大 n分解不出来 n+e=d.py

 

11.[BJDCTF 2nd]rsa0

题目:

解答:

rsa0

类型:根据等式  p、q\p+q p-q.py

 

12.RSA5

题目:

解答:

RSA5

类型:低加密指数广播攻击

加密指数e非常小

一份明文使用不同的模数n,相同的加密指数e进行多次加密

可以拿到每一份加密后的密文和对应的模数n、加密指数e

 

 

 

13.BabyRSA

题目:

解答:

BabyRSA

类型:根据等式  p+q (p+1)(q+1) d c.py

 

下面是查看这位博主的:

https://blog.csdn.net/MikeCoke/article/details/107206707

 

14.[NCTF2019]childRSA

题目:

from random import choice

from Crypto.Util.number import isPrime, sieve_base as primes

from flag import flag

def getPrime(bits):

    while True:

        n = 2

        while n.bit_length() < bits:

            n *= choice(primes)

        if isPrime(n + 1):

            return n + 1

e = 0x10001

m = int.from_bytes(flag.encode(), 'big')

p, q = [getPrime(2048) for _ in range(2)]

n = p * q

c = pow(m, e, n)

# n = 32849718197337581823002243717057659218502519004386996660885100592872201948834155543125924395614928962750579667346279456710633774501407292473006312537723894221717638059058796679686953564471994009285384798450493756900459225040360430847240975678450171551048783818642467506711424027848778367427338647282428667393241157151675410661015044633282064056800913282016363415202171926089293431012379261585078566301060173689328363696699811123592090204578098276704877408688525618732848817623879899628629300385790344366046641825507767709276622692835393219811283244303899850483748651722336996164724553364097066493953127153066970594638491950199605713033004684970381605908909693802373826516622872100822213645899846325022476318425889580091613323747640467299866189070780620292627043349618839126919699862580579994887507733838561768581933029077488033326056066378869170169389819542928899483936705521710423905128732013121538495096959944889076705471928490092476616709838980562233255542325528398956185421193665359897664110835645928646616337700617883946369110702443135980068553511927115723157704586595844927607636003501038871748639417378062348085980873502535098755568810971926925447913858894180171498580131088992227637341857123607600275137768132347158657063692388249513

# c = 26308018356739853895382240109968894175166731283702927002165268998773708335216338997058314157717147131083296551313334042509806229853341488461087009955203854253313827608275460592785607739091992591431080342664081962030557042784864074533380701014585315663218783130162376176094773010478159362434331787279303302718098735574605469803801873109982473258207444342330633191849040553550708886593340770753064322410889048135425025715982196600650740987076486540674090923181664281515197679745907830107684777248532278645343716263686014941081417914622724906314960249945105011301731247324601620886782967217339340393853616450077105125391982689986178342417223392217085276465471102737594719932347242482670320801063191869471318313514407997326350065187904154229557706351355052446027159972546737213451422978211055778164578782156428466626894026103053360431281644645515155471301826844754338802352846095293421718249819728205538534652212984831283642472071669494851823123552827380737798609829706225744376667082534026874483482483127491533474306552210039386256062116345785870668331513725792053302188276682550672663353937781055621860101624242216671635824311412793495965628876036344731733142759495348248970313655381407241457118743532311394697763283681852908564387282605279108

类型:n+e+c+p+q= m + yafu-1.34_大数分解

解答:

解题思路:

1.py文件给了,n , c , e。为了求m 由算法pow(c,d,n),可知要先求出d来

由算法

gmpy2.invert(e,N) # N = (q-1)*(p-1)

可知我们要先求出p,q来,即分解n

用yafu进行素数分解,先把模n新建一个txt文件,文件末尾要进行换行

进入cmd,命令 cd Desktop 进入桌面

命令

yafu-x64 "factor(@)" -batchfile 1.txt 进行10进制大整数分解

当数比较小时 用命令 yafu-x64 factor(n)

15.[BJDCTF 2nd]rsa1

题目:

e=12383489

 

p^2+q^2=314159935199409528855543190930370831610544606791885743828787728888169940576801488912886869459426148649617607007207064415361002287859918044717958023503361550654112187326720336584807372969840428548886840356085792670201560759971574286049511089809997082458397790355463913471592230515276858444422432564159208516058

 

p-q=

-165414786144020237083348663408005175530498290416929591942813103505849900202434656134042220642433156290473004065977118177026821676007095824869265136511654

 

c=998896160938320989401424547511666932070477513640999195769186522700049532189320052713384606599966777588583345115108658327237902906659968587760522674291092327152594149182354680477602273199911405406913234998336849522017937786354950520956339977934630832487978433223705114907402268437559006359878734405684844720

 

flag=??????

类型:根据等式  p+q (p+1)(q+1) d c.py

解答:

 

16.[HDCTF2019]bbbbbbrsa

题目:

p = 177077389675257695042507998165006460849

n = 37421829509887796274897162249367329400988647145613325367337968063341372726061

c = ==gMzYDNzIjMxUTNyIzNzIjMyYTM4MDM0gTMwEjNzgTM2UTN4cjNwIjN2QzM5ADMwIDNyMTO4UzM2cTM5kDN2MTOyUTO5YDM0czM3MjM

from base64 import b64encode as b32encode

from gmpy2 import invert,gcd,iroot

from Crypto.Util.number import *

from binascii import a2b_hex,b2a_hex

import random

 

flag = "******************************"

 

nbit = 128

 

p = getPrime(nbit)

q = getPrime(nbit)

n = p*q

 

print p

print n

 

phi = (p-1)*(q-1)

 

e = random.randint(50000,70000)

 

while True:

if gcd(e,phi) == 1:

break;

else:

e -= 1;

 

c = pow(int(b2a_hex(flag),16),e,n)

 

print b32encode(str(c))[::-1]

 

# 2373740699529364991763589324200093466206785561836101840381622237225512234632

类型:代码分析 + 已知pqnc 遍历e求明文 flag

解答:

1.第一张图给了 p,n,c,所以我们能够求出q

 

2.为了求出明文m ,我们先要求出d来

 

3.第二种图告诉我们 e 的范围在(50000,70000),我们可以对e进行遍历,爆破求出d

4. 对于每个符合条件的 e,都会得到一个与之对应的 m,我们知道 一般的 m中都会含有flag字符,所以用search()进行查找

import gmpy2 as gy

import re

import libnum

 

p = 177077389675257695042507998165006460849

n = 37421829509887796274897162249367329400988647145613325367337968063341372726061

c =2373740699529364991763589324200093466206785561836101840381622237225512234632

 

q = n // p

 

N = (p-1)*(q-1)

 

for e in range(50000,70000):

    try:

        d = gy.invert(e,N)

        flag = libnum.n2s(pow(c,d,n))

        if re.search('flag',flag):         #扫描整个字符串,返回第一个成功的匹配

            print(flag)

    except:

        pass

flag{rs4_1s_s1mpl3!#}

 

 

 

 

 

相关推荐

相关文章