forked from perryflynn/find-log4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-log4j-docker.sh
36 lines (24 loc) · 910 Bytes
/
find-log4j-docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Finds log4j resources in running docker containers
# by Christian Blechert <christian@serverless.industries>
while read -r CONTAINER
do
CONTAINER=$(echo "$CONTAINER" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
if [ -z "$CONTAINER" ]; then
continue
fi
while read -u 3 -r JAR
do
JAR=$(echo "$JAR" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
if [ -z "$JAR" ]; then
continue
fi
rm -f moep.jar
docker cp "$CONTAINER:$JAR" moep.jar
NUM=$(unzip -l moep.jar | grep -P "^\s+[0-9]+\s+[0-9-]+\s+[0-9:]+\s+.+" | awk '{print $4}' | grep -P 'org/apache/(log4j|logging/log4j)' | wc -l)
if [ $NUM -gt 0 ]; then
echo "$CONTAINER @ $JAR"
fi
done 3<<< "$(docker exec -u root $CONTAINER find / -type f -name "*.jar" 2> /dev/null)"
done <<< "$(docker ps --format '{{.Names}}')"
# eof