forked from juaromu/wazuh-yara
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyara_full_scan.sh
More file actions
54 lines (49 loc) · 1.92 KB
/
yara_full_scan.sh
File metadata and controls
54 lines (49 loc) · 1.92 KB
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
#!/bin/bash
# This program is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
#------------------------- Set Memory Limit (KB)-------------------------#
ulimit -v 128000
#------------------------- Aadjust IFS to read files -------------------------#
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# Static active response parameters
LOCAL=`dirname $0`
#------------------------- Folders to scan. Modify array as required -------------------------#
folders_to_scan=( "/home/" "/root/" )
#------------------------- Files extensions to scan. Modify array as required -------------------------#
file_extenstions_to_scan=( ".sh" ".bin" ".js" )
#------------------------- Active Response Log File -------------------------#
LOG_FILE="/var/ossec/logs/active-responses.log"
#------------------------- Main workflow --------------------------#
# Execute YARA scan on home folder and subfolders
for f in "${folders_to_scan[@]}"
do
for f1 in $( find $f -type f); do
yara_output=$(/usr/bin/yara -C -w -r -f -m /usr/share/yara/yara_base_ruleset_compiled.yar "$f1")
if [[ $yara_output != "" ]]
then
# Iterate every detected rule and append it to the LOG_FILE
while read -r line; do
echo "wazuh-yara: info: $line" >> ${LOG_FILE}
done <<< "$yara_output"
fi
done
done
# Execute YARA scan on files types, all locations
for e in "${file_extenstions_to_scan[@]}"
do
for f1 in $( find / -type f | grep -F $e ); do
yara_output=$(/usr/bin/yara -C -w -r -f -m /usr/share/yara/yara_base_ruleset_compiled.yar "$f1")
if [[ $yara_output != "" ]]
then
# Iterate every detected rule and append it to the LOG_FILE
while read -r line; do
echo "wazuh-yara: info: $line" >> ${LOG_FILE}
done <<< "$yara_output"
fi
done
done
IFS=$SAVEIFS
exit 1;