Skip to content

Commit b0a8c77

Browse files
author
HD Moore
committed
Switch RuntimeError -> EncodingError
1 parent 7989a29 commit b0a8c77

File tree

11 files changed

+24
-24
lines changed

11 files changed

+24
-24
lines changed

modules/encoders/cmd/echo.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def encode_block(state, buf)
3434
end
3535

3636
if state.badchars.include?("-")
37-
raise RuntimeError
37+
raise EncodingError
3838
else
3939
# Without an escape character we can't escape anything, so echo
4040
# won't work.
4141
if state.badchars.include?("\\")
42-
raise RuntimeError
42+
raise EncodingError
4343
else
4444
buf = encode_block_bash_echo(state,buf)
4545
end
@@ -68,7 +68,7 @@ def encode_block_bash_echo(state, buf)
6868
if state.badchars.include?("`")
6969
# Last ditch effort, dollar paren
7070
if state.badchars.include?("$") or state.badchars.include?("(")
71-
raise RuntimeError
71+
raise EncodingError
7272
else
7373
buf = "$(/bin/echo -ne #{hex})"
7474
end

modules/encoders/cmd/generic_sh.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def encode_block_perl(state, buf)
6868
state.badchars.unpack('C*') { |c| qot.delete(c.chr) }
6969

7070
# Throw an error if we ran out of quotes
71-
raise RuntimeError if qot.length == 0
71+
raise EncodingError if qot.length == 0
7272

7373
sep = qot[0].chr
7474

@@ -83,7 +83,7 @@ def encode_block_perl(state, buf)
8383
if (state.badchars.match(/\(|\)/))
8484

8585
# No paranthesis...
86-
raise RuntimeError
86+
raise EncodingError
8787
end
8888

8989
cmd << "system\\(pack\\(qq#{sep}H\\*#{sep},qq#{sep}#{hex}#{sep}\\)\\)"
@@ -92,7 +92,7 @@ def encode_block_perl(state, buf)
9292
if (state.badchars.match(/\(|\)/))
9393
if (state.badchars.include?(" "))
9494
# No spaces allowed, no paranthesis, give up...
95-
raise RuntimeError
95+
raise EncodingError
9696
end
9797

9898
cmd << "'system pack qq#{sep}H*#{sep},qq#{sep}#{hex}#{sep}'"
@@ -124,7 +124,7 @@ def encode_block_bash_echo(state, buf)
124124
if (state.badchars.include?("`"))
125125
# Last ditch effort, dollar paren
126126
if (state.badchars.include?("$") or state.badchars.include?("("))
127-
raise RuntimeError
127+
raise EncodingError
128128
else
129129
buf = "$(/bin/echo -ne #{hex})"
130130
end

modules/encoders/cmd/perl.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def encode_block(state, buf)
3535
end
3636

3737
if state.badchars.include?("-")
38-
raise RuntimeError
38+
raise EncodingError
3939
else
4040
buf = encode_block_perl(state,buf)
4141
end
@@ -55,7 +55,7 @@ def encode_block_perl(state, buf)
5555
# Convert spaces to IFS...
5656
if state.badchars.include?(" ")
5757
if state.badchars.match(/[${IFS}]/n)
58-
raise RuntimeError
58+
raise EncodingError
5959
end
6060
cmd.gsub!(/\s/, '${IFS}')
6161
end
@@ -118,7 +118,7 @@ def perl_qq(state, qot, hex)
118118
state.badchars.unpack('C*') { |c| qot.delete(c.chr) }
119119

120120
# Throw an error if we ran out of quotes
121-
raise RuntimeError if qot.length == 0
121+
raise EncodingError if qot.length == 0
122122

123123
sep = qot[0].chr
124124
# Use an explicit length for the H specifier instead of just "H*"

modules/encoders/cmd/printf_php_mq.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def encode_block(state, buf)
5050
(state.badchars.include?("|")) or
5151
# We must have at least ONE of these two..
5252
(state.badchars.include?("x") and state.badchars.include?("0"))
53-
raise RuntimeError
53+
raise EncodingError
5454
end
5555

5656
# Now we build a string of the original payload with bad characters

