From 74a47c85cdc728a91d2d13520a0826875a3fe8d1 Mon Sep 17 00:00:00 2001 From: burge10099 <76193847+startstarz@users.noreply.github.com> Date: Wed, 23 Jun 2021 12:53:24 +0800 Subject: [PATCH] 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. --- routing/update_linux.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/routing/update_linux.go b/routing/update_linux.go index 016fe8f4..4ee71151 100644 --- a/routing/update_linux.go +++ b/routing/update_linux.go @@ -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 +}