当前位置:网站首页>Xctf attack and defense world crypto advanced area best_ rsa
Xctf attack and defense world crypto advanced area best_ rsa
2022-07-03 19:26:00 【l8947943】
1. Enter the environment , Download the attachment
Compressed package for topic , Include 4 File , Pictured :
given 2 Public key files and 2 Ciphertext file , With regular RSA Decryption methods: decrypt separately , Decryption failed (n by 2048 Bits are hard to decompose )
2. Problem analysis
- Continue to review RSA
- In plain text m, The secret is c, modulus n = p * q
- Use Euler functions ,φ(n) = (p - 1) * (q- 1)
- Select a large integer e, bring gcd(e, φ(n) ) = 1,e Used to encrypt the secret key
- Private key d It can be calculated from the value of Euler function , Satisfy ed mod φ(n) ≡ 1
- In plain text m Encrypted into ciphertext c:m^e ≡ c (mod n)
- Will ciphertext c Decrypt to plaintext m:c^d ≡ m (mod n)
- Common mode attack
Guess it should be the same plaintext , Used 2 Different public key encryption results in different ciphertexts , Using the same modulus and different public key indices for multiple encryption of the same plaintext may lead to common mode attacks .
Look at the boss's wp after :https://blog.csdn.net/weixin_44795952/article/details/108933406, Understand what common mode attack is
So called common mode , Is plaintext m identical , model n identical , Use two public keys e1,e2 Encrypt to get two private keys d1,d2 And two ciphertexts c1,c2
Common mode attack , When n Without change , know n,e1,e2,c1,c2 . Can be in the don't know d1,d2 Under the circumstances , figure out m.
There's a condition , namely
gcd(e1,e2)=1
- Attack principle
There are integers s 1 s_{1} s1, s 1 s_{1} s1( One is one minus one. ), Satisfy :
e 1 ∗ s 1 + e 2 ∗ s 2 = 1 e_{1} * s_{1} + e_{2} * s_{2} = 1 e1∗s1+e2∗s2=1
from Crypto.Util.number import long_to_bytes, bytes_to_long
from Crypto.PublicKey import RSA
from gmpy2 import gcd, invert
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
with open('pic/publickey1.pem', 'rb') as f:
f1 = f.read()
pub1 = RSA.importKey(f1)
n = int(pub1.n)
e1 = int(pub1.e)
with open('pic/publickey2.pem', 'rb') as f:
f2 = f.read()
pub2 = RSA.importKey(f2)
e2 = int(pub2.e)
with open('pic/cipher1.txt', 'rb') as f:
c1 = f.read()
c1 = bytes_to_long(c1)
print(c1)
with open('pic/cipher2.txt', 'rb') as f:
c2 = f.read()
c2 = bytes_to_long(c2)
print(c2)
print(gcd(e1, e2))
s = egcd(e1, e2)
s1 = s[1]
s2 = s[2]
if s1 < 0:
s1 = -s1
c1 = invert(c1, n)
elif s2 < 0:
s2 = -s2
c2 = invert(c2, n)
m = pow(c1, s1, n) * pow(c2, s2, n) % n
print(m)
print(long_to_bytes(m).decode())
边栏推荐
- Pecan - route
- I study database at station B (4): DQL
- 第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
- Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
- 03 -- QT OpenGL EBO draw triangle
- BUUCTF
- Cross compile opencv with contrib
- Random numbers in a long range, is that right- Random number in long range, is this the way?
- 第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
- 交叉编译Opencv带Contrib
猜你喜欢
Simulation scheduling problem of SystemVerilog (1)
第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
Ego planner code parsing Bspline_ Optimizer section (3)
第一章: 舍罕王失算
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
10 smart contract developer tools that miss and lose
Chapter 1: find the factorial n of n!
随机推荐
Comments on flowable source code (37) asynchronous job processor
The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
The most valuable thing
Why should we do feature normalization / standardization?
2022-06-25 网工进阶(十一)IS-IS-三大表(邻居表、路由表、链路状态数据库表)、LSP、CSNP、PSNP、LSP的同步过程
03 -- QT OpenGL EBO draw triangle
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
Analysis of dart JSON encoder and decoder
Strict data sheet of new features of SQLite 3.37.0
UE source code analysis: uccharactermovementcomponent - rootmotion
math_ Taylor formula
10 smart contract developer tools that miss and lose
Difference between surface go1 and surface GO2 (non professional comparison)
Scrape crawler framework
Ego planner code parsing Bspline_ Optimizer section (3)
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
Thinking about festivals
OSPF - detailed explanation of stub area and full stub area
Pecan — Overview