Since, Function prologue starts with endbr64; push rbp; mov rbp, rsp so we have the 8 bytes of the key.We then took the next 24 bytes in dump and xorred the encrypted bytes using IDAPython.
1 2 3 4 5 6 7
ea = 0x13A9 a = [0x42,0x8C,0x81,0xC5,0xEA,0x13,0xE0,0xC2,0x15,0x5C,0x43,0x1D,0x54,0xB5,0x99,0xAA,0x2D,0x27,0x57,0x1A,0x26,0x5B,0x6D,0x00,0x68,0xC9,0x4B,0xF4,0x80,0xBA,0xCA,0x5E]
for i inrange(896): tmp = get_wide_byte(ea + i) patch_loc = ea + i patch_byte(patch_loc,tmp ^ a[i%32])
After this we defined the functions and got the binary.
Analysing the recovered bytes
We see that in one of the recovered functions our flag is being read and also srand() is being called and the seed is the timestamp which should be there in the dump.
It was also encrypting our flag using AES and the key and IV used to encrypt and the function doing this had one extra function which was calling memset() being called multiple times that was done to fill the heap with random bytes and all of this info is stored in the heap dump.
As you can see First some random bytes are stored then the space for key is set then random bytes again then iv and random bytes again and then aes and key and iv is read and then the random bytes after all this the next memset called is for xor_key.Also, before all this memset our memset(flag,128) is also done and the starting point where it start writing this is 0x5060.
Final Steps
So, using the offset of xor_key we can bruteforce the offset of timestamp.
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> intmain() { void *v1; int ran; int sum;
sum = 0x5060 + 128;
longint c=1614211200; longint chae = 0; for (longint l = 0; l <=24*3600 ; l++) { chae = c+l; srand(chae); sum = 0x5060 + 128; printf("seed = %x\n", chae); for (int i = 0; i <= 63; ++i) { ran = rand() % 2047; //printf("%d\n",ran); sum = sum + ran; } printf("key at %x\n", sum); sum = sum + 32; for (int i = 0; i <= 63; ++i) { ran = rand() % 2047; //printf("%d\n",ran); sum = sum + ran; } printf("IV at %x\n", sum); sum = sum + 16; for (int i = 0; i <= 63; ++i) { ran = rand() % 2047; //printf("%d\n",ran); sum = sum + ran; } printf("aes object at %x\n", sum); sum = sum + 192; for (int i = 0; i <= 63; ++i) { ran = rand() % 2047; //printf("%d\n",ran); sum = sum + ran; } printf("xor key at %x\n", sum); printf("---------snip-----------\n"); if (sum == 0x4ba74) { printf("%d found the seed\n", l, sum); exit(0); } } }
In this script we are bruteforcing the timestamp until the last sum is 0x4ba74 and that is the offset for xor_key.We are also finding the respective AES_key and iv.And CT is from 0x5060 to 0x5060+0x80.We then using ghex extracted the AES_key ,iv and the CT. Now, the only thing left to do AES_CBC decrypt.