-
Notifications
You must be signed in to change notification settings - Fork 10
/
url_publisher.go
57 lines (48 loc) · 1.11 KB
/
url_publisher.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
package agents
import (
"crypto/tls"
"strconv"
"strings"
"fmt"
"github.com/shelld3v/aquatone/core"
)
type URLPublisher struct {
session *core.Session
}
func NewURLPublisher() *URLPublisher {
return &URLPublisher{}
}
func (d *URLPublisher) ID() string {
return "agent:url_publisher"
}
func (a *URLPublisher) Register(s *core.Session) error {
s.EventBus.SubscribeAsync(core.TCPPort, a.OnTCPPort, false)
a.session = s
return nil
}
func (a *URLPublisher) OnTCPPort(port int, host string) {
a.session.Out.Debug("[%s] Received new open port on %s: %d\n", a.ID(), host, port)
var url string
if a.isTLS(port, host) {
url = HostAndPortToURL(host, port, "https")
} else {
url = HostAndPortToURL(host, port, "http")
}
a.session.EventBus.Publish(core.URL, url)
}
func (a *URLPublisher) isTLS(port int, host string) bool {
if strings.HasSuffix(strconv.Itoa(port), "443") {
return true
} else if port == 80 {
return false
}
conf := &tls.Config{
InsecureSkipVerify: true,
}
conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", host, port), conf)
if err != nil {
return false
}
conn.Close()
return true
}