Skip to content

Commit a09762a

Browse files
committed
Gumper: 1
Slack: 0
1 parent d09bb61 commit a09762a

4 files changed

Lines changed: 59 additions & 37 deletions

File tree

networking/bubba/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ func main() {
5353
log.Fatalln(err)
5454
}
5555

56+
go handleMsg()
57+
5658
log.Fatalln(router.Run(":80"))
5759
}

networking/bubba/middleware.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ func handleWebSocket(conn *websocket.Conn) {
6262
}
6363

6464
agentChan <- jsonData
65-
sendToAgents(msg)
66-
6765
}
6866
}
6967

@@ -124,13 +122,7 @@ func handleMsg() {
124122
log.Println(err)
125123
return
126124
}
127-
ip := msg["IP"].(string)
128-
for client := range agentClients {
129-
clientIP := strings.Split(client.NetConn().RemoteAddr().String(), ":")[0]
130-
if ip == clientIP {
131-
client.WriteMessage(websocket.TextMessage, jsonData)
132-
}
133-
}
125+
sendToAgents(jsonData)
134126
case msg := <-connChan:
135127
if msg["OpCode"].(float64) == 5 {
136128
AddConnection(msg)

networking/bubba/templates/pages/agents.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="ModifyList(11)">Remove from Whitelist</button>
99
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="ModifyList(1)">Add to Blacklist</button>
1010
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="ModifyList(2)">Remove from Blacklist</button>
11+
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="ModifyMin(5)">Set Min Connection Count</button>
1112
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="SendCmd(13)">Enable Blacklist Mode</button>
1213
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="SendCmd(14)">Enable Whitelist Mode</button>
1314
<button type="button" class="btn btn-primary mx-1 mb-1" style="padding: 0.5em 1em; height: 10vh; font-size: 1.75vh" onclick="SendCmd(15)">Clear Whitelist</button>
@@ -79,6 +80,19 @@
7980
}));
8081
}
8182

83+
function ModifyMin() {
84+
var min = document.getElementById("cidr").value;
85+
if (min === "") {
86+
alert("Please enter a CIDR");
87+
return;
88+
}
89+
min = parseInt(min);
90+
socket.send(JSON.stringify({
91+
"OpCode": 5,
92+
"Count": min
93+
}));
94+
}
95+
8296
function SendCmd(opcode) {
8397
socket.send(JSON.stringify({
8498
"OpCode": opcode,

networking/gumpa/main.go

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,26 @@ import (
2525
)
2626

2727
var (
28+
ifaces []pcap.Interface
29+
2830
blacklist []*net.IPNet
2931
blacklistMode = true
3032
whitelist []*net.IPNet
3133
whitelistMode = false
3234

3335
SERVER_IP *string
3436
hostname, _ = os.Hostname()
37+
hostHash string
3538

3639
serverChan = make(chan []byte)
3740

3841
connMap = make(map[string]int)
39-
minConnCount = 3
42+
minConnCount = 1
4043

4144
rwLock sync.RWMutex
4245
mu sync.Mutex
46+
47+
quit = make(chan bool)
4348
)
4449

4550
func main() {
@@ -68,37 +73,17 @@ func main() {
6873

6974
log.Println("Starting up...")
7075

71-
ifaces, err := pcap.FindAllDevs()
76+
ifaces, err = pcap.FindAllDevs()
7277
if err != nil {
7378
log.Println(err)
7479
}
75-
7680
blacklist = appendFilter("224.0.0.0/3", blacklist)
7781

78-
hostHash := fmt.Sprint(hash(hostname))
82+
hostHash = fmt.Sprint(hash(hostname))
7983
RegisterAgent(hostHash, key)
8084

81-
conn := initializeWebSocket(*SERVER_IP, "/ws/agent")
82-
defer conn.Close()
83-
84-
go checkin(hostHash)
85-
go readFilter(conn)
86-
87-
for _, device := range ifaces {
88-
log.Printf("Interface Name: %s", device.Name)
89-
go capturePackets(device.Name)
90-
}
91-
92-
for {
93-
select {
94-
case t := <-serverChan:
95-
err = conn.WriteMessage(websocket.TextMessage, t)
96-
if err != nil {
97-
log.Println(err)
98-
return
99-
}
100-
}
101-
}
85+
go initializeWebSocket(*SERVER_IP, "/ws/agent")
86+
select {}
10287
}
10388

10489
func capturePackets(iface string) {
@@ -265,14 +250,38 @@ func isInterfaceUp(interfaceName string) bool {
265250
return iface.Flags&net.FlagUp != 0
266251
}
267252

268-
func initializeWebSocket(server, path string) *websocket.Conn {
253+
func initializeWebSocket(server, path string) {
269254
log.Println("Initializing WebSocket...")
270255
url := url.URL{Scheme: "ws", Host: server, Path: path}
271256
conn, _, err := websocket.DefaultDialer.Dial(url.String(), nil)
272257
if err != nil {
273-
log.Println(err)
258+
fmt.Println(err)
259+
time.Sleep(5 * time.Second)
260+
go initializeWebSocket(server, path)
261+
return
262+
}
263+
264+
go checkin(hostHash)
265+
go readFilter(conn)
266+
267+
for _, device := range ifaces {
268+
log.Printf("Interface Name: %s", device.Name)
269+
go capturePackets(device.Name)
270+
}
271+
272+
for {
273+
select {
274+
case t := <-serverChan:
275+
fmt.Println(string(t))
276+
err = conn.WriteMessage(websocket.TextMessage, t)
277+
if err != nil {
278+
log.Println(err)
279+
return
280+
}
281+
case <-quit:
282+
return
283+
}
274284
}
275-
return conn
276285
}
277286

278287
func RegisterAgent(hash, key string) {
@@ -311,6 +320,11 @@ func readFilter(conn *websocket.Conn) {
311320
_, msg, err := conn.ReadMessage()
312321
if err != nil {
313322
fmt.Println(err)
323+
quit <- true
324+
conn.Close()
325+
time.Sleep(5 * time.Second)
326+
go initializeWebSocket(*SERVER_IP, "/ws/agent")
327+
return
314328
} else {
315329
filter := make(map[string]interface{})
316330
err := json.Unmarshal(msg, &filter)

0 commit comments

Comments
 (0)