Open savely-krasovsky opened 8 months ago
@schwabe I am not sure what cause problem and how it could be fixed properly. I double checked:
GetModuleFileNameW
really returns lower case path.QueryFullProcessImageNameW
returns proper path.ImagePath = C:\Program Files\OpenVPN...
).Man here has the same problem: https://stackoverflow.com/questions/31239726/getmodulefilename-always-return-lowercase-in-service
From what I found, Windows doesn't allow to set entire drive as case-sensitive. So administator can set C:\Program Files
as case-sensitive, but user still won't be able to create (to exploit possible vulnerability) C:\program files
as C:\
still case-insensitive, because directory will already exist from NTFS perspective.
I tried fsutil.exe file setCaseSensitiveInfo C:\ enable
but it responded "not supported".
Any comments in the new context?
I am not able to reproduce this. I used ovpnagent
and ovpncliagent
for testing, registered the service with ovpnagent install
and checked that the server exe path is a case-sensitive.
We could use QueryFullProcessImageNameW
to get the path - we already have all the code in place. Could you apply following patch and see if that works for you?
diff --git a/openvpn/win/modname.hpp b/openvpn/win/modname.hpp
index 00142dd1..d3cafb45 100644
--- a/openvpn/win/modname.hpp
+++ b/openvpn/win/modname.hpp
@@ -32,20 +32,15 @@
#include <openvpn/common/wstring.hpp>
#include <openvpn/win/winerr.hpp>
#include <openvpn/win/reg.hpp>
+#include <openvpn/win/npinfo.hpp>
namespace openvpn {
namespace Win {
inline std::wstring module_name()
{
- // get path to our binary
- wchar_t path[MAX_PATH];
- if (!::GetModuleFileNameW(NULL, path, MAX_PATH))
- {
- const Win::LastError err;
- OPENVPN_THROW_EXCEPTION("GetModuleFileNameW failed: " << err.message());
- }
- return std::wstring(path);
+ auto current_process_handle = NamedPipePeerInfo::get_process(GetCurrentProcessId(), true);
+ return NamedPipePeerInfo::get_exe_path(current_process_handle());
}
inline std::string module_name_utf8()
We have faced with ovpnagent problem. In some cases Windows paths of client and server differ. It leads to server rejecting client connection via named pipe. I double checked source code and found nothing suspicious, but after adding additional logging we've found this:
As you can imagine check compares paths and fails.
We have found that it was users who have English localization instead of Russian (as many others in our case). Probably it's easy to fix but converting both paths to lower case, but I am not it's good from security point.