-
Notifications
You must be signed in to change notification settings - Fork 0
/
log4j_detector.sh
executable file
·64 lines (59 loc) · 2.47 KB
/
log4j_detector.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#ddd
if [ $# -eq 0 ]
then
echo "No arguments supplied"
exit
fi
check_variables () {
if [ -z ${LOG4J_FORMAT_MSG_NO_LOOKUPS} ]; then
echo "Enviroment Variable Not Found!"
else
echo "LOG4J_FORMAT_MSG_NO_LOOKUPS enviroment variable found!"
fi
proc=$(ps -ef | grep java | grep -v grep)
result=$(ps -ef | grep java | grep -v grep | grep log4j2.formatMsgNoLookups=true | wc -l)
# echo "Found java procces: " $proc
if [ $((result)) -eq 0 ]; then
echo "Java Flag Not Found!"
else
echo "Found Java Flag!"
fi
}
check_jar(){
# echo "Checking jars"
wget 'https://raw.githubusercontent.com/RoiSec/log4j_detector/main/logpresso/logpresso-log4j2-scan-1.6.3.jar' --no-check-certificate -q -O '/tmp/logpresso-log4j2-scan-1.6.3.jar' 2>/dev/null
curl -s 'https://raw.githubusercontent.com/RoiSec/log4j_detector/main/logpresso/logpresso-log4j2-scan-1.6.3.jar' -o '/tmp/logpresso-log4j2-scan-1.6.3.jar' 2>/dev/null
FILE=$1
java_path=$(find /usr/ /bin/ -name java -type f -perm /a+x 2>/dev/null | head -n 1)
# echo $java_path
eval $java_path -jar /tmp/logpresso-log4j2-scan-1.6.3.jar $FILE >>/tmp/out.txt 2>/dev/null
grep -i "Found CVE-2021-44228" /tmp/out.txt 2>/dev/null
result=$(grep -i "Found CVE-2021-44228" /tmp/out.txt | wc -l 2>/dev/null)
if [ $((result)) -ne 0 ]; then
check_variables
fi
rm /tmp/out.txt 2>/dev/null
# else
# echo "$FILE File not exists."
rm /tmp/logpresso-log4j2-scan-1.6.3.jar 2>/dev/null
}
check_container () {
jar_paths=$1
for containerId in $(docker ps -q)
do
echo -n "Image Name: " ;docker ps -f "id=$containerId" --format '{{.Image}}'
docker exec -i $containerId sh -c 'wget https://raw.githubusercontent.com/RoiSec/log4j_detector/main/log4j_detector.sh -q --no-check-certificate -O /tmp/log4j_detector.sh' 2>/dev/null
docker exec -i $containerId sh -c 'curl -s https://raw.githubusercontent.com/RoiSec/log4j_detector/main/log4j_detector.sh -o /tmp/log4j_detector.sh' 2>/dev/null
docker exec -i $containerId sh -c 'chmod +x /tmp/log4j_detector.sh'
# cmd="./log4j_detector.sh ${jar_paths}"
# echo $cmd
docker exec -i $containerId sh -c "/tmp/log4j_detector.sh $jar_paths"
docker exec -i $containerId sh -c 'rm /tmp/log4j_detector.sh'
echo ""
done
}
check_jar "$1" #array argument from client
if docker info > /dev/null 2>&1; then
check_container "$1"
fi