Skip to content

Commit adb2ac5

Browse files
authored
Merge pull request #9 from zxyxx/master
Add BlockSameIP
2 parents c21f2cc + c416107 commit adb2ac5

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

lib/cli/dispatcher/block_same_ip.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package dispatcher
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
7+
"github.com/WangYihang/Platypus/lib/context"
8+
"github.com/WangYihang/Platypus/lib/util/log"
9+
)
10+
11+
func (dispatcher Dispatcher) BlockSameIP(args []string) {
12+
if len(args) != 1 {
13+
log.Error("Arguments error, use `Help BlockSameIP` to get more information")
14+
dispatcher.BlockSameIPHelp([]string{})
15+
return
16+
}
17+
parseInt,err := strconv.Atoi(args[0])
18+
if err != nil {
19+
log.Error("Something error")
20+
return
21+
}
22+
if parseInt == 1 {
23+
log.Success("BlockSameIP set to 1, will only accept one client from every unique IP")
24+
context.Ctx.BlockSameIP = 1
25+
} else if parseInt == 0 {
26+
log.Success("BlockSameIP set to 0, every IP can have many clients")
27+
context.Ctx.BlockSameIP = 0
28+
}
29+
}
30+
31+
func (dispatcher Dispatcher) BlockSameIPHelp(args []string) {
32+
fmt.Println("Usage of BlockSameIP")
33+
fmt.Println("\tBlockSameIP [01]")
34+
fmt.Println("\tWhen BlockSameIP set to 1, will only accept one client from every unique IP, by default")
35+
fmt.Println("\tWhen BlockSameIP set to 0, every IP can have many clients")
36+
}
37+
38+
func (dispatcher Dispatcher) BlockSameIPDesc(args []string) {
39+
fmt.Println("BlockSameIP")
40+
fmt.Println("\tIf a client is online, decline other requests from the same IP")
41+
}

lib/cli/dispatcher/jump.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func (dispatcher Dispatcher) Jump(args []string) {
1212
if len(args) != 1 {
13-
log.Error("Arguments error, use `Help Jump` to get more Jumprmation")
13+
log.Error("Arguments error, use `Help Jump` to get more information")
1414
dispatcher.JumpHelp([]string{})
1515
return
1616
}

lib/context/context.go

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type Context struct {
44
Servers map[string](*TCPServer)
55
Current *TCPClient
66
CommandPrompt string
7+
BlockSameIP int
78
}
89

910
var Ctx *Context
@@ -14,6 +15,7 @@ func CreateContext() {
1415
Servers: make(map[string](*TCPServer)),
1516
Current: nil,
1617
CommandPrompt: ">> ",
18+
BlockSameIP: 1,
1719
}
1820
}
1921
}

lib/context/server.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func (s *TCPServer) Run() {
8080
continue
8181
}
8282
client := CreateTCPClient(conn)
83-
log.Info("New client %s Connected", client.Desc())
8483
// Reverse shell as a service
8584
buffer := make([]byte, 4)
8685
client.Conn.SetReadDeadline(time.Now().Add(time.Second * 3))
@@ -141,7 +140,26 @@ func (s *TCPServer) Run() {
141140
Ctx.DeleteTCPClient(client)
142141
log.Info("RaaS: %s", command)
143142
} else {
144-
s.AddTCPClient(client)
143+
switch Ctx.BlockSameIP {
144+
case 1:
145+
newclientIP := client.Conn.RemoteAddr().String()
146+
newclientIP = strings.Split(newclientIP, ":")[0]
147+
clientExist := 0
148+
for _, client := range s.Clients {
149+
clientIP := client.Conn.RemoteAddr().String()
150+
clientIP = strings.Split(clientIP, ":")[0]
151+
if newclientIP == clientIP {
152+
clientExist = 1
153+
}
154+
}
155+
if clientExist == 0 {
156+
log.Info("New client %s Connected", client.Desc())
157+
s.AddTCPClient(client)
158+
}
159+
case 0:
160+
log.Info("New client %s Connected", client.Desc())
161+
s.AddTCPClient(client)
162+
}
145163
}
146164
}
147165
}

0 commit comments

Comments
 (0)