User Tools

Site Tools


htb-cryptochallenges-brainys-cipher

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
htb-cryptochallenges-brainys-cipher [2019/07/04 18:38] didzkovitchzhtb-cryptochallenges-brainys-cipher [2020/12/15 21:41] (current) – removed didzkovitchz
Line 1: Line 1:
-====== HTB ~~ Crypto Challenges ~~ Brainy's Cipher ====== 
-[[htb|Retour]] 
  
-- 
- 
-===== Présentation ===== 
- 
-<code> 
-Brainy likes playing around with esoteric programming. 
-He also likes math and has therefore encrypted his very secure password with a popular encryption algorithm. 
-Claiming that his password cannot be retrieved now, he has sent the ciphertext to some of his friends. 
-Can you prove to Brainy that his password can actually be recovered? 
-</code> 
- 
-1 fichier : 
-  * ''brainy.txt'' 
- 
-===== Résolution ===== 
- 
-Contenu du fichier ''brainy.txt'' : 
-<code> 
-++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>>+++++++++++++++++++++++.-----------.<------------.---.++.---------.+.++.-.++.+.-----.++..++++.--.++++.+..-------.+.+++.---.+.+++++.-------.+.---.+++++++.+.-------..+++.-.+++++.-------.++.+++++.-----.+++++..-----.--.++++++++.-------.--.++++.+++.---.++..+++.------.+++.--.-..++++++.-.----..+++++.------.++++++.---.---.--.+++.++++.-------.+++++..-.++..-------.++++++.---.++..+++.----.++++.-------.++++++++..----.+++.+.------.--.-.++.-.+++++.--..--.++++.-.++++.---.------.+++++.++.+.---.+++.---.----.++++.--.+++.-----.+++++.+.---.--.+++++++.---.---...---.+.++++++++.----.++++.-----.++.--.-.--.++.-.-.+++++.--..+++++.-------.-.++++.++.-----.++++++.--------.+++.+++.-.+++.----.----.++++++.----.++++++.-------.-----.>+.<++++++++++++++.---------.+.++++++.--------.++.+++++++.--------.+++++++.----.+.----.+++...----.++++..++.----..+++.+++.-----.++++.--.++..-------.+++.++++.--.---.--.++++++..-----..+++++++.-------.+++++++.--------..++++++.++.--..++.----.+++.++.------.++++.+.-..+.+.-------.++++++.-.---.---.-.++++++++..-----.---.++.+.++..-.--.+++.++++.--..------.++++++++.-------.+++++++..---.+.++..---.----.+.++++++..-.-.-----.--.++++.--.+++++++.----.++++.-----.-.+.++.+..+..--.-.---.+++++.--.--.++++++.--------.++.---.+++++++..----.---.+++++++++.-...-------.++++++++.-------.++.-.+++++.----.-.+++++.---.----.+++++.++.-----.---.+++++++.++.---------...++.+++++++.------.+++++.-------.++++.-----.+++++.----.-----.>-------------.++++++++++++.<++++++++++++++.-----..-.----.++++++.-..-----.++.++++++.--.----..--.++.-.++++++++.------.+..--.+++++++.------.---.++++++.----.++++++.-.++.------.++++...--.---.+++++++.--------.++++++++.----..+.----.+..---.++++++++.+.---.-.---.--.++++++++.-----.+++++.----.+.+++.------.--..+++++++++.-.---.++.----.++++.-.------.+++++.--.++.+++.-----.++.++.--..----.-.+++++++.+.----.---.+++++.+++.---.-----.+++++.------.++++++.-.----..++.+++.--.---.++.++++++.--------..+++++.+++.---.-----.++.++++++.---.+++.-.-------.++.+++.-.---.+++.---.+.++.-----.+++++++.---.--.-..++++.++.-------.++++.+.--.++++..+.+.-.---.-.--.+.+++++.--.+++.------..--.++++++++.-.------.++++.+++.-----.+.----.-----.>------------.+++++++++++++.<++++++++++++++.-.---------.++++++..++.+.--.----.-.--.+++.---.++++++++..-----.+.--.--.++++++.+++.----.---.+.++.++++.------.++++++..--.----.++++..---.+++.----.--..++++++++.-.-----..---.+++++++++.---------.++++++.----.+++++.-.--.---.++++++.+.+.---------.++++++.----.++++.+++.-----.+++.--.+++.----.+++.------.++++++.----.++++++.---..------.+++++++.----.++.+.+.++.-..-------.++++++.-------.++++.---.++++.+++.-----.++++++..----.-.+++++..---.---.-..+.--.+++.---.++++.++.---.-.+++++.-..-------.++..+++.++++.----.---.++.+++++.--------.++++.+.------..+++++.---.++++++.-.------.+++.++.--.---.++.+++.-----.+++++.---.+.--.-.+++++++.+.-------.--.+++++.-----..+++++.++.---.+++++.-.--.-.----.-----.>--------------.<++++++++++++++.----.----.--.+++++++.+.--------.++++++++.--..+..---.---.+++++..++.--.++.--.+.------.+++++++.-----.+++++.---.++.++.----.++.----.++.-----.+++..+++++.-----.--.+++...++.----.++++++.--------.+++++++++.--------.+.++++.+.----..++++++.-------.++..++++.--------.++++++.-.-----.++.++++.++.---.-----.++.-.+.++++.++.---.--.-.++++.-..----..+++++++.-----.++++++.---.----.--.+++++.+.--.+++++.----.++++.---.--.+.++.++.--.+.------.+.-.+++.--.---.++.--.++++++++.------.--.+++++.-.-.++++++.------.++++++.------..+++.++.------..++++.-.++..-----.++++++.--------.++.+++++.--.-----.++++++++..-.-----.+++++++.------.+++.------.++.++.-.-.+++.----.+.+++++++.---.+.++..-----.++++.--------.+++++..-.+++++..---.-.-----.++.--.+++++++++.--------.+++++.+++.----.--.+++.--..++.---.++.++++.---.-.++++.--------.+++++..------.+++++++.++.-------.+++.--..++.+.---.++++++.---------.++.+++++.--.++.++.--------.+++++++.-.---.-.++.----.+++++++.--------.++++++.------.+++++++.---.+++.--.++++.---.---..-..++.++.-.-.---.++++++..--.+++.+.----.++++.---------..++.+.+++++.---.-.+.----.+++++++.--.---.--.+..-.-.++++++.--.++++.-.+.-----.+.+++.+.----.++.++..--------.++.+++++++.--------.+++++.+..-----.--.+.++++++.--.----.+.++++++.--------.++++++++.------.--.++++++...+.-------.+++++++++.-----.+.+.----.+++.-----.++++++.+.+.--------.+++.+++++.-------.+.+++++++.--.-------.++++++++.-.------.>++++++++++++++++++++++++++. 
-</code> 
- 
-Je reconnais cela, c'est du brain fuck. 
- 
-Décodé ça donne ça: 
-<code> 
-{p:7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281,q:12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051,dp:5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451,dq:9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651,c:62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871} 
-</code> 
- 
-Le fait d'avoir plusieurs valeurs comme ça, ça me fait penser à du RSA (j'ai jeté un œil au challenge Richelieu de la DGSE il n'y a pas longtemps). 
- 
-Je cherche donc "p q dp dq c" sur Google, il s'avère que c'est effectivement du RSA, implémentation ''Chinese remainder algorithm''. 
- 
-J'ai suivi l'article https://www.rootnetsec.com/picoctf-weird-rsa/ pour résoudre cela. 
-C'est du copier/coller de code Python. 
- 
-1 : 
-<code> 
-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) 
- 
-def modinv(a, m): 
-    g, x, y = egcd(a, m) 
-    if g != 1: 
-        raise Exception('modular inverse does not exist') 
-    else: 
-        return x % m 
-</code> 
- 
-2 : 
-<code> 
-qinv = modinv(q, p) 
-m1 = pow(c, dp, p) 
-m2 = pow(c, dq, q) 
-h = (qinv * (m1 - m2)) % p 
-m = m2 + h * q 
-print(m) 
- 
-49437413074993986257824490238275931180994249527518860068137626874351971280859988288289074 
-</code> 
- 
-3 : 
-<code> 
-hex(m) 
- 
-'0x6368316e337a5f72336d34696e6433725f7468653072656d5f7230636b2424245f39373932' 
- 
-txt = '6368316e337a5f72336d34696e6433725f7468653072656d5f7230636b2424245f39373932' 
- 
-''.join([chr(int(''.join(c), 16)) for c in zip(txt[0::2],txt[1::2])]) 
- 
- 
-'ch1n3z_r3m4ind3r_the0rem_r0ck$$$_9792' 
-</code> 
- 
-Nous avons le flag : ''HTB{ch1n3z_r3m4ind3r_the0rem_r0ck$$$_9792}'' 
- 
-Quelques liens : 
-  * [[https://github.com/zionspike/ctf-writeup/blob/master/Crypto/%5BpicoCTF%202017%5D%20-%20Weird%20RSA%20-%2090/kapi-note.md]] 
-  * [[https://www.rootnetsec.com/picoctf-weird-rsa/]] 
-  * [[https://github.com/lflare/picoctf_2017_writeup/tree/master/cryptography/weird-rsa]] 
-  * [[http://www.libelium.com/v11-files/Examples_wasp/Example_109.php]] 
-  * [[https://www.geeksforgeeks.org/weak-rsa-decryption-chinese-remainder-theorem/]] 
-  * [[https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Using_the_Chinese_remainder_algorithm]] 
- 
-===== FLAG ===== 
- 
-''HTB{ch1n3z_r3m4ind3r_the0rem_r0ck$$$_9792}'' 
htb-cryptochallenges-brainys-cipher.1562258312.txt.gz · Last modified: 2019/07/04 18:38 by didzkovitchz