mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
fix: fixed a logic bug which made targets lookup by alias fail.
This commit is contained in:
parent
89cccf028a
commit
ca421cf8e3
1 changed files with 19 additions and 15 deletions
|
@ -80,7 +80,7 @@ func ParseMACs(targets string) (macs []net.HardwareAddr, err error) {
|
||||||
mac = NormalizeMac(mac)
|
mac = NormalizeMac(mac)
|
||||||
hw, err := net.ParseMAC(mac)
|
hw, err := net.ParseMAC(mac)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error while parsing MAC '%s': %s", mac, err)
|
return nil, fmt.Errorf("error while parsing MAC '%s': %s", mac, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
macs = append(macs, hw)
|
macs = append(macs, hw)
|
||||||
|
@ -103,7 +103,7 @@ func ParseTargets(targets string, aliasMap *data.UnsortedKV) (ips []net.IP, macs
|
||||||
mac = NormalizeMac(mac)
|
mac = NormalizeMac(mac)
|
||||||
hw, err := net.ParseMAC(mac)
|
hw, err := net.ParseMAC(mac)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("Error while parsing MAC '%s': %s", mac, err)
|
return nil, nil, fmt.Errorf("error while parsing MAC '%s': %s", mac, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
macs = append(macs, hw)
|
macs = append(macs, hw)
|
||||||
|
@ -112,18 +112,22 @@ func ParseTargets(targets string, aliasMap *data.UnsortedKV) (ips []net.IP, macs
|
||||||
targets = strings.Trim(targets, ", ")
|
targets = strings.Trim(targets, ", ")
|
||||||
|
|
||||||
// check and resolve aliases
|
// check and resolve aliases
|
||||||
for _, alias := range aliasParser.FindAllString(targets, -1) {
|
for _, targetAlias := range aliasParser.FindAllString(targets, -1) {
|
||||||
if mac, found := aliasMap.Get(alias); found {
|
found := false
|
||||||
mac = NormalizeMac(mac)
|
aliasMap.Each(func(mac, alias string) bool {
|
||||||
hw, err := net.ParseMAC(mac)
|
if alias == targetAlias {
|
||||||
if err != nil {
|
if hw, err := net.ParseMAC(mac); err == nil {
|
||||||
return nil, nil, fmt.Errorf("Error while parsing MAC '%s': %s", mac, err)
|
macs = append(macs, hw)
|
||||||
|
targets = strings.Replace(targets, targetAlias, "", -1)
|
||||||
|
found = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
macs = append(macs, hw)
|
if !found {
|
||||||
targets = strings.Replace(targets, alias, "", -1)
|
return nil, nil, fmt.Errorf("could not resolve alias %s", targetAlias)
|
||||||
} else {
|
|
||||||
return nil, nil, fmt.Errorf("Could not resolve alias %s", alias)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
targets = strings.Trim(targets, ", ")
|
targets = strings.Trim(targets, ", ")
|
||||||
|
@ -132,7 +136,7 @@ func ParseTargets(targets string, aliasMap *data.UnsortedKV) (ips []net.IP, macs
|
||||||
if targets != "" {
|
if targets != "" {
|
||||||
list, err := iprange.ParseList(targets)
|
list, err := iprange.ParseList(targets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("Error while parsing address list '%s': %s.", targets, err)
|
return nil, nil, fmt.Errorf("error while parsing address list '%s': %s.", targets, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ips = list.Expand()
|
ips = list.Expand()
|
||||||
|
@ -225,7 +229,7 @@ func findInterfaceByName(name string, ifaces []net.Interface) (*Endpoint, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("No interface matching '%s' found.", name)
|
return nil, fmt.Errorf("no interface matching '%s' found.", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindInterface(name string) (*Endpoint, error) {
|
func FindInterface(name string) (*Endpoint, error) {
|
||||||
|
@ -244,7 +248,7 @@ func FindInterface(name string) (*Endpoint, error) {
|
||||||
for _, iface := range ifaces {
|
for _, iface := range ifaces {
|
||||||
addrs, err := iface.Addrs()
|
addrs, err := iface.Addrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("WTF of the day: %s", err)
|
fmt.Printf("wtf of the day: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue