From dfa0a1e8ce108cf2008b1690a83bc8ec9eca4a15 Mon Sep 17 00:00:00 2001 From: CapacitorSet Date: Thu, 3 May 2018 14:48:47 +0200 Subject: [PATCH 1/4] Remove unused field --- director/dummy.go | 49 --------------------------------------------- server/honeytrap.go | 3 --- 2 files changed, 52 deletions(-) delete mode 100644 director/dummy.go diff --git a/director/dummy.go b/director/dummy.go deleted file mode 100644 index e43302d05..000000000 --- a/director/dummy.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Honeytrap -* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) -* -* This program is free software; you can redistribute it and/or modify it under -* the terms of the GNU Affero General Public License version 3 as published by the -* Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -* details. -* -* You should have received a copy of the GNU Affero General Public License -* version 3 along with this program in the file "LICENSE". If not, see -* . -* -* See https://honeytrap.io/ for more details. All requests should be sent to -* licensing@honeytrap.io -* -* The interactive user interfaces in modified source and object code versions -* of this program must display Appropriate Legal Notices, as required under -* Section 5 of the GNU Affero General Public License version 3. -* -* In accordance with Section 7(b) of the GNU Affero General Public License version 3, -* these Appropriate Legal Notices must retain the display of the "Powered by -* Honeytrap" logo and retain the original copyright notice. If the display of the -* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices -* must display the words "Powered by Honeytrap" and retain the original copyright notice. - */ -package director - -import "net" - -func MustDummy(options ...func(Director) error) Director { - l, _ := Dummy() - return l -} - -func Dummy(options ...func(Director) error) (Director, error) { - return &dummyDirector{}, nil -} - -type dummyDirector struct { -} - -func (*dummyDirector) Dial(net.Conn) (net.Conn, error) { - return nil, nil -} diff --git a/server/honeytrap.go b/server/honeytrap.go index e84ed6e8b..7985531c8 100644 --- a/server/honeytrap.go +++ b/server/honeytrap.go @@ -110,8 +110,6 @@ type Honeytrap struct { // TODO(nl5887): rename to bus, should we encapsulate this? bus *eventbus.EventBus - director director.Director - token string dataDir string @@ -131,7 +129,6 @@ func New(options ...OptionFn) (*Honeytrap, error) { h := &Honeytrap{ config: conf, - director: director.MustDummy(), bus: bus, profiler: profiler.Dummy(), } From b64414a0814e7189d73d233b6f21c1a370f9c8ed Mon Sep 17 00:00:00 2001 From: CapacitorSet Date: Sat, 5 May 2018 16:43:32 +0200 Subject: [PATCH 2/4] Remove unused file --- config/delay.go | 55 ------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 config/delay.go diff --git a/config/delay.go b/config/delay.go deleted file mode 100644 index 3bb38b79b..000000000 --- a/config/delay.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -* Honeytrap -* Copyright (C) 2016-2017 DutchSec (https://dutchsec.com/) -* -* This program is free software; you can redistribute it and/or modify it under -* the terms of the GNU Affero General Public License version 3 as published by the -* Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -* details. -* -* You should have received a copy of the GNU Affero General Public License -* version 3 along with this program in the file "LICENSE". If not, see -* . -* -* See https://honeytrap.io/ for more details. All requests should be sent to -* licensing@honeytrap.io -* -* The interactive user interfaces in modified source and object code versions -* of this program must display Appropriate Legal Notices, as required under -* Section 5 of the GNU Affero General Public License version 3. -* -* In accordance with Section 7(b) of the GNU Affero General Public License version 3, -* these Appropriate Legal Notices must retain the display of the "Powered by -* Honeytrap" logo and retain the original copyright notice. If the display of the -* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices -* must display the words "Powered by Honeytrap" and retain the original copyright notice. - */ -package config - -import "time" - -// Delay defines a duration type. -type Delay time.Duration - -// Duration returns the type of the giving duration from the provided pointer. -func (t *Delay) Duration() time.Duration { - return time.Duration(*t) -} - -// UnmarshalText handles unmarshalling duration values from the provided slice. -func (t *Delay) UnmarshalText(text []byte) error { - s := string(text) - - d, err := time.ParseDuration(s) - if err != nil { - log.Errorf("Error parsing duration (%s): %s", s, err.Error()) - return err - } - - *t = Delay(d) - return nil -} From 374fad9e18abc84f41644d5313a111243efb5076 Mon Sep 17 00:00:00 2001 From: CapacitorSet Date: Sat, 5 May 2018 17:26:28 +0200 Subject: [PATCH 3/4] Remove unused code --- director/director.go | 8 -------- server/honeytrap.go | 22 +++++++--------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/director/director.go b/director/director.go index 7645a6066..5392cb8c1 100644 --- a/director/director.go +++ b/director/director.go @@ -54,14 +54,6 @@ func Get(key string) (func(...func(Director) error) (Director, error), bool) { return nil, false } -func GetAvailableDirectorNames() []string { - var out []string - for key := range directors { - out = append(out, key) - } - return out -} - // Director defines an interface which exposes an interface to allow structures that // implement this interface allow us to control containers which they provide. type Director interface { diff --git a/server/honeytrap.go b/server/honeytrap.go index 7985531c8..569149470 100644 --- a/server/honeytrap.go +++ b/server/honeytrap.go @@ -408,7 +408,6 @@ func (hc *Honeytrap) Run(ctx context.Context) { // initialize directors directors := map[string]director.Director{} - availableDirectorNames := director.GetAvailableDirectorNames() for key, s := range hc.config.Directors { x := struct { @@ -427,7 +426,7 @@ func (hc *Honeytrap) Run(ctx context.Context) { } if directorFunc, ok := director.Get(x.Type); !ok { - log.Error("Director type=%s not supported on platform (director=%s). Available directors: %s", x.Type, key, strings.Join(availableDirectorNames, ", ")) + log.Error("Director type=%s not supported on platform (director=%s) (use --list-directors to see available directors)", x.Type, key) } else if d, err := directorFunc( director.WithChannel(hc.bus), director.WithConfig(s), @@ -452,13 +451,8 @@ func (hc *Honeytrap) Run(ctx context.Context) { fmt.Println(color.RedString("Listener not set")) } - var enabledDirectorNames []string - for key := range directors { - enabledDirectorNames = append(enabledDirectorNames, key) - } - - serviceList := make(map[string]*ServiceMap) isServiceUsed := make(map[string]bool) // Used to check that every service is used by a port + serviceList := make(map[string]*ServiceMap) // same for proxies for key, s := range hc.config.Services { x := struct { @@ -487,13 +481,13 @@ func (hc *Honeytrap) Run(ctx context.Context) { } else if d, ok := directors[x.Director]; ok { options = append(options, services.WithDirector(d)) } else { - log.Error(color.RedString("Could not find director=%s for service=%s. Enabled directors: %s", x.Director, key, strings.Join(enabledDirectorNames, ", "))) + log.Error("Could not find director=%s for service=%s (use --list-directors to see available directors)", x.Director, key) continue } fn, ok := services.Get(x.Type) if !ok { - log.Error(color.RedString("Could not find type %s for service %s", x.Type, key)) + log.Error("Could not find type %s for service %s", x.Type, key) continue } @@ -509,8 +503,7 @@ func (hc *Honeytrap) Run(ctx context.Context) { listenerFunc, ok := listener.Get(x.Type) if !ok { - fmt.Println(color.RedString("Listener %s not support on platform", x.Type)) - return + log.Fatalf("Listener %s not support on platform", x.Type) } l, err := listenerFunc( @@ -614,8 +607,7 @@ func (hc *Honeytrap) Run(ctx context.Context) { } if err := l.Start(ctx); err != nil { - fmt.Println(color.RedString("Error starting listener: %s", err.Error())) - return + log.Fatalf("Error starting listener: %s", err.Error()) } incoming := make(chan net.Conn) @@ -717,7 +709,7 @@ func (hc *Honeytrap) handle(conn net.Conn) { ctx := context.Background() if err := sm.Service.Handle(ctx, newConn); err != nil { - log.Errorf(color.RedString("Error handling service: %s: %s", sm.Name, err.Error())) + log.Errorf("Error handling service: %s: %s", sm.Name, err.Error()) } } From 84c3e195e68c5fc2c0deb7c56477f7ed62a578a4 Mon Sep 17 00:00:00 2001 From: CapacitorSet Date: Mon, 9 Jul 2018 13:25:40 +0200 Subject: [PATCH 4/4] Remove unused code --- pushers/eventbus/eventbus.go | 3 +-- server/honeytrap.go | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pushers/eventbus/eventbus.go b/pushers/eventbus/eventbus.go index 81d26ab8a..332dec91d 100644 --- a/pushers/eventbus/eventbus.go +++ b/pushers/eventbus/eventbus.go @@ -47,9 +47,8 @@ func New() *EventBus { } // Subscribe adds the giving channel to the list of subscribers for the giving bus. -func (eb *EventBus) Subscribe(channel pushers.Channel) error { +func (eb *EventBus) Subscribe(channel pushers.Channel) { eb.subscribers = append(eb.subscribers, channel) - return nil } // Send deliverers the slice of messages to all subscribers. diff --git a/server/honeytrap.go b/server/honeytrap.go index 569149470..3ab0fcd82 100644 --- a/server/honeytrap.go +++ b/server/honeytrap.go @@ -394,9 +394,7 @@ func (hc *Honeytrap) Run(ctx context.Context) { channel = pushers.FilterChannel(channel, pushers.RegexFilterFunc("service", x.Services)) } - if err := hc.bus.Subscribe(channel); err != nil { - log.Error("Could not add channel %s to bus: %s", name, err.Error()) - } + hc.bus.Subscribe(channel) } }