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:
burge10099 2021-06-23 12:53:24 +08:00 committed by GitHub
commit 74a47c85cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}