-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
135 lines (109 loc) · 3.15 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
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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"strings"
"time"
)
var storageFolder string = ""
var addr string = ":8080"
var form string = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
</head>
<body>
<form enctype="multipart/form-data" action="/p" method="post">
<input type="file" name="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>`
func exfilGet(w http.ResponseWriter, req *http.Request) {
// We could also check for req.Header.Get("X-REAL-IP") or "X-FORWARDED-FOR" (better with proxies)
host := strings.Split(req.RemoteAddr, ":")
var filename string = fmt.Sprintf("%s_%s.txt", host[0], time.Now().Format("2006-01-02_15-04-05"))
var filePath = path.Join(storageFolder, filename)
out, err := os.Create(filePath)
if err != nil {
fmt.Println(err)
} else {
req.Write(out)
fmt.Printf("[*] Request Stored (%s)\n", filename)
}
}
func uploadForm(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, form)
}
func uploadFile(w http.ResponseWriter, r *http.Request) {
file, handler, err := r.FormFile("file")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fileBytes, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
}
ioutil.WriteFile(path.Join(storageFolder, handler.Filename), fileBytes, 0644)
fmt.Fprintf(w, "Done\n")
fmt.Printf("[*] File Uploaded (%s)\n", handler.Filename)
}
func setupRoutes() {
http.HandleFunc("/", uploadForm)
http.HandleFunc("/p", uploadFile)
http.HandleFunc("/g", exfilGet)
// Directory Listing
http.Handle("/l/", http.StripPrefix("/l", http.FileServer(http.Dir(storageFolder))))
//HTTP or HTTPs
if _, err := os.Stat("HTTPUploadExfil.csr"); err == nil {
http.ListenAndServeTLS(addr, "HTTPUploadExfil.csr", "HTTPUploadExfil.key", nil)
} else {
http.ListenAndServe(addr, nil)
}
}
func ascii_art() {
var ascii string = `
_____ _____ _____ _____ _____ _ _ _____ ___ _ _
| | |_ _|_ _| _ | | |___| |___ ___ _| | __|_ _| _|_| |
| | | | | | | __| | | . | | . | .'| . | __|_'_| _| | |
|__|__| |_| |_| |__| |_____| _|_|___|__,|___|_____|_,_|_| |_|_|
|_|
`
fmt.Print(ascii)
fmt.Printf("\n")
fmt.Println("Version: 2021-11-13")
fmt.Println("Usage: ./httpuploadexfil :8080 /home/kali/exfil")
fmt.Printf("\n")
}
func main() {
ascii_art()
if len(os.Args) <= 2 {
storageFolder, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(0)
}
fmt.Println("[+] Server Running")
fmt.Printf("[+] Default Settings: Addr '%s'; Folder '%s'\n", addr, storageFolder)
} else {
addr = os.Args[1]
storageFolder = os.Args[2]
if _, err := os.Stat(storageFolder); os.IsNotExist(err) {
err := os.Mkdir(storageFolder, 0755)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
}
fmt.Println("[+] Server Running")
fmt.Printf("[+] Settings: Addr '%s'; Folder '%s'\n", addr, storageFolder)
}
setupRoutes()
}