Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix symlink and junction detection on Python windows #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

smashery
Copy link
Contributor

This PR resolves #657 - use ctypes to detect whether a directory is a link (symlink or junction on Windows). This applies even to newer versions of Python 3, because it doesn't do junction point detection.

C:\Users\smash\Desktop\shells>mklink /J junction directory
Junction created for junction <<===>> directory

C:\Users\smash\Desktop\shells>"C:\Program Files\Python38\python.exe"
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.islink('junction')
False

Verify

  • Run the tests over at Added new failing test for windows junction points metasploit-framework#19554
  • Create some links (mkdir /D) and junctions (mkdir /J)
  • Place content inside those directories (once we remove the link, the content inside it should remain)
  • Use Python meterpreter on both Python2 and Python3 to rmdir the links and junctions
  • Verify that the contents of the actual folder being linked to is not deleted

@adfoster-r7
Copy link
Contributor

Thanks! 🎉

Not a blocker - just for visibility, we've also got automated python tests over here - which runs across more versions of Python than the framework PR setup does 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 2.7 symlink detection doesn't work
2 participants