82 lines
1.5 KiB
Go
82 lines
1.5 KiB
Go
|
package http
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"git.loafle.net/overflow/overflow_discovery/service/matcher"
|
||
|
)
|
||
|
|
||
|
type HTTPMatcher struct {
|
||
|
matcher.Matchers
|
||
|
}
|
||
|
|
||
|
func (h *HTTPMatcher) ServiceName() string {
|
||
|
return "HTTP"
|
||
|
}
|
||
|
|
||
|
func (h *HTTPMatcher) IsPrePacket() bool {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func (h *HTTPMatcher) HasResponse(index int) bool {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func (h *HTTPMatcher) IsError(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func (h *HTTPMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.Packet) bool {
|
||
|
result := false
|
||
|
|
||
|
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
str := string(packet.Buffer)
|
||
|
//fmt.Println(str)
|
||
|
elems := strings.Split(str, "\r\n")
|
||
|
|
||
|
if len(elems) <= 0 {
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
protocol := (elems[0])[:8]
|
||
|
|
||
|
httpv0 := strings.Compare(protocol, "HTTP/1.0")
|
||
|
httpv1 := strings.Compare(protocol, "HTTP/1.1")
|
||
|
httpv2 := strings.Compare(protocol, "HTTP/1.2")
|
||
|
|
||
|
if 0 == httpv0 || 0 == httpv1 || 0 == httpv2 {
|
||
|
result = true
|
||
|
}
|
||
|
|
||
|
serverName := "Unknown Server"
|
||
|
|
||
|
for _, valueStr := range elems {
|
||
|
tempElems := strings.Split(valueStr, ":")
|
||
|
|
||
|
if 0 == strings.Compare(tempElems[0], "Server") {
|
||
|
serverName = tempElems[1]
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
strings.Compare(serverName, "Unknown")
|
||
|
//fmt.Println("HTTP Server Name: ", serverName)
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
func NewMatcher() matcher.Matcher {
|
||
|
|
||
|
m := &HTTPMatcher{}
|
||
|
reqStr := "GET / HTTP/1.1\r\n\r\n"
|
||
|
byte := make([]byte, len(reqStr))
|
||
|
copy(byte[:], reqStr)
|
||
|
|
||
|
m.AddPacket(matcher.NewPacket(byte, len(reqStr)))
|
||
|
|
||
|
return m
|
||
|
}
|