From 74a824b3dbf46199f1d24eb9327d18d1d988ee95 Mon Sep 17 00:00:00 2001 From: Alexandre Beaulieu Date: Tue, 16 Apr 2019 15:26:07 -0400 Subject: [PATCH] feat(RDP): RDP-Proxy prototype. --- modules/rdp_proxy/packet_proxy_darwin.go | 39 -------------------- modules/rdp_proxy/packet_proxy_linux.go | 41 ---------------------- modules/rdp_proxy/packet_proxy_windows.go | 39 -------------------- modules/rdp_proxy/rdp_proxy_darwin.go | 39 ++++++++++++++++++++ modules/rdp_proxy/rdp_proxy_linux.go | 41 ++++++++++++++++++++++ modules/rdp_proxy/rdp_proxy_linux_amd64.go | 33 ++++++++--------- modules/rdp_proxy/rdp_proxy_windows.go | 39 ++++++++++++++++++++ 7 files changed, 136 insertions(+), 135 deletions(-) delete mode 100644 modules/rdp_proxy/packet_proxy_darwin.go delete mode 100644 modules/rdp_proxy/packet_proxy_linux.go delete mode 100644 modules/rdp_proxy/packet_proxy_windows.go create mode 100644 modules/rdp_proxy/rdp_proxy_darwin.go create mode 100644 modules/rdp_proxy/rdp_proxy_linux.go create mode 100644 modules/rdp_proxy/rdp_proxy_windows.go diff --git a/modules/rdp_proxy/packet_proxy_darwin.go b/modules/rdp_proxy/packet_proxy_darwin.go deleted file mode 100644 index 0e464be0..00000000 --- a/modules/rdp_proxy/packet_proxy_darwin.go +++ /dev/null @@ -1,39 +0,0 @@ -package packet_proxy - -import ( - "github.com/bettercap/bettercap/session" -) - -type PacketProxy struct { - session.SessionModule -} - -func NewPacketProxy(s *session.Session) *PacketProxy { - return &PacketProxy{ - SessionModule: session.NewSessionModule("packet.proxy", s), - } -} - -func (mod PacketProxy) Name() string { - return "packet.proxy" -} - -func (mod PacketProxy) Description() string { - return "Not supported on this OS" -} - -func (mod PacketProxy) Author() string { - return "Simone Margaritelli " -} - -func (mod *PacketProxy) Configure() (err error) { - return session.ErrNotSupported -} - -func (mod *PacketProxy) Start() error { - return session.ErrNotSupported -} - -func (mod *PacketProxy) Stop() error { - return session.ErrNotSupported -} diff --git a/modules/rdp_proxy/packet_proxy_linux.go b/modules/rdp_proxy/packet_proxy_linux.go deleted file mode 100644 index c1530699..00000000 --- a/modules/rdp_proxy/packet_proxy_linux.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build !amd64 - -package packet_proxy - -import ( - "github.com/bettercap/bettercap/session" -) - -type PacketProxy struct { - session.SessionModule -} - -func NewPacketProxy(s *session.Session) *PacketProxy { - return &PacketProxy{ - SessionModule: session.NewSessionModule("packet.proxy", s), - } -} - -func (mod PacketProxy) Name() string { - return "packet.proxy" -} - -func (mod PacketProxy) Description() string { - return "Not supported on this OS" -} - -func (mod PacketProxy) Author() string { - return "Simone Margaritelli " -} - -func (mod *PacketProxy) Configure() (err error) { - return session.ErrNotSupported -} - -func (mod *PacketProxy) Start() error { - return session.ErrNotSupported -} - -func (mod *PacketProxy) Stop() error { - return session.ErrNotSupported -} diff --git a/modules/rdp_proxy/packet_proxy_windows.go b/modules/rdp_proxy/packet_proxy_windows.go deleted file mode 100644 index 0e464be0..00000000 --- a/modules/rdp_proxy/packet_proxy_windows.go +++ /dev/null @@ -1,39 +0,0 @@ -package packet_proxy - -import ( - "github.com/bettercap/bettercap/session" -) - -type PacketProxy struct { - session.SessionModule -} - -func NewPacketProxy(s *session.Session) *PacketProxy { - return &PacketProxy{ - SessionModule: session.NewSessionModule("packet.proxy", s), - } -} - -func (mod PacketProxy) Name() string { - return "packet.proxy" -} - -func (mod PacketProxy) Description() string { - return "Not supported on this OS" -} - -func (mod PacketProxy) Author() string { - return "Simone Margaritelli " -} - -func (mod *PacketProxy) Configure() (err error) { - return session.ErrNotSupported -} - -func (mod *PacketProxy) Start() error { - return session.ErrNotSupported -} - -func (mod *PacketProxy) Stop() error { - return session.ErrNotSupported -} diff --git a/modules/rdp_proxy/rdp_proxy_darwin.go b/modules/rdp_proxy/rdp_proxy_darwin.go new file mode 100644 index 00000000..899ee605 --- /dev/null +++ b/modules/rdp_proxy/rdp_proxy_darwin.go @@ -0,0 +1,39 @@ +package rdp_proxy + +import ( + "github.com/bettercap/bettercap/session" +) + +type RdpProxy struct { + session.SessionModule +} + +func NewRdpProxy(s *session.Session) *RdpProxy { + return &RdpProxy{ + SessionModule: session.NewSessionModule("rdp.proxy", s), + } +} + +func (mod RdpProxy) Name() string { + return "rdp.proxy" +} + +func (mod RdpProxy) Description() string { + return "Not supported on this OS" +} + +func (mod RdpProxy) Author() string { + return "Alexandre Beaulieu " +} + +func (mod *RdpProxy) Configure() (err error) { + return session.ErrNotSupported +} + +func (mod *RdpProxy) Start() error { + return session.ErrNotSupported +} + +func (mod *RdpProxy) Stop() error { + return session.ErrNotSupported +} diff --git a/modules/rdp_proxy/rdp_proxy_linux.go b/modules/rdp_proxy/rdp_proxy_linux.go new file mode 100644 index 00000000..5ddac0a3 --- /dev/null +++ b/modules/rdp_proxy/rdp_proxy_linux.go @@ -0,0 +1,41 @@ +// +build !amd64 + +package rdp_proxy + +import ( + "github.com/bettercap/bettercap/session" +) + +type RdpProxy struct { + session.SessionModule +} + +func NewRdpProxy(s *session.Session) *RdpProxy { + return &RdpProxy{ + SessionModule: session.NewSessionModule("rdp.proxy", s), + } +} + +func (mod RdpProxy) Name() string { + return "rdp.proxy" +} + +func (mod RdpProxy) Description() string { + return "Not supported on this OS" +} + +func (mod RdpProxy) Author() string { + return "Alexandre Beaulieu " +} + +func (mod *RdpProxy) Configure() (err error) { + return session.ErrNotSupported +} + +func (mod *RdpProxy) Start() error { + return session.ErrNotSupported +} + +func (mod *RdpProxy) Stop() error { + return session.ErrNotSupported +} diff --git a/modules/rdp_proxy/rdp_proxy_linux_amd64.go b/modules/rdp_proxy/rdp_proxy_linux_amd64.go index 7c223912..dd703e8b 100644 --- a/modules/rdp_proxy/rdp_proxy_linux_amd64.go +++ b/modules/rdp_proxy/rdp_proxy_linux_amd64.go @@ -13,9 +13,6 @@ import ( "github.com/chifflier/nfqueue-go/nfqueue" "github.com/google/gopacket" "github.com/google/gopacket/layers" - - // "github.com/evilsocket/islazy/fs" - // "github.com/evilsocket/islazy/tui" ) type RdpProxy struct { @@ -73,16 +70,6 @@ func (mod RdpProxy) Author() string { return "Alexandre Beaulieu " } -func (mod *RdpProxy) destroyQueue() { - if mod.queue == nil { - return - } - - mod.queue.DestroyQueue() - mod.queue.Close() - mod.queue = nil -} - // Adds the firewall rule for proxy instance. func (mod *RdpProxy) doProxy(addr string, port string, enable bool) (err error) { _, err = core.Exec("iptables", []string { "-t", "nat", @@ -225,12 +212,26 @@ func (mod *RdpProxy) Start() error { } func (mod *RdpProxy) Stop() error { - for _, cmd := range mod.active { - cmd.Process.Kill() // FIXME: More graceful way to shutdown? - } + + return mod.SetRunning(false, func() { mod.queue.StopLoop() mod.configureFirewall(false) + for _, cmd := range mod.active { + cmd.Process.Kill() // FIXME: More graceful way to shutdown proxy agents? + } + <-mod.done }) } + +func (mod *RdpProxy) destroyQueue() { + if mod.queue == nil { + return + } + + mod.queue.DestroyQueue() + mod.queue.Close() + mod.queue = nil +} + diff --git a/modules/rdp_proxy/rdp_proxy_windows.go b/modules/rdp_proxy/rdp_proxy_windows.go new file mode 100644 index 00000000..899ee605 --- /dev/null +++ b/modules/rdp_proxy/rdp_proxy_windows.go @@ -0,0 +1,39 @@ +package rdp_proxy + +import ( + "github.com/bettercap/bettercap/session" +) + +type RdpProxy struct { + session.SessionModule +} + +func NewRdpProxy(s *session.Session) *RdpProxy { + return &RdpProxy{ + SessionModule: session.NewSessionModule("rdp.proxy", s), + } +} + +func (mod RdpProxy) Name() string { + return "rdp.proxy" +} + +func (mod RdpProxy) Description() string { + return "Not supported on this OS" +} + +func (mod RdpProxy) Author() string { + return "Alexandre Beaulieu " +} + +func (mod *RdpProxy) Configure() (err error) { + return session.ErrNotSupported +} + +func (mod *RdpProxy) Start() error { + return session.ErrNotSupported +} + +func (mod *RdpProxy) Stop() error { + return session.ErrNotSupported +}