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

VCL-ActiveDirectory4Delphi contain DLL hijacking vulnerability #5

Open
mh4x0f opened this issue Nov 1, 2023 · 6 comments
Open

VCL-ActiveDirectory4Delphi contain DLL hijacking vulnerability #5

mh4x0f opened this issue Nov 1, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@mh4x0f
Copy link

mh4x0f commented Nov 1, 2023

Impact

High! VCL-ActiveDirectory4Delphi (current version) was discovered to contain a DLL hijacking vulnerability that allows attackers to escalate privileges and execute arbitrary code via a crafted DLL.

Vulnerability

The file ActiveDirectory.Winapi.DllMapper.pas has two reference to import external DLL from the Windows OS activeds.dll and adsldpc.dll

Here is the current ActiveDirectory.Winapi.DllMapper.pas code:

image
ref: https://github.com/EdZava/VCL-ActiveDirectory4Delphi/blob/master/src/Winapi/ActiveDirectory.Winapi.DllMapper.pas#L93

Using the Process Monitor (procmon) it possible to see the external import of the binary TestActiveDirectory.exe on runtime execution.

image

highlighted in red, we can see that be default, if you do not set the path complete of variable, the DLL will be stored in the local directory of the executable, which in my case is C:\Users\mh4x0f\Desktop\activeds.dll and the result is NAME NOT FOUND becasue the file .dll" cannot be faulted into the current directory.

The vulnerability occurs because the VCL-ActiveDirectory4Delphi not set the complete path into code for import only from System32/x.dll

POC

The exploration can be simple in this demo I will show only exploit the activeds.dll but with same modification is possible to apply for adsldpc.dll.

I checked the source of this project the functions you are using that come from the activeds.dll and i found.
image

But the attacker can find this using some PE file explorer, i used the die.exe (detect it easy) checkout.

image

After that, I wrote a code .dll and proxy the functions that binary needed to work fine.

image

Then, i rename the project.dll to activeds.dll and moved it to the same path of executable TestActiveDirectory.exe

image

After that, it was only necessary to execute the binary TestActiveDirectory.exe that will see the calc.exe execution the same time.

image

Recommendation

The recommendation is to pass the complete path on System32, the change will force the search file activeds.dll to be in the system directory C:\Windows\System32\activeds.dll the same modification can be added for adsldpc.dll

@mh4x0f
Copy link
Author

mh4x0f commented Nov 1, 2023

File used to exploit it
activeds.dll.zip

@EdZava
Copy link
Owner

EdZava commented Nov 7, 2023

@mh4x0f
What an incredible job! 👏
I'll fix it as soon as possible.

Thank you very much for your contribution.

@EdZava EdZava added the enhancement New feature or request label Nov 7, 2023
@jmgway
Copy link

jmgway commented Oct 8, 2024

Hello @EdZava
did you update the complete sources since this fantastic job of @mh4x0f ?
Thank you !

@EdZava
Copy link
Owner

EdZava commented Oct 8, 2024

@jmgway, I haven't been able to do it yet. But the project is open to contributions, so if you'd like to do it, we'd be happy to review and accept your PR.

@jmgway
Copy link

jmgway commented Oct 8, 2024 via email

@EdZava
Copy link
Owner

EdZava commented Oct 9, 2024

@jmgway
It should work with FMX with little effort. However, it's important to note that this project uses Windows-specific libraries, so it would only work on that operating system.

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

No branches or pull requests

3 participants