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:
57
protocols/strategies/transmission_control_protocol.go
Normal file
57
protocols/strategies/transmission_control_protocol.go
Normal file
@ -0,0 +1,57 @@
|
||||
package strategies
|
||||
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/tracer"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TransmissionControlProtocolStrategy struct {
|
||||
}
|
||||
|
||||
func (TCPStrategy *TransmissionControlProtocolStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
listen, err := net.Listen("tcp", beelzebubServiceConfiguration.Address)
|
||||
if err != nil {
|
||||
log.Errorf("Error during init TCP Protocol: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
if conn, err := listen.Accept(); err == nil {
|
||||
go func() {
|
||||
conn.SetDeadline(time.Now().Add(time.Duration(beelzebubServiceConfiguration.DeadlineTimeoutSeconds) * time.Second))
|
||||
conn.Write([]byte(fmt.Sprintf("%s\n", beelzebubServiceConfiguration.Banner)))
|
||||
|
||||
buffer := make([]byte, 1024)
|
||||
command := ""
|
||||
|
||||
if n, err := conn.Read(buffer); err == nil {
|
||||
command = string(buffer[:n])
|
||||
}
|
||||
|
||||
tr.TraceEvent(tracer.Event{
|
||||
Msg: "New TCP attempt",
|
||||
Protocol: tracer.TCP.String(),
|
||||
Command: command,
|
||||
Status: tracer.Stateless.String(),
|
||||
RemoteAddr: conn.RemoteAddr().String(),
|
||||
ID: uuid.New().String(),
|
||||
Description: beelzebubServiceConfiguration.Description,
|
||||
})
|
||||
conn.Close()
|
||||
}()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"port": beelzebubServiceConfiguration.Address,
|
||||
"banner": beelzebubServiceConfiguration.Banner,
|
||||
}).Infof("Init service %s", beelzebubServiceConfiguration.Protocol)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user