mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
new: http parser
This commit is contained in:
parent
27b1f48584
commit
c98191c43e
4 changed files with 56 additions and 0 deletions
|
@ -5,5 +5,7 @@ events.stream on
|
|||
|
||||
set net.sniffer.verbose false
|
||||
set net.sniffer.local true
|
||||
# http://biot.com/capstats/bpf.html
|
||||
# set net.sniffer.filter not arp and not udp port 53
|
||||
|
||||
net.sniffer on
|
||||
|
|
42
modules/net_sniff_http.go
Normal file
42
modules/net_sniff_http.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
"regexp"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
var httpRe = regexp.MustCompile("(?s).*(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) (.+) HTTP/\\d\\.\\d.+Host: ([^\\s]+)")
|
||||
|
||||
func httpParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
|
||||
data := tcp.Payload
|
||||
dataSize := len(data)
|
||||
|
||||
if dataSize < 20 {
|
||||
return false
|
||||
}
|
||||
|
||||
m := httpRe.FindSubmatch(data)
|
||||
if len(m) != 4 {
|
||||
return false
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("http://%s", string(m[3]))
|
||||
if tcp.DstPort != 80 {
|
||||
url += fmt.Sprintf(":%s", vPort(tcp.DstPort))
|
||||
}
|
||||
url += fmt.Sprintf("%s", string(m[2]))
|
||||
|
||||
fmt.Printf("[%s] %s %s %s %s\n",
|
||||
vTime(pkt.Metadata().Timestamp),
|
||||
core.W(core.BG_RED+core.FG_BLACK, "http"),
|
||||
vIP(ip.SrcIP),
|
||||
core.W(core.BG_LBLUE+core.FG_BLACK, vURL(string(m[1]))),
|
||||
core.Yellow(url))
|
||||
|
||||
return true
|
||||
}
|
|
@ -15,6 +15,8 @@ func tcpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
|
|||
|
||||
if sniParser(ip, pkt, tcp) {
|
||||
return
|
||||
} else if httpParser(ip, pkt, tcp) {
|
||||
return
|
||||
}
|
||||
|
||||
if verbose == true {
|
||||
|
|
|
@ -48,3 +48,13 @@ func vPort(p interface{}) string {
|
|||
|
||||
return sp
|
||||
}
|
||||
|
||||
var maxUrlSize = 40
|
||||
|
||||
func vURL(u string) string {
|
||||
ul := len(u)
|
||||
if ul > maxUrlSize {
|
||||
u = fmt.Sprintf("%s...", u[0:maxUrlSize-3])
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue