This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (68 loc) · 1.77 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
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"regexp"
"strconv"
)
func main() {
fmt.Println("Starting endpoint...")
http.HandleFunc("/", endpoint)
err := http.ListenAndServe(":6969", nil)
if err != nil {
fmt.Println(err.Error())
}
}
func validateString(input string) bool {
validationString := `^[a-zA-Z0-9-_.]+$`
inputValidation := regexp.MustCompile(validationString)
return inputValidation.MatchString(input)
}
func sendFile(platform string, writer http.ResponseWriter) {
file := "aeacus-" + platform + ".zip"
openFile, err := os.Open(file)
defer openFile.Close()
if err != nil {
http.Error(writer, "File "+file+" not found", 404)
return
}
fileHeader := make([]byte, 512)
openFile.Read(fileHeader)
contentType := http.DetectContentType(fileHeader)
fileStat, _ := openFile.Stat()
fileSize := strconv.FormatInt(fileStat.Size(), 10)
writer.Header().Set("Content-Disposition", "attachment; filename="+file)
writer.Header().Set("Content-Type", contentType)
writer.Header().Set("Content-Length", fileSize)
openFile.Seek(0, 0)
io.Copy(writer, openFile)
}
func endpoint(writer http.ResponseWriter, request *http.Request) {
platform := request.URL.Query().Get("os")
password := request.URL.Query().Get("pass")
pass, err := ioutil.ReadFile("pass.txt")
if err != nil {
http.Error(writer, "Error: server could not read pass.txt.", 400)
return
}
if password != string(pass) {
http.Error(writer, "Error: Incorrect password.", 400)
return
}
if !validateString(platform) {
http.Error(writer, "Error: DTA attempted. This incident will be reported.", 400)
return
}
switch platform {
case "win32":
sendFile("win32", writer)
case "linux":
sendFile("linux", writer)
default:
http.Error(writer, "Error: invalid OS", 400)
}
return
}