Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit cde4820

Browse files
author
tom
committed
adding missing files
1 parent dc73594 commit cde4820

File tree

77 files changed

+857668
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+857668
-3
lines changed

config/id.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package config
2+
3+
import (
4+
"crypto/sha256"
5+
"encoding/hex"
6+
"encoding/json"
7+
"fmt"
8+
"net"
9+
"os"
10+
"strings"
11+
12+
"github.com/denisbrodbeck/machineid"
13+
. "github.com/klauspost/cpuid/v2"
14+
15+
"helix-honeypot/model"
16+
)
17+
18+
func getMacAddress() ([]string, error) {
19+
ifas, err := net.Interfaces()
20+
if err != nil {
21+
return nil, fmt.Errorf("error getting network interfaces: %v", err)
22+
}
23+
var as []string
24+
for _, ifa := range ifas {
25+
a := ifa.HardwareAddr.String()
26+
if a != "" {
27+
as = append(as, a)
28+
}
29+
}
30+
return as, nil
31+
}
32+
33+
func MakeMachineId() (string, error) {
34+
// Generate a machine id from multiple values
35+
var hostid model.HostIDStruct
36+
id, err := machineid.ID()
37+
if err != nil {
38+
fmt.Errorf("error generating machine id: %v", err)
39+
}
40+
hostname, err := os.Hostname()
41+
if err != nil {
42+
fmt.Errorf("error getting hostname: %v", err)
43+
}
44+
macSlice, err := getMacAddress()
45+
if err != nil {
46+
fmt.Errorf("error getting mac address: %v", err)
47+
}
48+
49+
hostid.MachineID = id
50+
hostid.ProcessorHash = CPU.BrandName
51+
hostid.ProcessorFeatures = strings.Join(CPU.FeatureSet(), ",")
52+
hostid.CacheLine = fmt.Sprint(CPU.CacheLine)
53+
hostid.CacheL1D = fmt.Sprint(CPU.Cache.L1D)
54+
hostid.CacheL1I = fmt.Sprint(CPU.Cache.L1I)
55+
hostid.CacheL2 = fmt.Sprint(CPU.Cache.L2)
56+
hostid.CacheL3 = fmt.Sprint(CPU.Cache.L3)
57+
hostid.CPUFrequency = fmt.Sprint(CPU.Hz)
58+
hostid.PhysicalCores = fmt.Sprint(CPU.PhysicalCores)
59+
hostid.LogicalCores = fmt.Sprint(CPU.LogicalCores)
60+
hostid.ThreadsPerCore = fmt.Sprint(CPU.ThreadsPerCore)
61+
hostid.VendorID = CPU.VendorID.String() // convert VendorID to string
62+
hostid.MacAddress = macSlice
63+
hostid.Hostname = hostname
64+
65+
hostIDBytes, err := json.Marshal(hostid)
66+
if err != nil {
67+
return "", fmt.Errorf("error marshalling hostid: %v", err)
68+
}
69+
hash := sha256.Sum256(hostIDBytes)
70+
71+
return hex.EncodeToString(hash[:]), nil
72+
}
73+

honeypots/defense/defense.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package defense
2+
3+
import (
4+
"github.com/labstack/echo/v4"
5+
"helix-honeypot/model"
6+
"helix-honeypot/logger"
7+
8+
"net/http"
9+
"math/rand"
10+
crand "crypto/rand"
11+
"strconv"
12+
)
13+
14+
// Literally streams cruff to the response
15+
func ActiveDefenseHandler(c echo.Context) error {
16+
prng := crand.Reader
17+
return c.Stream(http.StatusCreated, "application/json", prng)
18+
}
19+
20+
// RedirectLoopHandler serves a redirect loop that follows a sequence of URLs from "a" to "z"
21+
func RedirectLoopHandler(c echo.Context) error {
22+
// Get the current redirect index from the query parameter "index"
23+
index := c.QueryParam("index")
24+
if index == "" {
25+
index = "0"
26+
}
27+
28+
// Convert the index to an integer
29+
redirectIndex := 0
30+
// Handle any conversion errors
31+
if i, err := strconv.Atoi(index); err == nil && i >= 0 {
32+
redirectIndex = i
33+
}
34+
35+
// Calculate the next character in the sequence
36+
nextIndex := (redirectIndex + 1) % 26
37+
nextChar := string('a' + nextIndex)
38+
39+
// Set the next redirect URL
40+
nextURL := "/" + nextChar
41+
42+
// Set response headers for the forever redirect
43+
c.Response().Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
44+
c.Response().Header().Set("Pragma", "no-cache")
45+
c.Response().Header().Set("Expires", "0")
46+
c.Response().Header().Set("Location", nextURL)
47+
48+
// Send the forever redirect response
49+
return c.Redirect(http.StatusMovedPermanently, nextURL)
50+
}
51+
52+
// RandomHandler randomly chooses between ActiveDefenseHandler and RedirectLoopHandler
53+
func RandomHandler(c echo.Context) error {
54+
handlers := []func(echo.Context) error{
55+
ActiveDefenseHandler,
56+
func(c echo.Context) error {
57+
return RedirectLoopHandler(c)
58+
},
59+
}
60+
61+
// Randomly select a handler
62+
randomIndex := rand.Intn(len(handlers))
63+
selectedHandler := handlers[randomIndex]
64+
65+
// Execute the selected handler
66+
return selectedHandler(c)
67+
}
68+
69+
func StartDefenseHoneypot(cfg *model.Config) {
70+
e := NewRouter()
71+
72+
// Initialize logger
73+
customLogger, err := logger.NewCustomLogger(cfg)
74+
if err != nil {
75+
e.Logger.Fatal(err)
76+
return
77+
}
78+
79+
// Set the logger middleware
80+
e.Use(customLogger.Middleware)
81+
// Routes for Active Defense Mode
82+
e.GET("/*", RandomHandler)
83+
e.POST("/*", RandomHandler)
84+
85+
e.Logger.Fatal(e.Start(cfg.DEF.Host + ":" + cfg.DEF.Port))
86+
}

