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

Update log4shell_deep_scan.sh #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions log4shell/log4shell_deep_scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ fi
# 2: path of current archive to inspect
#######################################
checkarchive() {
manifest=$( ( unzip -l "$2" 2>/dev/null || echo '_unknownjar_' ) | grep -E '(Jndi.*\.class|\.[ejw]ar|_unknownjar_)$')

manifest=$( ( unzip -l "$2" 2>/dev/null || echo '_unknownjar_' ) | grep -E '(Jndi.*\.class|\.[nejw]ar|_unknownjar_)$')
# added n for NiFi nar files
if printf '%s\n' "$manifest" | grep -q '_unknownjar_' ; then
log 'WARN' "failed to read $1"
return 1
Expand All @@ -139,8 +139,8 @@ checkarchive() {
printf '%s\n' "$1"
else
# awk '{ind = index($0, $4); if (ind > 1) print substr($0, index($0, $4))}'
printf '%s\n' "$manifest" | grep -E '\.*[ejw]ar$' | while read -r line ; do
printf '%s\n' "$line" | grep -E '\.[ejw]ar$' | awk '{ind = index($0, $4); if (ind > 1) print substr($0, index($0, $4))}' | while read -r subarchive; do
printf '%s\n' "$manifest" | grep -E '\.*[nejw]ar$' | while read -r line ; do
printf '%s\n' "$line" | grep -E '\.[nejw]ar$' | awk '{ind = index($0, $4); if (ind > 1) print substr($0, index($0, $4))}' | while read -r subarchive; do
log 'INFO' "found $subarchive in $1"
extract_path=$(mktemp "tmp/tmp-XXXXXX")
unzip -p "$2" "$subarchive" 2>/dev/null > "$extract_path" || log 'WARN' "failed to read $1"
Expand All @@ -166,7 +166,7 @@ printf '%s\n' "Finding all JAR files under $search_root and scanning each."
printf '%s\n\n' "This can take several minutes. Ctrl-c to abort."
log 'INFO' "scanning $search_root on $hostname"
mkdir -p "tmp"
output=$(find "$search_root" -mount -type f -regex '.*\.[ejw]ar$' 2>/dev/null | while read -r file; do log 'INFO' "checking $file"; checkarchive "$file" "$file"; done)
output=$(find "$search_root" -mount -type f -regex '.*\.[nejw]ar$' 2>/dev/null | while read -r file; do log 'INFO' "checking $file"; checkarchive "$file" "$file"; done)
rmdir "tmp" 2>/dev/null


Expand Down