feat(scan): Display listen port of affected procs for each vulnerable pkgs (#859)

* refactor(redhat): move rpmQa and rpmQf to redhatbase.go

* feat(scan): Display listen port of affected procs
This commit is contained in:
Kota Kanbe
2019-07-03 23:01:59 +09:00
committed by GitHub
parent 3e5390309c
commit 836e4704f8
12 changed files with 141 additions and 46 deletions

View File

@@ -781,3 +781,30 @@ func (l *base) parseGrepProcMap(stdout string) (soPaths []string) {
}
return soPaths
}
func (l *base) lsOfListen() (stdout string, err error) {
cmd := `lsof -i -P | grep LISTEN`
r := l.exec(util.PrependProxyEnv(cmd), sudo)
if !r.isSuccess() {
return "", xerrors.Errorf("Failed to SSH: %s", r)
}
return r.Stdout, nil
}
func (l *base) parseLsOf(stdout string) map[string]string {
portPid := map[string]string{}
scanner := bufio.NewScanner(strings.NewReader(stdout))
for scanner.Scan() {
ss := strings.Fields(scanner.Text())
if len(ss) < 10 {
continue
}
pid, ipPort := ss[1], ss[8]
sss := strings.Split(ipPort, ":")
if len(sss) != 2 {
continue
}
portPid[sss[1]] = pid
}
return portPid
}