当前位置:网站首页>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())
边栏推荐
- Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
- Chapter 2: 4-digit Kaplan number, search even digit Kaplan number, search n-digit 2-segment sum square number, m-digit ingenious square number without 0, specify the number to form a 7-digit square nu
- 第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
- 2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
- SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
- 【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
- 利用可视化结果,点击出现对应的句子
- BUUCTF
- math_ Taylor formula
- EGO Planner代码解析bspline_optimizer部分(1)
猜你喜欢

第一章:简化同码小数和s(d, n)

Analysis of dart JSON encoder and decoder
![[free sharing] kotalog diary2022 plan electronic manual ledger](/img/ca/1ffbfcc16e3019261f70274a89c16f.jpg)
[free sharing] kotalog diary2022 plan electronic manual ledger

第一章:求同吗小数和s(d, n)
![第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数](/img/c5/0081689817700770f6210d50ec4e1f.png)
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数

Basic principle of LSM tree

Chapitre 1: le roi de shehan a mal calculé

2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)

Leetcode 1189. Maximum number of balloons (special character count)

【光学】基于matlab介电常数计算【含Matlab源码 1926期】
随机推荐
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
[wallpaper] (commercially available) 70 wallpaper HD free
These problems should be paid attention to in the production of enterprise promotional videos
Pecan — @expose()
10 smart contract developer tools that miss and lose
EGO Planner代码解析bspline_optimizer部分(2)
Chapter 1: find the factorial n of n!
第一章:递归求n的阶乘n!
Chapter 1: simplify the same code decimal sum s (D, n)
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
Zhang Fei hardware 90 day learning notes - personal record on day 6. Please see my personal profile / homepage for the complete record
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
2022.2.14 Li Kou - daily question - single element in an ordered array
Floating source code comment (38) parallel job processor
Nous avons fait une plateforme intelligente de règlement de détail
03 -- QT OpenGL EBO draw triangle
Ego planner code parsing Bspline_ Optimizer section (3)
CMD implements the language conversion of locale non Unicode programs
01. Preparation for automated office (free guidance, only three steps)