-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.07 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
package main
import (
"log"
"flag"
"fmt"
"net/http"
"honey-collector/honey"
)
var (
honeyClient honey.HoneyClient
ports string
responseText string
)
func ReqHandler(resp http.ResponseWriter, req *http.Request) {
lr := honey.NewLoggedRequest(*req)
log.Println(lr.ToJson())
honeyClient.Publish([]byte(lr.ToJson()))
fmt.Fprint(resp, responseText)
}
func startListener(startErrorChannel chan<- error, port string) {
addr := fmt.Sprintf(":%s", port)
fmt.Printf("Starting honey pot on port: %s\n", port)
err := http.ListenAndServe(addr, nil)
if err != nil {
startErrorChannel <- err
}
}
func main() {
flag.StringVar(&ports, "ports", "", "Wrap your port list in double quotes")
flag.StringVar(&responseText, "response", "\\( ^ o ^)/", "String to respond to web requests with")
flag.Parse()
preppedPorts := honey.PreparePorts(ports)
honeyClient = honey.NewHoneyClientFromEnv()
http.HandleFunc("/", ReqHandler)
startErrorChannel := make(chan error)
for _, p := range preppedPorts {
go startListener(startErrorChannel, p)
}
panic(<-startErrorChannel)
}