forked from nicocha30/ligolo-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packets.go
155 lines (134 loc) · 4.16 KB
/
packets.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package protocol
import (
"net"
)
// Envelope is the structure used when Encoding/Decode ligolo packets
type Envelope struct {
Type uint8
Size int32
Payload interface{}
}
const (
MessageInfoRequest = uint8(iota)
MessageInfoReply
MessageConnectRequest
MessageConnectResponse
MessageHostPingRequest
MessageHostPingResponse
MessageListenerRequest // Start a listener
MessageListenerResponse
MessageListenerBindRequest // Bind to a listener
MessageListenerBindResponse
MessageListenerSockRequest // Bind to a socket
MessageListenerSockResponse
MessageListenerCloseRequest
MessageListenerCloseResponse
MessageClose
)
const (
TransportTCP = uint8(iota)
TransportUDP
)
const (
Networkv4 = uint8(iota)
Networkv6
)
// InfoRequestPacket is sent by the proxy to discover the agent information
type InfoRequestPacket struct {
}
// InfoReplyPacket contains the Name of the agent and the network interfaces configuration
type InfoReplyPacket struct {
Name string
Interfaces []NetInterface
}
// ListenerSockRequestPacket is used by the proxy when relaying a listener socket
type ListenerSockRequestPacket struct {
SockID int32
}
// ListenerSockRequestPacket is the response to ListenerSockRequestPacket
type ListenerSockResponsePacket struct {
ErrString string
Err bool
}
// ListenerRequestPacket is used when a new listener socket is created by the proxy.
type ListenerRequestPacket struct {
Network string
Address string
}
// ListenerResponsePacket is used to indicate if the Listener was created, and send the ListenerID.
type ListenerResponsePacket struct {
ListenerID int32
Err bool
ErrString string
}
// ListenerBindPacket is used by the proxy to Bind to a ListenerID, waiting for connections.
type ListenerBindPacket struct {
ListenerID int32
}
// ListenerBindReponse is returned when listener sockets are ready to be relayed from the agent to the proxy.
type ListenerBindReponse struct {
SockID int32
Err bool
ErrString string
}
// ListenerCloseRequestPacket is the packet sent when closing Listeners
type ListenerCloseRequestPacket struct {
ListenerID int32
}
// ListenerCloseResponsePacket is the response to ListenerCloseRequestPacket
type ListenerCloseResponsePacket struct {
ErrString string
Err bool
}
// NetInterface is the structure containing the agent network informations
type NetInterface struct {
Index int // positive integer that starts at one, zero is never used
MTU int // maximum transmission unit
Name string // e.g., "en0", "lo0", "eth0.100"
HardwareAddr net.HardwareAddr // IEEE MAC-48, EUI-48 and EUI-64 form
Flags net.Flags // e.g., FlagUp, FlagLoopback, FlagMulticast
Addresses []string
}
// NewNetInterfaces converts a net.Interface slice to a NetInterface slice that can be transmitted over Gob
func NewNetInterfaces(netif []net.Interface) (out []NetInterface) {
// the net.Interface struct doesn't contains the IP Address, we need a new struct that store IPs
for _, iface := range netif {
var addrs []string
addresses, err := iface.Addrs()
if err != nil {
addresses = []net.Addr{}
}
for _, addrStr := range addresses {
addrs = append(addrs, addrStr.String())
}
out = append(out, NetInterface{
Index: iface.Index,
MTU: iface.MTU,
Name: iface.Name,
HardwareAddr: iface.HardwareAddr,
Flags: iface.Flags,
Addresses: addrs,
})
}
return
}
// ConnectRequestPacket is sent by the proxy to request a new TCP/UDP connection
type ConnectRequestPacket struct {
Net uint8
Transport uint8
Address string
Port uint16
}
// ConnectResponsePacket is the response to the ConnectRequestPacket and indicate if the connection can be established, and if a RST packet need to be sent
type ConnectResponsePacket struct {
Established bool
Reset bool
}
// HostPingRequestPacket is used when a ICMP packet is received on the proxy server. It is used to request a ping request to the agent
type HostPingRequestPacket struct {
Address string
}
// HostPingResponsePacket is sent by the agent to indicate the requested host status
type HostPingResponsePacket struct {
Alive bool
}