POC of windows.system.domain

This commit is contained in:
clement rouault
2022-05-27 15:34:27 +02:00
parent b8788058e5
commit 63dd0130f1
5 changed files with 105 additions and 49 deletions
@@ -0,0 +1,62 @@
BOOL GetComputerNameExA(
[in] COMPUTER_NAME_FORMAT NameType,
[out] LPSTR lpBuffer,
[in, out] LPDWORD nSize
);
BOOL GetComputerNameExW(
[in] COMPUTER_NAME_FORMAT NameType,
[out] LPWSTR lpBuffer,
[in, out] LPDWORD nSize
);
BOOL WINAPI GetComputerNameA(
_Out_ LPCSTR lpBuffer,
_Inout_ LPDWORD lpnSize
);
BOOL WINAPI GetComputerNameW(
_Out_ LPWSTR lpBuffer,
_Inout_ LPDWORD lpnSize
);
BOOL WINAPI LookupAccountSidA(
_In_opt_ LPCSTR lpSystemName,
_In_ PSID lpSid,
_Out_opt_ LPCSTR lpName,
_Inout_ LPDWORD cchName,
_Out_opt_ LPCSTR lpReferencedDomainName,
_Inout_ LPDWORD cchReferencedDomainName,
_Out_ PSID_NAME_USE peUse
);
BOOL WINAPI LookupAccountSidW(
_In_opt_ LPWSTR lpSystemName,
_In_ PSID lpSid,
_Out_opt_ LPWSTR lpName,
_Inout_ LPDWORD cchName,
_Out_opt_ LPWSTR lpReferencedDomainName,
_Inout_ LPDWORD cchReferencedDomainName,
_Out_ PSID_NAME_USE peUse
);
BOOL LookupAccountNameA(
LPCSTR lpSystemName,
LPCSTR lpAccountName,
PSID Sid,
LPDWORD cbSid,
LPSTR ReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);
BOOL LookupAccountNameW(
LPCWSTR lpSystemName,
LPCWSTR lpAccountName,
PSID Sid,
LPDWORD cbSid,
LPWSTR ReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);
@@ -961,55 +961,6 @@ INT WINAPI GetSystemMetrics(
_In_ INT nIndex
);
BOOL WINAPI GetComputerNameA(
_Out_ LPCSTR lpBuffer,
_Inout_ LPDWORD lpnSize
);
BOOL WINAPI GetComputerNameW(
_Out_ LPWSTR lpBuffer,
_Inout_ LPDWORD lpnSize
);
BOOL WINAPI LookupAccountSidA(
_In_opt_ LPCSTR lpSystemName,
_In_ PSID lpSid,
_Out_opt_ LPCSTR lpName,
_Inout_ LPDWORD cchName,
_Out_opt_ LPCSTR lpReferencedDomainName,
_Inout_ LPDWORD cchReferencedDomainName,
_Out_ PSID_NAME_USE peUse
);
BOOL WINAPI LookupAccountSidW(
_In_opt_ LPWSTR lpSystemName,
_In_ PSID lpSid,
_Out_opt_ LPWSTR lpName,
_Inout_ LPDWORD cchName,
_Out_opt_ LPWSTR lpReferencedDomainName,
_Inout_ LPDWORD cchReferencedDomainName,
_Out_ PSID_NAME_USE peUse
);
BOOL LookupAccountNameA(
LPCSTR lpSystemName,
LPCSTR lpAccountName,
PSID Sid,
LPDWORD cbSid,
LPSTR ReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);
BOOL LookupAccountNameW(
LPCWSTR lpSystemName,
LPCWSTR lpAccountName,
PSID Sid,
LPDWORD cbSid,
LPWSTR ReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);
DWORD WINAPI GetInterfaceInfo(
_Out_ PIP_INTERFACE_INFO pIfTable,
@@ -54,3 +54,16 @@ typedef struct _SYSTEM_BASIC_INFORMATION {
PVOID Reserved2[4];
CHAR NumberOfProcessors;
} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
typedef enum _COMPUTER_NAME_FORMAT {
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
} COMPUTER_NAME_FORMAT;
+17
View File
@@ -174,6 +174,23 @@ class System(object):
winproxy.GetComputerNameA(buf, ctypes.byref(size))
return buf[:size.value]
def _computer_name_ex(self, nametype):
size = gdef.DWORD(0)
try:
winproxy.GetComputerNameExW(nametype, None, ctypes.byref(size))
except WindowsError as e:
if e.winerror != gdef.ERROR_MORE_DATA:
raise
buf = ctypes.create_unicode_buffer(size.value)
winproxy.GetComputerNameExW(nametype, buf, ctypes.byref(size))
return buf[:size.value]
@utils.fixedproperty
def domain(self):
# [WIP] name of the domain joined by the computer, None is no domain joined
return self._computer_name_ex(gdef.ComputerNameDnsDomain) or None
@utils.fixedpropety
def version(self):
"""The version of the system
+13
View File
@@ -335,6 +335,8 @@ def GetVersionExA(lpVersionInformation):
def GetVersionExW(lpVersionInformation):
return GetVersionExW.ctypes_function(lpVersionInformation)
## Hardware
@Kernel32Proxy()
@@ -373,6 +375,14 @@ def GetComputerNameA(lpBuffer, lpnSize):
def GetComputerNameW(lpBuffer, lpnSize):
return GetComputerNameW.ctypes_function(lpBuffer, lpnSize)
@Kernel32Proxy()
def GetComputerNameExA(NameType, lpBuffer, nSize):
return GetComputerNameExA.ctypes_function(NameType, lpBuffer, nSize)
@Kernel32Proxy()
def GetComputerNameExW(NameType, lpBuffer, nSize):
return GetComputerNameExW.ctypes_function(NameType, lpBuffer, nSize)
@Kernel32Proxy()
def GetWindowsDirectoryA(lpBuffer, uSize=None):
if uSize is None:
@@ -389,6 +399,9 @@ def GetWindowsDirectoryW(lpBuffer, uSize=None):
def GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType):
return GetProductInfo.ctypes_function(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType)
## Other
@Kernel32Proxy(error_check=no_error_check)