new: centralized pcap capture configuration management

This commit is contained in:
Simone Margaritelli 2021-08-21 14:21:36 +02:00
commit 59dce4ced6
8 changed files with 118 additions and 62 deletions

View file

@ -5,12 +5,13 @@ import (
"net/http"
"net/url"
"regexp"
"strings"
"strconv"
"strings"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/bettercap/bettercap/modules/dns_spoof"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/session"
"github.com/elazarl/goproxy"
"github.com/google/gopacket"
@ -23,9 +24,9 @@ import (
)
var (
httpsLinksParser = regexp.MustCompile(`https://[^"'/]+`)
httpsLinksParser = regexp.MustCompile(`https://[^"'/]+`)
domainCookieParser = regexp.MustCompile(`; ?(?i)domain=.*(;|$)`)
flagsCookieParser = regexp.MustCompile(`; ?(?i)(secure|httponly)`)
flagsCookieParser = regexp.MustCompile(`; ?(?i)(secure|httponly)`)
)
type SSLStripper struct {
@ -83,7 +84,7 @@ func (s *SSLStripper) Enable(enabled bool) {
if enabled && s.handle == nil {
var err error
if s.handle, err = pcap.OpenLive(s.session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil {
if s.handle, err = network.Capture(s.session.Interface.Name()); err != nil {
panic(err)
}
@ -168,7 +169,7 @@ func (s *SSLStripper) fixCookies(res *http.Response) {
origDomain := origParts[len(origParts)-2] + "." + origParts[len(origParts)-1]
strippedDomain := strippedParts[len(strippedParts)-2] + "." + strippedParts[len(strippedParts)-1]
log.Info("[%s] Fixing cookies on %s", tui.Green("sslstrip"),tui.Bold(strippedHost.Hostname))
log.Info("[%s] Fixing cookies on %s", tui.Green("sslstrip"), tui.Bold(strippedHost.Hostname))
cookies := make([]string, len(res.Header["Set-Cookie"]))
// replace domain and strip "secure" flag for each cookie
for i, cookie := range res.Header["Set-Cookie"] {