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

Add BlockSameIP #9

Merged
merged 3 commits into from
Mar 12, 2019
Merged
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
41 changes: 41 additions & 0 deletions lib/cli/dispatcher/block_same_ip.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion lib/cli/dispatcher/jump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions lib/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Context struct {
Servers map[string](*TCPServer)
Current *TCPClient
CommandPrompt string
BlockSameIP int
}

var Ctx *Context
Expand All @@ -14,6 +15,7 @@ func CreateContext() {
Servers: make(map[string](*TCPServer)),
Current: nil,
CommandPrompt: ">> ",
BlockSameIP: 1,
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions lib/context/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -141,7 +140,26 @@ func (s *TCPServer) Run() {
Ctx.DeleteTCPClient(client)
log.Info("RaaS: %s", command)
} else {
s.AddTCPClient(client)
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 {
log.Info("New client %s Connected", client.Desc())
s.AddTCPClient(client)
}
case 0:
log.Info("New client %s Connected", client.Desc())
s.AddTCPClient(client)
}
}
}
}
Expand Down