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

Can not exclude specific files (only paths/directories is working) #223

Open
thl-cmk opened this issue Dec 30, 2021 · 10 comments
Open

Can not exclude specific files (only paths/directories is working) #223

thl-cmk opened this issue Dec 30, 2021 · 10 comments
Assignees
Labels
discussion question or suggestion enhancement New feature or request patch released

Comments

@thl-cmk
Copy link

thl-cmk commented Dec 30, 2021

Hi,

I need to exclude specific files (not paths/directories) from the scan. So far I have tryed the --exclude and --exclude-config options, but no success.

PS C:\> & .\log4j2-scan --exclude "C:\Program Files (x86)\checkmk\service\install\python-3.8.zip" --scan-logback --scan-log4j1 --scan-zip --silent c:\
Logpresso CVE-2021-44228 Vulnerability Scanner 2.6.5 (2021-12-29)
Scanning directory: c:\ (without C:\PROGRAM FILES (X86)\CHECKMK\SERVICE\INSTALL\PYTHON-3.8.ZIP)
Skipping broken jar file c:\Program Files (x86)\checkmk\service\install\python-3.8.zip ('zip END header not found')

and with the --exclude-config option

PS C:\> & .\log4j2-scan --scan-logback --scan-log4j1 --scan-zip --silent --exclude-config .\exclude.cfg c:\
Logpresso CVE-2021-44228 Vulnerability Scanner 2.6.5 (2021-12-29)
Scanning directory: c:\ (without C:\PROGRAM FILES (X86)\CHECKMK\SERVICE\INSTALL\PYTHON-3.8.ZIP)
Skipping broken jar file c:\Program Files (x86)\checkmk\service\install\python-3.8.zip ('zip END header not found')

In both cases the scanner showes the file as excluded but still tryes to scan it.

@xeraph xeraph self-assigned this Dec 30, 2021
@xeraph xeraph added the discussion question or suggestion label Dec 30, 2021
@xeraph
Copy link
Contributor

xeraph commented Dec 30, 2021

@thl-cmk You are right. Current version only excludes directories for maximum scan speed. If scanner tries to exclude also files, it should match all files (millions of..) and performance will be severely degraded. If you want to scan specific files, compose log4j2-scan with find command.

@thl-cmk
Copy link
Author

thl-cmk commented Dec 30, 2021

I see.

If you want to scan specific files
I want exacly the oposite, scann all files except a few...

@xeraph
Copy link
Contributor

xeraph commented Dec 30, 2021

Maybe another option should be added for that.. Exact full path match is relatively cheap (can use hash code), but current option uses prefix match for directory matching.. (comparison count = exclude pattern count x file count)

@thl-cmk
Copy link
Author

thl-cmk commented Dec 30, 2021

Exact full path match is relatively cheap

would be great to have this, so I could exclude known errors (broken zip for any reason for example)

@mrl-siemens
Copy link

This discussion confirms that --exclude-pattern is completely non-functional for files and will continue to be. Please update the help output to clarify that the pattern only applies to directory names, not file names.

@xeraph
Copy link
Contributor

xeraph commented Dec 30, 2021

@mrl-siemens Send me Pull Request. I think it already states directory like this:

--exclude [path_prefix]
        Full paths of ***directories*** whose absolute path starts with the specified value will be excluded.
        Does not support relative paths. You can specify multiple --exclude [path_prefix] pairs

--exclude-pattern [pattern]
        Exclude specified paths of ***directories*** by pattern. Supports fragments.
        You can specify multiple --exclude-pattern [pattern] pairs (non regex)

@mrl-siemens
Copy link

mrl-siemens commented Dec 30, 2021 via email

@xeraph xeraph added the enhancement New feature or request label Jan 2, 2022
@xeraph
Copy link
Contributor

xeraph commented Jan 2, 2022

@thl-cmk @mrl-siemens
Would you test v2.7.0 release? You can use --exclude-file-config option to specify exclude file path list.

@thl-cmk
Copy link
Author

thl-cmk commented Jan 2, 2022

@xeraph just tested. Windows looks good. Linux dosen't work :-(

the config file

thl-cmk@checkmk:~$ sudo cat /etc/check_mk/cve_2021_44228_log4j_exclude_files.cfg
# Specify file list. Files should be separated by new line. Prepend # for comment.
/home/thl-cmk/.cache/JetBrains/PyCharmCE2020.3/plugins/ideolog.zip
/home/thl-cmk/.cache/JetBrains/PyCharmCE2021.1/plugins/PowerShell.zip

the output from the scanner

thl-cmk@checkmk:~$ sudo /usr/lib/check_mk_agent/bin/log4j2-scan --exclude /mnt --exclude-file-config /etc/check_mk/cve_2021_44228_log4j_exclude_files.cfg --scan-logback --scan-log4j1 --scan-zip --no-symlink --silent /
Logpresso CVE-2021-44228 Vulnerability Scanner 2.7.1 (2022-01-02)
Scanning directory: / (without /mnt, /dev, /run, /dev/shm, /run/lock, /sys/fs/cgroup, /proc/sys/fs/binfmt_misc, /run/user/1000, /mnt/build, /mnt/cmk16nb)
Skipping broken jar file /home/thl-cmk/.cache/JetBrains/PyCharmCE2020.3/plugins/ideolog.zip ('Unexpected record signature: 0X1614')
Skipping broken jar file /home/thl-cmk/.cache/JetBrains/PyCharmCE2021.1/plugins/PowerShell.zip ('Unexpected record signature: 0X1754')
[?] Found CVE-2021-4104  (log4j 1.2) vulnerability in /usr/bin/pycharm/pycharm-community-2021.1.3/lib/log4j.jar, log4j 1.2.17.2 (mitigated)

Scanned 36078 directories and 297538 files
Found 0 vulnerable files
Found 0 potentially vulnerable files
Found 1 mitigated files
Completed in 33.60 seconds

as you can see the excluded files are not excluded.

@thl-cmk
Copy link
Author

thl-cmk commented Jan 13, 2022

@xeraph I did a little more digging on the Linux issu with the --exclude-file-config option. Looks like it is working for zip files that get skipped because of ('zip END header not found') but not for files skipped becaus of ('Unexpected record signature: 0X1614') for example or ('unsupported feature encryption used in entry settings').

Hope this will help to get this option fixed ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion question or suggestion enhancement New feature or request patch released
Projects
None yet
Development

No branches or pull requests

3 participants