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:
27
scan/base.go
27
scan/base.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user