Tags: ptrace __do_global_ctors_aux xor reversing 

Rating:

## Challenge
Whats the matter it's just an xor
[its-just-an-xor.zip](https://squarectf.com/2021/data/its-just-an-xor.zip)

Note that provided zip file also has solution by organizer ctf team.

### main function
```c
undefined8 main(void)

{
int iVar1;
FILE *__stream;
long in_FS_OFFSET;
ulong local_b8;
long local_b0;
ulong local_a8 [8];
char local_68 [72];
long local_20;

local_20 = *(long *)(in_FS_OFFSET + 0x28);
puts("password pls, no brute forcing:");
fgets((char *)local_a8,0x40,stdin);
local_b8 = xor_key ^ local_a8[0];
local_b0 = (long)local_b8 >> 0x3f;
sleep(2);
iVar1 = strcmp((char *)&local_b8,"yoteyeet");
if (iVar1 == 0) {
__stream = fopen("flag.txt","r");
fgets(local_68,0x40,__stream);
fclose(__stream);
printf("nice work, here\'s the flag! %s",local_68);
}
else {
puts("that aint it dawg\n");
}
if (local_20 != *(long *)(in_FS_OFFSET + 0x28)) {
/* WARNING: Subroutine does not return */
__stack_chk_fail();
}
return 0;
}
```

### __do_global_ctors_aux
```c
void __do_global_ctors_aux(void)

{
int i_8;
ulong *local_20;

syscall();
for (i_8 = 0; (i_8 < 0x100 &&
(local_20 = (ulong *)(&data_start + i_8), *local_20 != 0x539053905390539));
i_8 = i_8 + 8) {
}
*local_20 = *local_20 ^ 0x119011901190119;
return;
}

```
## Solution
I was think it is a basic XOR challenge but whenever try to send data generated with xor key `0x0539053905390539` it just not worked.
Then I tried to attach with pwntools gdb attach but it just not worked, because it was calling `ptrace()` syscall in somewhere, so I realesed that there is an logic in `__do_global_ctors_aux` to ptrace and change actual XOR key to `0x420042004200420`. Note that `__do_global_ctors_aux` function executes before main function.