-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-db.sh
executable file
·63 lines (57 loc) · 2.01 KB
/
find-db.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
#!/bin/sh
set -eu
usage() {
echo "Usage: ${0##*/} <target-hosts-list.txt> <exclude-hosts-list.txt>"
}
if [ "$#" -eq 0 ]; then
echo "Error: Target hosts must be specified"
usage
exit 1
fi
if [ "$1" = "-h" ]; then
usage
exit 0
fi
today=`date +%Y%m%d`
if [ ! -d ./results/${today} ]; then
mkdir -p ./results/${today}
fi
hosts=`cat $1`
echo "Target: ${hosts}"
if [ "$#" -eq 2 ]; then
exclude_hosts=`cat $2`
for h in $hosts
do
host_name=`echo $h | tr "/" "_"`
# MySQL
now=`date +%Y%m%d_%H%M%S`
echo "Now Launching: nmap --exclude ${exclude_hosts} -p3306 -v -oX results/${today}/${host_name}_mysql_${now}.xml ${h}"
nmap --exclude ${exclude_hosts} -p3306 -v -oX results/${today}/${host_name}_mysql_${now}.xml ${h}
# PostgresSQL
now=`date +%Y%m%d_%H%M%S`
echo "Now Launching: nmap --exclude ${exclude_hosts} -p5432 -v -oX results/${today}/${host_name}_postgre_${now}.xml ${h}"
nmap --exclude ${exclude_hosts} -p5432 -v -oX results/${today}/${host_name}_postgres_${now}.xml ${h}
# Redis
now=`date +%Y%m%d_%H%M%S`
echo "Now Launching: nmap --exclude ${exclude_hosts} -p6379 -v -oX results/${today}/${host_name}_redis_${now}.xml ${h}"
nmap --exclude ${exclude_hosts} -p6379 -v -oX results/${today}/${host_name}_redis_${now}.xml ${h}
done
fi
if [ "$#" -eq 1 ]; then
for h in $hosts
do
host_name=`echo $h | tr "/" "_"`
# MySQL
now=`date +%Y%m%d_%H%M%S`
echo "Now Launching: nmap -p3306 -v -oX results/${today}/${host_name}_mysql_${now}.xml ${h}"
nmap -p3306 -v -oX results/${today}/${host_name}_mysql_${now}.xml ${h}
# PostgresSQL
now=`date +%Y%m%d_%H%M%S`
echo "Now Launching: nmap -p5432 -v -oX results/${today}/${host_name}_postgre_${now}.xml ${h}"
nmap -p5432 -v -oX results/${today}/${host_name}_postgres_${now}.xml ${h}
# Redis
now=`date +%Y%m%d_%H%M%S`
echo "Now Launching: nmap -p6379 -v -oX results/${today}/${host_name}_redis_${now}.xml ${h}"
nmap -p6379 -v -oX results/${today}/${host_name}_redis_${now}.xml ${h}
done
fi