mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
refactor:Added Integration test and tiny refactoring (#23)
* Refactoring name convention * Added integration test * Added Makefile * Bump golang.org/x/crypto from 0.0.0-20220826181053-bd7e27e6170d to 0.6.0 Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20220826181053-bd7e27e6170d to 0.6.0. - [Release notes](https://github.com/golang/crypto/releases) - [Commits](https://github.com/golang/crypto/commits/v0.6.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor ... * Upgrade go from 1.16 to 1.20 * Added integration test: HTTP, TCP, SSH * Added Makefile Improve README.md * Fixed unit test CI * Fixed go-version * Added integration test into C.I. actions --------- Signed-off-by: Mario Candela <m4r10.php@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
9
integration_test/configurations/beelzebub.yaml
Normal file
9
integration_test/configurations/beelzebub.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
core:
|
||||
logging:
|
||||
debug: false
|
||||
debugReportCaller: false
|
||||
logDisableTimestamp: true
|
||||
logsPath: ./logs
|
||||
tracing:
|
||||
rabbitMQEnabled: false
|
||||
rabbitMQURI: ""
|
19
integration_test/configurations/services/http-8080.yaml
Normal file
19
integration_test/configurations/services/http-8080.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
apiVersion: "v1"
|
||||
protocol: "http"
|
||||
address: ":8080"
|
||||
description: "Wordpress 6.0"
|
||||
commands:
|
||||
- regex: "index.php"
|
||||
handler: "mocked response"
|
||||
headers:
|
||||
- "Content-Type: text/html"
|
||||
- "Server: Apache/2.4.53 (Debian)"
|
||||
- "X-Powered-By: PHP/7.4.29"
|
||||
statusCode: 200
|
||||
- regex: "^(/wp-login.php|/wp-admin)$"
|
||||
handler: "mocked response"
|
||||
headers:
|
||||
- "Content-Type: text/html"
|
||||
- "Server: Apache/2.4.53 (Debian)"
|
||||
- "X-Powered-By: PHP/7.4.29"
|
||||
statusCode: 400
|
25
integration_test/configurations/services/ssh-2222.yaml
Normal file
25
integration_test/configurations/services/ssh-2222.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
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
|
6
integration_test/configurations/services/tcp-3306.yaml
Normal file
6
integration_test/configurations/services/tcp-3306.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
apiVersion: "v1"
|
||||
protocol: "tcp"
|
||||
address: ":3306"
|
||||
description: "Mysql 8.0.29"
|
||||
banner: "8.0.29"
|
||||
deadlineTimeoutSeconds: 10
|
115
integration_test/integration_test.go
Normal file
115
integration_test/integration_test.go
Normal file
@ -0,0 +1,115 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"beelzebub/builder"
|
||||
"beelzebub/parser"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/melbahja/goph"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
beelzebubBuilder *builder.Builder
|
||||
httpHoneypotHost string
|
||||
tcpHoneypotHost string
|
||||
sshHoneypotHost string
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) SetupSuite() {
|
||||
suite.T().Helper()
|
||||
if os.Getenv("INTEGRATION") == "" {
|
||||
suite.T().Skip("skipping integration tests, set environment variable INTEGRATION")
|
||||
}
|
||||
suite.httpHoneypotHost = "http://localhost:8080"
|
||||
suite.tcpHoneypotHost = "localhost:3306"
|
||||
suite.sshHoneypotHost = "localhost"
|
||||
|
||||
beelzebubConfigPath := "./configurations/beelzebub.yaml"
|
||||
servicesConfigDirectory := "./configurations/services/"
|
||||
|
||||
parser := parser.Init(beelzebubConfigPath, servicesConfigDirectory)
|
||||
|
||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.beelzebubBuilder = builder.NewBuilder()
|
||||
|
||||
director := builder.NewDirector(suite.beelzebubBuilder)
|
||||
|
||||
suite.beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Require().NoError(suite.beelzebubBuilder.Run())
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestInvokeHTTPHoneypot() {
|
||||
response, err := resty.New().R().
|
||||
Get(suite.httpHoneypotHost + "/index.php")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
suite.Equal("mocked response", string(response.Body()))
|
||||
|
||||
response, err = resty.New().R().
|
||||
Get(suite.httpHoneypotHost + "/wp-admin")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusBadRequest, response.StatusCode())
|
||||
suite.Equal("mocked response", string(response.Body()))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestInvokeTCPHoneypot() {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", suite.tcpHoneypotHost)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
conn, err := net.DialTCP("tcp", nil, tcpAddr)
|
||||
suite.Require().NoError(err)
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte("hello!"))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
reply := make([]byte, 1024)
|
||||
|
||||
n, err := conn.Read(reply)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("8.0.29\n", string(reply[:n]))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestInvokeSSHHoneypot() {
|
||||
client, err := goph.NewConn(
|
||||
&goph.Config{
|
||||
User: "root",
|
||||
Addr: suite.sshHoneypotHost,
|
||||
Port: 2222,
|
||||
Auth: goph.Password("root"),
|
||||
Callback: ssh.InsecureIgnoreHostKey(),
|
||||
})
|
||||
suite.Require().NoError(err)
|
||||
defer client.Close()
|
||||
|
||||
out, err := client.Run("")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("root@ubuntu:~$ ", string(out))
|
||||
}
|
||||
|
||||
//TODO test rabbitmq
|
||||
|
||||
func (suite *IntegrationTestSuite) TestShutdownBeelzebub() {
|
||||
suite.Require().NoError(suite.beelzebubBuilder.Close())
|
||||
}
|
Reference in New Issue
Block a user