Skip to content

Commit

Permalink
Resolve "Use proper encoding for http command"
Browse files Browse the repository at this point in the history
  • Loading branch information
hidde-jan authored and RabbITCybErSeC committed Feb 29, 2024
1 parent d1a181d commit bf90ba6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/capability/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package http

import (
"bytes"
"encoding/hex"
"encoding/base64"
"errors"
"io"
"net/http"
Expand Down Expand Up @@ -143,15 +143,15 @@ func ObtainHttpRequestContentDataFromCommand(
// Reads if either command or command_b64 are populated, and
// Returns a byte slice from either
content := command.Content
content_b64 := command.ContentB64
contentB64 := command.ContentB64

var nil_content []byte

if content == "" && content_b64 == "" {
if content == "" && contentB64 == "" {
return nil_content, nil
}

if content != "" && content_b64 != "" {
if content != "" && contentB64 != "" {
log.Warn("both content and content_b64 are populated. using content.")
return []byte(content), nil
}
Expand All @@ -160,5 +160,5 @@ func ObtainHttpRequestContentDataFromCommand(
return []byte(content), nil
}

return hex.DecodeString(content_b64)
return base64.StdEncoding.DecodeString(contentB64)
}
6 changes: 2 additions & 4 deletions test/capability/http/http_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ssh_test

import (
"encoding/hex"
"errors"
"fmt"
"soarca/internal/capability/http"
Expand Down Expand Up @@ -182,7 +181,7 @@ func TestObtainHttpRequestContentDataFromCommandBothTypes(t *testing.T) {
assert.Equal(t, err, nil)
}
func TestObtainHttpRequestContentDataFromCommandB64Only(t *testing.T) {
test_b64_content := "923948a09a"
test_b64_content := "R08gU09BUkNBIQ=="
expectedCommand := cacao.Command{
Type: "http-api",
Command: "GET 0.0.0.0:80/",
Expand All @@ -191,8 +190,7 @@ func TestObtainHttpRequestContentDataFromCommandB64Only(t *testing.T) {

ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand)

expected, _ := hex.DecodeString(test_b64_content)
assert.Equal(t, ret_content, expected)
assert.Equal(t, ret_content, []byte("GO SOARCA!"))
assert.Equal(t, err, nil)
}
func TestObtainHttpRequestContentDataFromCommandPlainTextOnly(t *testing.T) {
Expand Down

0 comments on commit bf90ba6

Please sign in to comment.