mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Implemented tcp honeypot
This commit is contained in:
@ -3,6 +3,8 @@ package protocols
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/tracer"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"time"
|
||||
@ -12,18 +14,37 @@ type TransmissionControlProtocolStrategy struct {
|
||||
}
|
||||
|
||||
func (TCPStrategy *TransmissionControlProtocolStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
listen, err := net.Listen("TCP", beelzebubServiceConfiguration.Address)
|
||||
listen, err := net.Listen("tcp", beelzebubServiceConfiguration.Address)
|
||||
if err != nil {
|
||||
log.Errorf("Error during init TCP Protocol: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
defer listen.Close()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
if conn, err := listen.Accept(); err == nil {
|
||||
conn.SetDeadline(time.Now().Add(time.Duration(beelzebubServiceConfiguration.DeadlineTimeoutSeconds) * time.Second))
|
||||
go handleIncomingRequest(conn)
|
||||
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()
|
||||
}()
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -34,16 +55,3 @@ func (TCPStrategy *TransmissionControlProtocolStrategy) Init(beelzebubServiceCon
|
||||
}).Infof("Init service %s", beelzebubServiceConfiguration.Protocol)
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleIncomingRequest(conn net.Conn) {
|
||||
buffer := make([]byte, 1024)
|
||||
_, err := conn.Read(buffer)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// respond
|
||||
conn.Write([]byte("Hi back!\n"))
|
||||
|
||||
// close conn
|
||||
conn.Close()
|
||||
}
|
||||
|
Reference in New Issue
Block a user