forked from vanhauser-thc/AutoNmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autonmap.sh
executable file
·65 lines (52 loc) · 2.28 KB
/
autonmap.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
65
#!/bin/bash
DATE=`date +%F`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
test -e /etc/autonmap.conf && . /etc/autonmap.conf || {
test -e /usr/local/etc/autonmap.conf && . /usr/local/etc/autonmap.conf || {
test -e "$DIR/"autonmap.conf && . "$DIR/"autonmap.conf || {
test -e ./autonmap.conf && . ./autonmap.conf || {
echo Error: can not find config file autonmap.conf, place it in /etc/
exit 1
}
}
}
}
test -n "$RUN_DIRECTORY" -a -n "$WEB_DIRECTORY" || {
echo Error: no configuration data loaded
exit 1
}
# be sure the paths are there
mkdir -p /usr/local/autonmap/
mkdir -p /var/www/autonmap/
echo "`date` - Welcome to AutoNmap2. "
# Ensure we can change to the run directory
cd $RUN_DIRECTORY || exit 2
echo "`date` - Running nmap, please wait. This may take a while. "
$NMAP --open -T4 -PN $SCAN_SUBNETS -n -oX scan-$DATE.xml --stylesheet "nmap.xsl" > /dev/null
echo "`date` - Nmap process completed with exit code $?"
# If this is not the first time autonmap2 has run, we can check for a diff. Otherwise skip this section, and tomorrow when the link exists we can diff.
if [ -e scan-prev.xml ]
then
echo "`date` - Running ndiff..."
# Run ndiff with the link to yesterdays scan and todays scan
DIFF=`$NDIFF scan-prev.xml scan-$DATE.xml`
echo "`date` - Checking ndiff output"
# There is always two lines of difference; the run header that has the time/date in. So we can discount that.
if [ `echo "$DIFF" | wc -l` -gt 2 ]
then
echo "`date` - Differences Detected. Sending mail."
echo -e "AutoNmap2 found differences in a scan for '${SCAN_SUBNETS}' since yesterday. \n\n$DIFF\n\nFull report available at $WEB_URL" | mail -s "AutoNmap2" $EMAIL_RECIPIENTS
else
echo "`date` - No differences, skipping mail. "
fi
else
echo "`date` - There is no previous scan (scan-prev.xml). Cannot diff today; will do so tomorrow."
fi
# Copy the scan report to the web directory so it can be viewed later.
echo "`date` - Copying XML to web directory. "
cp scan-$DATE.xml $WEB_DIRECTORY
# Create the link from today's report to scan-prev so it can be used tomorrow for diff.
echo "`date` - Linking todays scan to scan-prev.xml"
ln -sf scan-$DATE.xml scan-prev.xml
echo "`date` - AutoNmap2 is complete."
exit 0