modules/encoders/x86/add_sub.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def decoder_stub(state)
9999
@inst = {}
100100
@set = add_or_sub(@avchars)
101101
if @set == 0 then
102-
raise RuntimeError, "Bad character list includes essential characters."
102+
raise EncodingError, "Bad character list includes essential characters."
103103
exit
104104
elsif @set == 1 then #add
105105
@inst["opcode"] = 0x05
@@ -112,7 +112,7 @@ def decoder_stub(state)
112112
@inst["push_esp"] = 0x54
113113
@inst["pop_esp"] = 0x5c
114114
if state.buf.size%4 != 0 then
115-
raise RuntimeError, "Shellcode size must be divisible by 4, try nop padding."
115+
raise EncodingError, "Shellcode size must be divisible by 4, try nop padding."
116116
exit
117117
end
118118
#init

modules/encoders/x86/alpha_mixed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def decoder_stub(state)
4444
else
4545
res = Rex::Arch::X86.geteip_fpu(state.badchars)
4646
if (not res)
47-
raise RuntimeError, "Unable to generate geteip code"
47+
raise EncodingError, "Unable to generate geteip code"
4848
end
4949
buf, reg, off = res
5050
end

modules/encoders/x86/alpha_upper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def decoder_stub(state)
4747
else
4848
res = Rex::Arch::X86.geteip_fpu(state.badchars)
4949
if (not res)
50-
raise RuntimeError, "Unable to generate geteip code"
50+
raise EncodingError, "Unable to generate geteip code"
5151
end
5252
buf, reg, off = res
5353
end

modules/encoders/x86/opt_sub.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ def decoder_stub(state)
161161

162162
# determine if we have any invalid characters that we rely on.
163163
unless all_bytes_valid
164-
raise RuntimeError, "Bad character set contains characters that are required for this encoder to function."
164+
raise EncodingError, "Bad character set contains characters that are required for this encoder to function."
165165
end
166166

167167
unless @asm['PUSH'][@base_reg]
168-
raise RuntimeError, "Invalid base register"
168+
raise EncodingError, "Invalid base register"
169169
end
170170

171171
# get the offset from the specified base register, or default to zero if not specifed
@@ -176,7 +176,7 @@ def decoder_stub(state)
176176

177177
# if we can't then we bomb, because we know we need to clear out EAX at least once
178178
unless @clear1
179-
raise RuntimeError, "Unable to find AND-able chars resulting 0 in the valid character set."
179+
raise EncodingError, "Unable to find AND-able chars resulting 0 in the valid character set."
180180
end
181181

182182
protect_payload = (datastore['OverwriteProtect'] || "").downcase == "true"
@@ -288,7 +288,7 @@ def encode_payload(buf, reg_offset, protect_payload)
288288
# Write out a stubbed placeholder for the offset instruction based on
289289
# the base register, we'll update this later on when we know how big our payload is.
290290
encoded, _ = sub_3(0, 0)
291-
raise RuntimeError, "Couldn't offset base register." if encoded.nil?
291+
raise EncodingError, "Couldn't offset base register." if encoded.nil?
292292
data << create_sub(encoded)
293293

294294
# finally push the value of EAX back into ESP
@@ -312,7 +312,7 @@ def encode_payload(buf, reg_offset, protect_payload)
312312
end
313313

314314
# if we're still nil here, then we have an issue
315-
raise RuntimeError, "Couldn't encode payload" if encoded.nil?
315+
raise EncodingError, "Couldn't encode payload" if encoded.nil?
316316

317317
data << create_sub(encoded)
318318
end
@@ -324,7 +324,7 @@ def encode_payload(buf, reg_offset, protect_payload)
324324
encoded, _ = sub_3(total_offset, 0)
325325

326326
# if we're still nil here, then we have an issue
327-
raise RuntimeError, "Couldn't encode protection" if encoded.nil?
327+
raise EncodingError, "Couldn't encode protection" if encoded.nil?
328328
patch = create_sub(encoded)
329329

330330
# patch in the correct offset back at the start of our payload

modules/encoders/x86/shikata_ga_nai.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def generate_shikata_block(state, length, cutoff)
281281
begin
282282
# Generate a permutation saving the ECX, ESP, and user defined registers
283283
loop_inst.generate(block_generator_register_blacklist, nil, state.badchars)
284-
rescue RuntimeError => e
284+
rescue EncodingError => e
285285
raise EncodingError
286286
end
287287
end

modules/encoders/x86/unicode_mixed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def decoder_stub(state)
3737
reg = datastore['BufferRegister']
3838
offset = datastore['BufferOffset'].to_i || 0
3939
if (not reg)
40-
raise RuntimeError, "Need BufferRegister"
40+
raise EncodingError, "Need BufferRegister"
4141
end
4242
Rex::Encoder::Alpha2::UnicodeMixed::gen_decoder(reg, offset)
4343
end

0 commit comments

Comments
 (0)