Skip to content

Commit a1cc152

Browse files
authored
feat(library): add auto detect library (future-architect#1417)
1 parent 1c77bc1 commit a1cc152

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

models/library.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,24 @@ var LibraryMap = map[string]string{
137137
"Gemfile.lock": "ruby",
138138
"Cargo.lock": "rust",
139139
"composer.lock": "php",
140+
"requirements.txt": "python",
140141
"Pipfile.lock": "python",
141142
"poetry.lock": "python",
142143
"packages.lock.json": ".net",
144+
"packages.config": ".net",
143145
"go.sum": "gomod",
146+
"pom.xml": "java",
147+
"*.jar": "java",
148+
"*.war": "java",
149+
"*.ear": "java",
150+
"*.par": "java",
144151
}
145152

146153
// GetLibraryKey returns target library key
147154
func (s LibraryScanner) GetLibraryKey() string {
148155
fileName := filepath.Base(s.LockfilePath)
149156
switch s.Type {
150-
case "jar", "war", "ear":
157+
case "jar", "war", "ear", "par":
151158
return "java"
152159
}
153160
return LibraryMap[fileName]

scanner/base.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,12 @@ func (l *base) scanLibraries() (err error) {
592592
if l.ServerInfo.FindLock {
593593
findopt := ""
594594
for filename := range models.LibraryMap {
595-
findopt += fmt.Sprintf("-name %q -o ", "*"+filename)
595+
findopt += fmt.Sprintf("-name %q -o ", filename)
596596
}
597597

598598
// delete last "-o "
599-
// find / -name "*package-lock.json" -o -name "*yarn.lock" ... 2>&1 | grep -v "find: "
600-
cmd := fmt.Sprintf(`find / ` + findopt[:len(findopt)-3] + ` 2>&1 | grep -v "find: "`)
599+
// find / -type f -and \( -name "package-lock.json" -o -name "yarn.lock" ... \) 2>&1 | grep -v "find: "
600+
cmd := fmt.Sprintf(`find / -type f -and \( ` + findopt[:len(findopt)-3] + ` \) 2>&1 | grep -v "find: "`)
601601
r := exec(l.ServerInfo, cmd, noSudo)
602602
if r.ExitStatus != 0 && r.ExitStatus != 1 {
603603
return xerrors.Errorf("Failed to find lock files")

subcmds/discover.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ func printConfigToml(ips []string) (err error) {
185185
#keyPath = "/home/username/.ssh/id_rsa"
186186
#scanMode = ["fast", "fast-root", "deep", "offline"]
187187
#scanModules = ["ospkg", "wordpress", "lockfile", "port"]
188+
#lockfiles = ["/path/to/package-lock.json"]
188189
#cpeNames = [
189190
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
190191
#]
191192
#owaspDCXMLPath = "/tmp/dependency-check-report.xml"
192193
#ignoreCves = ["CVE-2014-6271"]
193-
#containersOnly = false
194194
#containerType = "docker" #or "lxd" or "lxc" default: docker
195195
#containersIncluded = ["${running}"]
196196
#containersExcluded = ["container_name_a"]
@@ -209,6 +209,8 @@ host = "{{$ip}}"
209209
#scanModules = ["ospkg", "wordpress", "lockfile", "port"]
210210
#type = "pseudo"
211211
#memo = "DB Server"
212+
#findLock = true
213+
#lockfiles = ["/path/to/package-lock.json"]
212214
#cpeNames = [ "cpe:/a:rubyonrails:ruby_on_rails:4.2.1" ]
213215
#owaspDCXMLPath = "/path/to/dependency-check-report.xml"
214216
#ignoreCves = ["CVE-2014-0160"]

0 commit comments

Comments
 (0)