File tree 4 files changed +64
-3
lines changed
4 files changed +64
-3
lines changed Original file line number Diff line number Diff line change
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 ("\t BlockSameIP [01]" )
34
+ fmt .Println ("\t When BlockSameIP set to 1, will only accept one client from every unique IP, by default" )
35
+ fmt .Println ("\t When 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 ("\t If a client is online, decline other requests from the same IP" )
41
+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
11
11
func (dispatcher Dispatcher ) Jump (args []string ) {
12
12
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 " )
14
14
dispatcher .JumpHelp ([]string {})
15
15
return
16
16
}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ type Context struct {
4
4
Servers map [string ](* TCPServer )
5
5
Current * TCPClient
6
6
CommandPrompt string
7
+ BlockSameIP int
7
8
}
8
9
9
10
var Ctx * Context
@@ -14,6 +15,7 @@ func CreateContext() {
14
15
Servers : make (map [string ](* TCPServer )),
15
16
Current : nil ,
16
17
CommandPrompt : ">> " ,
18
+ BlockSameIP : 1 ,
17
19
}
18
20
}
19
21
}
Original file line number Diff line number Diff line change @@ -80,7 +80,6 @@ func (s *TCPServer) Run() {
80
80
continue
81
81
}
82
82
client := CreateTCPClient (conn )
83
- log .Info ("New client %s Connected" , client .Desc ())
84
83
// Reverse shell as a service
85
84
buffer := make ([]byte , 4 )
86
85
client .Conn .SetReadDeadline (time .Now ().Add (time .Second * 3 ))
@@ -141,7 +140,26 @@ func (s *TCPServer) Run() {
141
140
Ctx .DeleteTCPClient (client )
142
141
log .Info ("RaaS: %s" , command )
143
142
} 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
+ }
145
163
}
146
164
}
147
165
}
You can’t perform that action at this time.
0 commit comments