From 62e59e6250b687ef7282806fc70d33350a885f2e Mon Sep 17 00:00:00 2001 From: RageLtMan Date: Wed, 10 May 2023 11:10:08 -0400 Subject: [PATCH] Replace [System.IO.File]::Exists with Test-Path 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 ``` --- lib/msf/core/post/file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msf/core/post/file.rb b/lib/msf/core/post/file.rb index 093eded5be..a06fe282c7 100644 --- a/lib/msf/core/post/file.rb +++ b/lib/msf/core/post/file.rb @@ -305,7 +305,7 @@ module Msf::Post::File end return !!stat elsif session.type == 'powershell' - return cmd_exec("[System.IO.File]::Exists( \"#{path}\")")&.include?('True') + return cmd_exec("Test-Path \"#{path}\"")&.include?('True') else if session.platform == 'windows' f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")