-
Notifications
You must be signed in to change notification settings - Fork 9
/
appfinger.go
78 lines (70 loc) · 2.04 KB
/
appfinger.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
package appfinger
import (
"errors"
"github.com/lcvvvv/appfinger/gorpc"
"github.com/lcvvvv/appfinger/httpfinger"
"net/http"
"net/url"
"regexp"
"strings"
)
var supportProtocols = []string{
"http",
"https",
"rpc",
}
var supportProtocolRegx = regexp.MustCompile("^" + strings.Join(supportProtocols, "|") + "$")
func Search(URL *url.URL, banner *Banner) *FingerPrint {
var products, hostnames []string
switch URL.Scheme {
case "http":
products = search(convHttpBanner(URL, banner))
return &FingerPrint{products, "", "", ""}
case "https":
products := search(convHttpBanner(URL, banner))
return &FingerPrint{products, "", "", ""}
case "rpc":
hostnames, _ = gorpc.GetHostname(URL.Hostname())
return &FingerPrint{emptyProductName, strings.Join(hostnames, ";"), "", ""}
}
return nil
}
func SupportCheck(protocol string) bool {
return supportProtocolRegx.MatchString(protocol)
}
func GetBannerWithResponse(URL *url.URL, response string, req *http.Request, cli *http.Client) (*Banner, error) {
switch URL.Scheme {
case "http":
httpBanner, err := httpfinger.GetBannerWithResponse(URL, response, req, cli)
return convBanner(httpBanner), err
case "https":
httpBanner, err := httpfinger.GetBannerWithResponse(URL, response, req, cli)
return convBanner(httpBanner), err
default:
return convBannerWithRaw(response), nil
}
}
func GetBannerWithURL(URL *url.URL, req *http.Request, cli *http.Client) (*Banner, error) {
switch URL.Scheme {
case "http":
httpBanner, err := httpfinger.GetBannerWithURL(URL, req, cli)
return convBanner(httpBanner), err
case "https":
httpBanner, err := httpfinger.GetBannerWithURL(URL, req, cli)
return convBanner(httpBanner), err
}
return nil, errors.New("unsupported protocol")
}
func convHttpBanner(URL *url.URL, banner *Banner) *httpfinger.Banner {
return &httpfinger.Banner{
Protocol: URL.Scheme,
Port: URL.Port(),
Header: banner.Header,
Body: banner.Body,
Response: banner.Response,
Cert: banner.Cert,
Title: banner.Title,
Hash: banner.Hash,
Icon: banner.Icon,
}
}