dvCTF Warmup 문제입니다.
Description :
Our team has found a cipher text: there seems to be some clues to decipher it. Can you help us to read it?
암호를 발견했다며 해독을 요구하는 문제입니다.
문제 분석
문제 제목부터 보란듯이 RSA를 사용한것을 알려주고 있습니다.
n = 0x7CD1020889B4382BE84B3F14EAAE242755CC1BD56F431B348F4FF8F207A96F41AFCF3EBDF4C17CB6537AD4B01B9FF9497763B22D013B614C8FCDB0C34F9D88F1A523013791EDFEB1FBBA160799892C118892FB7F199C9957DF5A26DAB4D776E5226F06ACD05412F6DD2B1B75D24CE9DC2DDAC513BCB96CD9B97F9BEF8543A3A1
phi = 0x7CD1020889B4382BE84B3F14EAAE242755CC1BD56F431B348F4FF8F207A96F41AFCF3EBDF4C17CB6537AD4B01B9FF9497763B22D013B614C8FCDB0C34F9D88F037D2317D3864035ECE8BCDD458711B788B5B3FDFD5164F7D736D0A56F416E8C16126E3868D73F54AF4D61F6033E069994319C849460C60A725A0F4DD97EDCC84
e = 0x10001
ct = 0x268D7D5F5593EA30F536635B58585620B51D2D143AFE4734635C259278D61413D0C89678E81EDF466B1E45E27EBF802F62F61263E499A516465163C7CB668F94258B3424C3E2BD76634923DECD670E4B6034F8FD00C76F9DAD00A72DB22B70B9408C89FCEE4C9B0D2D4B5664284328711BFAD57FBE1EDCC0854AAD57390DCAD6
뿐만아니라 n, phi, e, chiper text 값까지 제공해주었습니다.
위 식에 의하면 RSA를 복호화 하기 위해서는 C(ct), d, n값이 필요합니다.
현재 확보 되지 않은 값은 d입니다. 하지만 e값과 phi 값이 있기 때문에 d를 구할 수 있습니다.
d = invert(e, phi)
위 식에 대입하여 얻어낼 수 있습니다.
문제 풀이
from gmpy2 import *
from Crypto.Util.number import *
n = '0x7CD1020889B4382BE84B3F14EAAE242755CC1BD56F431B348F4FF8F207A96F41AFCF3EBDF4C17CB6537AD4B01B9FF9497763B22D013B614C8FCDB0C34F9D88F1A523013791EDFEB1FBBA160799892C118892FB7F199C9957DF5A26DAB4D776E5226F06ACD05412F6DD2B1B75D24CE9DC2DDAC513BCB96CD9B97F9BEF8543A3A1'
phi = '0x7CD1020889B4382BE84B3F14EAAE242755CC1BD56F431B348F4FF8F207A96F41AFCF3EBDF4C17CB6537AD4B01B9FF9497763B22D013B614C8FCDB0C34F9D88F037D2317D3864035ECE8BCDD458711B788B5B3FDFD5164F7D736D0A56F416E8C16126E3868D73F54AF4D61F6033E069994319C849460C60A725A0F4DD97EDCC84'
e = '0x10001'
ct = '0x268D7D5F5593EA30F536635B58585620B51D2D143AFE4734635C259278D61413D0C89678E81EDF466B1E45E27EBF802F62F61263E499A516465163C7CB668F94258B3424C3E2BD76634923DECD670E4B6034F8FD00C76F9DAD00A72DB22B70B9408C89FCEE4C9B0D2D4B5664284328711BFAD57FBE1EDCC0854AAD57390DCAD6'
pt=''
n = int(n, 16)
phi = int(phi, 16)
e = int(e, 16)
ct = int(ct, 16)
d = invert(e, phi)
pt = pow(ct, d, n)
print(pt)
M(pt) : 100118678470123102108521039599861127251114116518811695988695828352125
Convert Decimal to ASCII - Online ASCII Tools
얻어낸 plaint text 값을 위 사이트를 통해 변환하면 flag를 획득할 수 있습니다.
더보기
dvCTF{fl4g_cVpH3rt3Xt_bV_RS4}
'Challenge > CTF' 카테고리의 다른 글
[dvCTF] CyberStreak v1.0 (0) | 2022.03.14 |
---|---|
[dvCTF] CyberStreak v2.0 (0) | 2022.03.14 |
[Codegate2022] PrimeGenerator (0) | 2022.03.07 |
[CODEGATE2022] CAFE (0) | 2022.03.05 |
[MHSCTF] Erlenmeyer Biscuits (Cuppa Joe 2) (0) | 2022.02.23 |