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

New SMB/WMI Module BitLocker #286

Merged
merged 12 commits into from
Jun 24, 2024
Merged

Conversation

termanix
Copy link
Contributor

@termanix termanix commented May 1, 2024

Checking BitLocker status on all drives.

image

@Adamkadaban
Copy link
Contributor

Would it perhaps be better to run this via WMI? Seems slightly more op-sec safe.

I haven't tested, but it seems possible: https://4sysops.com/archives/check-the-bitlocker-status-of-all-pcs-in-the-network/#rtoc-3

@termanix
Copy link
Contributor Author

termanix commented May 1, 2024

Would it perhaps be better to run this via WMI? Seems slightly more op-sec safe.

I haven't tested, but it seems possible: https://4sysops.com/archives/check-the-bitlocker-status-of-all-pcs-in-the-network/#rtoc-3

Test's an great idea, I'm testing now, I will share results manually. Thank you.

@termanix
Copy link
Contributor Author

termanix commented May 1, 2024

It works @Adamkadaban I can also adapt it to this method. Let me edit it.

image

@Adamkadaban
Copy link
Contributor

Adamkadaban commented May 1, 2024

@termanix Sorry, I should've been clearer. I meant through the WMI protocol rather than through powershell

Just checked with wmiquery and it seems to work. Also produces less security events

I think this should work for doing it through WMI:

iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login)
iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface)

bitlockerNamespace = "root\\CIMv2\\Security\\MicrosoftVolumeEncryption"
try:
    iWbemServices= iWbemLevel1Login.NTLMLogin(bitlockerNamespace, NULL, NULL)
except Exception as e:
    if str(e).find("WBEM_E_INVALID_NAMESPACE") >= 0:
        iWbemLevel1Login.RemRelease()
        dcom.disconnect()
    else:
        nxc_logger.debug(str(e))

iWbemServices.get_dce_rpc().set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY)

classQuery = "SELECT DriveLetter, ConversionStatus, ProtectionStatus, EncryptionMethod FROM Win32_EncryptableVolume"

try:
    iEnumWbemClassObject = iWbemServices.ExecQuery(classQuery)
    iWbemClassObject = iEnumWbemClassObject.Next(0xffffffff,1)[0]
    queryResult = iWbemClassObject.getProperties()
    # parse and print data from here
    iEnumWbemClassObject.RemRelease()
except Exception as e:
    if str(e).find("WBEM_E_INVALID_CLASS") >= 0:
        iWbemLevel1Login.RemRelease()
        iWbemServices.RemRelease()
        dcom.disconnect()
    print(str(e))
    nxc_logger.debug(str(e))

iWbemLevel1Login.RemRelease()
iWbemServices.RemRelease()
dcom.disconnect()

@termanix
Copy link
Contributor Author

termanix commented May 1, 2024

@termanix Sorry, I should've been clearer. I meant through the WMI protocol rather than through powershell

Just checked with wmiquery and it seems to work. Also produces less security events

I think this should work for doing it through WMI:

iInterface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login,wmi.IID_IWbemLevel1Login)
iWbemLevel1Login = wmi.IWbemLevel1Login(iInterface)

bitlockerNamespace = "root\\CIMv2\\Security\\MicrosoftVolumeEncryption"
try:
    iWbemServices= iWbemLevel1Login.NTLMLogin(bitlockerNamespace, NULL, NULL)
except Exception as e:
    if str(e).find("WBEM_E_INVALID_NAMESPACE") >= 0:
        iWbemLevel1Login.RemRelease()
        dcom.disconnect()
    else:
        nxc_logger.debug(str(e))

iWbemServices.get_dce_rpc().set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY)

classQuery = "SELECT DriveLetter, ConversionStatus, ProtectionStatus, EncryptionMethod FROM Win32_EncryptableVolume"

try:
    iEnumWbemClassObject = iWbemServices.ExecQuery(classQuery)
    iWbemClassObject = iEnumWbemClassObject.Next(0xffffffff,1)[0]
    queryResult = iWbemClassObject.getProperties()
    # parse and print data from here
    iEnumWbemClassObject.RemRelease()
except Exception as e:
    if str(e).find("WBEM_E_INVALID_CLASS") >= 0:
        iWbemLevel1Login.RemRelease()
        iWbemServices.RemRelease()
        dcom.disconnect()
    print(str(e))
    nxc_logger.debug(str(e))

iWbemLevel1Login.RemRelease()
iWbemServices.RemRelease()
dcom.disconnect()

Oh okay, I didn't test it with wmi protocol yet. I was just be quick for get result.

Using WMI is your idea and I don't want to steal your idea :D I can add it for WMI if it's okay to you.

@Adamkadaban
Copy link
Contributor

I can add it for WMI if it's okay to you.

Yes, feel free. Add me as a co-author to the commit if you so please ;)

@Marshall-Hallenbeck
Copy link
Collaborator

You could check exec-method and do SMB if it's smbexec, or WMI if it's wmiexec, and also add this to the WMI protocol and run it straight through WMI.

@termanix
Copy link
Contributor Author

