Skip to content

Commit 0f4196d

Browse files
committed
Land rapid7#2229 - Re-implement fail_with() function
2 parents 0ef4b4c + 462ccc3 commit 0f4196d

File tree

179 files changed

+606
-602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+606
-602
lines changed

lib/msf/core/exploit.rb

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -101,81 +101,6 @@ module CheckCode
101101
Unsupported = [ 'unsupported', "This exploit does not support check." ]
102102
end
103103

104-
105-
106-
##
107-
#
108-
# Constants indicating the reason for an unsuccessful exploit attempt
109-
#
110-
##
111-
module Failure
112-
113-
#
114-
# No confidence in success or failure
115-
#
116-
None = 'none'
117-
118-
#
119-
# No confidence in success or failure
120-
#
121-
Unknown = 'unknown'
122-
123-
#
124-
# The network service was unreachable (connection refused, etc)
125-
#
126-
Unreachable = 'unreachable'
127-
128-
#
129-
# The exploit settings were incorrect
130-
#
131-
BadConfig = 'bad-config'
132-
133-
#
134-
# The network service disconnected us mid-attempt
135-
#
136-
Disconnected = 'disconnected'
137-
138-
#
139-
# The application endpoint or specific service was not found
140-
#
141-
NotFound = 'not-found'
142-
143-
#
144-
# The application replied in an unexpected fashion
145-
#
146-
UnexpectedReply = 'unexpected-reply'
147-
148-
#
149-
# The exploit triggered some form of timeout
150-
#
151-
TimeoutExpired = 'timeout-expired'
152-
153-
#
154-
# The exploit was interrupted by the user
155-
#
156-
UserInterrupt = 'user-interrupt'
157-
158-
#
159-
# The application replied indication we do not have access
160-
#
161-
NoAccess = 'no-access'
162-
163-
#
164-
# The target is not compatible with this exploit or settings
165-
#
166-
NoTarget = 'no-target'
167-
168-
#
169-
# The application response indicated it was not vulnerable
170-
#
171-
NotVulnerable = 'not-vulnerable'
172-
173-
#
174-
# The payload was delivered but no session was opened (AV, network, etc)
175-
#
176-
PayloadFailed = 'payload-failed'
177-
end
178-
179104
#
180105
# The various basic types of exploits
181106
#

lib/msf/core/module.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,85 @@ def search_filter(search_string)
734734
false
735735
end
736736

737+
#
738+
# Support fail_with for all module types, allow specific classes to override
739+
#
740+
def fail_with(reason, msg=nil)
741+
raise RuntimeError, "#{reason.to_s}: #{msg}"
742+
end
743+
744+
#
745+
# Constants indicating the reason for an unsuccessful module attempt
746+
#
747+
module Failure
748+
749+
#
750+
# No confidence in success or failure
751+
#
752+
None = 'none'
753+
754+
#
755+
# No confidence in success or failure
756+
#
757+
Unknown = 'unknown'
758+
759+
#
760+
# The network service was unreachable (connection refused, etc)
761+
#
762+
Unreachable = 'unreachable'
763+
764+
#
765+
# The exploit settings were incorrect
766+
#
767+
BadConfig = 'bad-config'
768+
769+
#
770+
# The network service disconnected us mid-attempt
771+
#
772+
Disconnected = 'disconnected'
773+
774+
#
775+
# The application endpoint or specific service was not found
776+
#
777+
NotFound = 'not-found'
778+
779+
#
780+
# The application replied in an unexpected fashion
781+
#
782+
UnexpectedReply = 'unexpected-reply'
783+
784+
#
785+
# The exploit triggered some form of timeout
786+
#
787+
TimeoutExpired = 'timeout-expired'
788+
789+
#
790+
# The exploit was interrupted by the user
791+
#
792+
UserInterrupt = 'user-interrupt'
793+
794+
#
795+
# The application replied indication we do not have access
796+
#
797+
NoAccess = 'no-access'
798+
799+
#
800+
# The target is not compatible with this exploit or settings
801+
#
802+
NoTarget = 'no-target'
803+
804+
#
805+
# The application response indicated it was not vulnerable
806+
#
807+
NotVulnerable = 'not-vulnerable'
808+
809+
#
810+
# The payload was delivered but no session was opened (AV, network, etc)
811+
#
812+
PayloadFailed = 'payload-failed'
813+
end
814+
815+
737816
##
738817
#
739818
# Just some handy quick checks

