Finito server per polictf
This commit is contained in:
parent
b758947a87
commit
05ad0c6364
81
polictf/pasticciotto_server.cpp
Normal file
81
polictf/pasticciotto_server.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#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;
|
||||||
|
}
|
1
polictf/res/decrypteddatasection.txt
Normal file
1
polictf/res/decrypteddatasection.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
TheDataSectionHasBeenEncrypted
|
1
polictf/res/flag.txt
Normal file
1
polictf/res/flag.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
PoliCTF17{DajeFunziona}
|
@ -11,15 +11,15 @@ void encrypt(uint16_t *v) {
|
|||||||
uint16_t k1 = 0x7065; // "pe"
|
uint16_t k1 = 0x7065; // "pe"
|
||||||
uint16_t k2 = 0x7275; // "ru"
|
uint16_t k2 = 0x7275; // "ru"
|
||||||
uint16_t k3 = 0x6e73; // "ns"
|
uint16_t k3 = 0x6e73; // "ns"
|
||||||
printf("v0: 0x%x, v1: 0x%x\n", v0, v1);
|
// printf("v0: 0x%x, v1: 0x%x\n", v0, v1);
|
||||||
for (i = 0; i < 128; i++) {
|
for (i = 0; i < 128; i++) {
|
||||||
sum += delta;
|
sum += delta;
|
||||||
v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
|
v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
|
||||||
v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
|
v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
|
||||||
//printf("Intermediate v0: 0x%x | v1: 0x%x\n", v0, v1);
|
// printf("Intermediate v0: 0x%x | v1: 0x%x\n", v0, v1);
|
||||||
}
|
}
|
||||||
printf("SUM: 0x%x\n", sum);
|
// printf("SUM: 0x%x\n", sum);
|
||||||
printf("v0: 0x%x, v1: 0x%x\n", v0, v1);
|
// printf("v0: 0x%x, v1: 0x%x\n", v0, v1);
|
||||||
v[0] = v0;
|
v[0] = v0;
|
||||||
v[1] = v1;
|
v[1] = v1;
|
||||||
}
|
}
|
||||||
@ -35,13 +35,10 @@ int main(int argc, char *argv[]) {
|
|||||||
buf = (uint8_t *)malloc(buflen);
|
buf = (uint8_t *)malloc(buflen);
|
||||||
memcpy(buf, argv[1], buflen);
|
memcpy(buf, argv[1], buflen);
|
||||||
for (i = 0; i < buflen; i++) {
|
for (i = 0; i < buflen; i++) {
|
||||||
printf("----\n");
|
|
||||||
encrypt((uint16_t *)&buf[i]);
|
encrypt((uint16_t *)&buf[i]);
|
||||||
}
|
}
|
||||||
printf("Result:\n");
|
|
||||||
for (i = 0; i < buflen; i++) {
|
for (i = 0; i < buflen; i++) {
|
||||||
printf("%02x", buf[i]);
|
printf("%c", buf[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
2
vm/vm.h
2
vm/vm.h
@ -18,7 +18,6 @@ private:
|
|||||||
uint16_t regs[0xb];
|
uint16_t regs[0xb];
|
||||||
flags_t flags;
|
flags_t flags;
|
||||||
|
|
||||||
VMAddrSpace as;
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// FUNCTIONS
|
// FUNCTIONS
|
||||||
///////////////////////
|
///////////////////////
|
||||||
@ -82,6 +81,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
VM(uint8_t *key);
|
VM(uint8_t *key);
|
||||||
VM(uint8_t *key, uint8_t *code, uint32_t codesize);
|
VM(uint8_t *key, uint8_t *code, uint32_t codesize);
|
||||||
|
VMAddrSpace as;
|
||||||
void status(void);
|
void status(void);
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user