diff --git a/scan/base.go b/scan/base.go index e9aa24f4..e000bc74 100644 --- a/scan/base.go +++ b/scan/base.go @@ -787,7 +787,7 @@ func (l *base) parseGrepProcMap(stdout string) (soPaths []string) { } func (l *base) lsOfListen() (stdout string, err error) { - cmd := `lsof -i -P | grep LISTEN` + cmd := `lsof -i -P -n | grep LISTEN` r := l.exec(util.PrependProxyEnv(cmd), sudo) if !r.isSuccess() { return "", xerrors.Errorf("Failed to SSH: %s", r) @@ -804,11 +804,7 @@ func (l *base) parseLsOf(stdout string) map[string]string { continue } pid, ipPort := ss[1], ss[8] - sss := strings.Split(ipPort, ":") - if len(sss) != 2 { - continue - } - portPid[sss[1]] = pid + portPid[ipPort] = pid } return portPid } diff --git a/scan/base_test.go b/scan/base_test.go index d9219145..bd2c92ce 100644 --- a/scan/base_test.go +++ b/scan/base_test.go @@ -274,12 +274,12 @@ node 1498 ubuntu 22u IPv6 20133 0t0 TCP *:44801 (LISTEN docker-pr 9135 root 4u IPv6 297133 0t0 TCP *:6379 (LISTEN)`, }, wantPortPid: map[string]string{ - "53": "474", - "22": "644", - "3128": "959", - "35401": "1498", - "44801": "1498", - "6379": "9135", + "localhost:53": "474", + "*:22": "644", + "*:3128": "959", + "*:35401": "1498", + "*:44801": "1498", + "*:6379": "9135", }, }, }