-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathelog
261 lines (218 loc) · 5.75 KB
/
elog
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
####################################################################
# Elog is a depedency of Eternal Scanner (Denveloped by peterpt) #
# https://gitlab.com/peterpt/eternal_scanner #
####################################################################
#setup colors
green='\033[92m'
yellow='\e[0;33m'
orange='\e[38;5;166m'
cyan='\e[0;36m'
sleep 3
if [ "$EUID" -ne 0 ]
then
root="n"
else
root="y"
fi
# Set Default Data directory
if [[ "$root" == "y" ]]
then
defdir="/usr/local/share/Eternal_Scanner"
else
echo "This tools requires root previleges to run"
exit 0
fi
# Default file that defines which program is running
masstat="$defdir/stat"
if [[ ! -f "$masstat" ]]
then
echo -e "$green""Elog is a dependency from Eternal Scanner"
echo -e "Run escan instead"
exit 1
fi
stat=$(sed -n '1p' < $masstat)
echo ""
# When CTRL+C is pressed
trap ctrl_c INT
function ctrl_c() {
if [ "$stat" == "1" ]
then
pkill -f masscan* >/dev/null 2>&1
rm -rf "$defdir/pid.tmp" >/dev/null 2>&1
elif [ "$stat" == "2" ]
then
kill "$PID" >/dev/null 2>&1
rm -rf "$defdir/pid.tmp" >/dev/null 2>&1
fi
exit 1
}
# Read Process ID generated by escan
PID=$(cat $defdir/pid.tmp)
function start(){
# Define where it should be msflog file
mlog="$defdir/msflog.log"
# Check if msfconsole pid is running
ps --pid "$PID" &>/dev/null
pd="$?"
# Start routine to grab the value "100% from msflog file"
# In case metasploit already exited then
if [ "$pd" -eq "1" ]
then
# Check if msflog file exists
if [ -f "$mlog" ]
then
# open the log and search in last lines the value (Scanned)"
gmsf=$(sed -n -e 's/^.*Scanned //p' $mlog | tail -1 | sed 's/ *$//')
if [[ -z "$gmsf" ]]
then
gmsft="Verified: "
else
gmsft="Verified: $gmsf"
fi
# Compare output with current value of variable (a)
# At this point variable (a) should be at < (Scanned 90%) from msflog
if [ "$gmsft" != "$a" ]
then
# In case the values are different then display that line (100%) and exit elog
echo "$gmsft"
exit 0
fi
fi
else
# In case msflog does not exists yet then start a timing process to wait for it .
# Some machines may take a while to load metasploit , and this is why this timming exists
if [ ! -f "$mlog" ]
then
# Increase tm value + 1 from its current value
tm=$((tm+1))
# until 60s if msflog is not created then elog will exit
if [ "$tm" == "60" ]
then
echo -e "$yellow" "Metasploit Not Detected"
exit 0
else
# Timmer is not yet at 60 , pause 1 second and loop again
sleep 1
start
fi
else
# At this point msfconsole PID is running and msflog was generated to be consulted
# gmsft will grab the last value (scanned) from msflog
gmsf=$(sed -n -e 's/^.*Scanned //p' $mlog | tail -1 | sed 's/ *$//')
if [[ -z "$gmsf" ]]
then
gmsft="Verified: "
else
gmsft="Verified: $gmsf"
fi
# In case gmsft is equal to variable (a) then set variable a with same value and wait 1 second
if [ "$gmsft" == "$a" ]
then
a="$gmsft"
sleep 1
# timer value sets to 59 of 60 seconds , this way when elog ends its job it will reach 60s in 1 second and will exit itself so escan can continue its job
tm="59"
#start loop
start
else
# In case gmsft is different then variable (a) then setup a with same value
# this process avoids repeating the same percentage on screen from msflog
echo "$gmsft"
a="$gmsft"
tm="59"
sleep 1
# start loop
start
fi
fi
fi
}
# output splash screen when elog will check metasploit
msfc(){
echo -e "$orange" "+-----------------------------------------------------+"
echo -e "$orange" "|$green Realtime Eternal Scan Metasploit 6 results Checkout$orange |"
echo -e "$orange" "+-----------------------------------------------------+"
echo -e "$orange" "|$yellow Please wait for percentage output $orange |"
echo -e "$orange" "+-----------------------------------------------------+$cyan"
# Timer start value to wait for msflog file generated by metasploit
tm="0"
# variable used to check in msflog for percentage
a="Verified: "
}
mass() {
# Define where it should be masscan file
massl="$defdir/masscan"
# Check if masscan pid is running
ps --pid "$PID" &>/dev/null
pd="$?"
if [ "$pd" -eq "1" ]
then
if [ -f "$massl" ]
then
gmsft=$(grep "open" $massl | wc -l)
if [ "$gmsft" != "$a" ]
then
echo -ne "$yellow $gmsft$cyan Ips To Check Ahead\033[0K\r"
exit 1
fi
fi
else
if [ ! -f "$massl" ]
then
tm=$((tm+1))
# until 10s if masscan file output is not created then elog will exit
if [ "$tm" == "10" ]
then
echo -e "$yellow" "Masscan file was not found"
rm -rf "$defdir/pid.tmp" >/dev/null 2>&1
exit 1
else
# Timmer is not yet at 10 , pause 1 second and loop again
sleep 1
mass
fi
else
# At this point masscan PID is running and masscan ip output was generated to be consulted
# gmsft will grab the last value (scanned) from masscan
gmsft=$(grep "open" $massl | wc -l)
# In case gmsft is equal to variable (a) then set variable a with same value and wait 1 second
if [ "$gmsft" == "$a" ]
then
a="$gmsft"
sleep 1
# timer value sets to 9 of 10 seconds , this way when elog ends its job it will reach 15s in 1 second and will exit itself so escan can continue its job
tm="9"
#start loop
mass
else
# In case gmsft is different then variable (a) then setup a with same value
# this process avoids repeating the same percentage on screen from scanner output
echo -ne "$green Ips detected with port$yellow 445$green opened so far$yellow :$cyan $gmsft\033[0K\r"
a="$gmsft"
tm="9"
sleep 1
# start loop
mass
fi
fi
fi
}
masplsh () {
echo -e "$orange -------------------------------------------"
echo -e "$orange |$green Scanning for Ips with port$yellow 445$green opened $orange |"
echo -e "$orange -------------------------------------------"
echo ""
}
# If stat file is 1 then it means that masscan is running
if [ "$stat" == "1" ]
then
masplsh
mass
fi
# If stat file is 2 then it means that metasploit is running
if [ "$stat" == "2" ]
then
msfc
start
fi