honeypots/defense/router.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package defense
2+
3+
import (
4+
"github.com/labstack/echo/v4"
5+
"github.com/labstack/gommon/log"
6+
)
7+
8+
func NewRouter() *echo.Echo {
9+
echoRouter := echo.New()
10+
echoRouter.Logger.SetLevel(log.DEBUG)
11+
echoRouter.HideBanner = true
12+
return echoRouter
13+
}

honeypots/http/http.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package http
2+
3+
import (
4+
"github.com/labstack/echo/v4"
5+
"helix-honeypot/model"
6+
"helix-honeypot/logger"
7+
"net/http"
8+
)
9+
10+
func StartHTTPHoneypot(cfg *model.Config) {
11+
e := NewRouter()
12+
13+
// Initialize logger
14+
customLogger, err := logger.NewCustomLogger(cfg)
15+
if err != nil {
16+
e.Logger.Fatal(err)
17+
return
18+
}
19+
20+
// Set the logger middleware
21+
e.Use(customLogger.Middleware)
22+
23+
e.GET("/*", func(c echo.Context) error {
24+
return c.String(http.StatusOK, "OK")
25+
})
26+
27+
e.Logger.Fatal(e.Start(cfg.HTTP.Host + ":" + cfg.HTTP.Port))
28+
}

honeypots/http/router.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package http
2+
3+
import (
4+
"github.com/labstack/echo/v4"
5+
"github.com/labstack/gommon/log"
6+
)
7+
8+
func NewRouter() *echo.Echo {
9+
echoRouter := echo.New()
10+
echoRouter.Logger.SetLevel(log.DEBUG)
11+
echoRouter.HideBanner = true
12+
return echoRouter
13+
}

honeypots/k8s/generator/empty.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package generator
2+
3+
type Metadata struct {
4+
ResourceVersion string `json:"resourceVersion"`
5+
}
6+
7+
type ColumnDefinition struct {
8+
Name string `json:"name"`
9+
Type string `json:"type"`
10+
Format string `json:"format"`
11+
Description string `json:"description"`
12+
Priority int `json:"priority"`
13+
}
14+
15+
type Table struct {
16+
Kind string `json:"kind"`
17+
ApiVersion string `json:"apiVersion"`
18+
Metadata Metadata `json:"metadata"`
19+
ColumnDefinitions []map[string]interface{} `json:"columnDefinitions"`
20+
Rows []interface{} `json:"rows"`
21+
}
22+
23+
// ConvertMapToColumnDefinition converts a map into a ColumnDefinition struct
24+
func ConvertMapToColumnDefinition(defMap map[string]interface{}) ColumnDefinition {
25+
return ColumnDefinition{
26+
Name: defMap["name"].(string),
27+
Type: defMap["type"].(string),
28+
Format: defMap["format"].(string),
29+
Description: defMap["description"].(string),
30+
Priority: defMap["priority"].(int),
31+
}
32+
}
33+
34+
// GenerateEmptyList generates a Table instance with default values
35+
func GenerateEmptyList() Table {
36+
columnDefs := GenerateColumnDefinitions()
37+
return Table{
38+
Kind: "Table",
39+
ApiVersion: "meta.k8s.io/v1",
40+
Metadata: Metadata{ResourceVersion: "561"},
41+
ColumnDefinitions: columnDefs,
42+
Rows: []interface{}{},
43+
}
44+
}

