RSA ๊ณต๊ฒฉ
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๋น ๋ฅธ ์ด๊ธฐ ํ๊ฐ
์์ง:
n,e,c(and any additional ciphertexts)- ๋ฉ์์ง ๊ฐ์ ๊ด๊ณ (same plaintext? shared modulus? structured plaintext?)
- Any leaks (partial
p/q, bits ofd,dp/dq, known padding)
๊ทธ ๋ค์ ์๋:
- ์ธ์๋ถํด ํ์ธ (Factordb /
sage: factor(n)โ ์์ ๊ท๋ชจ์ ๊ฒฝ์ฐ) - ๋ฎ์ ์ง์ ํจํด (
e=3, broadcast) - ๊ณตํต modulus / ๋ฐ๋ณต๋ primes
- ๋ฌด์ธ๊ฐ ๊ฑฐ์ ์๋ ค์ ธ ์์ ๋ Lattice ๋ฐฉ๋ฒ (Coppersmith/LLL)
์ผ๋ฐ์ ์ธ RSA ๊ณต๊ฒฉ
Common modulus
๋ง์ฝ ๋ ๊ฐ์ ์ํธ๋ฌธ c1, c2๊ฐ ๊ฐ์ ๋ฉ์์ง๋ฅผ ๋์ผํ modulus n ์๋ ์๋ก ๋ค๋ฅธ ์ง์ e1, e2 (๊ทธ๋ฆฌ๊ณ gcd(e1,e2)=1)๋ก ์ํธํํ๋ค๋ฉด, ํ์ฅ ์ ํด๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํด m์ ๋ณต๊ตฌํ ์ ์์ต๋๋ค:
m = c1^a * c2^b mod n where a*e1 + b*e2 = 1.
์์ ๊ฐ์:
(a, b) = xgcd(e1, e2)๋ฅผ ๊ณ์ฐํดa*e1 + b*e2 = 1์ ๋ง๋ ๋ค- ๋ง์ฝ
a < 0๋ผ๋ฉด,c1^a๋ฅผinv(c1)^{-a} mod n๋ก ํด์ํ๋ค (b๋ ๋์ผ) - ๊ณฑํ ํ
n์ผ๋ก ๋๋จธ์ง๋ฅผ ์ทจํ๋ค
์ฌ๋ฌ moduli์์์ ๊ณต์ ๋ primes
๋์ผํ ์ฑ๋ฆฐ์ง์์ ์ฌ๋ฌ RSA moduli๋ฅผ ์ป์๋ค๋ฉด, ์ด๋ค์ด prime์ ๊ณต์ ํ๋์ง ํ์ธํ์ธ์:
gcd(n1, n2) != 1์ ์น๋ช ์ ์ธ ํค ์์ฑ ์คํจ๋ฅผ ์๋ฏธํฉ๋๋ค.
์ด๋ CTF์์ ์์ฃผ ๋ํ๋๋ฉฐ โwe generated many keys quicklyโ ๋๋ โbad randomnessโ ๊ฐ์ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.
Hรฅstad broadcast / low exponent
If the same plaintext is sent to multiple recipients with small e (often e=3) and no proper padding, you can recover m via CRT and integer root.
๊ธฐ์ ์ ์กฐ๊ฑด:
๋ง์ฝ ์๋ก ์์ธ pairwise-coprime moduli n_i ์๋ ๋์ผํ ๋ฉ์์ง์ ๋ํ e ๊ฐ์ ์ํธ๋ฌธ์ด ์๋ค๋ฉด:
- CRT๋ฅผ ์ฌ์ฉํด
N = ฮ n_i์์์M = m^e๋ฅผ ๋ณต์ํ๋ค - ๋ง์ฝ
m^e < N์ด๋ฉด,M์ ์ง์ง ์ ์ ๊ฑฐ๋ญ์ ๊ณฑ์ด๊ณm = integer_root(M, e)์ด๋ค
Wiener attack: small private exponent
If d is too small, continued fractions can recover it from e/n.
Textbook RSA์ ํจ์
๋ง์ฝ ๋ค์์ ๋ณด๋ฉด:
- No OAEP/PSS, raw modular exponentiation
- Deterministic encryption
๊ทธ๋ฌ๋ฉด algebraic attacks์ oracle abuse๊ฐ ํจ์ฌ ๋ ๊ฐ๋ฅ์ฑ์ด ๋์์ง๋๋ค.
Tools
- RsaCtfTool: https://github.com/Ganapati/RsaCtfTool
- SageMath (CRT, roots, CF): https://www.sagemath.org/
๊ด๋ จ ๋ฉ์์ง ํจํด
๊ฐ์ modulus ์๋์์ ๋ฉ์์ง๋ค์ด ๋์์ ์ผ๋ก ๊ด๋ จ๋์ด ์๋ค๋ฉด (์: m2 = a*m1 + b), FranklinโReiter์ ๊ฐ์ โrelated-messageโ ๊ณต๊ฒฉ์ ์ฐพ์๋ณด์ธ์. ์ด๋ค์ ๋ณดํต ๋ค์์ ํ์๋ก ํฉ๋๋ค:
- ๊ฐ์ modulus
n - ๊ฐ์ exponent
e - plaintexts ๊ฐ์ ์๋ ค์ง ๊ด๊ณ
์ค์ ๋ก๋ Sage์์ n์ ๋ชจ๋๋ก ํ๋ ๋คํญ์์ ์ค์ ํ๊ณ GCD๋ฅผ ๊ณ์ฐํ์ฌ ํด๊ฒฐํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.
๊ฒฉ์ / Coppersmith
๋ฏธ์ง๊ฐ์ ์ผ๋ถ ๋นํธ๊ฐ ์๋ ค์ ธ ์๊ฑฐ๋, ๊ตฌ์กฐํ๋ plaintext, ๋๋ ๋ฏธ์ง๊ฐ์ด ์์์ง๋ ๊ทผ์ ํ ๊ด๊ณ๊ฐ ์์ ๋ ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ธ์.
๊ฒฉ์ ๋ฐฉ๋ฒ(LLL/Coppersmith)์ ๋ถ๋ถ ์ ๋ณด๊ฐ ์์ ๋ ์์ฃผ ๋ฑ์ฅํฉ๋๋ค:
- ๋ถ๋ถ์ ์ผ๋ก ์๋ ค์ง plaintext (๋ฏธ์ง์ ๊ผฌ๋ฆฌ๋ฅผ ๊ฐ์ง ๊ตฌ์กฐํ๋ ๋ฉ์์ง)
- ๋ถ๋ถ์ ์ผ๋ก ์๋ ค์ง
p/q(์์ ๋นํธ leaked) - ๊ด๋ จ ๊ฐ๋ค ์ฌ์ด์ ์์ ๋ฏธ์ง ์ฐจ์ด
ํ์ธํด์ผ ํ ์ฌํญ
์ฑ๋ฆฐ์ง์์ ์์ฃผ ๋์ค๋ ํํธ:
- โWe leaked the top/bottom bits of pโ
- โThe flag is embedded like:
m = bytes_to_long(b\"HTB{\" + unknown + b\"}\")โ - โWe used RSA but with a small random paddingโ
๋๊ตฌ
์ค์ ๋ก๋ LLL์ ์ํด Sage๋ฅผ ์ฌ์ฉํ๊ณ ํน์ ์ธ์คํด์ค์ ๋ง๋ ํ ํ๋ฆฟ์ ์ฌ์ฉํฉ๋๋ค.
์์์ :
- Sage CTF crypto templates: https://github.com/defund/coppersmith
- A survey-style reference: https://martinralbrecht.wordpress.com/2013/05/06/coppersmiths-method/
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


