diff --git a/README.md b/README.md index 65388fe..4427d73 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,21 @@ We provide two quick start options for build and run Beelzebub: using Docker Com $ ./beelzebub ``` +### Deploy on kubernetes cluster using helm + +1. Install helm + +2. Deploy beelzebub: + + ```bash + $ helm install beelzebub ./beelzebub-chart + ``` + +3. Next release + + ```bash + $ helm upgrade beelzebub ./beelzebub-chart + ``` ## Testing We provide two types of tests: unit tests and integration tests. @@ -82,13 +97,14 @@ $ make test.integration Beelzebub offers a wide range of features to enhance your honeypot environment: -- OpenAPI ChatBot GPT-3 Linux virtualization +- OpenAI Generative Pre-trained Transformer act as Linux virtualization - SSH Honeypot - HTTP Honeypot - TCP Honeypot - Prometheus openmetrics integration - Docker integration - RabbitMQ integration +- kubernetes ## Example Configuration diff --git a/beelzebub-chart/.helmignore b/beelzebub-chart/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/beelzebub-chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/beelzebub-chart/Chart.yaml b/beelzebub-chart/Chart.yaml new file mode 100644 index 0000000..8a2750c --- /dev/null +++ b/beelzebub-chart/Chart.yaml @@ -0,0 +1,12 @@ +apiVersion: v2 +name: beelzebub-chart +description: A Helm chart for Kubernetes + +type: application +version: 0.1.0 +appVersion: "v3.0.0" + +maintainers: + - name: mariocandela + email: mario.candela.personal@gmail.com + url: https://github.com/mariocandela \ No newline at end of file diff --git a/beelzebub-chart/templates/NOTES.txt b/beelzebub-chart/templates/NOTES.txt new file mode 100644 index 0000000..732eda5 --- /dev/null +++ b/beelzebub-chart/templates/NOTES.txt @@ -0,0 +1,28 @@ +██████ ███████ ███████ ██ ███████ ███████ ██████ ██ ██ ██████ +██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ +██████ █████ █████ ██ ███ █████ ██████ ██ ██ ██████ +██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ +██████ ███████ ███████ ███████ ███████ ███████ ██████ ██████ ██████ +Honeypot Framework, happy hacking! +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "beelzebub-chart.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "beelzebub-chart.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "beelzebub-chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "beelzebub-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your honeypot or ssh root@127.0.0.1 -p 8080 for ssh honeypot" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/beelzebub-chart/templates/_helpers.tpl b/beelzebub-chart/templates/_helpers.tpl new file mode 100644 index 0000000..2cc42b9 --- /dev/null +++ b/beelzebub-chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "beelzebub-chart.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "beelzebub-chart.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "beelzebub-chart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "beelzebub-chart.labels" -}} +helm.sh/chart: {{ include "beelzebub-chart.chart" . }} +{{ include "beelzebub-chart.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "beelzebub-chart.selectorLabels" -}} +app.kubernetes.io/name: {{ include "beelzebub-chart.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "beelzebub-chart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "beelzebub-chart.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/beelzebub-chart/templates/configmap_core.yaml b/beelzebub-chart/templates/configmap_core.yaml new file mode 100644 index 0000000..05dcce8 --- /dev/null +++ b/beelzebub-chart/templates/configmap_core.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "beelzebub-configuration" + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} +data: + beelzebub.yaml: + {{- toYaml .Values.beelzebubCoreConfigs | nindent 12 }} diff --git a/beelzebub-chart/templates/configmap_services.yaml b/beelzebub-chart/templates/configmap_services.yaml new file mode 100644 index 0000000..d38593d --- /dev/null +++ b/beelzebub-chart/templates/configmap_services.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "beelzebub-services" + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} +data: + service.yaml: + {{- toYaml .Values.beelsebubServiceConfigs | nindent 12 }} \ No newline at end of file diff --git a/beelzebub-chart/templates/deployment.yaml b/beelzebub-chart/templates/deployment.yaml new file mode 100644 index 0000000..ece5cff --- /dev/null +++ b/beelzebub-chart/templates/deployment.yaml @@ -0,0 +1,77 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "beelzebub-chart.fullname" . }} + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "beelzebub-chart.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "beelzebub-chart.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "beelzebub-chart.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + volumeMounts: + - name: config-core-volume + mountPath: /configurations/beelzebub.yaml + subPath: beelzebub.yaml + readOnly: true + - name: config-services-volume + mountPath: /configurations/services/service.yaml + subPath: service.yaml + readOnly: true + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + # livenessProbe: + # httpGet: + # path: / + # port: http + # readinessProbe: + # httpGet: + # path: / + # port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: config-core-volume + configMap: + name: beelzebub-configuration + - name: config-services-volume + configMap: + name: beelzebub-services + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/beelzebub-chart/templates/hpa.yaml b/beelzebub-chart/templates/hpa.yaml new file mode 100644 index 0000000..2d1b5c1 --- /dev/null +++ b/beelzebub-chart/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "beelzebub-chart.fullname" . }} + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "beelzebub-chart.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/beelzebub-chart/templates/ingress.yaml b/beelzebub-chart/templates/ingress.yaml new file mode 100644 index 0000000..f9dd461 --- /dev/null +++ b/beelzebub-chart/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "beelzebub-chart.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/beelzebub-chart/templates/service.yaml b/beelzebub-chart/templates/service.yaml new file mode 100644 index 0000000..6e6e1b2 --- /dev/null +++ b/beelzebub-chart/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "beelzebub-chart.fullname" . }} + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "beelzebub-chart.selectorLabels" . | nindent 4 }} diff --git a/beelzebub-chart/templates/serviceaccount.yaml b/beelzebub-chart/templates/serviceaccount.yaml new file mode 100644 index 0000000..5afca38 --- /dev/null +++ b/beelzebub-chart/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "beelzebub-chart.serviceAccountName" . }} + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/beelzebub-chart/templates/tests/test-connection.yaml b/beelzebub-chart/templates/tests/test-connection.yaml new file mode 100644 index 0000000..d392720 --- /dev/null +++ b/beelzebub-chart/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "beelzebub-chart.fullname" . }}-test-connection" + labels: + {{- include "beelzebub-chart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "beelzebub-chart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/beelzebub-chart/values.yaml b/beelzebub-chart/values.yaml new file mode 100644 index 0000000..78b417c --- /dev/null +++ b/beelzebub-chart/values.yaml @@ -0,0 +1,96 @@ +# Default values for beelzebub-chart. +replicaCount: 1 + +image: + repository: m4r10/beelzebub + pullPolicy: IfNotPresent + tag: v3.0.0 + + +beelzebubCoreConfigs: | + core: + logging: + debug: false + debugReportCaller: false + logDisableTimestamp: true + logsPath: ./logs + tracings: + rabbit-mq: + enabled: false + uri: "" + prometheus: + path: "/metrics" + port: ":2112" + +beelsebubServiceConfigs: | + apiVersion: "v1" + protocol: "ssh" + address: ":2222" + description: "SSH interactive" + commands: + - regex: "^ls$" + handler: "Documents Images Desktop Downloads .m2 .kube .ssh .docker" + - regex: "^pwd$" + handler: "/home/" + - regex: "^uname -m$" + handler: "x86_64" + - regex: "^docker ps$" + handler: "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES" + - regex: "^docker .*$" + handler: "Error response from daemon: dial unix docker.raw.sock: connect: connection refused" + - regex: "^uname$" + handler: "Linux" + - regex: "^ps$" + handler: " PID TTY TIME CMD\n21642 ttys000 0:00.07 /bin/dockerd" + - regex: "^(.+)$" + handler: "command not found" + serverVersion: "OpenSSH" + serverName: "ubuntu" + passwordRegex: "^(root|qwerty|Smoker666|123456|jenkins|minecraft|sinus|alex|postgres|Ly123456)$" + deadlineTimeoutSeconds: 60 + +# Port and address(beelsebubServiceConfigs) must equals. +service: + type: ClusterIP + port: 2222 + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + name: "beelzebub-service-account" + +podAnnotations: {} + +podSecurityContext: {} + +securityContext: {} + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + +resources: {} + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} +tolerations: [] +affinity: {} \ No newline at end of file