Skip to content

Commit d9a43a4

Browse files
committed
Update readme with Token/SecurityDescriptor demo + fix flag repr in README + small docstring fix
1 parent c2f2f4c commit d9a43a4

5 files changed

Lines changed: 83 additions & 35 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
*.pyc
22
doctrees
33
*.inv
4-
*.pickle
4+
*.pickle
5+
6+
.vscode/
7+
.cache/
8+
dist/

CHANGELOG

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
Between 0.5 & 0.6:
2-
windows.wmi
3-
- WmiRequester -> WmiNamespace qui herite maintenat de Iwebmservice
4-
- real error display handling :)
5-
- Toutes les API WMI :)
1+
Between 0.4 & 0.5:
2+
== New features ==
3+
- windows.security
4+
- SecurityDescriptor / ACL / ACE objects
5+
- Improved Token object
6+
- windows.debug
7+
- New callback Debugger.on_setup
8+
9+
== Change / Break ==
10+
- windows.winproxy
11+
- Kernel32Error replaced by WinproxyError
12+
- It seemed weird that ntdll/advapi32/etc raised Kernel32Error..
13+
- windows.wmi
14+
- Wmi API changed, most of them do not return dict anymore but WmiObject
15+
- It can be used like mapping
16+
- It offers improved feature
17+
- real error display handling :)
18+
619
- windows.com
7-
- ImprovedVariant -> variant + new api variant
8-
- debugger.on_setup
9-
- ndr string add final \x00 if needed
20+
- ImprovedVariant renamed Variant + new api variant
21+
- This is not documented yet
22+
23+
- windows.rpc.ndr
24+
- ndr strings add final \x00 when packing if not present
1025
- crypto
1126
- CertificateStore.find return None if certif is not found (was raising in the past)
1227
- removed ECRYPT_DATA_BLOB
1328
- new CRYPT_DATA_BLOB is an _extended_struct :)
1429

1530

1631

17-
1832
Since 0.35:
1933
* WinProcess.get_mapped_filename can now raise on non-standard error (like: ERROR_TRANSACTION_NOT_ACTIVE)
2034
* WinProcess.get_mapped_filename now use GetMappedFilenameW (returning an unicode string)

