-
Notifications
You must be signed in to change notification settings - Fork 1
/
enmass3.sh
212 lines (168 loc) · 5.3 KB
/
enmass3.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
#bash -n driver.sh # dry run for syntax
#bash -v driver.sh # trace
#bash -x driver.sh # more vergbose trace
#Fail safe
set -o errexit # fail on exit
set -o nounset # fail on variable issues
set -o pipefail # fail for pipe related stuff
#Create a Log Directory
function debug_dir()
{
mkdir ./"${1}"
printf "Creating a Directory for Debugging!!\n"
}
function check_masscan()
{
if ! [ -x "$(command -v masscan)" ]
then
:
#installing masscan
printf "Masscan is not installed, Installing it!!\n"
#building from source
#echo 'Installing Dependancies for masscan'
#apt-get --assume-yes install git libpcap-dev make gcc 1>/dev/null 2>depenadancies.error_log.log
#cd /opt && git clone https://github.com/robertdavidgraham/masscan 1>/dev/null 2>depenadancies.error_log.log
#cd /opt/masscan && make 1>/dev/null 2>depenadancies.error_log.log
#using repo
apt install masscan 1>/dev/null 2>./debug/depenadancies.error_log.log
printf "Masscan Installed\n"
exit
else
:
#echo 'masscan installed'
#return 0
fi
}
function check_nrich()
{
if ! [ -x "$(command -v nrich)" ]
then
:
#installing masscan
printf 'Nrich not installed\n'
printf "installing nrich\n"
apt install wget 1>/dev/null 2>./debug/depenadancies.error_log.log
mkdir /opt/nrich && cd "$_" && wget https://gitlab.com/api/v4/projects/33695681/packages/generic/nrich/latest/nrich_latest_amd64.deb 1>/dev/null 2>./debug/depenadancies.error_log.log
apt install /opt/nrich/nrich_latest_amd64.deb 1>/dev/null 2>./debug/depenadancies.error_log.log
printf "Nrich Installed!"
exit
else
:
#echo 'nrich installed'
#return 0
fi
}
function check_jq()
{
if ! [ -x "$(command -v jq)" ]
then
:
#jq not found installing jq
printf 'JQ not installed\n'
printf "Installing jq\n"
apt install jq 1>/dev/null 2>./debug/depenadancies.error_log.log
printf "jq Installed!"
exit
else
:
#echo 'jq already installed'
#return 0
fi
}
function check_inputFile()
{
inputFile="$1"
if [ -f "${inputFile}" ]; then
echo "${inputFile} exists"
if grep -q -E '[0-9]{1,3}(?:\.[0-9]{1,3}){0,3}\/[0-9]+' "${inputFile}"; then
echo "${inputFile} format is valid"
return 0
else
echo "${inputFile} has invalid IP CIDR blocks, provide one in a valid format"
fi
else
echo "${inputFile} does not exist, please provide a valid file name"
exit
fi
}
# function masscan_grepaableOutput()
# {
# sudo masscan -iL "$1" --excludeFile AntiScanIPList.txt --top-ports 20 ---max-rate 100000 -oG masscan_output.txt 2>|./masscan.error_log.log
# }
function masscan_jsonOutput()
{
masscan -iL "$1" --excludeFile AntiScanIPList.txt --top-ports --rate "${2}" --wait "${3}" -oJ masscan_output.json 2>|./"${4}"/masscan.error_log.log
}
# function extractIp_awk()
# {
# while IFS= read -r line || [[ -n "$line" ]]; do
# awk '{print $4}' >> nrich_input.txt
# done < masscan_output.txt
# }
function extractIp_jq()
{
jq -r '.[].ip' masscan_output.json >> nrich_input.txt
}
function nrichScan_json()
{
nrich --output json nrich_input.txt 1>|./enmass3_output.json 2>|./"${1}"/nrich.error_log.log
}
# function nrichScan_ndjson()
# {
# nrich --output ndjson nrich_input.txt 1>|./enmass3_output.ndjson 2>|./"${1}"/nrich.error_log.log
# }
function nrichScan_shell()
{
nrich --output shell nrich_input.txt 1>|./enmass3_output.txt 2>|./"${1}"/nrich.error_log.log
}
trapcleanup()
{
#rm -f nrich_input.txt
#rm -f
echo 'Trapped!'
}
main()
{
trap trapcleanup INT TERM ERR
clear
# checking for sudo perms
if [ "$EUID" -ne 0 ];then
echo "Run the script as root"
echo "Exitting..."
exit
fi
# checking if inputfile is provided as a parameter
[[ "$#" -eq "0" ]] && { echo "No inputfile provided"; exit 1; } || { var=$1; echo -n "${var:?No file}" "being used as the input file"; echo ""; }
# setting debug directory
debug_directory="debug"
# creating a debug directory
debug_dir "${debug_directory}"
# check depenadancies
if check_masscan && check_nrich && check_jq; then
:
#echo " -> All Dependancies Installed..."
# check meta input file
if check_inputFile "$1" ; then
:
#echo " -> All checks done"
echo "Running masscan..."
# running masscan
masscan_jsonOutput "$1" "250000" "3.7" "${debug_directory}"
echo "Extracting Ips"
# extracting ips from json output
extractIp_jq
echo "Running nrich..."
# running nrich
nrichScan_shell "${debug_directory}"
echo "Scanning complete! Look at enmass3_output.json for the results"
times
fi
fi
}
# set -x # set Debug
# for source issues
if ! (return 0 2> /dev/null); then
main "$@"
fi
# set +x # unset Debug