__int64 __fastcall main(int a1, char **a2, char **a3)
{
char ptr; // [rsp+Bh] [rbp-25h] BYREF
int v5; // [rsp+Ch] [rbp-24h]
_BYTE *v6; // [rsp+10h] [rbp-20h]
FILE *stream; // [rsp+18h] [rbp-18h]
FILE *s; // [rsp+20h] [rbp-10h]
unsigned __int64 v9; // [rsp+28h] [rbp-8h]
v9 = __readfsqword(0x28u);
v6 = &unk_2004;
stream = fopen("flag.png", "rb");
if ( !stream )
{
puts("fopen() error");
exit(1);
}
s = fopen("encrypted", "wb");
if ( !s )
{
puts("fopen() error");
fclose(stream);
exit(1);
}
v5 = 0;
while ( fread(&ptr, 1uLL, 1uLL, stream) == 1 )
{
ptr ^= v6[v5 % 4];
ptr += 19;
fwrite(&ptr, 1uLL, 1uLL, s);
++v5;
}
fclose(stream);
fclose(s);
return 0LL;
}
// Name: dec.c
// Compile: gcc -Wall dec.c -o dec
#include <stdlib.h>
#include <stdio.h>
int main(void) {
FILE *encrypted_file;
FILE *flag_file;
char byte;
char *key = "\xde\xad\xbe\xef";
int i;
encrypted_file = fopen("encrypted", "rb");
if (encrypted_file == NULL) {
puts("fopen() error");
exit(1);
}
flag_file = fopen("flag.png", "wb");
if (flag_file == NULL) {
puts("fopen() error");
fclose(encrypted_file);
exit(1);
}
i = 0;
while (fread(&byte, 1, 1, encrypted_file) == 1) {
byte -= 19;
byte ^= key[i % 4];
fwrite(&byte, 1, 1, flag_file);
i++;
}
fclose(encrypted_file);
fclose(flag_file);
return 0;
}
리눅스에서 nano dec.c
gcc dec-c
./dec
ls
'Dreamhack > CTF' 카테고리의 다른 글
Dreamhack CTF Season 6 Round #10 (🌱Div2) Secure Secret (0) | 2024.10.28 |
---|---|
Dreamhack CTF Season 6 Round #10 (🌱Div2) dowell (0) | 2024.10.27 |