-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsshranger
193 lines (125 loc) · 3.85 KB
/
sshranger
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
#!/bin/bash
#Written by xVlaze
#Version: 1.0
function scan() {
#Traps the script in an infinite loop the only way of getting out of it is choosing a valid option
while true; do
read -p "Enter your preferred scanning style. Type 'help' for more information: " STYLE
case "$STYLE" in
"arp")
echo "Scanning network..."
IPLIST=$(arp | grep -vi incomplete | awk '!/Address/ {print $1}' | sort -u)
break
;;
"nmap")
echo ""
read -p 'Enter a custom subnet value (192.168.[VALUE].*): ' VALUE
while ! [[ "$VALUE" =~ ^-?[0-9]+$ ]]; do
echo "Please specify an integer as your value, we (still) can't process alien IP addresses!"
sleep 1
read -p 'Enter a custom subnet value (192.168.[VALUE].*): ' VALUE
done
echo 'Scanning network...'
IPLIST=$(nmap -sn 192.168.$VALUE.* | grep report | awk '{print $5}' | sort -u)
break
;;
"help")
echo ""
echo "You need to specify which scanning method you want to use. Possible options are 'arp' or 'nmap'"
echo "-without quotes-. While arp is faster, nmap will provide a more accurate result, as arp relies on"
echo "computer network memory, which might have problems with recently created servers."
echo ""
;;
*)
clear
echo 'Please enter a valid value.'
sleep 0.5
;;
esac
done
}
function connect() {
iparr=($IPLIST) #Converts IP list to an easier to process array
read -p "Enter network's username: " USERNAME
while [ "$USERNAME" == "" ]; do
clear
echo -n "Please enter a valid username."
sleep 1
clear
read -p "Enter network's username: " USERNAME
done
clear
read -n1 -p "Do you want to try another username? [Y/n]"
if [[ "$REPLY" = [yY] ]]; then
read -p "Enter a second username: " USERNAME2
while [ "$USERNAME2" == "" ]; do
clear
echo "Please enter a valid username."
sleep 1
clear
read -p "Enter a second username: " USERNAME2
done
fi
clear
read -p 'Do you want to specify a custom port? (Default: 22) [Y/n] '
if [[ "$REPLY" = [yY] ]]; then
read -p 'Enter port number: ' PORT
while ! [[ "$PORT" =~ ^-?[0-9]+$ ]]; do
echo "Please enter a valid value."
sleep 1
read -p "Enter port number: " PORT
done
clear
echo '---------------------------------------------------------------------------------------------------------'
echo 'These are the IPs found for connecting:'
echo
echo ${iparr[@]}
# Only if USERNAME2 exists. -> echo $USERNAME2@${iparr[@]}':'$PORT
echo
echo '---------------------------------------------------------------------------------------------------------'
echo
echo 'Connecting...'
echo
for address in "${iparr[@]}"; do
ssh "$address" -p $PORT
done
else
clear
PORT=22
echo '--------------------------------------------------------------------'
echo 'These are the IPs found for connecting:'
echo
echo ${iparr[@]}
echo
echo '--------------------------------------------------------------------'
echo
echo 'Connecting...'
echo
fi
}
clear
echo 'Welcome to SSHRanger, your easy-to-use multifunction SSH handler. This script will help you to scan'
echo "and connect to SSH servers found in your network. Note that this is NOT a hacking tool: we don't (but"
echo "you should) know any of your server passwords, so if you forget yours, think about your pet's name next time."
sleep 1
echo
read -p "Do you want to start a new network scan? [Y/n] "
if [[ $REPLY = [yY] ]]; then
scan
else
echo
echo
echo "We won't tell anybody you have been here..."
sleep 1
clear
exit 1
fi
read -p "The network has been successfully scanned. Do you want to start an SSH connection? " ANSCONN
if [[ "$ANSCONN" = [yY] ]]; then
connect
else
echo "We won't tell anybody you have been here..."
sleep 1
clear
exit 1
fi