Skip to content

Commit 6d07f80

Browse files
committed
Add -network switch
1 parent 8501789 commit 6d07f80

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ page.
3535
```
3636
$ ./local-log4j-vuln-scanner [--verbose] [--quiet] \
3737
[--ignore-v1] [--ignore-vulns=...] \
38-
[--exclude /path/to/exclude …] [--log /path/to/file.log] \
38+
[--exclude /path/to/exclude …] \
39+
[--scan-network] \
40+
[--log /path/to/file.log] \
3941
/path/to/app1 /path/to/app2 …
4042
```
4143

@@ -54,6 +56,8 @@ The `--log` flag allows everythig to be written to a log file instead of stdout/
5456

5557
Use the `--exclude` flag to exclude subdirectories from being scanned. Can be used multiple times.
5658

59+
The `--scan-network` flag tells the scanner to search network filesystems (disabled by default). This has not been implemented for Windows.
60+
5761
If class files indicating one of the vulnerabilities are found,
5862
messages like the following are printed to standard output:
5963
``` console

scanner/fs_darwin.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,26 @@ func typeToString(name [16]int8) string {
1717
return string(b)
1818
}
1919

20+
func isPseudoFS(path string) bool {
21+
var buf syscall.Statfs_t
22+
if err := syscall.Statfs(path, &buf); err != nil {
23+
return false
24+
}
25+
switch typeToString(buf.Fstypename) {
26+
case "devfs":
27+
return true
28+
default:
29+
return false
30+
}
31+
}
32+
2033
func isNetworkFS(path string) bool {
2134
var buf syscall.Statfs_t
2235
if err := syscall.Statfs(path, &buf); err != nil {
2336
return false
2437
}
2538
switch typeToString(buf.Fstypename) {
26-
case "nfs", "afpfs", "smbfs", "webdav", "devfs":
39+
case "nfs", "afpfs", "smbfs", "webdav":
2740
return true
2841
default:
2942
return false

scanner/fs_generic.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
package main
44

5+
func isPseudoFS(string) bool { return false }
6+
57
func isNetworkFS(string) bool { return false }

scanner/fs_linux.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,13 @@ const (
106106
OPENAFS_FS_MAGIC = 0x5346414f
107107
)
108108

109-
func isNetworkFS(path string) bool {
109+
func isPseudoFS(path string) bool {
110110
var buf syscall.Statfs_t
111111
if err := syscall.Statfs(path, &buf); err != nil {
112112
return false
113113
}
114114
switch uint32(buf.Type) {
115115
case
116-
// pseudo filesystems
117116
BDEVFS_MAGIC,
118117
BINFMTFS_MAGIC,
119118
CGROUP_SUPER_MAGIC,
@@ -125,8 +124,20 @@ func isNetworkFS(path string) bool {
125124
PROC_SUPER_MAGIC,
126125
SELINUX_MAGIC,
127126
SMACK_MAGIC,
128-
SYSFS_MAGIC,
129-
// network filesystems
127+
SYSFS_MAGIC:
128+
return true
129+
default:
130+
return false
131+
}
132+
}
133+
134+
func isNetworkFS(path string) bool {
135+
var buf syscall.Statfs_t
136+
if err := syscall.Statfs(path, &buf); err != nil {
137+
return false
138+
}
139+
switch uint32(buf.Type) {
140+
case
130141
AFS_FS_MAGIC,
131142
OPENAFS_FS_MAGIC,
132143
CEPH_SUPER_MAGIC,

scanner/main.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var quiet bool
104104
var vulns filter.Vulnerabilities
105105
var ignoreVulns filter.Vulnerabilities = filter.CVE_2021_45046 | filter.CVE_2021_44832
106106
var ignoreV1 bool
107+
var network bool
107108

108109
func main() {
109110
flag.Var(&excludes, "exclude", "paths to exclude (can be used multiple times)")
@@ -112,6 +113,7 @@ func main() {
112113
flag.BoolVar(&quiet, "quiet", false, "no ouput unless vulnerable")
113114
flag.BoolVar(&ignoreV1, "ignore-v1", false, "ignore log4j 1.x versions")
114115
flag.Var(&ignoreVulns, "ignore-vulns", "ignore vulnerabilities")
116+
flag.BoolVar(&network, "scan-network", false, "search network filesystems")
115117

116118
flag.Parse()
117119

@@ -144,12 +146,19 @@ func main() {
144146

145147
for _, root := range flag.Args() {
146148
filepath.Walk(filepath.Clean(root), func(path string, info os.FileInfo, err error) error {
147-
if isNetworkFS(path) {
149+
if isPseudoFS(path) {
148150
if !quiet {
149-
fmt.Fprintf(logFile, "Skipping %s: pseudo or network filesystem\n", path)
151+
fmt.Fprintf(logFile, "Skipping %s: pseudo filesystem\n", path)
150152
}
151153
return filepath.SkipDir
152154
}
155+
if !network && isNetworkFS(path) {
156+
if !quiet {
157+
fmt.Fprintf(logFile, "Skipping %s: network filesystem\n", path)
158+
}
159+
return filepath.SkipDir
160+
}
161+
153162
if !quiet {
154163
fmt.Fprintf(logFile, "examining %s\n", path)
155164
}

0 commit comments

Comments
 (0)