mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
fix gateway and arpspoof in android 7 nethunter
in android 7~10 based nethunter, the default gateway can not be found in 'ip route', while the command 'getprop' is not available in nethunter terminal. Without defined the gw, arpspoof will treated the local device as gw hence it can not work. To fix it, we need to manually added a 'default gw' line in 'ip route' results.
This commit is contained in:
parent
c1770b3aa6
commit
74a47c85cd
1 changed files with 20 additions and 3 deletions
|
@ -9,6 +9,8 @@ import (
|
|||
|
||||
var parser = regexp.MustCompile(`^(.+)\sdev\s([^\s]+)\s(.+)$`)
|
||||
|
||||
|
||||
|
||||
func update() ([]Route, error) {
|
||||
table = make([]Route, 0)
|
||||
|
||||
|
@ -17,7 +19,13 @@ func update() ([]Route, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(regexp.MustCompile(`(default)`).FindStringSubmatch(output))!=2 {
|
||||
gwline, err := find_gateway_android7(inet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
output = gwline + "\n" + output
|
||||
}
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
if line = str.Trim(line); len(line) > 0 {
|
||||
matches := parser.FindStringSubmatch(line)
|
||||
|
@ -34,12 +42,21 @@ func update() ([]Route, error) {
|
|||
route.Gateway = route.Destination[idx + len(" via "):]
|
||||
route.Destination = route.Destination[:idx]
|
||||
}
|
||||
|
||||
table = append(table, route)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return table, nil
|
||||
}
|
||||
|
||||
func find_gateway_android7(inet string) (string, error) {
|
||||
output, err := core.Exec("ip", []string{"-f", inet, "route", "get", "8.8.8.8"})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
parser3 := regexp.MustCompile(`8.8.8.8`)
|
||||
first_line := strings.Split(output, "\n")[0]
|
||||
replaced := parser3.ReplaceAllString(first_line, "default")
|
||||
return replaced, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue