From 007675b2279b109edc670950ae1e478fa06733a2 Mon Sep 17 00:00:00 2001 From: zxyxx <379951650@qq.com> Date: Sun, 10 Mar 2019 21:43:07 +0800 Subject: [PATCH 1/3] handle same ip request --- lib/context/server.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/context/server.go b/lib/context/server.go index 2c242b2e..dec18461 100644 --- a/lib/context/server.go +++ b/lib/context/server.go @@ -141,7 +141,19 @@ func (s *TCPServer) Run() { Ctx.DeleteTCPClient(client) log.Info("RaaS: %s", command) } else { - s.AddTCPClient(client) + newclientIP := client.Conn.RemoteAddr().String() + newclientIP = strings.Split(newclientIP, ":")[0] + clientExist := 0 + for _, client := range s.Clients { + clientIP := client.Conn.RemoteAddr().String() + clientIP = strings.Split(clientIP, ":")[0] + if newclientIP == clientIP { + clientExist = 1 + } + } + if clientExist == 0 { + s.AddTCPClient(client) + } } } } From c81ed355354e1aee08396a0aac042999410384dd Mon Sep 17 00:00:00 2001 From: zxyxx <379951650@qq.com> Date: Tue, 12 Mar 2019 09:41:29 +0800 Subject: [PATCH 2/3] [+] add BlockSameIP option, which can restrict every ip only have one client --- lib/cli/dispatcher/block_same_ip.go | 41 +++++++++++++++++++++++++++++ lib/cli/dispatcher/jump.go | 2 +- lib/context/context.go | 2 ++ lib/context/server.go | 29 ++++++++++++-------- 4 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 lib/cli/dispatcher/block_same_ip.go diff --git a/lib/cli/dispatcher/block_same_ip.go b/lib/cli/dispatcher/block_same_ip.go new file mode 100644 index 00000000..7fbd6677 --- /dev/null +++ b/lib/cli/dispatcher/block_same_ip.go @@ -0,0 +1,41 @@ +package dispatcher + +import ( + "fmt" + "strconv" + + "github.com/WangYihang/Platypus/lib/context" + "github.com/WangYihang/Platypus/lib/util/log" +) + +func (dispatcher Dispatcher) BlockSameIP(args []string) { + if len(args) != 1 { + log.Error("Arguments error, use `Help BlockSameIP` to get more information") + dispatcher.BlockSameIPHelp([]string{}) + return + } + parseInt,err := strconv.Atoi(args[0]) + if err != nil { + log.Error("Something error") + return + } + if parseInt == 1 { + log.Success("BlockSameIP set to 1, will only accept one client from every unique IP") + context.Ctx.BlockSameIP = 1 + } else if parseInt == 0 { + log.Success("BlockSameIP set to 0, every IP can have many clients") + context.Ctx.BlockSameIP = 0 + } +} + +func (dispatcher Dispatcher) BlockSameIPHelp(args []string) { + fmt.Println("Usage of BlockSameIP") + fmt.Println("\tBlockSameIP [01]") + fmt.Println("\tWhen BlockSameIP set to 1, will only accept one client from every unique IP, by default") + fmt.Println("\tWhen BlockSameIP set to 0, every IP can have many clients") +} + +func (dispatcher Dispatcher) BlockSameIPDesc(args []string) { + fmt.Println("BlockSameIP") + fmt.Println("\tIf a client is online, decline other requests from the same IP") +} diff --git a/lib/cli/dispatcher/jump.go b/lib/cli/dispatcher/jump.go index a12ef0f6..3cad04b9 100644 --- a/lib/cli/dispatcher/jump.go +++ b/lib/cli/dispatcher/jump.go @@ -10,7 +10,7 @@ import ( func (dispatcher Dispatcher) Jump(args []string) { if len(args) != 1 { - log.Error("Arguments error, use `Help Jump` to get more Jumprmation") + log.Error("Arguments error, use `Help Jump` to get more information") dispatcher.JumpHelp([]string{}) return } diff --git a/lib/context/context.go b/lib/context/context.go index dd375dff..b37a58b2 100644 --- a/lib/context/context.go +++ b/lib/context/context.go @@ -4,6 +4,7 @@ type Context struct { Servers map[string](*TCPServer) Current *TCPClient CommandPrompt string + BlockSameIP int } var Ctx *Context @@ -14,6 +15,7 @@ func CreateContext() { Servers: make(map[string](*TCPServer)), Current: nil, CommandPrompt: ">> ", + BlockSameIP: 1, } } } diff --git a/lib/context/server.go b/lib/context/server.go index dec18461..fe6d9e57 100644 --- a/lib/context/server.go +++ b/lib/context/server.go @@ -80,7 +80,6 @@ func (s *TCPServer) Run() { continue } client := CreateTCPClient(conn) - log.Info("New client %s Connected", client.Desc()) // Reverse shell as a service buffer := make([]byte, 4) client.Conn.SetReadDeadline(time.Now().Add(time.Second * 3)) @@ -141,17 +140,25 @@ func (s *TCPServer) Run() { Ctx.DeleteTCPClient(client) log.Info("RaaS: %s", command) } else { - newclientIP := client.Conn.RemoteAddr().String() - newclientIP = strings.Split(newclientIP, ":")[0] - clientExist := 0 - for _, client := range s.Clients { - clientIP := client.Conn.RemoteAddr().String() - clientIP = strings.Split(clientIP, ":")[0] - if newclientIP == clientIP { - clientExist = 1 + log.Info("blocksameip: %d", Ctx.BlockSameIP) + switch Ctx.BlockSameIP { + case 1: + newclientIP := client.Conn.RemoteAddr().String() + newclientIP = strings.Split(newclientIP, ":")[0] + clientExist := 0 + for _, client := range s.Clients { + clientIP := client.Conn.RemoteAddr().String() + clientIP = strings.Split(clientIP, ":")[0] + if newclientIP == clientIP { + clientExist = 1 + } } - } - if clientExist == 0 { + if clientExist == 0 { + log.Info("New client %s Connected", client.Desc()) + s.AddTCPClient(client) + } + case 0: + log.Info("New client %s Connected", client.Desc()) s.AddTCPClient(client) } } From c416107aca51fa72ac4d656aad0fd7ec49163972 Mon Sep 17 00:00:00 2001 From: zxyxx <379951650@qq.com> Date: Tue, 12 Mar 2019 09:42:36 +0800 Subject: [PATCH 3/3] [+] add BlockSameIP option, which can restrict every ip only have one client --- lib/context/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/context/server.go b/lib/context/server.go index fe6d9e57..48ae1bfc 100644 --- a/lib/context/server.go +++ b/lib/context/server.go @@ -140,7 +140,6 @@ func (s *TCPServer) Run() { Ctx.DeleteTCPClient(client) log.Info("RaaS: %s", command) } else { - log.Info("blocksameip: %d", Ctx.BlockSameIP) switch Ctx.BlockSameIP { case 1: newclientIP := client.Conn.RemoteAddr().String()