Skip to content

Commit c361846

Browse files
authored
Merge pull request rapid7#9150 from bcook-r7/runtimeerror
Fix several broken raise RuntimeError calls in error paths
2 parents f1e6e7e + aa0ac57 commit c361846

File tree

8 files changed

+25
-27
lines changed

8 files changed

+25
-27
lines changed

lib/metasploit/framework/mssql/client.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,7 @@ def mssql_prelogin(enc_error=false)
634634
if idx > 0
635635
encryption_mode = resp[idx, 1].unpack("C")[0]
636636
else
637-
raise RunTimeError, "Unable to parse encryption req. "\
638-
"from server during prelogin"
637+
raise "Unable to parse encryption req during pre-login, this may not be a MSSQL server"
639638
encryption_mode = ENCRYPT_NOT_SUP
640639
end
641640

@@ -682,8 +681,7 @@ def mssql_prelogin(enc_error=false)
682681
if idx > 0
683682
encryption_mode = resp[idx, 1].unpack("C")[0]
684683
else
685-
raise RuntimeError, "Unable to parse encryption "\
686-
"req during pre-login"
684+
raise "Unable to parse encryption req during pre-login, this may not be a MSSQL server"
687685
end
688686
end
689687
encryption_mode

lib/msf/core/auxiliary/nmap.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def rport
4343
end
4444

4545
def set_nmap_cmd
46-
self.nmap_bin || (raise RuntimeError, "Cannot locate nmap binary")
46+
self.nmap_bin || (raise "Cannot locate nmap binary")
4747
nmap_set_log
4848
nmap_add_ports
4949
nmap_cmd = [self.nmap_bin]
@@ -54,7 +54,7 @@ def set_nmap_cmd
5454
end
5555

5656
def get_nmap_ver
57-
self.nmap_bin || (raise RuntimeError, "Cannot locate nmap binary")
57+
self.nmap_bin || (raise "Cannot locate nmap binary")
5858
res = ""
5959
nmap_cmd = [self.nmap_bin]
6060
nmap_cmd << "--version"
@@ -84,7 +84,7 @@ def nmap_version_at_least?(test_ver=nil)
8484
end
8585

8686
def nmap_build_args
87-
raise RuntimeError, "nmap_build_args() not defined by #{self.refname}"
87+
raise "nmap_build_args() not defined by #{self.refname}"
8888
end
8989

9090
def nmap_run
@@ -159,13 +159,13 @@ def nmap_reset_args
159159
# A helper to add in rport or rports as a -p argument
160160
def nmap_add_ports
161161
if not nmap_validate_rports
162-
raise RuntimeError, "Cannot continue without a valid port list."
162+
raise "Cannot continue without a valid port list."
163163
end
164164
port_arg = "-p \"#{datastore['RPORT'] || rports}\""
165165
if nmap_validate_arg(port_arg)
166166
self.nmap_args << port_arg
167167
else
168-
raise RunTimeError, "Argument is invalid"
168+
raise "Argument is invalid"
169169
end
170170
end
171171

@@ -237,7 +237,7 @@ def nmap_validate_arg(str)
237237
# module to ferret out whatever's interesting in this host
238238
# object.
239239
def nmap_hosts(&block)
240-
@nmap_bin || (raise RuntimeError, "Cannot locate the nmap binary.")
240+
@nmap_bin || (raise "Cannot locate the nmap binary.")
241241
fh = self.nmap_log[0]
242242
nmap_data = fh.read(fh.stat.size)
243243
# fh.unlink

lib/msf/core/db_manager/report.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def report_artifact(opts)
4444

4545
unless artifact.valid?
4646
errors = artifact.errors.full_messages.join('; ')
47-
raise RuntimeError "Artifact to be imported is not valid: #{errors}"
47+
raise "Artifact to be imported is not valid: #{errors}"
4848
end
4949
artifact.save
5050
end
@@ -66,7 +66,7 @@ def report_report(opts)
6666

6767
unless report.valid?
6868
errors = report.errors.full_messages.join('; ')
69-
raise RuntimeError "Report to be imported is not valid: #{errors}"
69+
raise "Report to be imported is not valid: #{errors}"
7070
end
7171
report.state = :complete # Presume complete since it was exported
7272
report.save
@@ -83,4 +83,4 @@ def reports(wspace=workspace)
8383
wspace.reports
8484
}
8585
end
86-
end
86+
end

modules/auxiliary/scanner/discovery/arp_sweep.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def run_batch(hosts)
4646
@interface = datastore['INTERFACE'] || Pcap.lookupdev
4747
shost = datastore['SHOST']
4848
shost ||= get_ipv4_addr(@interface) if @netifaces
49-
raise RuntimeError ,'SHOST should be defined' unless shost
49+
raise 'SHOST should be defined' unless shost
5050

5151
smac = datastore['SMAC']
5252
smac ||= get_mac(@interface) if @netifaces
53-
raise RuntimeError ,'SMAC should be defined' unless smac
53+
raise 'SMAC should be defined' unless smac
5454

5555
begin
5656

modules/auxiliary/scanner/discovery/ipv6_neighbor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def run_batch(hosts)
4949
@interface = datastore['INTERFACE'] || Pcap.lookupdev
5050
@shost = datastore['SHOST']
5151
@shost ||= get_ipv4_addr(@interface) if @netifaces
52-
raise RuntimeError ,'SHOST should be defined' unless @shost
52+
raise 'SHOST should be defined' unless @shost
5353

5454
@smac = datastore['SMAC']
5555
@smac ||= get_mac(@interface) if @netifaces
56-
raise RuntimeError ,'SMAC should be defined' unless @smac
56+
raise 'SMAC should be defined' unless @smac
5757

5858
addrs = []
5959

modules/auxiliary/scanner/discovery/ipv6_neighbor_router_advertisement.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ def run
161161
@interface = datastore['INTERFACE'] || Pcap.lookupdev
162162
@shost = datastore['SHOST']
163163
@shost ||= get_ipv4_addr(@interface) if @netifaces
164-
raise RuntimeError ,'SHOST should be defined' unless @shost
164+
raise 'SHOST should be defined' unless @shost
165165

166166
@smac = datastore['SMAC']
167167
@smac ||= get_mac(@interface) if @netifaces
168168
@smac ||= ipv6_mac
169-
raise RuntimeError ,'SMAC should be defined' unless @smac
169+
raise 'SMAC should be defined' unless @smac
170170

171171
# Send router advertisement
172172
print_status("Sending router advertisement...")

modules/auxiliary/server/icmp_exfil.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def icmp_listener
153153
icmp_response, contents = icmp_packet(packet, datastore['RESP_START'])
154154

155155
if not icmp_response
156-
raise RuntimeError ,"Could not build ICMP response"
156+
raise "Could not build ICMP response"
157157
else
158158
# send response packet icmp_pkt
159159
send_icmp(icmp_response, contents)
@@ -172,7 +172,7 @@ def icmp_listener
172172
icmp_response, contents = icmp_packet(packet, datastore['RESP_END'])
173173

174174
if not icmp_response
175-
raise RuntimeError , "Could not build ICMP response"
175+
raise "Could not build ICMP response"
176176
else
177177
# send response packet icmp_pkt
178178
send_icmp(icmp_response, contents)
@@ -192,7 +192,7 @@ def icmp_listener
192192
icmp_response, contents = icmp_packet(packet, datastore['RESP_CONT'])
193193

194194
if not icmp_response
195-
raise RuntimeError , "Could not build ICMP response"
195+
raise "Could not build ICMP response"
196196
else
197197
# send response packet icmp_pkt
198198
send_icmp(icmp_response, contents)

modules/auxiliary/spoof/arp/arp_poisoning.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def run
7272
@interface = get_interface_guid(@interface)
7373
@smac = datastore['SMAC']
7474
@smac ||= get_mac(@interface) if @netifaces
75-
raise RuntimeError ,'SMAC is not defined and can not be guessed' unless @smac
76-
raise RuntimeError ,'Source MAC is not in correct format' unless is_mac?(@smac)
75+
raise 'SMAC is not defined and can not be guessed' unless @smac
76+
raise 'Source MAC is not in correct format' unless is_mac?(@smac)
7777

7878
@sip = datastore['LOCALSIP']
7979
@sip ||= get_ipv4_addr(@interface) if @netifaces
@@ -162,7 +162,7 @@ def broadcast_spoof
162162

163163
def arp_poisoning
164164
lsmac = datastore['LOCALSMAC'] || @smac
165-
raise RuntimeError ,'Local Source Mac is not in correct format' unless is_mac?(lsmac)
165+
raise 'Local Source Mac is not in correct format' unless is_mac?(lsmac)
166166

167167
dhosts_range = Rex::Socket::RangeWalker.new(datastore['DHOSTS'])
168168
@dhosts = []
@@ -199,7 +199,7 @@ def arp_poisoning
199199
end
200200
Kernel.select(nil, nil, nil, 0.50)
201201
end
202-
raise RuntimeError, "No hosts found" unless @dsthosts_cache.length > 0
202+
raise "No hosts found" unless @dsthosts_cache.length > 0
203203

204204
# Build the local src hosts cache
205205
if datastore['BIDIRECTIONAL']
@@ -236,7 +236,7 @@ def arp_poisoning
236236
end
237237
Kernel.select(nil, nil, nil, 0.50)
238238
end
239-
raise RuntimeError, "No hosts found" unless @srchosts_cache.length > 0
239+
raise "No hosts found" unless @srchosts_cache.length > 0
240240
end
241241

242242
if datastore['AUTO_ADD']

0 commit comments

Comments
 (0)