From 14899a98fc025d7932e6e5a4e461cf2440ec24f2 Mon Sep 17 00:00:00 2001 From: zarkones Date: Sun, 17 Nov 2024 22:37:23 +0100 Subject: [PATCH] http scans --- http-scans.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ types.go | 15 +++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 http-scans.go diff --git a/http-scans.go b/http-scans.go new file mode 100644 index 0000000..0eaa058 --- /dev/null +++ b/http-scans.go @@ -0,0 +1,59 @@ +package c2api + +import ( + "bytes" + "encoding/json" + "errors" + "net/http" + "strings" +) + +func GetHttpScans(page int) (scans []HttpScan, err error) { + req, err := http.NewRequest(http.MethodGet, *BaseURL+"/v1/scans/http", nil) + if err != nil { + return nil, err + } + + setAuth(req) + + resp, err := c.Do(req) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + if resp.StatusCode == http.StatusNoContent { + return []HttpScan{}, nil + } + + return scans, json.NewDecoder(resp.Body).Decode(&scans) +} + +func InsertHttpScan(requestID string, agentIDs []string) (err error) { + jsonBody, err := json.Marshal(&HttpScan{ + ReqID: requestID, + AgentIDs: strings.Join(agentIDs, ","), + }) + if err != nil { + return err + } + + req, err := http.NewRequest(http.MethodPost, *BaseURL+"/v1/scans/http", bytes.NewBuffer(jsonBody)) + if err != nil { + return err + } + + setAuth(req) + + resp, err := c.Do(req) + if err != nil { + return err + } + + if resp.StatusCode != http.StatusCreated { + return errors.Join(ErrUnexpectedStatusCode, errors.New(resp.Status)) + } + + return nil +} diff --git a/types.go b/types.go index 346eaf8..f3c3d10 100644 --- a/types.go +++ b/types.go @@ -4,6 +4,21 @@ import ( "fyne.io/fyne/v2" ) +type HttpScan struct { + ID string `json:"id"` + ReqID string `json:"reqId"` + AgentIDs string `json:"agentIds"` +} + +type HttpScanTask struct { + ScanID string `json:"scanId"` + AgentID string `json:"agentId"` + ReqID int64 `json:"reqId"` + Payload string `json:"payload"` + RawRequest string `json:"rawRequest"` + RawResponse string `json:"rawResponse"` +} + type Attack struct { ID string `json:"id"` AgentID string `json:"agentId"`