Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- dreamhack
- return address overflow
- 웹해킹
- XSS
- bandit
- rao
- CSRF
- shellcode
- Bandit Level 1 → Level 2
- Franklin-Reiter Related Message Attack
- picoCTF
- cryptography
- 드림핵
- Crypto
- OverTheWire Bandit Level 1 → Level 2
- 시스템해킹
- spoofing
- RSA
- AES
- arp
- redirect
- overthewire
- 암호학
- pycrpytodome
- dns
- Cube Root Attack
- RSA Common Modulas Attack
- Hastad
- Montgomery Reduction
- weak key
Archives
- Today
- Total
암호(수학) 등.. 공부한 거 잊을거 같아서 만든 블로그
[Cryptography] RSA Common Modulas Attack 본문
RSA Common Modulus Attack
동일한 모듈러 값으로 각기 다른 공개지수 e1, e2 ( gcd(e1, e2) = 1 인 ) 를 사용하여 암호화 한 암호문의 평문을 알아내는 공격이다.
아래와 같이 평문 M이 있을 때, 각기 다른 공개지수 e1, e2로 암호화 한 값을 C1, C2라 하자.


확장 유클리드 알고리즘은 필요하다면 아래 페이지를 참고하자.
확장 유클리드 알고리즘 (Extended Euclidean Algorithm)
유클리드 알고리즘 유클리드 알고리즘이란? 유클리드 알고리즘이란 두 정수의 최대 공약수를 효율적으로 구하는 방법으로써 다음과 같은 정리를 이용한다, a = bp + r (0 0 else print(result[2] + result[1]
heahgo.tistory.com
구한 s와 t를 각각 e1과 e2를 이용하여 암호화한 값인 c1, c2에 지수승을 하고 둘을 곱하면 평문이 복원된다.

아래의 파이썬 코드는 RSA Common Modulas Attack 의 예시 코드이다.
poc.py
# poc.py
from sage.all import *
from Crypto.Util.number import getPrime
from Crypto.Util.number import long_to_bytes, bytes_to_long
# RSA Key Generation
p = getPrime(256)
q = getPrime(256)
n = p * q
e1, e2 = 3, 5
# Encryption
m = b"I hate cryptography"
print("Plain text:", m.decode())
m = bytes_to_long(m)
c1 = pow(m, e1, n)
c2 = pow(m, e2, n)
print(f"\nn = {n}")
print(f"c1 = {long_to_bytes(c1)}")
print(f"c2 = {long_to_bytes(c2)}")
# RSA Common Modulas Attack
u, s, t = xgcd(e1, e2) # Extended Euclidean Algorithm from sage
decrypted = (pow(c1, s, n) * pow(c2, t, n)) % n
decrypted = int(decrypted)
decrypted = long_to_bytes(decrypted)
print(f"\nAttck Result: {decrypted.decode()}")
poc.py 실행 결과

'Cryptography' 카테고리의 다른 글
[Cryptography] Hastad's Broadcast Attack (0) | 2024.02.13 |
---|---|
[Cryptography] RSA Cube Root Attack (0) | 2024.02.03 |
[Cryptograhpy] AES-ECB (Electronic Code Book) 운영 모드 (0) | 2023.07.07 |
[Cryptograhpy] AES (Advanced Encrytion Standard) (0) | 2023.07.07 |
[Cryptograhpy] CRT를 이용한 빠른 RSA 복호화 (0) | 2022.10.29 |