My implementation of authentication mechanisms in C turned out to be failures. But my implementation in Rust is unbreakable. Can you retrieve my password?
Initial Analysis#
Rauth це ELF binary під архітерутур x86-64.
1$ file rauth
2rauth: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=fc374b8206147fac9067599050989191b39eefcf, with debug_info, not strippedПри запуску нас просять вести пароль.
1$ ./rauth
2Welcome to secure login portal!
3Enter the password to access the system:
4aaaaaaaaaaa
5You entered a wrong password!При введені невірного пароля виводиться повідомлення “You entered a wrong password!”. Тому найпершою ідеєю в мене було відкрити цей файл в дизассемблері IDA та подивитися яка перевірка призводить до цієї гілки.
Dissasembling#
Розгалуження виконання робить ці рядки.
Йде перевірка чи bl = 0, якщо так то відбуєвать стрибок loc_6992 та виконується print("You entered a wrong password!")

Debagging#
Вирішив змінити хід виконання, змінивши в дебагері значення rbx
1(gdb) b *0x55555540683e
2Breakpoint 2 at 0x55555540683e
3(gdb) c
4Continuing.
5Welcome to secure login portal!
6Breakpoint 2, 0x000055555540683e in rauth::main ()
7(gdb) set $rbx = 1
8(gdb) c
9Continuing.
10Successfully Authenticated
11(gdb) "HTB{F4k3_f74g_4_t3s7ing}"
12[Inferior 1 (process 24204) exited normally]Бачимо що ми отримали fake flag.
salsa20#
Я помітив використання криптографічного алгоритму Salsa20.
1(gdb) info func salsa
2All functions matching regular expression "salsa":
3
4Non-debugging symbols:
50x00005555554056b0 salsa20::core::Core<R>::apply_keystream
60x0000555555405900 salsa20::core::Core<R>::new
70x00005555554059a0 salsa20::core::Core<R>::rounds
80x0000555555405d10 <salsa20::salsa::Salsa<R> as cipher::stream::StreamCipher>::try_apply_keystreamsalsa20::core::Core<R>::new - constructor that typically takes a 256-bit (32-byte) key and a 64-bit (8-byte) nonce (IV)salsa20::core::Core<R>::apply_keystream -
Вирішви подивитися які аргументи передаються в Salsa20::new
1(gdb) b salsa20::core::Core<R>::new
2Breakpoint 2 at 0x555555405900
3(gdb) b salsa20::core::Core<R>::apply_keystream
4Breakpoint 3 at 0x5555554056b0
5(gdb) start
6The program being debugged has been started already.
7Start it from the beginning? (y or n) y
8Temporary breakpoint 4 at 0x555555406bd0
9Starting program: /home/kali/Desktop/challanges/RAuth/rauth
10[Thread debugging using libthread_db enabled]
11Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
12
13Temporary breakpoint 4, 0x0000555555406bd0 in main ()
14(gdb) c
15Continuing.
16Welcome to secure login portal!
17Enter the password to access the system:
18aaaaa
19
20Breakpoint 2, 0x0000555555405900 in salsa20::core::Core<R>::new ()
21(gdb) i r
22rax 0x55555564fe20 93824993263136
23rbx 0x555555408530 93824990872880
24rcx 0x55555564fe20 93824993263136
25rdx 0x7fffffffdaa0 140737488345760
26rsi 0x7fffffffda70 140737488345712
27rdi 0x7fffffffd9e0 140737488345568
28rbp 0x1 0x1
29rsp 0x7fffffffd9d8 0x7fffffffd9d8
30r8 0x7ffff7e15ac0 140737352129216
31r9 0x30 48
32r10 0x1 1
33r11 0x0 0
34r12 0x0 0
35r13 0x555555439e28 93824991075880
36r14 0x555555649090 93824993235088
37r15 0x55555564fe20 93824993263136
38rip 0x555555405900 0x555555405900 <salsa20::core::Core<R>::new>
39eflags 0x202 [ IF ]
40cs 0x33 51
41ss 0x2b 43
42ds 0x0 0
43es 0x0 0
44fs 0x0 0
45gs 0x0 0
46fs_base 0x7ffff7f5d800 140737353472000
47gs_base 0x0 0
48(gdb) x/s $rdi
490x7fffffffd9e0: " "
50(gdb) x/s $rsi
510x7fffffffda70: "ef39f4f20e76e33bd25f4db338e81b10\001"
52(gdb) x/s $rdx
530x7fffffffdaa0: "d4c270a3"значення в rsi це 32byte ключ, в rdx це nonce
- key: ef39f4f20e76e33bd25f4db338e81b10
- nonce: d4c270a3
Далі потрібно дізнатися де лежать зашифровані дані.
перед викликом функції salsa20::core::Core<R>::new я помітив як на стек кладеться 32 байтне значення з xmmword_39CC0 та xmmword_39CD0
1.rodata:0000000000039CC0 xmmword_39CC0 xmmword 0F331CBA656F5D958D5A829A3B15F0505h
2.rodata:0000000000039CD0 xmmword_39CD0 xmmword 0F91BAD626FB63EE372EC9DC9312A4324hСпроба розшифрування
1$ python3
2Python 3.13.11 (main, Dec 8 2025, 11:43:54) [GCC 15.2.0] on linux
3Type "help", "copyright", "credits" or "license" for more information.
4>>> from Crypto.Cipher import Salsa20
5>>> c = "0505 5fb1 a329 a8d5 58d9 f556 a6cb 31f3 2443 2a31 c99d ec72 e33e b66f 62ad 1bf9"
6>>> Salsa20.new(key=b"ef39f4f20e76e33bd25f4db338e81b10", nonce=b"d4c270a3").decrypt(bytes.fromhex(c))
7b'TheCrucialRustEngineering@2021;)'І при спробі автентифікуватися на хості з цим паролем, ми отримуємо прапор
1$ nc 94.237.63.176 32734
2Welcome to secure login portal!
3Enter the password to access the system:
4TheCrucialRustEngineering@2021;)
5Successfully Authenticated
6Flag: "HTB{I_Kn0w_h0w_t0_5al54}"