modules/auxiliary/gather/apple_safari_webarchive_uxss.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def cleanup
9393
#
9494
def use_zlib
9595
if (!Rex::Text.zlib_present? and datastore['HTTP::compression'] == true)
96-
fail_with(Exploit::Failure::Unknown, "zlib support was not detected, yet the HTTP::compression option was set. Don't do that!")
96+
fail_with(Failure::Unknown, "zlib support was not detected, yet the HTTP::compression option was set. Don't do that!")
9797
end
9898
end
9999

modules/exploits/aix/rpc_cmsd_opcode21.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def brute_exploit(brute_target)
8383

8484
begin
8585
if (not sunrpc_create('udp', 100068, 4))
86-
fail_with(Exploit::Failure::Unknown, 'sunrpc_create failed')
86+
fail_with(Failure::Unknown, 'sunrpc_create failed')
8787
end
8888

8989
# spray the heap a bit (work around powerpc cache issues)

modules/exploits/bsdi/softcart/mercantec_softcart.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def brute_exploit(address)
7272
'uri' => normalize_uri(datastore['URI'])
7373
}, 5)
7474
@mercantec = (res and res.body and res.body =~ /Copyright.*Mercantec/)
75-
fail_with(Exploit::Failure::NotFound, "The target is not a Mercantec CGI") if not @mercantec
75+
fail_with(Failure::NotFound, "The target is not a Mercantec CGI") if not @mercantec
7676
end
7777

7878
buffer =

modules/exploits/freebsd/ftp/proftp_telnet_iac.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def exploit
148148
print_status("FTP Banner: #{banner.strip}")
149149
version = m[1]
150150
else
151-
fail_with(Exploit::Failure::NoTarget, "No matching target")
151+
fail_with(Failure::NoTarget, "No matching target")
152152
end
153153

154154
regexp = Regexp.escape(version)
@@ -160,14 +160,14 @@ def exploit
160160
end
161161

162162
if (not @mytarget)
163-
fail_with(Exploit::Failure::NoTarget, "No matching target")
163+
fail_with(Failure::NoTarget, "No matching target")
164164
end
165165

166166
print_status("Selected Target: #{@mytarget.name}")
167167

168168
pl = exploit_regenerate_payload(@mytarget.platform, arch)
169169
if not pl
170-
fail_with(Exploit::Failure::Unknown, 'Unable to regenerate payload!')
170+
fail_with(Failure::Unknown, 'Unable to regenerate payload!')
171171
end
172172
else
173173
print_status("Trying target #{@mytarget.name}...")

modules/exploits/freebsd/local/mmap.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def upload_payload
6969
fname = datastore['WritableDir']
7070
fname = "#{fname}/" unless fname =~ %r'/$'
7171
if fname.length > 36
72-
fail_with(Exploit::Failure::BadConfig, "WritableDir can't be longer than 33 characters")
72+
fail_with(Failure::BadConfig, "WritableDir can't be longer than 33 characters")
7373
end
7474
fname = "#{fname}#{Rex::Text.rand_text_alpha(4)}"
7575

@@ -100,11 +100,11 @@ def upload_exploit(payload_fname)
100100

101101
def exploit
102102
payload_fname = upload_payload
103-
fail_with(Exploit::Failure::NotFound, "Payload failed to upload") if payload_fname.nil?
103+
fail_with(Failure::NotFound, "Payload failed to upload") if payload_fname.nil?
104104
print_status("Payload #{payload_fname} uploaded.")
105105

