mirror of
https://github.com/telekom-security/tpotce.git
synced 2025-07-01 20:42:11 +00:00
glutton structured json logging
This commit is contained in:
parent
64fed3d15b
commit
5fcb7ed4ce
3 changed files with 108 additions and 3 deletions
|
@ -16,12 +16,15 @@ RUN apk -U --no-cache add \
|
||||||
|
|
||||||
# Setup go, glutton
|
# Setup go, glutton
|
||||||
export GOPATH=/opt/go/ && \
|
export GOPATH=/opt/go/ && \
|
||||||
mkdir -p /opt/go/ && \
|
|
||||||
go get -d github.com/mushorg/glutton && \
|
go get -d github.com/mushorg/glutton && \
|
||||||
go get -u github.com/golang/dep/cmd/dep && \
|
cd /opt/go/src/github.com/satori/ && \
|
||||||
|
rm -rf go.uuid && \
|
||||||
|
git clone https://github.com/satori/go.uuid && \
|
||||||
|
cd go.uuid && \
|
||||||
|
git checkout v1.2.0 && \
|
||||||
mv /root/dist/system.go /opt/go/src/github.com/mushorg/glutton/ && \
|
mv /root/dist/system.go /opt/go/src/github.com/mushorg/glutton/ && \
|
||||||
|
mv /root/dist/tcp.go /opt/go/src/github.com/mushorg/glutton/ && \
|
||||||
cd /opt/go/src/github.com/mushorg/glutton/ && \
|
cd /opt/go/src/github.com/mushorg/glutton/ && \
|
||||||
/opt/go/bin/dep ensure && \
|
|
||||||
make build && \
|
make build && \
|
||||||
cd / && \
|
cd / && \
|
||||||
mkdir -p /opt/glutton && \
|
mkdir -p /opt/glutton && \
|
||||||
|
|
58
docker/glutton/Dockerfile.old
Normal file
58
docker/glutton/Dockerfile.old
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
# Include dist
|
||||||
|
ADD dist/ /root/dist/
|
||||||
|
|
||||||
|
# Setup apk
|
||||||
|
RUN apk -U --no-cache add \
|
||||||
|
build-base \
|
||||||
|
git \
|
||||||
|
go \
|
||||||
|
g++ \
|
||||||
|
iptables-dev \
|
||||||
|
libnetfilter_queue-dev \
|
||||||
|
libcap \
|
||||||
|
libpcap-dev && \
|
||||||
|
|
||||||
|
# Setup go, glutton
|
||||||
|
export GOPATH=/opt/go/ && \
|
||||||
|
mkdir -p /opt/go/src/github.com/satori/ && \
|
||||||
|
go get -d github.com/mushorg/glutton && \
|
||||||
|
# go get -u github.com/golang/dep/cmd/dep && \
|
||||||
|
cd /opt/go/src/github.com/satori/ && \
|
||||||
|
rm -rf go.uuid && \
|
||||||
|
git clone https://github.com/satori/go.uuid && \
|
||||||
|
cd go.uuid && \
|
||||||
|
git checkout v1.2.0 && \
|
||||||
|
mv /root/dist/system.go /opt/go/src/github.com/mushorg/glutton/ && \
|
||||||
|
mv /root/dist/tcp.go /opt/go/src/github.com/mushorg/glutton/ && \
|
||||||
|
cd /opt/go/src/github.com/mushorg/glutton/ && \
|
||||||
|
# /opt/go/bin/dep ensure && \
|
||||||
|
make build && \
|
||||||
|
cd / && \
|
||||||
|
mkdir -p /opt/glutton && \
|
||||||
|
mv /opt/go/src/github.com/mushorg/glutton/bin /opt/glutton/ && \
|
||||||
|
mv /opt/go/src/github.com/mushorg/glutton/config /opt/glutton/ && \
|
||||||
|
mv /opt/go/src/github.com/mushorg/glutton/rules /opt/glutton/ && \
|
||||||
|
setcap cap_net_admin,cap_net_raw=+ep /opt/glutton/bin/server && \
|
||||||
|
setcap cap_net_admin,cap_net_raw=+ep /sbin/xtables-multi && \
|
||||||
|
|
||||||
|
# Setup user, groups and configs
|
||||||
|
addgroup -g 2000 glutton && \
|
||||||
|
adduser -S -s /bin/ash -u 2000 -D -g 2000 glutton && \
|
||||||
|
mkdir -p /var/log/glutton && \
|
||||||
|
mv /root/dist/rules.yaml /opt/glutton/rules/ && \
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
apk del --purge build-base \
|
||||||
|
git \
|
||||||
|
go \
|
||||||
|
g++ && \
|
||||||
|
rm -rf /var/cache/apk/* \
|
||||||
|
/opt/go \
|
||||||
|
/root/dist
|
||||||
|
|
||||||
|
# Start glutton
|
||||||
|
WORKDIR /opt/glutton
|
||||||
|
USER glutton:glutton
|
||||||
|
CMD exec bin/server -i $(/sbin/ip address | grep '^2: ' | awk '{ print $2 }' | tr -d [:punct:]) -l /var/log/glutton/glutton.log
|
44
docker/glutton/dist/tcp.go
vendored
Normal file
44
docker/glutton/dist/tcp.go
vendored
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package glutton
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/kung-foo/freki"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandleTCP takes a net.Conn and peeks at the data send
|
||||||
|
func (g *Glutton) HandleTCP(ctx context.Context, conn net.Conn) (err error) {
|
||||||
|
defer func() {
|
||||||
|
err = conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
g.logger.Error(fmt.Sprintf("[log.tcp ] error: %v", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
host, port, err := net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
if err != nil {
|
||||||
|
g.logger.Error(fmt.Sprintf("[log.tcp ] error: %v", err))
|
||||||
|
}
|
||||||
|
ck := freki.NewConnKeyByString(host, port)
|
||||||
|
md := g.processor.Connections.GetByFlow(ck)
|
||||||
|
buffer := make([]byte, 1024)
|
||||||
|
n, err := conn.Read(buffer)
|
||||||
|
if err != nil {
|
||||||
|
g.logger.Error(fmt.Sprintf("[log.tcp ] error: %v", err))
|
||||||
|
}
|
||||||
|
if n > 0 && n < 1024 {
|
||||||
|
g.logger.Info(
|
||||||
|
fmt.Sprintf("Packet got handled by TCP handler"),
|
||||||
|
zap.String("dest_port", strconv.Itoa(int(md.TargetPort))),
|
||||||
|
zap.String("src_ip", host),
|
||||||
|
zap.String("src_port", port),
|
||||||
|
zap.String("handler", "tcp"),
|
||||||
|
zap.String("payload_hex", hex.EncodeToString(buffer[0:n])),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
Loading…
Reference in a new issue