From 23b64ddb9d951b6e1373ee76e132d1405b272563 Mon Sep 17 00:00:00 2001 From: ek0ms savi0r Date: Tue, 2 Jun 2026 01:47:18 +0000 Subject: [PATCH] Upload files to "c2_websocket_abuse/pkg" --- c2_websocket_abuse/pkg/protocol.go | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 c2_websocket_abuse/pkg/protocol.go diff --git a/c2_websocket_abuse/pkg/protocol.go b/c2_websocket_abuse/pkg/protocol.go new file mode 100644 index 0000000..94fd257 --- /dev/null +++ b/c2_websocket_abuse/pkg/protocol.go @@ -0,0 +1,58 @@ +package protocol + +import ( + "encoding/json" + "fmt" +) + +// Message types +const ( + TypeExec = "exec" + TypeUpload = "upload" + TypeDownload = "download" + TypeBeacon = "beacon" + TypePing = "ping" + TypePong = "pong" + TypeHeartbeat = "heartbeat" + TypeResult = "result" + TypeCmd = "cmd" + TypeRegister = "register" + TypeExit = "exit" +) + +// Message is the shared JSON frame sent over WebSocket. +type Message struct { + Type string `json:"type"` + ID string `json:"id,omitempty"` + Data string `json:"data,omitempty"` + Err string `json:"error,omitempty"` +} + +// Marshal serializes a Message to JSON bytes. +func (m *Message) Marshal() ([]byte, error) { + return json.Marshal(m) +} + +// UnmarshalMessage deserializes JSON bytes into a Message. +func UnmarshalMessage(data []byte) (*Message, error) { + var msg Message + if err := json.Unmarshal(data, &msg); err != nil { + return nil, fmt.Errorf("unmarshal message: %w", err) + } + return &msg, nil +} + +// NewMessage is a convenience constructor. +func NewMessage(msgType, id, data string) *Message { + return &Message{Type: msgType, ID: id, Data: data} +} + +// NewErrorMessage creates an error result message. +func NewErrorMessage(id, err string) *Message { + return &Message{Type: TypeResult, ID: id, Err: err} +} + +// NewResult creates a success result message. +func NewResult(id, data string) *Message { + return &Message{Type: TypeResult, ID: id, Data: data} +}