Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistence of listeners on the server-side #154

Draft
wants to merge 3 commits into
base: config_file
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ require (
golang.org/x/sync v0.5.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Binject/debug v0.0.0-20201228082058-60012895f187 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/onsi/ginkgo/v2 v2.13.2 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/Binject/go-donut v0.0.0-20201215224200-d947cf4d090d h1:p1nbUZVkTna5JW
github.com/Binject/go-donut v0.0.0-20201215224200-d947cf4d090d/go.mod h1:+HPTw2E7tpmDKnls6np/4DMINtku9rw3TgLtKoydgMI=
github.com/Ne0nd0g/merlin-message v1.3.0 h1:HelXwN6Gtk80C2ted0+PAprq+zRiQRGLG6s6phyFY5o=
github.com/Ne0nd0g/merlin-message v1.3.0/go.mod h1:6eAh2KI4XrOAF+y4W2DN0qfRVWiAGzYlq148iKe3sSA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cretz/gopaque v0.1.0 h1:rC+coO7LzXnstyG7FmwK0XD7oV93tg9EZ+Fl2yZOeto=
github.com/cretz/gopaque v0.1.0/go.mod h1:0npz8L/gL98OX2nWKF8WRSP8ZCAg89UKBBrBVrDXJQg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -26,10 +27,15 @@ github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 h1:dHLYa5D8/Ta0aLR2Xc
github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
Expand All @@ -38,6 +44,8 @@ github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5
github.com/quic-go/qtls-go1-20 v0.4.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
github.com/quic-go/quic-go v0.40.1 h1:X3AGzUNFs0jVuO3esAGnTfvdgvL4fq655WaOi1snv1Q=
github.com/quic-go/quic-go v0.40.1/go.mod h1:PeN7kuVJ4xZbxSv/4OX6S1USOX8MJvydwpTx31vx60c=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
Expand Down Expand Up @@ -91,6 +99,10 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func main() {
trace := flag.Bool("trace", false, "Enable trace logging")
extra := flag.Bool("extra", false, "Enable extra debug logging")
v := flag.Bool("version", false, "Print the version number and exit")

var listenersStorageFile string
flag.StringVar(&listenersStorageFile, "listenersFile", "", "YAML file, load listeners from it and saves to it.")

flag.Parse()

if *v {
Expand All @@ -64,7 +68,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
err = service.Run(*addr)
err = service.Run(*addr, listenersStorageFile)
if err != nil {
log.Fatal(err)
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/listeners/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/google/uuid"

// Merlin Message
"github.com/Ne0nd0g/merlin-message"
messages "github.com/Ne0nd0g/merlin-message"

// Merlin
"github.com/Ne0nd0g/merlin/v2/pkg/authenticators"
Expand Down Expand Up @@ -189,12 +189,16 @@ func (l *Listener) ConfiguredOptions() map[string]string {
options["Name"] = l.name
options["Description"] = l.description
options["Authenticator"] = l.auth.String()
options["Transforms"] = ""
for _, transform := range l.transformers {
options["Transforms"] += fmt.Sprintf("%s,", transform)
}
// PSK is stored in l.PSK as a sha256 hash of the passed in clear-text PSK
options["PSK"] = l.options["PSK"]

transforms := make([]string, len(l.transformers))
options["Transforms"] = ""
for i, transform := range l.transformers {
transforms[i] = fmt.Sprintf("%s", transform)
}
options["Transforms"] = strings.Join(transforms, ",")

return options
}

Expand Down
15 changes: 10 additions & 5 deletions pkg/listeners/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/google/uuid"

// Merlin Message
"github.com/Ne0nd0g/merlin-message"
messages "github.com/Ne0nd0g/merlin-message"

// Internal
"github.com/Ne0nd0g/merlin/v2/pkg/authenticators"
Expand Down Expand Up @@ -219,12 +219,17 @@ func (l *Listener) ConfiguredOptions() (options map[string]string) {
options["Name"] = l.name
options["Description"] = l.description
options["Authenticator"] = l.auth.String()
options["Transforms"] = ""
for _, transform := range l.transformers {
options["Transforms"] += fmt.Sprintf("%s,", transform)
}
options["Protocol"] = listeners.String(l.Protocol())
options["PSK"] = l.options["PSK"]
options["Pipe"] = l.pipe

transforms := make([]string, len(l.transformers))
options["Transforms"] = ""
for i, transform := range l.transformers {
transforms[i] = fmt.Sprintf("%s", transform)
}
options["Transforms"] = strings.Join(transforms, ",")

return options
}

Expand Down
15 changes: 10 additions & 5 deletions pkg/listeners/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/google/uuid"

// Merlin Message
"github.com/Ne0nd0g/merlin-message"
messages "github.com/Ne0nd0g/merlin-message"

// Merlin
"github.com/Ne0nd0g/merlin/v2/pkg/authenticators"
Expand Down Expand Up @@ -225,13 +225,18 @@ func (l *Listener) ConfiguredOptions() (options map[string]string) {
options["Name"] = l.name
options["Description"] = l.description
options["Authenticator"] = l.auth.String()
options["Transforms"] = ""
for _, transform := range l.transformers {
options["Transforms"] += fmt.Sprintf("%s,", transform)
}
options["PSK"] = l.options["PSK"]
options["Interface"] = l.iface
options["Port"] = fmt.Sprintf("%d", l.port)
options["Protocol"] = listeners.String(l.Protocol())

transforms := make([]string, len(l.transformers))
options["Transforms"] = ""
for i, transform := range l.transformers {
transforms[i] = fmt.Sprintf("%s", transform)
}
options["Transforms"] = strings.Join(transforms, ",")

return options
}

Expand Down
14 changes: 9 additions & 5 deletions pkg/listeners/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/google/uuid"

// Merlin Message
"github.com/Ne0nd0g/merlin-message"
messages "github.com/Ne0nd0g/merlin-message"

// Merlin

Expand Down Expand Up @@ -224,13 +224,17 @@ func (l *Listener) ConfiguredOptions() (options map[string]string) {
options["Name"] = l.name
options["Description"] = l.description
options["Authenticator"] = l.auth.String()
options["Transforms"] = ""
for _, transform := range l.transformers {
options["Transforms"] += fmt.Sprintf("%s,", transform)
}
options["PSK"] = l.options["PSK"]
options["Interface"] = l.iface
options["Port"] = fmt.Sprintf("%d", l.port)
options["Protocol"] = listeners.String(l.Protocol())

transforms := make([]string, len(l.transformers))
options["Transforms"] = ""
for i, transform := range l.transformers {
transforms[i] = fmt.Sprintf("%s", transform)
}
options["Transforms"] = strings.Join(transforms, ",")
return options
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/servers/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,18 @@ type Template struct {
func New(options map[string]string) (Server, error) {
var err error
var s Server
s.id = uuid.New()
s.state = Stopped

id, ok := options["ID"]
if ok {
s.id, err = uuid.Parse(id)
if err != nil {
return s, fmt.Errorf("the \"ID\" key UUID value (%s) was incorrect, please provide a correct one", id)
}
} else {
s.id = uuid.New()
}

// Protocol
proto, ok := options["Protocol"]
if ok {
Expand Down
Loading