README.md

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can also make some operation on threads (suspend/resume/wait/get(or set) con
4949
>>> windows.current_process.bitness
5050
32
5151
>>> windows.current_process.token.integrity
52-
SECURITY_MANDATORY_MEDIUM_RID(0x2000L)
52+
SECURITY_MANDATORY_MEDIUM_RID(0x2000)
5353
>>> proc = [p for p in windows.system.processes if p.name == "notepad.exe"][0]
5454
>>> proc
5555
<WinProcess "notepad.exe" pid 16520 at 0x544e410>
@@ -89,7 +89,7 @@ Information about the Windows computer running the script are available through
8989
>>> windows.system.computer_name
9090
'DESKTOP-VKUGISR'
9191
>>> windows.system.product_type
92-
VER_NT_WORKSTATION(0x1L)
92+
VER_NT_WORKSTATION(0x1)
9393
>>> windows.system.version
9494
(10, 0)
9595
>>> windows.system.version_name
@@ -105,7 +105,7 @@ VER_NT_WORKSTATION(0x1L)
105105
>>> windows.system.logicaldrives[0]
106106
<LogicalDrive "C:\" (DRIVE_FIXED)>
107107
>>> windows.system.services[23]
108-
<ServiceA "Appinfo" SERVICE_RUNNING(0x4L)>
108+
<ServiceA "Appinfo" SERVICE_RUNNING(0x4)>
109109

110110
```
111111

@@ -187,6 +187,39 @@ a simple x86/x64 assembler.
187187
'\x81\xff\x00\x00\x00\x00u\x06\xc7\xc0\x01\x00\x00\x00\xc3'
188188
```
189189

190+
### Token / Security Descriptor
191+
192+
Objects easing access to some information about ``Token`` and ``SecurityDescriptor`` are also available.
193+
194+
```python
195+
>>> import windows.security
196+
>>> import windows.generated_def as gdef
197+
>>> tok = windows.current_process.token
198+
>>> tok
199+
<Token TokenId=0x6a2b4550 Type=TokenPrimary(0x1)>
200+
>>> tok.username
201+
u'hakril'
202+
>>> tok.type
203+
tagTOKEN_TYPE.TokenPrimary(0x1)
204+
>>> tok.integrity
205+
SECURITY_MANDATORY_MEDIUM_RID(0x2000)
206+
>>> tok.duplicate(type=gdef.TokenImpersonation, impersonation_level=gdef.SecurityIdentification)
207+
<Token TokenId=0x6a3532ce Type=TokenImpersonation(0x2) ImpersonationLevel=SecurityIdentification(0x1)>
208+
209+
# Security Descriptor
210+
>>> sd = windows.security.SecurityDescriptor.from_filename("c:\windows\system32\kernel32.dll")
211+
>>> sd
212+
<SecurityDescriptor object at 0x054E3DF0>
213+
>>> windows.utils.lookup_sid(sd.owner)
214+
(u'NT SERVICE', u'TrustedInstaller')
215+
>>> sd.dacl
216+
<Acl count=6>
217+
>>> list(sd.dacl)
218+
[<AccessAllowedACE mask=2032127>, <AccessAllowedACE mask=1179817>, <AccessAllowedACE mask=1179817>, <AccessAllowedACE mask=1179817>, <AccessAllowedACE mask=1179817>, <AccessAllowedACE mask=1179817>]
219+
>>> sd.dacl[1].sid
220+
<PSID "S-1-5-32-544">
221+
```
222+
190223
### Wintrust
191224

192225
To easily script some signature check script, PythonForWindows implements some wrapper functions around ``wintrust.dll``
@@ -202,7 +235,7 @@ SignatureData(signed=True,
202235
catalog=u'C:\\Windows\\system32\\CatRoot\\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\\Package_35_for_KB3128650~31bf3856ad364e35~amd64~~6.3.1.2.cat',
203236
catalogsigned=True, additionalinfo=0L)
204237
>>> windows.wintrust.full_signature_information(r"C:\Windows\system32\python27.dll")
205-
SignatureData(signed=False, catalog=None, catalogsigned=False, additionalinfo=TRUST_E_NOSIGNATURE(0x800b0100L))
238+
SignatureData(signed=False, catalog=None, catalogsigned=False, additionalinfo=TRUST_E_NOSIGNATURE(0x800b0100))
206239
```
207240

208241
### WMI
@@ -234,7 +267,7 @@ The project also contains some wrapping classes around `_winreg` for simpler use
234267
>>> cuuser_software
235268
<PyHKey "HKEY_CURRENT_USER\Software">
236269
>>> cuuser_software.sam
237-
KEY_READ(0x20019L)
270+
KEY_READ(0x20019)
238271
# Explore subkeys
239272
>>> cuuser_software.subkeys[:3]
240273
[<PyHKey "HKEY_CURRENT_USER\Software\7-Zip">, <PyHKey "HKEY_CURRENT_USER\Software\AppDataLow">, <PyHKey "HKEY_CURRENT_USER\Software\Audacity">]
@@ -408,9 +441,9 @@ calc.execute(x86.assemble("int3; mov [0x42424242], EAX; ret"))
408441
d.loop()
409442

410443
## Ouput ##
411-
Got exception EXCEPTION_BREAKPOINT(0x80000003L) at 0x77e13c7d
412-
Got exception EXCEPTION_BREAKPOINT(0x80000003L) at 0x230000
413-
Got exception EXCEPTION_ACCESS_VIOLATION(0xc0000005L) at 0x230001
444+
Got exception EXCEPTION_BREAKPOINT(0x80000003) at 0x77e13c7d
445+
Got exception EXCEPTION_BREAKPOINT(0x80000003) at 0x230000
446+
Got exception EXCEPTION_ACCESS_VIOLATION(0xc0000005) at 0x230001
414447
Access Violation: kill target process
415448
```
416449

@@ -469,10 +502,10 @@ print("Done!")
469502

470503
Code addr = 0x6a0002
471504
GOT AN HXBP at 0x6a0002
472-
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004L) at 0x6a0003
473-
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004L) at 0x6a0004
474-
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004L) at 0x6a0005
475-
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004L) at 0x770c7c04
505+
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004) at 0x6a0003
506+
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004) at 0x6a0004
507+
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004) at 0x6a0005
508+
EXCEPTION !!!! Got a EXCEPTION_SINGLE_STEP(0x80000004) at 0x770c7c04
476509
Done!
477510

478511
```

TODO

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ TODO:
22

33
=== CRITICAL BEFORE 0.5 ===
44

5-
- Add news features to index.html
5+
6+
-- CRITICAL BEFORE 0.6 ? --
7+
68
- Document / fix / release:
79
- windows.bits
810
- window
9-
- WMI
10-
- verif samples
11-
- add create_process sample to doc
12-
- rewrite / check doc + samples
13-
- Token
14-
- Finish code
15-
- samples
16-
- doc :)
11+
- Ndr:
12+
- Handle les struct conformant imbriquees
13+
- Handle le packing de struct specifique
1714

1815
======
1916

windows/winobject/wmi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ def spawn_instance(self):
8383
def genus(self):
8484
"""The genus of the object.
8585
86-
:returns: ``WBEM_GENUS_CLASS(0x1L)`` if the :class:`WmiObject` is a Class and
87-
``WBEM_GENUS_INSTANCE(0x2L)`` for instances and events
86+
:returns: ``WBEM_GENUS_CLASS(0x1L)`` if the :class:`WmiObject` is a Class and ``WBEM_GENUS_INSTANCE(0x2L)`` for instances and events.
8887
"""
8988
return gdef.tag_WBEM_GENUS_TYPE.mapper[self.get("__GENUS")]
9089

9190
## Higher level API
9291

9392
def get_properties(self, system_properties=False):
94-
"""Return the list of properties' names available for the current object.
95-
If ``system_properties`` is ``False`` property names begining with ``_` are ignored.
93+
"""Return the list of properties names available for the current object.
94+
If ``system_properties`` is ``False`` property names begining with ``_`` are ignored.
9695
9796
:returns: [:class:`str`] -- A list of string
97+
9898
.. note:
9999
100100
About system properties: https://docs.microsoft.com/en-us/windows/desktop/wmisdk/wmi-system-properties

0 commit comments

Comments
 (0)