mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Testing/Fixing some sample for py3
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import hashlib
|
||||
import base64
|
||||
import windows.crypto
|
||||
|
||||
windowscert = """-----BEGIN CERTIFICATE-----
|
||||
windowscert = b"""-----BEGIN CERTIFICATE-----
|
||||
MIIFBDCCA+ygAwIBAgITMwAAAQZuwyXEMckYDgAAAAABBjANBgkqhkiG9w0BAQsF
|
||||
ADCBhDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcT
|
||||
B1JlZG1vbmQxHjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjEuMCwGA1UE
|
||||
@@ -32,7 +33,7 @@ l2ec6CyjDQc6HcQBNCsbJVq6qGtQbYNE+ih+KhIU4tO5jf25xthf2g==
|
||||
-----END CERTIFICATE-----"""
|
||||
|
||||
|
||||
raw_cert = ("".join(windowscert.split("\n")[1:-1])).decode('base64')
|
||||
raw_cert = base64.decodestring(b"".join(windowscert.split(b"\n")[1:-1]))
|
||||
cert = windows.crypto.Certificate.from_buffer(raw_cert)
|
||||
|
||||
print("Analysing certificate: {0}".format(cert))
|
||||
@@ -42,7 +43,7 @@ print(" * raw_serial: <{0}>".format(cert.raw_serial))
|
||||
print(" * serial: <{0}>".format(cert.serial))
|
||||
print(" * encoded start: <{0!r}>".format(cert.encoded[:20]))
|
||||
|
||||
print ""
|
||||
print("")
|
||||
chains = cert.chains
|
||||
print("This certificate has {0} certificate chain(s)".format(len(chains)))
|
||||
for i, chain in enumerate(chains):
|
||||
@@ -52,7 +53,7 @@ for i, chain in enumerate(chains):
|
||||
print(" {0}:".format(ccert))
|
||||
print(" * issuer: <{0}>".format(ccert.issuer))
|
||||
|
||||
print ""
|
||||
print ("")
|
||||
cert_to_verif = ccert
|
||||
print("Looking for <{0}> in trusted certificates".format(cert_to_verif.name))
|
||||
root_store = windows.crypto.CertificateStore.from_system_store("Root")
|
||||
@@ -78,7 +79,7 @@ print("Analysing {0}".format(cryptobj))
|
||||
print("File has {0} signer(s):".format(cryptobj.crypt_msg.nb_signer))
|
||||
for i, signer in enumerate(cryptobj.crypt_msg.signers):
|
||||
print("Signer {0}:".format(i))
|
||||
print(" * Issuer: {0!r}".format(windows.crypto.ECRYPT_DATA_BLOB(signer.Issuer.cbData, signer.Issuer.pbData).data))
|
||||
print(" * Issuer: {0!r}".format(signer.Issuer.data))
|
||||
print(" * HashAlgorithme: {0}".format(signer.HashAlgorithm.pszObjId))
|
||||
cert = cryptobj.cert_store.find(signer.Issuer, signer.SerialNumber)
|
||||
print(" * Certificate: {0}".format(cert))
|
||||
|
||||
+14
-2
@@ -34,6 +34,12 @@ def search_name_in_windef(target):
|
||||
if match(target, name):
|
||||
print(repr(windef))
|
||||
|
||||
def search_name_in_winerror(target):
|
||||
for name, windef in meta.errors_walker():
|
||||
if match(target, name):
|
||||
print(repr(windef))
|
||||
|
||||
|
||||
def search_name_in_interface(target):
|
||||
for name, interface in meta.interfaces_walker():
|
||||
if not issubclass(interface, windows.generated_def.interfaces.COMInterface):
|
||||
@@ -54,17 +60,23 @@ def search_name(target):
|
||||
search_name_in_struct(target)
|
||||
print("== Windef ==")
|
||||
search_name_in_windef(target)
|
||||
print("== Winerror ==")
|
||||
search_name_in_winerror(target)
|
||||
print("== Interfaces ==")
|
||||
search_name_in_interface(target)
|
||||
|
||||
def search_value(target):
|
||||
for name, windef in meta.windef_walker():
|
||||
if target == windef:
|
||||
print(windef)
|
||||
print(repr(windef))
|
||||
|
||||
for status in gdef.ntstatus.NtStatusException.ALL_STATUS.values():
|
||||
if target == status[0]:
|
||||
print(status)
|
||||
print(repr(windef))
|
||||
|
||||
for name, windef in meta.errors_walker():
|
||||
if target == windef:
|
||||
print(repr(windef))
|
||||
|
||||
parser = argparse.ArgumentParser(prog=__file__)
|
||||
parser.add_argument('target', help='The name or value to research in PythonForWindows generated definition')
|
||||
|
||||
@@ -30,7 +30,7 @@ print(" * Definition: <{task.definition}>".format(task=task))
|
||||
print("Listing actions:")
|
||||
for action in task.definition.actions:
|
||||
print(" * Action: <{action}>".format(action=action))
|
||||
print(" * Type: <{action.type}>".format(action=action))
|
||||
print(" * Type: <{action.type!r}>".format(action=action))
|
||||
if getattr(action, "path", None):
|
||||
print(" * path: <{action.path}>".format(action=action))
|
||||
print(" * arguments: <{action.arguments}>".format(action=action))
|
||||
@@ -38,7 +38,7 @@ for action in task.definition.actions:
|
||||
# import pdb;pdb.set_trace()
|
||||
print("Listing triggers:")
|
||||
for trigger in task.definition.triggers:
|
||||
print(" * Trigger type: <{trigger.type}>".format(trigger=trigger))
|
||||
print(" * Trigger type: <{trigger.type!r}>".format(trigger=trigger))
|
||||
|
||||
print("")
|
||||
DEMO_FOLDER_NAME = "PFW_DEMO_FOLDER"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import argparse
|
||||
import os.path
|
||||
|
||||
import windows.security
|
||||
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(prog=__file__)
|
||||
parser.add_argument('sddl', help='The SDDL to explain')
|
||||
parser.add_argument('--type', help='The type of object described by the SDDL (used for the explication of values in the access mask)')
|
||||
res = parser.parse_args()
|
||||
|
||||
if os.path.exists(res.sddl):
|
||||
windows.security.SecurityDescriptor.from_filename(res.sddl).explain("file")
|
||||
else:
|
||||
windows.security.SecurityDescriptor.from_string(res.sddl).explain(res.type)
|
||||
Reference in New Issue
Block a user