mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
new: implemented sslstrip (ref #154)
This commit is contained in:
parent
d8223d9579
commit
2a601e1412
6 changed files with 231 additions and 203 deletions
62
modules/http_proxy_base_hosttracker.go
Normal file
62
modules/http_proxy_base_hosttracker.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
)
|
||||
|
||||
type Host struct {
|
||||
Hostname string
|
||||
Address net.IP
|
||||
Resolved sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewHost(name string) *Host {
|
||||
h := &Host{
|
||||
Hostname: name,
|
||||
Address: nil,
|
||||
Resolved: sync.WaitGroup{},
|
||||
}
|
||||
|
||||
h.Resolved.Add(1)
|
||||
go func(ph *Host) {
|
||||
defer ph.Resolved.Done()
|
||||
if addrs, err := net.LookupIP(ph.Hostname); err == nil && len(addrs) > 0 {
|
||||
ph.Address = make(net.IP, len(addrs[0]))
|
||||
copy(ph.Address, addrs[0])
|
||||
} else {
|
||||
log.Error("Could not resolve %s: %s", ph.Hostname, err)
|
||||
ph.Address = nil
|
||||
}
|
||||
}(h)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
type HostTracker struct {
|
||||
sync.RWMutex
|
||||
hosts map[string]*Host
|
||||
}
|
||||
|
||||
func NewHostTracker() *HostTracker {
|
||||
return &HostTracker{
|
||||
hosts: make(map[string]*Host, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *HostTracker) Track(host, stripped string) {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
t.hosts[stripped] = NewHost(host)
|
||||
}
|
||||
|
||||
func (t *HostTracker) Unstrip(stripped string) *Host {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
if host, found := t.hosts[stripped]; found == true {
|
||||
return host
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue