rapid7 / metasploit-payloads

Unified repository for different Metasploit Framework payloads
Other
1.73k stars 669 forks source link

Python 2.7 symlink detection doesn't work #657

Open adfoster-r7 opened 1 year ago

adfoster-r7 commented 1 year ago

When running the file deletion tests in Metasploit, the sym link tests fail on Python 2.7

https://github.com/rapid7/metasploit-payloads/blob/cbf451bcde93fbe3fce9b793f2004d98392d929a/python/meterpreter/ext_server_stdapi.py#L1895-L1896

Python 2.7's islink implementation is not implemented correctly https://stackoverflow.com/questions/15258506/os-path-islink-on-windows-with-python

Example showing different runtimes providing different results:

image

This could be updated to use ctypes, but I believe the required unlink implementation is also broken - I haven't confirmed.

smashery commented 2 weeks ago

There's another issue too, even on Python 3: Junction points always fail, because islink return false even on Python 3. So it might be that the solution for 2.7 should just be the "Windows" solution.

New acceptance test, running on Python 3:

[-] [should delete a junction target] FAILED: should delete a junction target
[-] [should delete a junction target] Exception: Rex::Post::Meterpreter::RequestError: stdapi_fs_delete_dir: Operation failed: Unknown error