Skip to content

Commit 0b7e58e

Browse files
thorhs1lann
authored andcommitted
Added additional file types and also exit code.
I added .ear and .zip to types of file to test. Also added an exit code if a match is found. Exit codes: * 0: No match found * 1: Error * 2: Error parsing flags * 3: Match was found This enables integration with Ansible, e.g: ```yaml --- - hosts: all become: true tasks: - name: Copy log4shelldetect to remote host copy: src: /home/XXX/log4shelldetect dest: /tmp/log4shelldetect mode: "0555" - name: Search for log4j shell: cmd: "/tmp/log4shelldetect -mode=list /" register: log4shelldetect changed_when: log4shelldetect.rc == 3 failed_when: log4shelldetect.rc == 1 or log4shelldetect.rc == 2 - name: copy: dest: "/home/XXX/log4shelldetect.out/{{ ansible_fqdn }}" content: "{{ log4shelldetect.stdout }}\n" when: log4shelldetect.rc == 3 delegate_to: localhost ```
1 parent dd84757 commit 0b7e58e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

main.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func main() {
6060
Callback: func(osPathname string, de *godirwalk.Dirent) error {
6161
// For each file in the directory, check if it ends in ".jar"
6262
ext := strings.ToLower(filepath.Ext(osPathname))
63-
if ext == ".jar" || ext == ".war" {
63+
if ext == ".jar" || ext == ".war" || ext == ".ear" || ext == ".zip" {
6464
pool <- struct{}{}
6565
// If it is, take a goroutine (thread) from the thread pool
6666
// and check the jar.
@@ -89,6 +89,8 @@ func main() {
8989
for i := 0; i < cap(pool); i++ {
9090
pool <- struct{}{}
9191
}
92+
93+
os.Exit(found)
9294
}
9395

9496
// checkJar checks a given jar file and returns a status and description for whether
@@ -194,7 +196,7 @@ func checkJar(pathToFile string, rd io.ReaderAt, size int64, depth int) (status
194196

195197
// If there is a jar in the jar, recurse into it.
196198
ext := strings.ToLower(path.Ext(file.Name))
197-
if ext == ".jar" || ext == ".war" {
199+
if ext == ".jar" || ext == ".war" || ext == ".ear" || ext == ".zip" {
198200
var subStatus Status
199201
var subDesc string
200202
// If the jar is larger than 500 MB, this can be dangerous
@@ -285,6 +287,8 @@ const (
285287
StatusVulnerable
286288
)
287289

290+
var found = 0
291+
288292
// printStatus takes in the path to the file, status and description, and
289293
// prints the result out to stdout.
290294
func printStatus(fileName string, status Status, desc string) {
@@ -295,6 +299,7 @@ func printStatus(fileName string, status Status, desc string) {
295299
if *mode == "list" {
296300
if status == StatusVulnerable || status == StatusMaybe {
297301
fmt.Println(fileName)
302+
found = 3
298303
}
299304

300305
return
@@ -309,12 +314,15 @@ func printStatus(fileName string, status Status, desc string) {
309314
case StatusPatched:
310315
c = color.New(color.FgGreen)
311316
c.Print("PATCHED ")
317+
found = 3
312318
case StatusVulnerable:
313319
c = color.New(color.FgRed)
314320
c.Print("VULNRBL ")
321+
found = 3
315322
case StatusMaybe:
316323
c = color.New(color.FgRed)
317324
c.Print("MAYBE ")
325+
found = 3
318326
case StatusUnknown:
319327
c = color.New(color.FgYellow)
320328
c.Print("UNKNOWN ")

0 commit comments

Comments
 (0)