2017-05-29 15:08:56 +01:00
|
|
|
#include "../../vm/vm.h"
|
|
|
|
#include "../../vm/debug.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define KEYLEN 15
|
|
|
|
#define CODESIZE 0x300
|
|
|
|
#define DATAKEYLEN 30
|
|
|
|
|
|
|
|
void gen_random(uint8_t *s, const int len) {
|
|
|
|
srand(time(NULL));
|
|
|
|
static const char alphanum[] = "0123456789"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz";
|
|
|
|
for (int i = 0; i < len; ++i) {
|
|
|
|
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
s[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char encrypted_data[] = {
|
2017-05-29 16:55:36 +01:00
|
|
|
0x8c, 0xea, 0xbe, 0xaa, 0xed, 0xa0, 0xd0, 0x6b, 0x99, 0x1c, 0x52, 0x25,
|
|
|
|
0xb9, 0xe6, 0xd8, 0xff, 0xf9, 0xe9, 0x92, 0x7a, 0x1c, 0xc5, 0xc4, 0x7e,
|
|
|
|
0x2a, 0xec, 0x67, 0x32, 0x1f, 0x45, 0x24, 0xd0, 0x4c, 0x7f, 0x15, 0x64,
|
|
|
|
0x59, 0xed, 0xa6, 0x78, 0xfe, 0xad, 0xd1, 0xbc, 0xe0, 0xd8, 0x3a, 0xf9,
|
|
|
|
0xfb, 0xf9, 0xf9, 0x6e, 0x5c, 0x52, 0x58, 0x46, 0x8d, 0x55, 0x58, 0x45,
|
|
|
|
0x21
|
|
|
|
};
|
|
|
|
unsigned int encrypted_data_len = 61;
|
|
|
|
|
2017-05-29 15:08:56 +01:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2017-05-29 16:55:36 +01:00
|
|
|
uint8_t *key = new uint8_t[KEYLEN], *decdatasec = new uint8_t[encrypted_data_len],
|
2017-05-29 15:08:56 +01:00
|
|
|
*flag = new uint8_t[DATAKEYLEN];
|
|
|
|
uint8_t *clientcode;
|
|
|
|
uint8_t i;
|
|
|
|
uint32_t clientcodesize, bytesread;
|
|
|
|
FILE *datap, *flagp;
|
|
|
|
|
|
|
|
gen_random(key, KEYLEN);
|
|
|
|
printf("Use this: \"%s\"\n", key);
|
|
|
|
fflush(stdout);
|
|
|
|
printf("How much data are you sending me?\n");
|
|
|
|
fflush(stdout);
|
|
|
|
scanf("%d", &clientcodesize);
|
|
|
|
printf("Go ahead then!\n");
|
|
|
|
fflush(stdout);
|
|
|
|
clientcode = new uint8_t[clientcodesize];
|
|
|
|
bytesread = read(0, clientcode, clientcodesize);
|
|
|
|
if (bytesread != clientcodesize) {
|
|
|
|
printf("ERROR! Couldn't read everything!\n");
|
|
|
|
fflush(stdout);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
VM vm(key, clientcode, clientcodesize);
|
|
|
|
vm.as.insData(encrypted_data, encrypted_data_len);
|
2017-05-29 16:55:36 +01:00
|
|
|
printf("BEFORE:\n");
|
|
|
|
for (i = 0; i < DATAKEYLEN; i++) {
|
|
|
|
fprintf(stdout, "buf[%d] = 0x%02x\n", i, vm.as.data[i]);
|
|
|
|
}
|
2017-05-29 15:08:56 +01:00
|
|
|
vm.run();
|
|
|
|
|
|
|
|
datap = fopen("../res/decrypteddatasection.txt", "r");
|
|
|
|
if (datap == NULL) {
|
|
|
|
printf("Couldn't open decrypteddatasection.txt!\n");
|
|
|
|
fflush(stdout);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fscanf(datap, "%s", decdatasec);
|
|
|
|
fclose(datap);
|
|
|
|
|
2017-05-29 16:55:36 +01:00
|
|
|
for (i = 0; i < DATAKEYLEN; i++) {
|
|
|
|
fprintf(stdout, "buf[%d] = 0x%02x\n", i, vm.as.data[i]);
|
|
|
|
}
|
2017-05-29 15:08:56 +01:00
|
|
|
for (i = 0; i < DATAKEYLEN; i++) {
|
|
|
|
if (vm.as.data[i] != decdatasec[i]) {
|
2017-05-29 16:55:36 +01:00
|
|
|
printf("Checking data[%d]..\n", i);
|
2017-05-29 15:08:56 +01:00
|
|
|
fflush(stdout);
|
|
|
|
printf("Nope!\n");
|
|
|
|
fflush(stdout);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flagp = fopen("../res/flag.txt", "r");
|
|
|
|
if (flagp == NULL) {
|
|
|
|
printf("Couldn't open flag.txt!\n");
|
|
|
|
fflush(stdout);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fscanf(flagp, "%s", flag);
|
|
|
|
fclose(flagp);
|
|
|
|
printf("Congratulations!\nThe flag is: %s\n", flag);
|
|
|
|
fflush(stdout);
|
|
|
|
return 0;
|
|
|
|
}
|