-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
105 lines (91 loc) · 2.06 KB
/
main.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
package main
import (
"embed"
"fmt"
"io/fs"
"log"
"net"
"net/http"
"strings"
"time"
)
//go:embed files
var files embed.FS
func getIps() []string {
ips := make([]string, 0)
ifaces, err := net.Interfaces()
if err != nil {
panic(err)
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
panic(err)
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip.To4() != nil && (ip.IsPrivate() || ip.IsLoopback()) {
ips = append(ips, ip.String())
}
}
}
return ips
}
func main() {
exploit, err := fs.Sub(files, "files/exploit")
if err != nil {
log.Println("Couldn't find exploit folder")
panic(err)
}
payloadFilePath := ""
func() {
fs.WalkDir(files, "files/payload", func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() && strings.HasSuffix(d.Name(), ".bin") {
payloadFilePath = path
}
return nil
})
}()
if payloadFilePath == "" {
panic("Couldn't find payload 😱")
}
send := func(ip string) {
log.Printf("Payload: %s\n", payloadFilePath)
log.Printf("Sending payload to : tcp://%s:%s\n", ip, "9020")
address := net.JoinHostPort(ip, "9020")
conn, err := net.DialTimeout("tcp", address, 3*time.Second)
if err != nil {
log.Printf("failed to connect: %s\n", err)
}
defer conn.Close()
conn.SetWriteDeadline(time.Now().Add(time.Second * 10))
fileB, err := fs.ReadFile(files, payloadFilePath)
if err != nil {
log.Printf("failed to open payload: %s, %s\n", payloadFilePath, err)
}
_, err = conn.Write(fileB)
if err != nil {
log.Printf("failed to send file: %s\n", err)
}
}
http.Handle("/", http.FileServerFS(exploit))
http.HandleFunc("/log/", func(w http.ResponseWriter, r *http.Request) {
ip := strings.Split(r.RemoteAddr, ":")[0]
go send(ip)
w.Write([]byte("OK"))
})
port := 1337
for _, u := range getIps() {
log.Printf("Serving at http://%s:%v/\n", u, port)
}
err = http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
if err != nil {
panic(err)
}
}