mirror of
https://github.com/bettercap/bettercap
synced 2025-07-05 20:42:09 -07:00
Fix bug in target parsing
When a MAC address with uppercase letters was provided, parsing would return an error because the parsing logic would only attempt to remove normalized versions (all lowercase) from the target list. This would leave the address with uppercase letters in the target list, which it would then try to interpet as an Alias. This fixes the bug by using the original address form when removing it from the target list.
This commit is contained in:
parent
ce5c5eb592
commit
32eee7d94b
2 changed files with 20 additions and 4 deletions
|
@ -101,10 +101,10 @@ func ParseTargets(targets string, aliasMap *data.UnsortedKV) (ips []net.IP, macs
|
|||
|
||||
// first isolate MACs and parse them
|
||||
for _, mac := range macParser.FindAllString(targets, -1) {
|
||||
mac = NormalizeMac(mac)
|
||||
hw, err := net.ParseMAC(mac)
|
||||
normalizedMac := NormalizeMac(mac)
|
||||
hw, err := net.ParseMAC(normalizedMac)
|
||||
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", normalizedMac, err)
|
||||
}
|
||||
|
||||
macs = append(macs, hw)
|
||||
|
|
|
@ -37,6 +37,14 @@ func TestNormalizeMac(t *testing.T) {
|
|||
|
||||
// TODO: refactor to parse targets with an actual alias map
|
||||
func TestParseTargets(t *testing.T) {
|
||||
aliasMap, err := data.NewMemUnsortedKV()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
aliasMap.Set("5c:00:0b:90:a9:f0", "test_alias")
|
||||
aliasMap.Set("5c:00:0b:90:a9:f1", "Home_Laptop")
|
||||
|
||||
cases := []struct {
|
||||
Name string
|
||||
InputTargets string
|
||||
|
@ -57,9 +65,17 @@ func TestParseTargets(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"MACs are parsed",
|
||||
"192.168.1.2, 192.168.1.3, 5c:00:0b:90:a9:f0, 6c:00:0b:90:a9:f0",
|
||||
"192.168.1.2, 192.168.1.3, 5c:00:0b:90:a9:f0, 6c:00:0b:90:a9:f0, 6C:00:0B:90:A9:F0",
|
||||
&data.UnsortedKV{},
|
||||
2,
|
||||
3,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Aliases are parsed",
|
||||
"test_alias, Home_Laptop",
|
||||
aliasMap,
|
||||
0,
|
||||
2,
|
||||
false,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue