Skip to content

Commit

Permalink
Separate jar/war/ear in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Skjaldbaka17 committed Dec 23, 2021
1 parent 79f22b4 commit a35b15e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,32 @@ Download binaries (Windows, Linux, Darwin, OpenBSD) here https://github.com/nani

Scan file for vulnerability
```
./bin/log4fix detect </path/to/file.war>
log4fix detect </path/to/file.war>
```

Scan file for vulnerability and remove the vulnerable class.
```
./bin/log4fix fix </path/to/file.war> --overwrite
log4fix fix </path/to/file.war> --overwrite
```

Scan directory for vulnerability.
Scan single directory for vulnerability.
```
./bin/log4fix scan </path/to/dir>
log4fix scan </path/to/dir>
```

Scan multiple directories for vulnerability.
```
log4fix scan </path/to/dir/1> </path/to/dir/2>
```

Scan directory for vulnerability and remove the vulnerable files. Note, this command overwrites the war/ear/jar files containing the vulnerable class that are found.
```
./bin/log4fix scan </path/to/dir> --fix
log4fix scan </path/to/dir> --fix
```

Scan directory for vulnerability and write the vulnerable jar/ear/war files found into the file supplied.
```
./bin/log4fix scan </path/to/dir> --output </path/to/text/file.txt>
log4fix scan </path/to/dir> --output </path/to/text/file.txt>
```

We recommend taking a backup of the files prior to overwriting them.
Expand Down
29 changes: 21 additions & 8 deletions finder/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ func Scan(dirPaths []string) ([]string, error) {

func ScanDir(dirPath string) ([]string, error) {
compressedFiles := []string{}
r, _ := regexp.Compile(`.*\.(jar|war|ear)`)
rJar, _ := regexp.Compile(`.*\.jar`)
rWar, _ := regexp.Compile(`.*\.war`)
rEar, _ := regexp.Compile(`.*\.ear`)
fileCount := 0
errCount := 0
jarFileCount := 0
warFileCount := 0
earCount := 0

fmt.Printf("\nScanning %s\n\n", dirPath)
IOLogger.Printf("Scanning %s\n", dirPath)
Expand All @@ -33,24 +38,32 @@ func ScanDir(dirPath string) ([]string, error) {

ErrorLogger.Printf("%v\n", err)
if fileCount%1000 == 0 {
IOLogger.Printf("Number of files scanned: %d \nNumber of files unable to access: %d\nNumber of JAR/WAR/EAR found: %d\n", fileCount, errCount, len(compressedFiles))
IOLogger.Printf("Number of files scanned: %d \nNumber of files unable to access: %d\nNumber of .JAR found: %d\nNumber of .WAR found: %d\nNumber of .EAR found: %d\n", fileCount, errCount, jarFileCount, warFileCount, earCount)
}

return nil
}

if fileCount%1000 == 0 {
IOLogger.Printf("Number of files scanned: %d \nNumber of files unable to access: %d\nNumber of JAR/WAR/EAR found: %d\n", fileCount, errCount, len(compressedFiles))
}

filename := filepath.Base(path)
if r.MatchString(filename) {

if rJar.MatchString(filename) {
compressedFiles = append(compressedFiles, path)
jarFileCount++
} else if rWar.MatchString(filename) {
compressedFiles = append(compressedFiles, path)
warFileCount++
} else if rEar.MatchString(filename) {
compressedFiles = append(compressedFiles, path)
earCount++
}

if fileCount%1000 == 0 {
IOLogger.Printf("Number of files scanned: %d \nNumber of files unable to access: %d\nNumber of .JAR found: %d\nNumber of .WAR found: %d\nNumber of .EAR found: %d\n", fileCount, errCount, jarFileCount, warFileCount, earCount)
}
return nil
})

IOLogger.Printf("Number of files scanned: %d \nNumber of files unable to access: %d\nNumber of JAR/WAR/EAR found: %d\n", fileCount, errCount, len(compressedFiles))
IOLogger.Printf("Number of files scanned: %d \nNumber of files unable to access: %d\nNumber of .JAR found: %d\nNumber of .WAR found: %d\nNumber of .EAR found: %d\n", fileCount, errCount, jarFileCount, warFileCount, earCount)
IOLogger.Close()

return compressedFiles, nil
Expand Down

0 comments on commit a35b15e

Please sign in to comment.