best_rsa
cipher1
e臅/a`?%?爱A9q掱Z懟XNZ狺<??蚣倳鬶酻SK蠊檍悔?ZU?ヽ徊\笊x瞏衷RX挝xWX纣呍獅哞R岳鎴記砶镎撱?咘i?儔[刯d?g倔/鳩g辷笖k[KLVK腞Q 績憾x??Lh轡櫱!+顱乩OV7?`冻2z袨τWd?胴g幧攃藏埭.罆鄕姸%苜??R;鏆*?ss?@F惹v]rt?X餫巍鴽﹖:
cipher2
6^k隠紶!熄r洴躒 鲋ワ?#藄?"<m癥通?V?0?JM*>8`O?`P靇€?=?{v例F媺\笀镜??秕7A\_=偨?翜g鋏c耹B??絏Y|$LБ帤∕a ?凖$G=脣u紼< $V乂&S淧P謗&篋OV(@-?J偲7X渏?OG峭礛.鱒兌.莦鵐疗m#溋k^楋庤#偣0 矏vM?衅??*詨鵥?縝p簹+檠??g
还给了两个公钥,先进行公钥解析
import Crypto.PublicKey.RSA as RSA
with open("publickey1.pem", "r") as f:
key = RSA.importKey(f.read())
n = key.n
e = key.e
print (f'n1={n}')
print (f'e1={e}')
with open("publickey2.pem", "r") as f:
key = RSA.importKey(f.read())
n = key.n
e = key.e
print (f'n2={n}')
print (f'e2={e}')
运行得到
n1=13060424286033164731705267935214411273739909173486948413518022752305313862238166593214772698793487761875251030423516993519714215306808677724104692474199215119387725741906071553437840256786220484582884693286140537492541093086953005486704542435188521724013251087887351409946184501295224744819621937322469140771245380081663560150133162692174498642474588168444167533621259824640599530052827878558481036155222733986179487577693360697390152370901746112653758338456083440878726007229307830037808681050302990411238666727608253452573696904083133866093791985565118032742893247076947480766837941319251901579605233916076425572961
e1=117
n2=13060424286033164731705267935214411273739909173486948413518022752305313862238166593214772698793487761875251030423516993519714215306808677724104692474199215119387725741906071553437840256786220484582884693286140537492541093086953005486704542435188521724013251087887351409946184501295224744819621937322469140771245380081663560150133162692174498642474588168444167533621259824640599530052827878558481036155222733986179487577693360697390152370901746112653758338456083440878726007229307830037808681050302990411238666727608253452573696904083133866093791985565118032742893247076947480766837941319251901579605233916076425572961
e2=65537
明显看出是用了两个一样的n,共模攻击
import gmpy2
from Crypto.Util.number import *
n=13060424286033164731705267935214411273739909173486948413518022752305313862238166593214772698793487761875251030423516993519714215306808677724104692474199215119387725741906071553437840256786220484582884693286140537492541093086953005486704542435188521724013251087887351409946184501295224744819621937322469140771245380081663560150133162692174498642474588168444167533621259824640599530052827878558481036155222733986179487577693360697390152370901746112653758338456083440878726007229307830037808681050302990411238666727608253452573696904083133866093791985565118032742893247076947480766837941319251901579605233916076425572961
e1=117
e2=65537
_, r, s = gmpy2.gcdext(e1, e2)
c1 = bytes_to_long(open('cipher1.txt','rb').read())
c2 = bytes_to_long(open('cipher2.txt','rb').read())
m = pow(c1, r, n) * pow(c2, s, n) % n
print(long_to_bytes(m))
运行得到:flag{interesting_rsa}
RSA256
被潘汉年按时来到上海百老汇大厦(今上海大厦),叩开了袁殊临时下榻处的房门。袁殊说明自己当前身份和处境后,突然话锋一转,问潘汉年:“你到我这里来,恐怕已经被日本特务注意到了。我应该怎么向他们解释呢?”潘汉年说:“你就将计就计在敌伪内部站住脚,取得合法地位。同时搜集敌伪情报向我提供。”“要是岩井要求我将你介绍给他怎么办?”“那我就用胡越明的化名同岩井见面,就说我愿意和你在香港合作搞情报。”时隔不久,潘汉年接到袁殊通知,通知内容为:RSA256.tar.gz,要他在上海虹口区一家日本人开的餐馆里,和岩井会见。 请以暗号形式告知我方人员前往保护潘汉年的安全。(答案为flag{XXX}形式)
RSA256
0000755 0000000 0000000 00000000000 13446064553 010450 5 ustar root root
RSA256/fllllllag.txt
0000644 0001750 0001750 00000000040 13446061273 012700 0 ustar www www
嵺??绘癥WZ闊℃?噋傌野(?
RSA256/gy.key
0000644 0001750 0001750 00000000212 13446061315 011321 0
ustar www www
-----BEGIN PUBLIC KEY-----
MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhAKm9THp3YzcKBC/mvsfdyEFgLblCx6Ni
0bXTcqTQiRLZAgMBAAE=
-----END PUBLIC KEY-----
其实可以加个后缀名再打开,比如加个rar,就能看到这是两个文件
一个是密文,一个是公钥
先进行公钥解析,得到
n1=76775333340223961139427050707840417811156978085146970312315886671546666259161
e1=65537
分解n得到
p=273821108020968288372911424519201044333
q=280385007186315115828483000867559983517
然后解rsa就行
import Crypto.PublicKey.RSA as RSA
key = RSA.importKey('''-----BEGIN PUBLIC KEY-----
MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhAKm9THp3YzcKBC/mvsfdyEFgLblCx6Ni
0bXTcqTQiRLZAgMBAAE=
-----END PUBLIC KEY-----''')
n = key.n
e = key.e
#print (f'n1={n}')
#print (f'e1={e}')
import gmpy2
from Crypto.Util.number import *
p=273821108020968288372911424519201044333
q=280385007186315115828483000867559983517
c = bytes_to_long(open('fllllllag.txt','rb').read())
phi = (q-1) * (p-1)
d = gmpy2.invert(e,phi)
m = gmpy2.powmod(c,d,n)
print(m)
print(long_to_bytes(m))
运行得到
4220722534205764009434028013523762457981424524987027846762890641397407613
b'\x02c\x8bL\xc2u\x86\xc6\xbe\x00flag{_2o!9_CTF_ECUN_}'
但是提交了flag{_2o!9_CTF_ECUN_}
显示不正确
经过尝试,正确答案为:flag{2o!9CTFECUN}