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

Replace [System.IO.File]::Exists with Test-Path #17980

Merged
merged 1 commit into from May 11, 2023

Conversation

sempervictus
Copy link
Contributor

@sempervictus sempervictus commented May 10, 2023

The exists? method in post/file has a different implementation for PSH sessions than other shells which are testing for the existence of a path, not the presence of a file.

Fix this by replacing [System.IO.File]::Exists with Test-Path.

Testing:

PS C:\Windows\system32> [System.IO.File]::Exists("C:\")
False
PS C:\Windows\system32>test-path C:\
PS C:\Windows\system32> test-path C:\
True

The exists? method in post/file has a different implementation for
PSH sessions than other shells which are testing for the existence
of a path, not the presence of a file.

Fix this by replacing [System.IO.File]::Exists with Test-Path.

Testing:
```
PS C:\Windows\system32> [System.IO.File]::Exists("C:\")
False
PS C:\Windows\system32>test-path C:\
PS C:\Windows\system32> test-path C:\
True
```
@smcintyre-r7 smcintyre-r7 self-assigned this May 10, 2023
@smcintyre-r7 smcintyre-r7 added library bug powershell Issues and PRs related to powershell sessions and payloads labels May 11, 2023
Copy link
Contributor

@smcintyre-r7 smcintyre-r7 left a comment

Choose a reason for hiding this comment

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

Changes look good to me.

Before:

[1] pry(#<Msf::Modules::Post__Test__File::MetasploitModule>)> exist?("C:\\")
=> false

After:

[1] pry(#<Msf::Modules::Post__Test__File::MetasploitModule>)> exist?("C:\\")
=> true

I also ran the post/test/file test module. The same number of tests pass and fail before and after this change. I think there are more updates that need to be made for those to all run smoothly but this is a step in the right direction and makes a tangible improvement.

@smcintyre-r7 smcintyre-r7 merged commit dbda20d into rapid7:master May 11, 2023
33 checks passed
@smcintyre-r7
Copy link
Contributor

Release Notes

This fixes the file system path check used by Powershell sessions.

@cdelafuente-r7 cdelafuente-r7 added the rn-fix release notes fix label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug library powershell Issues and PRs related to powershell sessions and payloads rn-fix release notes fix
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants