Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Henrik #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

![logo](logo.png)


(Written in Go because, you know, "write once, run anywhere.")

This is a simple tool that can be used to find vulnerable instances of
Expand Down
Binary file added local-log4j-vuln-scanner
Binary file not shown.
30 changes: 30 additions & 0 deletions scanner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var logFile = os.Stdout
var errFile = os.Stderr
var deletefiles []string

func handleJar(path string, ra io.ReaderAt, sz int64) {
if verbose {
Expand Down Expand Up @@ -71,12 +72,28 @@ func handleJar(path string, ra io.ReaderAt, sz int64) {
if info := filter.IsVulnerableClass(buf.Bytes(), file.Name, vulns); info != nil {
fmt.Fprintf(logFile, "indicator for vulnerable component found in %s (%s): %s %s %s\n",
path, file.Name, info.Filename, info.Version, info.Vulnerabilities&vulns)
if del {
mkDelFileSlice(path)
}
continue
}
}
}
}

func mkDelFileSlice(path string) {
warJar := strings.Split(string(path), "::")
exists := false
for _, file := range deletefiles {
if file == warJar[0] {
exists = true
}
}
if !exists {
deletefiles = append(deletefiles, warJar[0])
}
}

type excludeFlags []string

func (flags *excludeFlags) String() string {
Expand Down Expand Up @@ -105,6 +122,7 @@ var vulns filter.Vulnerabilities
var ignoreVulns filter.Vulnerabilities = filter.CVE_2021_45046 | filter.CVE_2021_44832
var ignoreV1 bool
var network bool
var del bool

func main() {
flag.Var(&excludes, "exclude", "paths to exclude (can be used multiple times)")
Expand All @@ -114,6 +132,7 @@ func main() {
flag.BoolVar(&ignoreV1, "ignore-v1", false, "ignore log4j 1.x versions")
flag.Var(&ignoreVulns, "ignore-vulns", "ignore vulnerabilities")
flag.BoolVar(&network, "scan-network", false, "search network filesystems")
flag.BoolVar(&del, "del", false, "delete vulnerable files")

flag.Parse()

Expand Down Expand Up @@ -195,7 +214,18 @@ func main() {
return nil
})
}
if del {
for _, file := range deletefiles {
// fmt.Println("Trying to delete: " + file)
err := os.Remove(file)
if err != nil {
fmt.Println("Got error trying to delete file: " + err.Error())
} else {
fmt.Println(file + " deleted.")
}
}

}
if !quiet {
fmt.Println("\nScan finished")
}
Expand Down