81 lines
2.2 KiB
C++
81 lines
2.2 KiB
C++
#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[] = {
|
|
0xcc, 0x8d, 0x5a, 0xcc, 0x73, 0xb5, 0xf2, 0xa3, 0xf3, 0x92,
|
|
0xa8, 0x8f, 0x2f, 0xf1, 0x3e, 0xf4, 0x69, 0x00, 0x4a, 0xcb,
|
|
0xed, 0xc4, 0x57, 0x9b, 0xf6, 0x9a, 0x78, 0x46, 0x83, 0xe9};
|
|
unsigned int encrypted_data_len = 30;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
uint8_t *key = new uint8_t[KEYLEN], *decdatasec = new uint8_t[DATAKEYLEN],
|
|
*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);
|
|
printf("How much data are you sending me?\n");
|
|
scanf("%d", &clientcodesize);
|
|
printf("Go ahead then!\n");
|
|
clientcode = new uint8_t[clientcodesize];
|
|
bytesread = read(0, clientcode, clientcodesize);
|
|
if (bytesread != clientcodesize) {
|
|
printf("ERROR! Couldn't read everything!\n");
|
|
exit(1);
|
|
}
|
|
VM vm(key, clientcode, clientcodesize);
|
|
vm.as.insData(encrypted_data, encrypted_data_len);
|
|
vm.run();
|
|
|
|
datap = fopen("./res/decrypteddatasection.txt", "r");
|
|
if (datap == NULL) {
|
|
printf("Couldn't open decrypteddatasection.txt!\n");
|
|
exit(1);
|
|
}
|
|
fscanf(datap, "%s", decdatasec);
|
|
fclose(datap);
|
|
|
|
for (i = 0; i < DATAKEYLEN; i++) {
|
|
if (vm.as.data[i] != decdatasec[i]) {
|
|
DBG_INFO(("Checking data[%d]..\n", i));
|
|
printf("Nope!\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
flagp = fopen("./res/flag.txt", "r");
|
|
if (flagp == NULL) {
|
|
printf("Couldn't open flag.txt!\n");
|
|
exit(1);
|
|
}
|
|
fscanf(flagp, "%s", flag);
|
|
fclose(flagp);
|
|
printf("Congratulations!\nThe flag is: %s\n", flag);
|
|
return 0;
|
|
} |