CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/payloads/win32/kernel.rb
Views: 11655
1
# -*- coding: binary -*-
2
module Rex
3
module Payloads
4
module Win32
5
6
7
module Kernel
8
9
#
10
# Constructs a kernel-mode payload using the supplied options. The options
11
# can be:
12
#
13
# Recovery : The recovery method to use, such as 'spin'.
14
# Stager : The stager method to use, such as 'sud_syscall_hook'.
15
# RecoveryStub : The recovery stub that should be used, if any.
16
# UserModeStub : The user-mode payload to execute, if any.
17
# KernelModeStub: The kernel-mode payload to execute, if any.
18
#
19
def self.construct(opts = {})
20
payload = nil
21
22
# Generate the recovery stub
23
if opts['Recovery'] and Kernel::Recovery.respond_to?(opts['Recovery'], true)
24
opts['RecoveryStub'] = Kernel::Recovery.send(opts['Recovery'], opts)
25
end
26
27
# Append supplied recovery stub information in case there is some
28
# context specific recovery that must be done.
29
if opts['AppendRecoveryStub']
30
opts['RecoveryStub'] = (opts['RecoveryStub'] || '') + opts['AppendRecoveryStub']
31
end
32
33
# Generate the stager
34
if opts['Stager'] and Kernel::Stager.respond_to?(opts['Stager'], true)
35
payload = Kernel::Stager.send(opts['Stager'], opts)
36
# Or, generate the migrator
37
elsif opts['Migrator'] and Kernel::Migration.respond_to?(opts['Migrator'], true)
38
payload = Kernel::Migration.send(opts['Migrator'], opts)
39
else
40
raise ArgumentError, "A stager or a migrator must be specified."
41
end
42
43
payload
44
end
45
46
end
47
48
end
49
end
50
end
51
52