Fixed detection mapping

This commit is contained in:
Frikky
2024-08-20 12:39:44 +02:00
parent 5aba926ef0
commit 0ccd4ef631
3 changed files with 188 additions and 166 deletions
+21 -7
View File
@@ -894,6 +894,20 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
Role: userInfo.ActiveOrg.Role, Role: userInfo.ActiveOrg.Role,
Image: org.Image, Image: org.Image,
} }
if parsedAdmin == "false" {
// Validating admin user again just to make sure
// This is to avoid issues for the first org ever
for _, user := range org.Users {
if user.Id != userInfo.Id {
continue
}
if user.Role == "admin" {
break
}
}
}
} }
orgPriorities := org.Priorities orgPriorities := org.Priorities
@@ -5182,14 +5196,14 @@ func initHandlers() {
r.HandleFunc("/api/v1/files", shuffle.HandleGetFiles).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/files", shuffle.HandleGetFiles).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/detection/sigma_rules", shuffle.HandleGetSigmaRules).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/detections/sigma_rules", shuffle.HandleGetSigmaRules).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/detection/{fileId}/{action}", shuffle.HandleToggleRule).Methods("PUT", "OPTIONS") r.HandleFunc("/api/v1/detections/{fileId}/{action}", shuffle.HandleToggleRule).Methods("PUT", "OPTIONS")
r.HandleFunc("/api/v1/detection/{action}", shuffle.HandleFolderToggle).Methods("PUT", "OPTIONS") r.HandleFunc("/api/v1/detections/{action}", shuffle.HandleFolderToggle).Methods("PUT", "OPTIONS")
r.HandleFunc("/api/v1/detection/siem/connect", shuffle.HandleConnectSiem).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/detections/siem/connect", shuffle.HandleConnectSiem).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/detection/siem/node_health", shuffle.HandleTenzirHealthUpdate).Methods("POST","OPTIONS") r.HandleFunc("/api/v1/detections/siem/node_health", shuffle.HandleTenzirHealthUpdate).Methods("POST","OPTIONS")
r.HandleFunc("/api/v1/detection/{triggerId}/selected_rules", shuffle.HandleGetSelectedRules).Methods("GET","OPTIONS") r.HandleFunc("/api/v1/detections/{triggerId}/selected_rules", shuffle.HandleGetSelectedRules).Methods("GET","OPTIONS")
r.HandleFunc("/api/v1/detection/{triggerId}/selected_rules/save", shuffle.HandleSaveSelectedRules).Methods("POST","OPTIONS") r.HandleFunc("/api/v1/detections/{triggerId}/selected_rules/save", shuffle.HandleSaveSelectedRules).Methods("POST","OPTIONS")
// Introduced in 0.9.21 to handle notifications for e.g. failed Workflow // Introduced in 0.9.21 to handle notifications for e.g. failed Workflow
+2
View File
@@ -267,6 +267,8 @@ github.com/shuffle/shuffle-shared v0.6.50 h1:MBeGAiBNkw9Eg+3YTJIlBOuskWntGvT0uef
github.com/shuffle/shuffle-shared v0.6.50/go.mod h1:RAJiSFjmuKmijKTbbEf9A6Ojb+3/te7g71lED7JjPus= github.com/shuffle/shuffle-shared v0.6.50/go.mod h1:RAJiSFjmuKmijKTbbEf9A6Ojb+3/te7g71lED7JjPus=
github.com/shuffle/shuffle-shared v0.6.59 h1:Pjvq4Lz6OAjA+hycwzUnm+f/pUiR5apR9Cz5f0fkAVs= github.com/shuffle/shuffle-shared v0.6.59 h1:Pjvq4Lz6OAjA+hycwzUnm+f/pUiR5apR9Cz5f0fkAVs=
github.com/shuffle/shuffle-shared v0.6.59/go.mod h1:RAJiSFjmuKmijKTbbEf9A6Ojb+3/te7g71lED7JjPus= github.com/shuffle/shuffle-shared v0.6.59/go.mod h1:RAJiSFjmuKmijKTbbEf9A6Ojb+3/te7g71lED7JjPus=
github.com/shuffle/shuffle-shared v0.6.60 h1:8OaiNxNpzJmIbYIcXI3TIYZVrPJ1sSCa+u7itMUMmxs=
github.com/shuffle/shuffle-shared v0.6.60/go.mod h1:RAJiSFjmuKmijKTbbEf9A6Ojb+3/te7g71lED7JjPus=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
+33 -27
View File
@@ -9,13 +9,13 @@ package main
// Ingress network may not exist (default) // Ingress network may not exist (default)
import ( import (
"github.com/shuffle/shuffle-shared"
"archive/zip" "archive/zip"
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/shuffle/shuffle-shared"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
@@ -24,12 +24,12 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"path/filepath"
//"os/signal" //"os/signal"
//"syscall" //"syscall"
@@ -179,7 +179,6 @@ func getThisContainerId() {
log.Printf(`[INFO] Started with containerId "%s"`, containerId) log.Printf(`[INFO] Started with containerId "%s"`, containerId)
} }
func skipCheckInCleanup(name string) bool { func skipCheckInCleanup(name string) bool {
return strings.HasPrefix(name, "backend") || return strings.HasPrefix(name, "backend") ||
strings.HasPrefix(name, "shuffle-backend") || strings.HasPrefix(name, "shuffle-backend") ||
@@ -865,7 +864,6 @@ func fixk8sRoles() {
} }
} }
func int32Ptr(i int32) *int32 { return &i } func int32Ptr(i int32) *int32 { return &i }
func deployK8sWorker(image string, identifier string, env []string) error { func deployK8sWorker(image string, identifier string, env []string) error {
@@ -1823,10 +1821,9 @@ func main() {
} }
} }
log.Printf("[WARNING] SHUFFLE_PIPELINE_URL not set, falling back to default URL: %s. If BASE_URL is set, we use the external IP for that",pipelineUrl) log.Printf("[WARNING] SHUFFLE_PIPELINE_URL not set, falling back to default URL: %s. If BASE_URL is set, we use the external IP for that", pipelineUrl)
} }
// FIXME - during init, BUILD and/or LOAD worker and app_sdk // FIXME - during init, BUILD and/or LOAD worker and app_sdk
// Build/load app_sdk so it can be loaded as 127.0.0.1:5000/walkoff_app_sdk // Build/load app_sdk so it can be loaded as 127.0.0.1:5000/walkoff_app_sdk
log.Printf("[INFO] Setting up Docker environment. Downloading worker and App SDK!") log.Printf("[INFO] Setting up Docker environment. Downloading worker and App SDK!")
@@ -2030,9 +2027,9 @@ func main() {
err := handlePipeline(incRequest) err := handlePipeline(incRequest)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed handling pipeline: %s", err) log.Printf("[ERROR] Failed handling pipeline: %s", err)
} } else {
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
}
} else if incRequest.Type == "DOCKER_IMAGE_DOWNLOAD" { } else if incRequest.Type == "DOCKER_IMAGE_DOWNLOAD" {
log.Printf("[INFO] Should delete -> download new image %#v", incRequest.ExecutionArgument) log.Printf("[INFO] Should delete -> download new image %#v", incRequest.ExecutionArgument)
@@ -2041,72 +2038,78 @@ func main() {
if err != nil { if err != nil {
log.Printf("[ERROR] Failed handling image delete -> download: %s", err) log.Printf("[ERROR] Failed handling image delete -> download: %s", err)
} }
} }
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
} else if incRequest.Type == "CATEGORY_UPDATE" { } else if incRequest.Type == "CATEGORY_UPDATE" {
err := deployTenzirNode() err := deployTenzirNode()
if err != nil{ if err != nil {
log.Printf("[ERROR] Failed to deploy CATEGORY UPDATE, reason: %s", err) log.Printf("[ERROR] Failed to deploy CATEGORY UPDATE, reason: %s", err)
} else {
continue
} }
err = handleFileCategoryChange() err = handleFileCategoryChange()
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to download the file category: %s", err) log.Printf("[ERROR] Failed to download the file category: %s", err)
} } else {
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
}
} else if incRequest.Type == "DISABLE_SIGMA_FILE" { } else if incRequest.Type == "DISABLE_SIGMA_FILE" {
fileName := incRequest.ExecutionArgument fileName := incRequest.ExecutionArgument
err := deployTenzirNode() err := deployTenzirNode()
if err != nil{ if err != nil {
log.Printf("[ERROR] Failed to deploy DISABLE SIGMA FILE, reason: %s", err) log.Printf("[ERROR] Failed to deploy DISABLE SIGMA FILE, reason: %s", err)
} else {
continue
} }
err = disableRule(fileName) err = disableRule(fileName)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to disable the sigma file %s, reason: %s", fileName, err) log.Printf("[ERROR] Failed to disable the sigma file %s, reason: %s", fileName, err)
} } else {
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
}
} else if incRequest.Type == "ENABLE_SIGMA_FILE" { } else if incRequest.Type == "ENABLE_SIGMA_FILE" {
fileName := incRequest.ExecutionArgument fileName := incRequest.ExecutionArgument
err := deployTenzirNode() err := deployTenzirNode()
if err != nil{ if err != nil {
log.Printf("[ERROR] Failed to deploy ENABLE SIGMA FILE, reason: %s", err) log.Printf("[ERROR] Failed to deploy ENABLE SIGMA FILE, reason: %s", err)
} else {
continue
} }
err = enableRule(fileName) err = enableRule(fileName)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to disable the sigma file %s, reason: %s", fileName, err) log.Printf("[ERROR] Failed to disable the sigma file %s, reason: %s", fileName, err)
} } else {
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
}
} else if incRequest.Type == "DISABLE_SIGMA_FOLDER" { } else if incRequest.Type == "DISABLE_SIGMA_FOLDER" {
err := deployTenzirNode() err := deployTenzirNode()
if err != nil{ if err != nil {
log.Printf("[ERROR] Failed to deploy DISABLE SIGMA FOLDER, reason: %s", err) log.Printf("[ERROR] Failed to deploy DISABLE SIGMA FOLDER, reason: %s", err)
} }
err = removeAllFiles() err = removeAllFiles()
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to disable the sigma rules: %s", err) log.Printf("[ERROR] Failed to disable the sigma rules: %s", err)
} } else {
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
}
} else if incRequest.Type == "START_TENZIR" { } else if incRequest.Type == "START_TENZIR" {
log.Printf("[INFO] Got job to start tenzir") log.Printf("[INFO] Got job to start tenzir")
err := deployTenzirNode() err := deployTenzirNode()
if err != nil{ if err != nil {
log.Printf("[ERROR] Failed to deploy the pipeline, reason: %s", err) log.Printf("[ERROR] Failed to deploy the pipeline, reason: %s", err)
} } else {
toBeRemoved.Data = append(toBeRemoved.Data, incRequest) toBeRemoved.Data = append(toBeRemoved.Data, incRequest)
}
} else { } else {
newrequests = append(newrequests, incRequest) newrequests = append(newrequests, incRequest)
@@ -2726,7 +2729,7 @@ func createNetworkIfNotExists(ctx context.Context, networkName, subnet, gateway
func checkTenzirNode() error { func checkTenzirNode() error {
retries := 5 retries := 5
retryInterval := 3 * time.Second retryInterval := 3 * time.Second
url := fmt.Sprintf("%s/api/v0/ping",pipelineUrl) url := fmt.Sprintf("%s/api/v0/ping", pipelineUrl)
forwardMethod := "POST" forwardMethod := "POST"
client := http.Client{} client := http.Client{}
@@ -3223,6 +3226,8 @@ func sendTenzirHealthStatus() error {
status = "active" status = "active"
} }
log.Printf("[DEBUG] Sending health update to backend url %s", baseUrl)
forwardMethod := "POST" forwardMethod := "POST"
payload := map[string]interface{}{ payload := map[string]interface{}{
"status": status, "status": status,
@@ -3250,12 +3255,13 @@ func sendTenzirHealthStatus() error {
log.Printf("[ERROR] Failed to send HTTP request: %s", err) log.Printf("[ERROR] Failed to send HTTP request: %s", err)
return err return err
} }
defer resp.Body.Close()
defer resp.Body.Close()
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
log.Printf("[ERROR] Received non-successful HTTP status code: %d", resp.StatusCode) log.Printf("[ERROR] Pipeline: Received non-successful HTTP status code: %d", resp.StatusCode)
return fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode) return fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode)
} }
return nil return nil
} }