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()
_, found := f.redirections[rkey]
if !enabled {
if enabled {
if found {
return fmt.Errorf("Redirection '%s' already enabled.", rkey)
}

View file

@ -134,7 +134,7 @@ func (api *RestAPI) Configure() error {
return err
} else if err, api.useWebsocket = api.BoolParam("api.rest.websocket"); err != nil {
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 certificate to %s", api.certFile)
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 == "" {
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)
} else {
http.Error(w, "Not Found", 404)
@ -88,7 +88,7 @@ func (api *RestAPI) showLan(w http.ResponseWriter, r *http.Request) {
if mac == "" {
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)
} else {
http.Error(w, "Not Found", 404)
@ -113,9 +113,9 @@ func (api *RestAPI) showWiFi(w http.ResponseWriter, r *http.Request) {
if mac == "" {
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)
} else if client, found := session.I.WiFi.GetClient(mac); found == true {
} else if client, found := session.I.WiFi.GetClient(mac); found {
toJSON(w, client)
} else {
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) {
setSecurityHeaders(w)
if api.checkAuth(r) == false {
if !api.checkAuth(r) {
setAuthFailed(w, r)
return
} 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) {
setSecurityHeaders(w)
if api.checkAuth(r) == false {
if !api.checkAuth(r) {
setAuthFailed(w, r)
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)
if p.ban == true {
if p.ban {
log.Warning("Running in BAN mode, forwarding not enabled!")
p.Session.Firewall.EnableForwarding(false)
} else if p.Session.Firewall.IsForwardingEnabled() == false {
} else if !p.Session.Firewall.IsForwardingEnabled() {
log.Info("Enabling forwarding.")
p.Session.Firewall.EnableForwarding(true)
}
@ -143,7 +143,7 @@ func (p *ArpSpoofer) isWhitelisted(ip string, mac net.HardwareAddr) bool {
}
for _, hw := range p.wMacs {
if bytes.Compare(hw, mac) == 0 {
if bytes.Equal(hw, mac) {
return true
}
}
@ -155,10 +155,9 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
p.waitGroup.Add(1)
defer p.waitGroup.Done()
targets := make(map[string]net.HardwareAddr, 0)
targets := make(map[string]net.HardwareAddr)
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)
continue
}
@ -180,7 +179,7 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
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)
continue
}
@ -189,7 +188,7 @@ func (p *ArpSpoofer) sendArp(saddr net.IP, smac net.HardwareAddr, check_running
}
for ip, mac := range targets {
if check_running && p.Running() == false {
if check_running && !p.Running() {
return
} else if p.isWhitelisted(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 {
// get
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)
if err != nil {
return errOtto("Could not convert to string: %s", varValue)
@ -228,7 +228,7 @@ func (s *ProxyScript) hasCallback(name string) bool {
// check the cache
has, found := s.cbCache[name]
if found == false {
if !found {
// check the VM
cb, err := s.VM.Get(name)
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,
"Enumerate services and characteristics for the given BLE device.",
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())
}
@ -174,7 +174,7 @@ func (d *BLERecon) writeBuffer(mac string, uuid gatt.UUID, data []byte) error {
func (d *BLERecon) enumAllTheThings(mac string) error {
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)
} else if d.Running() {
d.gattDevice.StopScanning()
@ -189,7 +189,7 @@ func (d *BLERecon) enumAllTheThings(mac string) error {
go func() {
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.onPeriphDisconnected(nil, nil)
}

View file

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

View file

@ -102,7 +102,7 @@ func (s *DHCP6Spoofer) Configure() error {
return err
}
if s.Session.Firewall.IsForwardingEnabled() == false {
if !s.Session.Firewall.IsForwardingEnabled() {
log.Info("Enabling forwarding.")
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)
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])
}
@ -140,7 +140,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
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.")
return
} 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
if h, found := s.Session.Lan.Get(target.String()); found == true {
if h, found := s.Session.Lan.Get(target.String()); found {
ip = h.IP
} else {
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
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.")
return
} 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
if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found == true {
if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found {
reqIAddr = raw[0]
} else {
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" {
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])
}
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)
} else {
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 {
if raw, found := dhcp.Options[dhcp6.OptionServerID]; found == true && len(raw) >= 1 {
if bytes.Compare(raw[0], s.DUIDRaw) == 0 {
if raw, found := dhcp.Options[dhcp6.OptionServerID]; found && len(raw) >= 1 {
if bytes.Equal(raw[0], s.DUIDRaw) {
return true
}
}
@ -338,7 +338,6 @@ func (s *DHCP6Spoofer) onPacket(pkt gopacket.Packet) {
// we just got a dhcp6 packet?
if err = dhcp.UnmarshalBinary(udp.Payload); err == nil {
eth := pkt.Layer(layers.LayerTypeEthernet).(*layers.Ethernet)
switch dhcp.MessageType {
case dhcp6.MessageTypeSolicit:
@ -369,7 +368,7 @@ func (s *DHCP6Spoofer) Start() error {
src := gopacket.NewPacketSource(s.Handle, s.Handle.LinkType())
s.pktSourceChan = src.Packets()
for packet := range s.pktSourceChan {
if s.Running() == false {
if !s.Running() {
break
}

View file

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

View file

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

View file

@ -80,8 +80,8 @@ func (t *Ticker) Start() error {
return t.SetRunning(true, func() {
log.Info("Ticker running with period %.fs.", t.Period.Seconds())
tick := time.Tick(t.Period)
for range tick {
tick := time.NewTicker(t.Period)
for range tick.C {
if t.Running() == false {
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)
mac, err = network.ArpLookup(s.Interface.Name(), ip.String(), false)
mac, _ = network.ArpLookup(s.Interface.Name(), ip.String(), false)
}
if mac == "" {