当前位置:网站首页>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())
边栏推荐
- Day10 ---- 强制登录, token刷新与jwt禁用
- Differential constrained SPFA
- 第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
- 2022-06-28 网工进阶(十三)IS-IS-路由过滤、路由汇总、认证、影响ISIS邻居关系建立的因素、其他命令和特性
- Octopus online ecological chain tour Atocha protocol received near grant worth $50000
- The way to treat feelings
- Streaming media server (16) -- figure out the difference between live broadcast and on-demand
- PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?
- Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
- Comments on flowable source code (37) asynchronous job processor
猜你喜欢
Basic principle of LSM tree
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
Recommend a GIF processing artifact less than 300K - gifsicle (free download)
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Chapter 1: simplify the same code decimal sum s (D, n)
10 smart contract developer tools that miss and lose
2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
第一章:简化同码小数和s(d, n)
Leetcode 1189. Maximum number of balloons (special character count)
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
随机推荐
Merge K ascending linked lists
Php based campus lost and found platform (automatic matching push)
Analyse du Code du planificateur ego bspline Section Optimizer (1)
BUUCTF
Detailed explanation of shuttle unity interworking principle
[optics] vortex generation based on MATLAB [including Matlab source code 1927]
2022-06-28 网工进阶(十三)IS-IS-路由过滤、路由汇总、认证、影响ISIS邻居关系建立的因素、其他命令和特性
2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
Win10 share you don't have permission
PR FAQ: how to set PR vertical screen sequence?
Ego planner code parsing Bspline_ Optimizer section (2)
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Buuctf's different flags and simplerev
Luogu-p1107 [bjwc2008] Lei Tao's kitten
The way to treat feelings
I didn't cancel
Today I am filled with emotion
Leetcode 1189. Maximum number of balloons (special character count)
How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
CMD implements the language conversion of locale non Unicode programs