honeypots/k8s/generator/generator.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package generator
2+
3+
import (
4+
"math/rand"
5+
"sort"
6+
"time"
7+
8+
"helix-honeypot/model"
9+
)
10+
11+
func generatePodConfig(cfg *model.Config, namespace string, podNames []string, resourceVersion string) map[string]interface{} {
12+
rand.Seed(time.Now().UnixNano()) // Seeding the random number generator
13+
pods := make([]interface{}, rand.Intn(110)+10)
14+
for i := range pods {
15+
pods[i] = GeneratePod(cfg, namespace, podNames)
16+
}
17+
18+
// Sort pods
19+
sort.SliceStable(pods, func(i, j int) bool {
20+
iPod := pods[i].(map[string]interface{})
21+
jPod := pods[j].(map[string]interface{})
22+
iName := iPod["object"].(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
23+
jName := jPod["object"].(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
24+
return iName < jName
25+
})
26+
27+
config := map[string]interface{}{
28+
"kind": "Table",
29+
"apiVersion": "meta.k8s.io/v1",
30+
"metadata": map[string]interface{}{
31+
"resourceVersion": resourceVersion,
32+
},
33+
"columnDefinitions": GenerateColumnDefinitions(),
34+
"rows": pods,
35+
}
36+
37+
return config
38+
}
39+
40+
func GenerateKubeSystemConfig(cfg *model.Config, namespace string) map[string]interface{} {
41+
podNames := []string{
42+
"kube-apiserver", "kube-controller-manager", "kube-scheduler",
43+
"kube-proxy", "etcd", "coredns", "kube-addon-manager",
44+
"kube-flannel", "kube-calico", "kube-dns", "kube-sidecar",
45+
"kube-state-metrics", "kube-ingress-controller", "kube-dashboard",
46+
"kube-metrics-scraper", "kube-network-manager", "kube-node-exporter",
47+
"kube-persistent-storage", "kube-csi", "kubelet", "kube-proxy",
48+
"kube-vpnkit-controller", "kube-storage-provisioner",
49+
}
50+
return generatePodConfig(cfg, namespace, podNames, "1110")
51+
}
52+
53+
54+
func GenerateDefaultNamespaceConfig(cfg *model.Config, namespace string) map[string]interface{} {
55+
podNames := []string{
56+
"database", "message-queue", "cache", "nginx", "apache", "tomcat",
57+
"redis", "elasticsearch", "rabbitmq", "kafka", "memcached", "mysql",
58+
"postgres", "mongo", "cassandra", "influxdb", "grafana", "prometheus",
59+
"wordpress", "jenkins", "gitlab", "drupal", "magento", "django",
60+
"laravel", "nodejs", "express", "flask", "spring-boot", "react",
61+
"angular", "vuejs", "emberjs", "kubernetes", "docker", "minio",
62+
"jupyter", "tensorflow", "spark", "git", "consul", "vault",
63+
"kibana", "haproxy", "traefik", "graylog", "sonarqube", "nexus",
64+
"zookeeper", "etcd", "nextcloud", "ghost", "owncloud", "clickhouse",
65+
"metabase", "nginx-ingress", "kong", "keycloak", "rancher", "logstash",
66+
"aws-lambda", "aws-s3", "aws-dynamodb", "aws-rds", "aws-sqs", "aws-sns",
67+
"gcp-cloud-run", "gcp-datastore", "gcp-pubsub", "azure-functions", "azure-storage", "azure-cosmosdb",
68+
"azure-service-bus", "kafka", "rabbitmq", "hadoop", "couchbase", "couchdb",
69+
"neo4j", "clickhouse", "varnish", "traefik", "gitlab-runner", "nats",
70+
"apollo", "jitsi", "rocketmq", "deno", "glusterfs", "prometheus-operator",
71+
"rancher", "knative", "fluentd", "openfaas", "loki", "istio",
72+
"redis-cache", "postgresql", "mongodb", "couchbase", "apache-kafka", "nginx-ingress-controller",
73+
"jenkins-x", "drone", "openshift", "gitlab-ci", "bitbucket-pipelines", "teamcity",
74+
"spinnaker", "artifactory", "nexus-repository", "kong-api-gateway", "tyk-api-gateway", "azure-apim",
75+
"consul-service-mesh", "linkerd", "kuma", "flannel", "weave", "cilium",
76+
"argocd", "fluxcd", "istio", "knative", "keda", "helm",
77+
"tekton", "argo-workflows", "falco", "sysdig", "calico", "openshift-sdn",
78+
"fluent-bit", "logstash", "telegraf", "papertrail", "logentries", "logdna",
79+
}
80+
return generatePodConfig(cfg, namespace, podNames, "3572")
81+
}

0 commit comments

Comments
 (0)