skelsec / pypykatz

Mimikatz implementation in pure Python
MIT License
2.81k stars 371 forks source link

Is this Expected Behaviour? handledup uses lsass process to get handle #81

Closed m-j-w-69 closed 3 years ago

m-j-w-69 commented 3 years ago

Reading your medium.com article I decided to give handledup a go. Ran it against a fully patched Win10 box running 3rd party AV and cool it worked :)

python -m pypykatz -v live lsa --method handledup

Decided to do a bit of digging and discovered the following output:

DEBUG:pypykatz:Failed to duplicate object! PID: 744 HANDLE: 0xdb8 DEBUG:pypykatz:Failed to duplicate object! PID: 744 HANDLE: 0xdd4 DEBUG:pypykatz:Failed to duplicate object! PID: 744 HANDLE: 0xe10 DEBUG:pypykatz:Found open handle to lsass! PID: 744 HANDLE: 0xee8 DEBUG:pypykatz:Failed to duplicate object! PID: 744 HANDLE: 0xefc DEBUG:pypykatz:Failed to duplicate object! PID: 744 HANDLE: 0xf00

There were a few other 744 handles but no other PIDs referenced. 744 was the LSASS process. I found this a little surprising as i thought (willing to be corrected on this) the idea was to evade touching this somewhat monitored process. Have I misunderstood the point of this flag and all is fine, or is this a bug?

Feel free to look at this in slow time, always grateful to open-source devs & i realise you are probably super busy.

Regards MJW

skelsec commented 3 years ago

Hello,

This is expected behavior, I will expand the wiki about it probably with the text below:

The handledup method will search for all open process handles in all processes and tests if the given handle is a process handle to LSASS. If it is then it will try to use that handle and if it succeeds then hurray, if not then it will continue with the next available handle. The handle searching does not know upfront which process has which handles, it simply requests ALL possible handles via windows API call, therefore some "bruteforcing" is needed. This method can succeed because of two possible reasons:

I hope this clears it up

m-j-w-69 commented 3 years ago

Many thanks for the super quick response. Really understand the use case now and when this could be useful and when it will trigger/flag. Will close now.

Regards