106106
exploit_fname = upload_exploit(payload_fname)
107-
fail_with(Exploit::Failure::NotFound, "Exploit failed to upload") if exploit_fname.nil?
107+
fail_with(Failure::NotFound, "Exploit failed to upload") if exploit_fname.nil?
108108
print_status("Exploit #{exploit_fname} uploaded.")
109109

110110
register_files_for_cleanup(payload_fname, exploit_fname)

modules/exploits/freebsd/telnet/telnet_encrypt_keyid.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def exploit_target(t)
9797
loop do
9898
data = sock.get_once(-1, 5) rescue nil
9999
if not data
100-
fail_with(Exploit::Failure::Unknown, "This system does not support encryption")
100+
fail_with(Failure::Unknown, "This system does not support encryption")
101101
end
102102
break if data.index("\xff\xfa\x26\x02\x01")
103103
end

modules/exploits/linux/ftp/proftp_sreplace.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def exploit
165165
print_status("FTP Banner: #{banner.strip}")
166166
version = m[1]
167167
else
168-
fail_with(Exploit::Failure::NoTarget, "No matching target")
168+
fail_with(Failure::NoTarget, "No matching target")
169169
end
170170

171171
regexp = Regexp.escape(version)
@@ -177,7 +177,7 @@ def exploit
177177
end
178178

179179
if (not mytarget)
180-
fail_with(Exploit::Failure::NoTarget, "No matching target")
180+
fail_with(Failure::NoTarget, "No matching target")
181181
end
182182

183183
print_status("Selected Target: #{mytarget.name}")
@@ -193,7 +193,7 @@ def exploit
193193

194194
pwd = send_cmd(['PWD'])
195195
if pwd !~ /257\s\"(.+)\"/
196-
fail_with(Exploit::Failure::Unknown, "Unable to get current working directory")
196+
fail_with(Failure::Unknown, "Unable to get current working directory")
197197
end
198198
pwd = $1
199199
pwd << "/" if pwd[-1,1] != "/"

modules/exploits/linux/ftp/proftp_telnet_iac.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def exploit
325325
print_status("FTP Banner: #{banner.strip}")
326326
version = m[1]
327327
else
328-
fail_with(Exploit::Failure::NoTarget, "No matching target")
328+
fail_with(Failure::NoTarget, "No matching target")
329329
end
330330

331331
regexp = Regexp.escape(version)
@@ -337,7 +337,7 @@ def exploit
337337
end
338338

339339
if (not mytarget)
340-
fail_with(Exploit::Failure::NoTarget, "No matching target")
340+
fail_with(Failure::NoTarget, "No matching target")
341341
end
342342

343343
print_status("Selected Target: #{mytarget.name}")
@@ -383,7 +383,7 @@ def exploit
383383
# Make sure we didn't introduce instability
384384
addr_badchars = "\x09\x0a\x0b\x0c\x20"
385385
if idx = Rex::Text.badchar_index(addrs, addr_badchars)
386-
fail_with(Exploit::Failure::Unknown, ("One or more address contains a bad character! (0x%02x @ 0x%x)" % [addrs[idx,1].unpack('C').first, idx]))
386+
fail_with(Failure::Unknown, ("One or more address contains a bad character! (0x%02x @ 0x%x)" % [addrs[idx,1].unpack('C').first, idx]))
387387
end
388388

389389
buf << addrs
@@ -432,7 +432,7 @@ def exploit
432432
end
433433

434434
if not session_created?
435-
fail_with(Exploit::Failure::Unknown, "Unable to guess the cookie value, sorry :-/")
435+
fail_with(Failure::Unknown, "Unable to guess the cookie value, sorry :-/")
436436
end
437437
else
438438
sock.put(buf)

0 commit comments

Comments
 (0)