mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
balls
This commit is contained in:
parent
6e6eb688d7
commit
1cffa33264
7 changed files with 74 additions and 75 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
|
@ -169,32 +168,6 @@ func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scrip
|
|||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
certCache = make(map[string]*tls.Certificate)
|
||||
certLock = &sync.Mutex{}
|
||||
)
|
||||
|
||||
func getCachedCert(domain string, port int) *tls.Certificate {
|
||||
key := fmt.Sprintf("%s:%d", domain, port)
|
||||
|
||||
certLock.Lock()
|
||||
defer certLock.Unlock()
|
||||
|
||||
if cert, found := certCache[key]; found == true {
|
||||
return cert
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setCachedCert(domain string, port int, cert *tls.Certificate) {
|
||||
key := fmt.Sprintf("%s:%d", domain, port)
|
||||
|
||||
certLock.Lock()
|
||||
defer certLock.Unlock()
|
||||
|
||||
certCache[key] = cert
|
||||
}
|
||||
|
||||
func TLSConfigFromCA(ca *tls.Certificate) func(host string, ctx *goproxy.ProxyCtx) (*tls.Config, error) {
|
||||
return func(host string, ctx *goproxy.ProxyCtx) (c *tls.Config, err error) {
|
||||
parts := strings.SplitN(host, ":", 2)
|
||||
|
|
33
modules/http_proxy_cert_cache.go
Normal file
33
modules/http_proxy_cert_cache.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
certCache = make(map[string]*tls.Certificate)
|
||||
certLock = &sync.Mutex{}
|
||||
)
|
||||
|
||||
func getCachedCert(domain string, port int) *tls.Certificate {
|
||||
key := fmt.Sprintf("%s:%d", domain, port)
|
||||
|
||||
certLock.Lock()
|
||||
defer certLock.Unlock()
|
||||
|
||||
if cert, found := certCache[key]; found == true {
|
||||
return cert
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setCachedCert(domain string, port int, cert *tls.Certificate) {
|
||||
key := fmt.Sprintf("%s:%d", domain, port)
|
||||
|
||||
certLock.Lock()
|
||||
defer certLock.Unlock()
|
||||
|
||||
certCache[key] = cert
|
||||
}
|
14
net/arp.go
14
net/arp.go
|
@ -8,9 +8,9 @@ import (
|
|||
type ArpTable map[string]string
|
||||
|
||||
var (
|
||||
arp_parsed = false
|
||||
arp_lock = &sync.Mutex{}
|
||||
arp_table = make(ArpTable)
|
||||
arpWasParsed = false
|
||||
arpLock = &sync.Mutex{}
|
||||
arpTable = make(ArpTable)
|
||||
)
|
||||
|
||||
func ArpDiff(current, before ArpTable) ArpTable {
|
||||
|
@ -34,7 +34,7 @@ func ArpLookup(iface string, address string, refresh bool) (string, error) {
|
|||
}
|
||||
|
||||
// Lookup the hardware address of this ip.
|
||||
if mac, found := arp_table[address]; found == true {
|
||||
if mac, found := arpTable[address]; found == true {
|
||||
return mac, nil
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func ArpLookup(iface string, address string, refresh bool) (string, error) {
|
|||
}
|
||||
|
||||
func ArpParsed() bool {
|
||||
arp_lock.Lock()
|
||||
defer arp_lock.Unlock()
|
||||
return arp_parsed
|
||||
arpLock.Lock()
|
||||
defer arpLock.Unlock()
|
||||
return arpWasParsed
|
||||
}
|
||||
|
|
|
@ -6,19 +6,19 @@ import (
|
|||
)
|
||||
|
||||
func ArpUpdate(iface string) (ArpTable, error) {
|
||||
arp_lock.Lock()
|
||||
defer arp_lock.Unlock()
|
||||
arpLock.Lock()
|
||||
defer arpLock.Unlock()
|
||||
|
||||
// Signal we parsed the ARP table at least once.
|
||||
arp_parsed = true
|
||||
arpWasParsed = true
|
||||
|
||||
// Run "arp -an" (darwin) or "ip neigh" (linux) and parse the output
|
||||
output, err := core.Exec(ArpCmd, ArpCmdOpts)
|
||||
if err != nil {
|
||||
return arp_table, err
|
||||
return arpTable, err
|
||||
}
|
||||
|
||||
new_table := make(ArpTable)
|
||||
newTable := make(ArpTable)
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
m := ArpTableParser.FindStringSubmatch(line)
|
||||
if len(m) == ArpTableTokens {
|
||||
|
@ -27,12 +27,12 @@ func ArpUpdate(iface string) (ArpTable, error) {
|
|||
ifname := m[ArpTableTokenIndex[2]]
|
||||
|
||||
if ifname == iface {
|
||||
new_table[address] = mac
|
||||
newTable[address] = mac
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arp_table = new_table
|
||||
arpTable = newTable
|
||||
|
||||
return arp_table, nil
|
||||
return arpTable, nil
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ import (
|
|||
)
|
||||
|
||||
type Environment struct {
|
||||
sync.Mutex
|
||||
|
||||
Padding int `json:"-"`
|
||||
Storage map[string]string `json:"storage"`
|
||||
lock *sync.Mutex
|
||||
sess *Session
|
||||
}
|
||||
|
||||
|
@ -18,7 +19,6 @@ func NewEnvironment(s *Session) *Environment {
|
|||
env := &Environment{
|
||||
Padding: 0,
|
||||
Storage: make(map[string]string),
|
||||
lock: &sync.Mutex{},
|
||||
sess: s,
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ func NewEnvironment(s *Session) *Environment {
|
|||
}
|
||||
|
||||
func (env *Environment) Has(name string) bool {
|
||||
env.lock.Lock()
|
||||
defer env.lock.Unlock()
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
|
||||
_, found := env.Storage[name]
|
||||
|
||||
|
@ -35,8 +35,8 @@ func (env *Environment) Has(name string) bool {
|
|||
}
|
||||
|
||||
func (env *Environment) Set(name, value string) string {
|
||||
env.lock.Lock()
|
||||
defer env.lock.Unlock()
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
|
||||
old, _ := env.Storage[name]
|
||||
env.Storage[name] = value
|
||||
|
@ -58,8 +58,8 @@ func (env *Environment) Set(name, value string) string {
|
|||
}
|
||||
|
||||
func (env *Environment) Get(name string) (bool, string) {
|
||||
env.lock.Lock()
|
||||
defer env.lock.Unlock()
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
|
||||
if value, found := env.Storage[name]; found == true {
|
||||
return true, value
|
||||
|
@ -81,8 +81,8 @@ func (env *Environment) GetInt(name string) (error, int) {
|
|||
}
|
||||
|
||||
func (env *Environment) Sorted() []string {
|
||||
env.lock.Lock()
|
||||
defer env.lock.Unlock()
|
||||
env.Lock()
|
||||
defer env.Unlock()
|
||||
|
||||
var keys []string
|
||||
for k := range env.Storage {
|
||||
|
|
|
@ -36,11 +36,12 @@ func (e Event) Label() string {
|
|||
}
|
||||
|
||||
type EventPool struct {
|
||||
sync.Mutex
|
||||
|
||||
NewEvents chan Event
|
||||
debug bool
|
||||
silent bool
|
||||
events []Event
|
||||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
func NewEventPool(debug bool, silent bool) *EventPool {
|
||||
|
@ -49,13 +50,12 @@ func NewEventPool(debug bool, silent bool) *EventPool {
|
|||
debug: debug,
|
||||
silent: silent,
|
||||
events: make([]Event, 0),
|
||||
lock: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EventPool) Add(tag string, data interface{}) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
e := NewEvent(tag, data)
|
||||
p.events = append([]Event{e}, p.events...)
|
||||
|
||||
|
@ -86,13 +86,13 @@ func (p *EventPool) Log(level int, format string, args ...interface{}) {
|
|||
}
|
||||
|
||||
func (p *EventPool) Clear() {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
p.events = make([]Event, 0)
|
||||
}
|
||||
|
||||
func (p *EventPool) Events() []Event {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
return p.events
|
||||
}
|
||||
|
|
|
@ -7,12 +7,13 @@ import (
|
|||
)
|
||||
|
||||
type Targets struct {
|
||||
sync.Mutex
|
||||
|
||||
Session *Session `json:"-"`
|
||||
Interface *net.Endpoint
|
||||
Gateway *net.Endpoint
|
||||
Targets map[string]*net.Endpoint
|
||||
TTL map[string]uint
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
|
||||
|
@ -25,17 +26,9 @@ func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
|
|||
}
|
||||
}
|
||||
|
||||
func (tp *Targets) Lock() {
|
||||
tp.lock.Lock()
|
||||
}
|
||||
|
||||
func (tp *Targets) Unlock() {
|
||||
tp.lock.Unlock()
|
||||
}
|
||||
|
||||
func (tp *Targets) Remove(ip, mac string) {
|
||||
tp.lock.Lock()
|
||||
defer tp.lock.Unlock()
|
||||
tp.Lock()
|
||||
defer tp.Unlock()
|
||||
|
||||
if e, found := tp.Targets[mac]; found {
|
||||
tp.TTL[mac]--
|
||||
|
@ -53,8 +46,8 @@ func (tp *Targets) shouldIgnore(ip string) bool {
|
|||
}
|
||||
|
||||
func (tp *Targets) Has(ip string) bool {
|
||||
tp.lock.Lock()
|
||||
defer tp.lock.Unlock()
|
||||
tp.Lock()
|
||||
defer tp.Unlock()
|
||||
|
||||
for _, e := range tp.Targets {
|
||||
if e.IpAddress == ip {
|
||||
|
@ -66,8 +59,8 @@ func (tp *Targets) Has(ip string) bool {
|
|||
}
|
||||
|
||||
func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
|
||||
tp.lock.Lock()
|
||||
defer tp.lock.Unlock()
|
||||
tp.Lock()
|
||||
defer tp.Unlock()
|
||||
|
||||
if tp.shouldIgnore(ip) {
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue