Skip to content

Commit

Permalink
http scans
Browse files Browse the repository at this point in the history
  • Loading branch information
zarkones committed Nov 17, 2024
1 parent 4f84f47 commit 14899a9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
59 changes: 59 additions & 0 deletions http-scans.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 14899a9

Please sign in to comment.