termanix commented May 1, 2024

I can add it for WMI if it's okay to you.

Yes, feel free. Add me as a co-author to the commit if you so please ;)

Ofc. I will add it for WMI too then. If you joined discord can you contact me? We can implement it together.

@termanix
Copy link
Contributor Author

termanix commented May 3, 2024

It can be review now. I just cant pwned on Win 11 machine while using WMI protocol. But SMB works.
image

@termanix termanix changed the title New SMB Module BitLocker New SMB/WMI Module BitLocker May 3, 2024
@NeffIsBack NeffIsBack added this to the v1.3.0 milestone May 5, 2024
@Marshall-Hallenbeck
Copy link
Collaborator

@termanix can you add this module to the e2e tests file?

nxc/modules/bitlocker.py Show resolved Hide resolved
nxc/modules/bitlocker.py Outdated Show resolved Hide resolved
nxc/modules/bitlocker.py Outdated Show resolved Hide resolved
nxc/modules/bitlocker.py Outdated Show resolved Hide resolved
nxc/modules/bitlocker.py Outdated Show resolved Hide resolved
nxc/modules/bitlocker.py Outdated Show resolved Hide resolved
nxc/modules/bitlocker.py Outdated Show resolved Hide resolved
termanix added a commit to termanix/NetExec that referenced this pull request May 10, 2024
Removed bitlocker modules for adding to Pennyw0rth#286

Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Copy link
Contributor Author

@termanix termanix left a comment

Choose a reason for hiding this comment

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

Update e2e_commands.txt

@termanix
Copy link
Contributor Author

Updated @Marshall-Hallenbeck , It can be review.

@quahac
Copy link

quahac commented May 16, 2024

First of all, very nice module!
Win10/11 is okay. However, Windows Server 2008 DC will raise an error on SMB:
image

My approach is to check services instead of calling functions, for AV and Legacy. I have been using this method for a long time, and I like it. Ensure error handling (on endpoint) for this sneaky approach ... -EA SilentlyContinue ... . Example:
image

@termanix
Copy link
Contributor Author

First of all, very nice module! Win10/11 is okay. However, Windows Server 2008 DC will raise an error on SMB: image

My approach is to check services instead of calling functions, for AV and Legacy. I have been using this method for a long time, and I like it. Ensure error handling (on endpoint) for this sneaky approach ... -EA SilentlyContinue ... . Example: image

Hi, firstly thank you for your good comment ^^, I actually did it on older NetExec powershell. Now I fixed it again, i forgot it, thank you for reminding. Also thank you for suggestion. I added -EA SilentlyContinue for now, let's se how does it work.

@quahac
Copy link

quahac commented May 16, 2024

@termanix , I see you're coding now. My mistake; I told you to use the -ErrorAction SilentlyContinue approach in my situation. However, since the function doesn't exist yet, you cannot call -EA, as it will also raise an error.
You have to try the function and catch the error:
try{Get-BitLockerVolume | Select-Object MountPoint, EncryptionMethod, ProtectionStatus}catch{}

image

@termanix
Copy link
Contributor Author

@termanix , I see you're coding now. My mistake; I told you to use the -ErrorAction SilentlyContinue approach in my situation. However, since the function doesn't exist yet, you cannot call -EA, as it will also raise an error. You have to try the function and catch the error: try{Get-BitLockerVolume | Select-Object MountPoint, EncryptionMethod, ProtectionStatus}catch{}

image

Oh okay got it. But about try catch, I just want to show it on NetExec output if system has not get-bitlocker. Code checks it in output. But I got it what you mean.

termanix added 4 commits May 17, 2024 14:18
Using WMI command

Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Co-authored-by: Adamkadaban <adamkadaban@gmail.com>

Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Fixed a bug, if bitlockervolume and namespace does not exist.

Co-authored-by: Adamkadaban <adamkadaban@gmail.com>

Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
termanix added 5 commits May 17, 2024 14:18
Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Updated according to the new powershell update.


Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Fixed smb error line.

Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
Copy link
Contributor

@NeffIsBack NeffIsBack left a comment

Choose a reason for hiding this comment

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

Changed command execution to cmd as this is more reliable in my experience (also in my tests). Also fixed some bugs with parsing the output.

Detecting Bitlocker on my laptop but not on the DC. LGTM now:
image

@NeffIsBack
Copy link
Contributor

Can't test wmi on my notebook as it is not domain joined, but the negative detectin on the dc seems to work:
image

@Marshall-Hallenbeck also saw your command regarding ps_execute. Changed it for now cause it fails on my most of the time and also is flagged pretty often by AVs (for example even win defender yelled at me lol). If that's fine for you please also approve (you have a pending change request)

Copy link
Collaborator

@Marshall-Hallenbeck Marshall-Hallenbeck left a comment

Choose a reason for hiding this comment

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

@NeffIsBack sounds good! Looks like my other changes were fixed

@NeffIsBack
Copy link
Contributor

Great! I'll merge🚀

@NeffIsBack NeffIsBack merged commit ead02d8 into Pennyw0rth:main Jun 24, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants