lint driven refactoring

This commit is contained in:
evilsocket 2018-04-24 16:33:38 +02:00
parent bc3be7dd2b
commit 7919cda5ec
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
12 changed files with 45 additions and 49 deletions

View file

@ -99,7 +99,7 @@ func (f *LinuxFirewall) EnableRedirection(r *Redirection, enabled bool) error {
rkey := r.String() rkey := r.String()
_, found := f.redirections[rkey] _, found := f.redirections[rkey]
if !enabled { if enabled {
if found { if found {
return fmt.Errorf("Redirection '%s' already enabled.", rkey) return fmt.Errorf("Redirection '%s' already enabled.", rkey)
} }

View file

@ -134,7 +134,7 @@ func (api *RestAPI) Configure() error {
return err return err
} else if err, api.useWebsocket = api.BoolParam("api.rest.websocket"); err != nil { } else if err, api.useWebsocket = api.BoolParam("api.rest.websocket"); err != nil {
return err return err
} else if core.Exists(api.certFile) == false || core.Exists(api.keyFile) == false { } else if !core.Exists(api.certFile) || !core.Exists(api.keyFile) {
log.Info("Generating TLS key to %s", api.keyFile) log.Info("Generating TLS key to %s", api.keyFile)
log.Info("Generating TLS certificate to %s", api.certFile) log.Info("Generating TLS certificate to %s", api.certFile)
if err := tls.Generate(api.certFile, api.keyFile); err != nil { if err := tls.Generate(api.certFile, api.keyFile); err != nil {

View file

@ -63,7 +63,7 @@ func (api *RestAPI) showBle(w http.ResponseWriter, r *http.Request) {
if mac == "" { if mac == "" {
toJSON(w, session.I.BLE) toJSON(w, session.I.BLE)
} else if dev, found := session.I.BLE.Get(mac); found == true { } else if dev, found := session.I.BLE.Get(mac); found {
toJSON(w, dev) toJSON(w, dev)
} else { } else {
http.Error(w, "Not Found", 404) http.Error(w, "Not Found", 404)
@ -88,7 +88,7 @@ func (api *RestAPI) showLan(w http.ResponseWriter, r *http.Request) {
if mac == "" { if mac == "" {
toJSON(w, session.I.Lan) toJSON(w, session.I.Lan)
} else if host, found := session.I.Lan.Get(mac); found == true { } else if host, found := session.I.Lan.Get(mac); found {
toJSON(w, host) toJSON(w, host)
} else { } else {
http.Error(w, "Not Found", 404) http.Error(w, "Not Found", 404)
@ -113,9 +113,9 @@ func (api *RestAPI) showWiFi(w http.ResponseWriter, r *http.Request) {
if mac == "" { if mac == "" {
toJSON(w, session.I.WiFi) toJSON(w, session.I.WiFi)
} else if station, found := session.I.WiFi.Get(mac); found == true { } else if station, found := session.I.WiFi.Get(mac); found {
toJSON(w, station) toJSON(w, station)
} else if client, found := session.I.WiFi.GetClient(mac); found == true { } else if client, found := session.I.WiFi.GetClient(mac); found {
toJSON(w, client) toJSON(w, client)
} else { } else {
http.Error(w, "Not Found", 404) http.Error(w, "Not Found", 404)
@ -172,7 +172,7 @@ func (api *RestAPI) clearEvents(w http.ResponseWriter, r *http.Request) {
func (api *RestAPI) sessionRoute(w http.ResponseWriter, r *http.Request) { func (api *RestAPI) sessionRoute(w http.ResponseWriter, r *http.Request) {
setSecurityHeaders(w) setSecurityHeaders(w)
if api.checkAuth(r) == false { if !api.checkAuth(r) {
setAuthFailed(w, r) setAuthFailed(w, r)
return return
} else if r.Method == "POST" { } else if r.Method == "POST" {
@ -223,7 +223,7 @@ func (api *RestAPI) sessionRoute(w http.ResponseWriter, r *http.Request) {
func (api *RestAPI) eventsRoute(w http.ResponseWriter, r *http.Request) { func (api *RestAPI) eventsRoute(w http.ResponseWriter, r *http.Request) {
setSecurityHeaders(w) setSecurityHeaders(w)
if api.checkAuth(r) == false { if !api.checkAuth(r) {
setAuthFailed(w, r) setAuthFailed(w, r)
return return
} }

View file

@ -94,10 +94,10 @@ func (p *ArpSpoofer) Configure() error {
log.Debug(" addresses=%v macs=%v whitelisted-addresses=%v whitelisted-macs=%v", p.addresses, p.macs, p.wAddresses, p.wMacs) log.Debug(" addresses=%v macs=%v whitelisted-addresses=%v whitelisted-macs=%v", p.addresses, p.macs, p.wAddresses, p.wMacs)
if p.ban == true { if p.ban {
log.Warning("Running in BAN mode, forwarding not enabled!") log.Warning("Running in BAN mode, forwarding not enabled!")
p.Session.Firewall.EnableForwarding(false) p.Session.Firewall.EnableForwarding(false)
} else if p.Session.Firewall.IsForwardingEnabled() == false { } else if !p.Session.Firewall.IsForwardingEnabled() {
log.Info("Enabling forwarding.") log.Info("Enabling forwarding.")
p.Session.Firewall.EnableForwarding(true) p.Session.Firewall.EnableForwarding(true)
} }
@ -143,7 +143,7 @@ func (p *ArpSpoofer) isWhitelisted(ip string, mac net.HardwareAddr) bool {
} }
for _, hw := range p.wMacs { for _, hw := range p.wMacs {
if bytes.Compare(hw, mac) == 0 { if bytes.Equal(hw, mac) {
return true return true
} }
} }
@ -155,10 +155,9 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
p.waitGroup.Add(1) p.waitGroup.Add(1)
defer p.waitGroup.Done() defer p.waitGroup.Done()
targets := make(map[string]net.HardwareAddr, 0) targets := make(map[string]net.HardwareAddr)
for _, ip := range p.addresses { for _, ip := range p.addresses {
if p.Session.Skip(ip) == true { if p.Session.Skip(ip) {
log.Debug("Skipping address %s from ARP spoofing.", ip) log.Debug("Skipping address %s from ARP spoofing.", ip)
continue continue
} }
@ -180,7 +179,7 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
continue continue
} }
if p.Session.Skip(net.ParseIP(ip)) == true { if p.Session.Skip(net.ParseIP(ip)) {
log.Debug("Skipping address %s from ARP spoofing.", ip) log.Debug("Skipping address %s from ARP spoofing.", ip)
continue continue
} }
@ -189,7 +188,7 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
} }
for ip, mac := range targets { for ip, mac := range targets {
if check_running && p.Running() == false { if check_running && !p.Running() {
return return
} else if p.isWhitelisted(ip, mac) { } else if p.isWhitelisted(ip, mac) {
log.Debug("%s (%s) is whitelisted, skipping from spoofing loop.", ip, mac) log.Debug("%s (%s) is whitelisted, skipping from spoofing loop.", ip, mac)

View file

@ -199,7 +199,7 @@ func (s *ProxyScript) defineBuiltins() error {
if argc == 1 { if argc == 1 {
// get // get
varName := call.Argument(0).String() varName := call.Argument(0).String()
if found, varValue := s.sess.Env.Get(varName); found == true { if found, varValue := s.sess.Env.Get(varName); found {
v, err := s.VM.ToValue(varValue) v, err := s.VM.ToValue(varValue)
if err != nil { if err != nil {
return errOtto("Could not convert to string: %s", varValue) return errOtto("Could not convert to string: %s", varValue)
@ -228,7 +228,7 @@ func (s *ProxyScript) hasCallback(name string) bool {
// check the cache // check the cache
has, found := s.cbCache[name] has, found := s.cbCache[name]
if found == false { if !found {
// check the VM // check the VM
cb, err := s.VM.Get(name) cb, err := s.VM.Get(name)
if err == nil && cb.IsFunction() { if err == nil && cb.IsFunction() {

View file

@ -65,7 +65,7 @@ func NewBLERecon(s *session.Session) *BLERecon {
d.AddHandler(session.NewModuleHandler("ble.enum MAC", "ble.enum "+macRegexp, d.AddHandler(session.NewModuleHandler("ble.enum MAC", "ble.enum "+macRegexp,
"Enumerate services and characteristics for the given BLE device.", "Enumerate services and characteristics for the given BLE device.",
func(args []string) error { func(args []string) error {
if d.isEnumerating() == true { if d.isEnumerating() {
return fmt.Errorf("An enumeration for %s is already running, please wait.", d.currDevice.Device.ID()) return fmt.Errorf("An enumeration for %s is already running, please wait.", d.currDevice.Device.ID())
} }
@ -174,7 +174,7 @@ func (d *BLERecon) writeBuffer(mac string, uuid gatt.UUID, data []byte) error {
func (d *BLERecon) enumAllTheThings(mac string) error { func (d *BLERecon) enumAllTheThings(mac string) error {
dev, found := d.Session.BLE.Get(mac) dev, found := d.Session.BLE.Get(mac)
if found == false || dev == nil { if !found || dev == nil {
return fmt.Errorf("BLE device with address %s not found.", mac) return fmt.Errorf("BLE device with address %s not found.", mac)
} else if d.Running() { } else if d.Running() {
d.gattDevice.StopScanning() d.gattDevice.StopScanning()
@ -189,7 +189,7 @@ func (d *BLERecon) enumAllTheThings(mac string) error {
go func() { go func() {
time.Sleep(d.connTimeout) time.Sleep(d.connTimeout)
if d.isEnumerating() && d.connected == false { if d.isEnumerating() && !d.connected {
d.Session.Events.Add("ble.connection.timeout", d.currDevice) d.Session.Events.Add("ble.connection.timeout", d.currDevice)
d.onPeriphDisconnected(nil, nil) d.onPeriphDisconnected(nil, nil)
} }

View file

@ -37,7 +37,7 @@ func (d *BLERecon) getRow(dev *network.BLEDevice) []string {
} }
isConnectable := core.Red("no") isConnectable := core.Red("no")
if dev.Advertisement.Connectable == true { if dev.Advertisement.Connectable {
isConnectable = core.Green("yes") isConnectable = core.Green("yes")
} }
@ -112,7 +112,7 @@ func parseProperties(ch *gatt.Characteristic) (props []string, isReadable bool,
func parseRawData(raw []byte) string { func parseRawData(raw []byte) string {
s := "" s := ""
for _, b := range raw { for _, b := range raw {
if b != 00 && strconv.IsPrint(rune(b)) == false { if b != 00 && !strconv.IsPrint(rune(b)) {
return fmt.Sprintf("%x", raw) return fmt.Sprintf("%x", raw)
} else if b == 0 { } else if b == 0 {
break break
@ -168,7 +168,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
props, isReadable, isWritable, withResponse := parseProperties(ch) props, isReadable, isWritable, withResponse := parseProperties(ch)
if wantsToWrite && d.writeUUID.Equal(ch.UUID()) == true { if wantsToWrite && d.writeUUID.Equal(ch.UUID()) {
foundToWrite = true foundToWrite = true
if isWritable { if isWritable {
log.Info("Writing %d bytes to characteristics %s ...", len(d.writeData), d.writeUUID) log.Info("Writing %d bytes to characteristics %s ...", len(d.writeData), d.writeUUID)
@ -203,7 +203,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
} }
} }
if wantsToWrite && foundToWrite == false { if wantsToWrite && !foundToWrite {
log.Error("Writable characteristics %s not found.", d.writeUUID) log.Error("Writable characteristics %s not found.", d.writeUUID)
} else { } else {
core.AsTable(os.Stdout, columns, rows) core.AsTable(os.Stdout, columns, rows)

View file

@ -102,7 +102,7 @@ func (s *DHCP6Spoofer) Configure() error {
return err return err
} }
if s.Session.Firewall.IsForwardingEnabled() == false { if !s.Session.Firewall.IsForwardingEnabled() {
log.Info("Enabling forwarding.") log.Info("Enabling forwarding.")
s.Session.Firewall.EnableForwarding(true) s.Session.Firewall.EnableForwarding(true)
} }
@ -126,7 +126,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
pip6 := pkt.Layer(layers.LayerTypeIPv6).(*layers.IPv6) pip6 := pkt.Layer(layers.LayerTypeIPv6).(*layers.IPv6)
fqdn := target.String() fqdn := target.String()
if raw, found := solicit.Options[packets.DHCP6OptClientFQDN]; found == true && len(raw) >= 1 { if raw, found := solicit.Options[packets.DHCP6OptClientFQDN]; found && len(raw) >= 1 {
fqdn = string(raw[0]) fqdn = string(raw[0])
} }
@ -140,7 +140,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
var solIANA dhcp6opts.IANA var solIANA dhcp6opts.IANA
if raw, found := solicit.Options[dhcp6.OptionIANA]; found == false || len(raw) < 1 { if raw, found := solicit.Options[dhcp6.OptionIANA]; !found || len(raw) < 1 {
log.Error("Unexpected DHCPv6 packet, could not find IANA.") log.Error("Unexpected DHCPv6 packet, could not find IANA.")
return return
} else if err := solIANA.UnmarshalBinary(raw[0]); err != nil { } else if err := solIANA.UnmarshalBinary(raw[0]); err != nil {
@ -149,7 +149,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
} }
var ip net.IP var ip net.IP
if h, found := s.Session.Lan.Get(target.String()); found == true { if h, found := s.Session.Lan.Get(target.String()); found {
ip = h.IP ip = h.IP
} else { } else {
log.Warning("Address %s not known, using random identity association address.", target.String()) log.Warning("Address %s not known, using random identity association address.", target.String())
@ -233,7 +233,7 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
} }
var reqIANA dhcp6opts.IANA var reqIANA dhcp6opts.IANA
if raw, found := req.Options[dhcp6.OptionIANA]; found == false || len(raw) < 1 { if raw, found := req.Options[dhcp6.OptionIANA]; !found || len(raw) < 1 {
log.Error("Unexpected DHCPv6 packet, could not find IANA.") log.Error("Unexpected DHCPv6 packet, could not find IANA.")
return return
} else if err := reqIANA.UnmarshalBinary(raw[0]); err != nil { } else if err := reqIANA.UnmarshalBinary(raw[0]); err != nil {
@ -242,7 +242,7 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
} }
var reqIAddr []byte var reqIAddr []byte
if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found == true { if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found {
reqIAddr = raw[0] reqIAddr = raw[0]
} else { } else {
log.Error("Unexpected DHCPv6 packet, could not deserialize request IANA IAAddr.") log.Error("Unexpected DHCPv6 packet, could not deserialize request IANA IAAddr.")
@ -303,11 +303,11 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
if toType == "request" { if toType == "request" {
var addr net.IP var addr net.IP
if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found == true { if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found {
addr = net.IP(raw[0]) addr = net.IP(raw[0])
} }
if h, found := s.Session.Lan.Get(target.String()); found == true { if h, found := s.Session.Lan.Get(target.String()); found {
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), h) log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), h)
} else { } else {
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), target) log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), target)
@ -318,8 +318,8 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
} }
func (s *DHCP6Spoofer) duidMatches(dhcp dhcp6.Packet) bool { func (s *DHCP6Spoofer) duidMatches(dhcp dhcp6.Packet) bool {
if raw, found := dhcp.Options[dhcp6.OptionServerID]; found == true && len(raw) >= 1 { if raw, found := dhcp.Options[dhcp6.OptionServerID]; found && len(raw) >= 1 {
if bytes.Compare(raw[0], s.DUIDRaw) == 0 { if bytes.Equal(raw[0], s.DUIDRaw) {
return true return true
} }
} }
@ -338,7 +338,6 @@ func (s *DHCP6Spoofer) onPacket(pkt gopacket.Packet) {
// we just got a dhcp6 packet? // we just got a dhcp6 packet?
if err = dhcp.UnmarshalBinary(udp.Payload); err == nil { if err = dhcp.UnmarshalBinary(udp.Payload); err == nil {
eth := pkt.Layer(layers.LayerTypeEthernet).(*layers.Ethernet) eth := pkt.Layer(layers.LayerTypeEthernet).(*layers.Ethernet)
switch dhcp.MessageType { switch dhcp.MessageType {
case dhcp6.MessageTypeSolicit: case dhcp6.MessageTypeSolicit:
@ -369,7 +368,7 @@ func (s *DHCP6Spoofer) Start() error {
src := gopacket.NewPacketSource(s.Handle, s.Handle.LinkType()) src := gopacket.NewPacketSource(s.Handle, s.Handle.LinkType())
s.pktSourceChan = src.Packets() s.pktSourceChan = src.Packets()
for packet := range s.pktSourceChan { for packet := range s.pktSourceChan {
if s.Running() == false { if !s.Running() {
break break
} }

View file

@ -118,7 +118,7 @@ func (s *DNSSpoofer) Configure() error {
s.Address = net.ParseIP(addr) s.Address = net.ParseIP(addr)
if s.Session.Firewall.IsForwardingEnabled() == false { if !s.Session.Firewall.IsForwardingEnabled() {
log.Info("Enabling forwarding.") log.Info("Enabling forwarding.")
s.Session.Firewall.EnableForwarding(true) s.Session.Firewall.EnableForwarding(true)
} }
@ -130,7 +130,7 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
redir := fmt.Sprintf("(->%s)", s.Address) redir := fmt.Sprintf("(->%s)", s.Address)
who := target.String() who := target.String()
if t, found := s.Session.Lan.Get(target.String()); found == true { if t, found := s.Session.Lan.Get(target.String()); found {
who = t.String() who = t.String()
} }
@ -192,7 +192,7 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
var raw []byte var raw []byte
if ipv6 == true { if ipv6 {
ip6 := layers.IPv6{ ip6 := layers.IPv6{
Version: 6, Version: 6,
NextHeader: layers.IPProtocolUDP, NextHeader: layers.IPProtocolUDP,
@ -259,14 +259,13 @@ func (s *DNSSpoofer) onPacket(pkt gopacket.Packet) {
} }
eth := typeEth.(*layers.Ethernet) eth := typeEth.(*layers.Ethernet)
if s.All || bytes.Equal(eth.DstMAC, s.Session.Interface.HW) {
if s.All || bytes.Compare(eth.DstMAC, s.Session.Interface.HW) == 0 {
dns, parsed := pkt.Layer(layers.LayerTypeDNS).(*layers.DNS) dns, parsed := pkt.Layer(layers.LayerTypeDNS).(*layers.DNS)
if parsed && dns.OpCode == layers.DNSOpCodeQuery && len(dns.Questions) > 0 && len(dns.Answers) == 0 { if parsed && dns.OpCode == layers.DNSOpCodeQuery && len(dns.Questions) > 0 && len(dns.Answers) == 0 {
udp := typeUDP.(*layers.UDP) udp := typeUDP.(*layers.UDP)
for _, q := range dns.Questions { for _, q := range dns.Questions {
qName := string(q.Name) qName := string(q.Name)
if s.shouldSpoof(qName) == true { if s.shouldSpoof(qName) {
s.dnsReply(pkt, eth, udp, qName, dns, eth.SrcMAC) s.dnsReply(pkt, eth, udp, qName, dns, eth.SrcMAC)
break break
} else { } else {
@ -289,7 +288,7 @@ func (s *DNSSpoofer) Start() error {
src := gopacket.NewPacketSource(s.Handle, s.Handle.LinkType()) src := gopacket.NewPacketSource(s.Handle, s.Handle.LinkType())
s.pktSourceChan = src.Packets() s.pktSourceChan = src.Packets()
for packet := range s.pktSourceChan { for packet := range s.pktSourceChan {
if s.Running() == false { if !s.Running() {
break break
} }

View file

@ -73,7 +73,7 @@ func (l *IgnoreList) Remove(expr string) (err error) {
toRemove := IgnoreFilter(expr) toRemove := IgnoreFilter(expr)
newList := make([]IgnoreFilter, 0) newList := make([]IgnoreFilter, 0)
for _, filter := range l.filters { for _, filter := range l.filters {
if toRemove.Matches(string(filter)) == false { if !toRemove.Matches(string(filter)) {
newList = append(newList, filter) newList = append(newList, filter)
} }
} }
@ -104,7 +104,6 @@ func (l *IgnoreList) Ignored(e session.Event) bool {
func (l *IgnoreList) Empty() bool { func (l *IgnoreList) Empty() bool {
l.RLock() l.RLock()
defer l.RUnlock() defer l.RUnlock()
return len(l.filters) == 0 return len(l.filters) == 0
} }

View file

@ -80,8 +80,8 @@ func (t *Ticker) Start() error {
return t.SetRunning(true, func() { return t.SetRunning(true, func() {
log.Info("Ticker running with period %.fs.", t.Period.Seconds()) log.Info("Ticker running with period %.fs.", t.Period.Seconds())
tick := time.Tick(t.Period) tick := time.NewTicker(t.Period)
for range tick { for range tick.C {
if t.Running() == false { if t.Running() == false {
break break
} }

View file

@ -30,7 +30,7 @@ func findMAC(s *session.Session, ip net.IP, probe bool) (net.HardwareAddr, error
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
mac, err = network.ArpLookup(s.Interface.Name(), ip.String(), false) mac, _ = network.ArpLookup(s.Interface.Name(), ip.String(), false)
} }
if mac == "" { if mac == "" {