mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
fix macParser, MACValidator and IPv4Validator regexp selectors + add IPv4BlockValidator
This commit fixes the `network.macParser` and `network.MACValidator` regexp selectors which could validate invalid MAC addresses (e.g. `a🅱️c:d:e:f`).
It also introduces a new `IPv4BlockValidator` regexp selector which allows us to distinguish IPv4 address blocks from single IPv4 addresses, as the previous implementation of `IPv4Validator` would also validate IPv4 address blocks (e.g. `10.0.0.0/8`) whilst only being used to validate single IPv4 addresses.
Both IPv4RangeValidator and IPv4Validator were optimized to only match the IPv4 format.
### Validation examples
- `IPv4BlockValidator` validates `10.0.0.0/8`
- `IPv4RangeValidator` validates `10.0-255.0-255.0-255`
- `IPv4Validator` validates `10.0.0.0`
This commit is contained in:
parent
74e3303963
commit
7fd9d18625
1 changed files with 18 additions and 4 deletions
|
@ -29,11 +29,25 @@ const (
|
|||
|
||||
var (
|
||||
BroadcastHw = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
||||
IPv4Validator = regexp.MustCompile(`^[0-9\.]+/?\d*$`)
|
||||
IPv4RangeValidator = regexp.MustCompile(`^[0-9\.\-]+/?\d*$`)
|
||||
MACValidator = regexp.MustCompile(`(?i)^[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}$`)
|
||||
IPv4BlockValidator = regexp.MustCompile(`^` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])` +
|
||||
`/(?:3[0-2]|2[0-9]|[1]?[0-9])` + `$`)
|
||||
IPv4RangeValidator = regexp.MustCompile(`^` +
|
||||
`(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])-)?(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])-)?(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])-)?(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])-)?(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])` + `$`)
|
||||
IPv4Validator = regexp.MustCompile(`^` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])\.` +
|
||||
`(?:25[0-5]|2[0-4][0-9]|[1][0-9]{2}|[1-9]?[0-9])` + `$`)
|
||||
MACValidator = regexp.MustCompile(`(?i)^(?:[a-f0-9]{2}:){5}[a-f0-9]{2}$`)
|
||||
// lulz this sounds like a hamburger
|
||||
macParser = regexp.MustCompile(`(?i)([a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2})`)
|
||||
macParser = regexp.MustCompile(`(?i)((?:[a-f0-9]{2}:){5}[a-f0-9]{2})`)
|
||||
aliasParser = regexp.MustCompile(`(?i)([a-z_][a-z_0-9]+)`)
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue