Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bettercap/bettercap
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Apr 8, 2020
2 parents 81b1cae + 877600f commit f5fb86d
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 13 deletions.
16 changes: 15 additions & 1 deletion modules/dns_spoof/dns_spoof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net"
"strconv"
"sync"

"github.com/bettercap/bettercap/packets"
Expand All @@ -20,6 +21,7 @@ type DNSSpoofer struct {
session.SessionModule
Handle *pcap.Handle
Hosts Hosts
TTL uint32
All bool
waitGroup *sync.WaitGroup
pktSourceChan chan gopacket.Packet
Expand All @@ -31,6 +33,7 @@ func NewDNSSpoofer(s *session.Session) *DNSSpoofer {
Handle: nil,
All: false,
Hosts: Hosts{},
TTL: 1024,
waitGroup: &sync.WaitGroup{},
}

Expand All @@ -55,6 +58,11 @@ func NewDNSSpoofer(s *session.Session) *DNSSpoofer {
"false",
"If true the module will reply to every DNS request, otherwise it will only reply to the one targeting the local pc."))

mod.AddParam(session.NewStringParameter("dns.spoof.ttl",
"1024",
"^[0-9]+$",
"TTL of spoofed DNS replies."))

mod.AddHandler(session.NewModuleHandler("dns.spoof on", "",
"Start the DNS spoofer in the background.",
func(args []string) error {
Expand Down Expand Up @@ -84,6 +92,7 @@ func (mod DNSSpoofer) Author() string {

func (mod *DNSSpoofer) Configure() error {
var err error
var ttl string
var hostsFile string
var domains []string
var address net.IP
Expand All @@ -102,6 +111,8 @@ func (mod *DNSSpoofer) Configure() error {
return err
} else if err, hostsFile = mod.StringParam("dns.spoof.hosts"); err != nil {
return err
} else if err, ttl = mod.StringParam("dns.spoof.ttl"); err != nil {
return err
}

mod.Hosts = Hosts{}
Expand Down Expand Up @@ -131,6 +142,9 @@ func (mod *DNSSpoofer) Configure() error {
mod.Session.Firewall.EnableForwarding(true)
}

_ttl, _ := strconv.Atoi(ttl)
mod.TTL = uint32(_ttl)

return nil
}

Expand Down Expand Up @@ -184,7 +198,7 @@ func (mod *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp
Name: []byte(q.Name),
Type: q.Type,
Class: q.Class,
TTL: 1024,
TTL: mod.TTL,
IP: address,
})
}
Expand Down
4 changes: 2 additions & 2 deletions modules/events_stream/events_view_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (mod *EventsStream) dumpForm(body []byte) string {
if err != nil {
value = v
}
form = append(form, fmt.Sprintf("%s", tui.Bold(tui.Red(value))))
form = append(form, tui.Bold(tui.Red(value)))
}
}
return "\n" + strings.Join(form, "&") + "\n"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (mod *EventsStream) dumpJSON(body []byte) string {
if err := json.Indent(&buf, body, "", " "); err != nil {
pretty = string(body)
} else {
pretty = string(buf.Bytes())
pretty = buf.String()
}

return "\n" + reJsonKey.ReplaceAllString(pretty, tui.Green(`$1:`)) + "\n"
Expand Down
2 changes: 1 addition & 1 deletion modules/mysql_server/mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (mod *MySQLServer) Start() error {
if _, err := conn.Write(packets.MySQLGreeting); err != nil {
mod.Warning("error while writing server greeting: %s", err)
continue
} else if read, err = reader.Read(readBuffer); err != nil {
} else if _, err = reader.Read(readBuffer); err != nil {
mod.Warning("error while reading client message: %s", err)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion modules/net_sniff/net_sniff_upnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
if data := packets.UPNPGetMeta(pkt); data != nil && len(data) > 0 {
if data := packets.UPNPGetMeta(pkt); len(data) > 0 {
s := ""
for name, value := range data {
s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value))
Expand Down
2 changes: 1 addition & 1 deletion modules/syn_scan/syn_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func (mod *SynScanner) synScan() error {
mod.State.Store("progress", 0.0)

// start the collector
mod.waitGroup.Add(1)
go func() {
mod.waitGroup.Add(1)
defer mod.waitGroup.Done()

for packet := range mod.packets {
Expand Down
3 changes: 1 addition & 2 deletions modules/wifi/wifi_assoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ func (mod *WiFiModule) startAssoc(to net.HardwareAddr) error {
}
return fmt.Errorf("%s is an unknown BSSID or it is in the association skip list.", to.String())
}

mod.writes.Add(1)
go func() {
mod.writes.Add(1)
defer mod.writes.Done()

// since we need to change the wifi adapter channel for each
Expand Down
2 changes: 1 addition & 1 deletion modules/wifi/wifi_deauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (mod *WiFiModule) startDeauth(to net.HardwareAddr) error {
return fmt.Errorf("%s is an unknown BSSID, is in the deauth skip list, or doesn't have detected clients.", to.String())
}

mod.writes.Add(1)
go func() {
mod.writes.Add(1)
defer mod.writes.Done()

// since we need to change the wifi adapter channel for each
Expand Down
2 changes: 1 addition & 1 deletion modules/wifi/wifi_hopping.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (mod *WiFiModule) channelHopper() {
}

select {
case _ = <-mod.hopChanges:
case <-mod.hopChanges:
mod.Debug("hop changed")
break loopCurrentChannels
case <-time.After(delay):
Expand Down
4 changes: 1 addition & 3 deletions session/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ func (p *EventPool) Listen() <-chan Event {
go func() {
for i := len(p.events) - 1; i >= 0; i-- {
defer func() {
if recover() != nil {

}
recover()
}()
l <- p.events[i]
}
Expand Down

0 comments on commit f5fb86d

Please sign in to comment.