-
Notifications
You must be signed in to change notification settings - Fork 4
/
Handlers.go
135 lines (120 loc) · 3.02 KB
/
Handlers.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 (
"crypto/rand"
"encoding/json"
"fmt"
"html/template"
"io"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
"github.com/replit/database-go"
"github.com/xojoc/useragent"
)
var tmpl = template.Must(template.ParseFiles("Templates/index.html"))
func Index(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, nil)
}
func NewToken(w http.ResponseWriter, r *http.Request) {
bytes := make([]byte, 20)
rand.Read(bytes)
database.Set(fmt.Sprintf("%X", bytes), "")
w.Write([]byte(fmt.Sprintf(`{"token":"%X"}`, bytes)))
}
func GetInfo(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
if len(q["token"]) == 0 {
w.Write([]byte(`{"Ok":false, "Error":"Token Does Not Exist"}`))
return
} else if q["token"][0] == "" || len(q["token"][0]) != 40 {
w.Write([]byte(`{"Ok":false, "Error":"Token Does Not Exist"}`))
return
}
info, err := database.Get(q["token"][0])
if err != nil {
w.Write([]byte(`{"Ok":false, "Error":"Token Does Not Exist"}`))
return
} else if info == "" {
w.Write([]byte(`{"Ok": false, "Error": "The victim has not opened the email yet."}`))
return
}
w.Write([]byte(info))
}
func Image(w http.ResponseWriter, r *http.Request) {
t := time.Now().UTC().UnixMilli()
if !strings.Contains(r.Header["User-Agent"][0], "GoogleImageProxy") {
q := r.URL.Query()
if len(q["token"]) == 0 {
return
} else if q["token"][0] == "" || len(q["token"][0]) != 40 {
return
}
key := q["token"][0]
v, err := database.Get(q["token"][0])
if err != nil {
return
}
var out Info
json.Unmarshal([]byte(v), &out)
if !out.Opened || v == "" {
info := GenerateInfoStruct(r, t)
j, _ := json.Marshal(info)
database.Set(key, string(j))
}
}
file, _ := os.ReadFile("image.png")
w.Header().Set("Content-Type", "image/png")
w.Write(file)
}
func getIP(r *http.Request) string {
ip := r.Header.Get("X-REAL-IP")
netIP := net.ParseIP(ip)
if netIP != nil {
return ip
}
ips := r.Header.Get("X-FORWARDED-FOR")
splitIps := strings.Split(ips, ",")
for _, ip := range splitIps {
netIP := net.ParseIP(ip)
if netIP != nil {
return ip
}
}
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
return ""
}
netIP = net.ParseIP(ip)
if netIP != nil {
return ip
}
return ""
}
func GenerateInfoStruct(r *http.Request, unixTime int64) (infoPack Info) {
var ipAddr IP
ua := r.Header.Get("User-Agent")
parsedua := useragent.Parse(ua)
ip := getIP(r)
resp, _ := http.Get(fmt.Sprintf("http://ip-api.com/json/%s", url.QueryEscape(ip)))
b, _ := io.ReadAll(resp.Body)
defer resp.Body.Close()
json.Unmarshal(b, &ipAddr)
geoLocation := fmt.Sprintf("\nCountry: %s\nRegion: %s\nCity: %s\nZip: %s\nISP: %s",
ipAddr.Country,
ipAddr.RegionName,
ipAddr.City,
ipAddr.Zip,
ipAddr.ISP,
)
device := fmt.Sprintf("\nName: %s\nOS: %s\nMobile: %v\nTablet: %v",
parsedua.Name,
parsedua.OS,
parsedua.Mobile,
parsedua.Tablet,
)
infoPack = Info{IP: ipAddr.Query, UserAgent: ua, Device: device, GeoLocation: geoLocation, Time: unixTime, Opened: true}
return infoPack
}