windows-tools-powershell 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- windows_tools_powershell-0.5.0/LICENSE +29 -0
- windows_tools_powershell-0.5.0/PKG-INFO +300 -0
- windows_tools_powershell-0.5.0/README.md +272 -0
- windows_tools_powershell-0.5.0/setup.cfg +4 -0
- windows_tools_powershell-0.5.0/setup.py +218 -0
- windows_tools_powershell-0.5.0/tests/test_antivirus.py +104 -0
- windows_tools_powershell-0.5.0/tests/test_bitlocker.py +45 -0
- windows_tools_powershell-0.5.0/tests/test_bitness.py +35 -0
- windows_tools_powershell-0.5.0/tests/test_file_utils.py +207 -0
- windows_tools_powershell-0.5.0/tests/test_impersonate.py +67 -0
- windows_tools_powershell-0.5.0/tests/test_installed_software.py +61 -0
- windows_tools_powershell-0.5.0/tests/test_logicial_disks.py +87 -0
- windows_tools_powershell-0.5.0/tests/test_office.py +43 -0
- windows_tools_powershell-0.5.0/tests/test_powershell.py +46 -0
- windows_tools_powershell-0.5.0/tests/test_product_key.py +50 -0
- windows_tools_powershell-0.5.0/tests/test_registry.py +105 -0
- windows_tools_powershell-0.5.0/tests/test_securityprivilege.py +38 -0
- windows_tools_powershell-0.5.0/tests/test_server.py +48 -0
- windows_tools_powershell-0.5.0/tests/test_signtool.py +146 -0
- windows_tools_powershell-0.5.0/tests/test_updates.py +98 -0
- windows_tools_powershell-0.5.0/tests/test_users.py +133 -0
- windows_tools_powershell-0.5.0/tests/test_virtualization.py +59 -0
- windows_tools_powershell-0.5.0/tests/test_windows_firewall.py +37 -0
- windows_tools_powershell-0.5.0/tests/test_wmi_queries.py +166 -0
- windows_tools_powershell-0.5.0/windows_tools/powershell/__init__.py +328 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/PKG-INFO +300 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/SOURCES.txt +30 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/dependency_links.txt +1 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/namespace_packages.txt +1 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/not-zip-safe +1 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/requires.txt +3 -0
- windows_tools_powershell-0.5.0/windows_tools_powershell.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2024, netinvent, Orsiris de Jong, contact@netinvent.fr
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: windows_tools_powershell
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: PowerShell interpreter wrapper
|
|
5
|
+
Home-page: https://github.com/netinvent/windows_tools
|
|
6
|
+
Author: NetInvent - Orsiris de Jong
|
|
7
|
+
Author-email: contact@netinvent.fr
|
|
8
|
+
Keywords: wmi,virtualization,file,acl,ntfs,refs,antivirus,security,firewall,office
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Topic :: Software Development
|
|
12
|
+
Classifier: Topic :: System
|
|
13
|
+
Classifier: Topic :: System :: Operating System
|
|
14
|
+
Classifier: Topic :: System :: Shells
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
+
Classifier: Operating System :: Microsoft
|
|
20
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
21
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
22
|
+
Requires-Python: >=3.5
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: command_runner>=1.2.1
|
|
26
|
+
Requires-Dist: windows_tools.registry>=1.0.1
|
|
27
|
+
Requires-Dist: ofunctions.json_sanitize>0.1.1
|
|
28
|
+
|
|
29
|
+
# windows_tools
|
|
30
|
+
## Collection of useful python functions around Microsoft Windows
|
|
31
|
+
|
|
32
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
33
|
+
[](http://isitmaintained.com/project/netinvent/ofunctions "Percentage of issues still open")
|
|
34
|
+
[](https://codeclimate.com/github/netinvent/windows_tools/maintainability)
|
|
35
|
+
[](https://codecov.io/gh/netinvent/windows_tools)
|
|
36
|
+
[](https://github.com/netinvent/windows_tools/actions/workflows/windows.yaml)
|
|
37
|
+
[](https://github.com/netinvent/windows_tools/releases/latest)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
windows_tools is a set of various recurrent functions amongst
|
|
41
|
+
|
|
42
|
+
- antivirus: antivirus state and list of installed AV engines
|
|
43
|
+
- bitlocker: drive encryption status and protector key retrieval
|
|
44
|
+
- bitness: simple bitness identification
|
|
45
|
+
- file_utils: file ownership handling, NTFS & ReFS ACL handling, file listing with permission fixes
|
|
46
|
+
- impersonate: python Runas implementation
|
|
47
|
+
- installed_software: list of installed software from registry, 32 and 64 bits
|
|
48
|
+
- logical_disk: logical disk listing
|
|
49
|
+
- misc: basic time related functions to convert windows ticks into epoch / date strings
|
|
50
|
+
- office: microsoft Office version identification, works for click & run, O365 and legacy
|
|
51
|
+
- powershell: powershell wrapper to identify interpreter and run scripts or commands
|
|
52
|
+
- product_key: windows product key retrieval
|
|
53
|
+
- registry: registry 32 and 64 bit API
|
|
54
|
+
- securityprivilege: enable / disable various security privileges for user
|
|
55
|
+
- server: windows server identification
|
|
56
|
+
- signtool: Easily sign executables with Authenticode
|
|
57
|
+
- updates: get all installed windows updates based on COM, WMI and registry retrieval methods
|
|
58
|
+
- users: user lookup for SID/PySID/username
|
|
59
|
+
- virtualization: virtualization platform identification for guest
|
|
60
|
+
- windows_firewall: windows firewall state retrieval
|
|
61
|
+
- wmi_queries: windows WMI query wrapper, wmi timezone converters
|
|
62
|
+
|
|
63
|
+
It is compatible with Python 3.5+ and is tested on Windows only (obviously).
|
|
64
|
+
|
|
65
|
+
## Setup
|
|
66
|
+
|
|
67
|
+
You may install the whole `windows_tools` package or any subpackage using the following commands
|
|
68
|
+
```
|
|
69
|
+
pip install windows_tools
|
|
70
|
+
pip install windows_tools.<subpackage>
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
### antivirus
|
|
77
|
+
|
|
78
|
+
The antivirus package tries to list installed Antivirus products via the SecurityCenter API (using WMI calls).
|
|
79
|
+
Since SecurityCenter API does not exist on Windows Servers, we also need to check for installed antivirus software using the uninstall registry keys.
|
|
80
|
+
These checks are more fuzzy, but allow to detect the following products:
|
|
81
|
+
|
|
82
|
+
- avast
|
|
83
|
+
- avira
|
|
84
|
+
- avg technologies
|
|
85
|
+
- bitdefender
|
|
86
|
+
- dr web
|
|
87
|
+
- eset
|
|
88
|
+
- f-secure
|
|
89
|
+
- g data software
|
|
90
|
+
- kaspersky
|
|
91
|
+
- mcafee
|
|
92
|
+
- panda security
|
|
93
|
+
- sophos
|
|
94
|
+
- trend micro
|
|
95
|
+
- malwarebytes
|
|
96
|
+
- vipre
|
|
97
|
+
- sentinel one
|
|
98
|
+
- cybereason
|
|
99
|
+
- cylance
|
|
100
|
+
|
|
101
|
+
On top of that list, it will detect any installed software containing "antivirus/antiviral/antimalware" in the name.
|
|
102
|
+
|
|
103
|
+
Please report back if your antivirus is not detected, so we can improve the fuzzy detection here.
|
|
104
|
+
|
|
105
|
+
Usage
|
|
106
|
+
```
|
|
107
|
+
import windows_tools.antivirus
|
|
108
|
+
|
|
109
|
+
result = windows_tools.antivirus.get_installed_antivirus_software()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`result` will contain a list of dict like
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
[{
|
|
116
|
+
'name': 'Windows Defender',
|
|
117
|
+
'version': None,
|
|
118
|
+
'publisher': None,
|
|
119
|
+
'enabled': False,
|
|
120
|
+
'is_up_to_date': True,
|
|
121
|
+
'type': 'Windows Defender / Security Essentials'
|
|
122
|
+
}, {
|
|
123
|
+
'name': 'Malwarebytes version 4.4.6.132',
|
|
124
|
+
'version': '4.4.6.132',
|
|
125
|
+
'publisher': 'Malwarebytes',
|
|
126
|
+
'enabled': None,
|
|
127
|
+
'is_up_to_date': None,
|
|
128
|
+
'type': None
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Warning**
|
|
134
|
+
Keys `enabled`, `is_up_to_date` and `type` are only filled via securityCenter API*.
|
|
135
|
+
Keys `version` and `publisher` are only filled via installed software list.
|
|
136
|
+
The only guaranteed filled key will always be `name`
|
|
137
|
+
|
|
138
|
+
### bitlocker
|
|
139
|
+
|
|
140
|
+
Bitlocker can only work on NTFS or ReFS formatted disks.
|
|
141
|
+
Bitlocker keys can only be retrieved on local disks.
|
|
142
|
+
|
|
143
|
+
#### Usage
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
import windows_tools.bitlocker
|
|
147
|
+
|
|
148
|
+
result = windows_tools.bitlocker.get_bitlocker_full_status()
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`result` will contain a dict as follows containing raw strings from `manage-bde` windows tool:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
{
|
|
155
|
+
'C:': {
|
|
156
|
+
'status': 'Chiffrement de lecteur BitLocker\xa0: outil de configuration version 10.0.19041\nCopyright (C) 2013 Microsoft Corporation. Tous droits réservés.\n\nVolume C: [Windows ]\n[Volume du système d?exploitation]\n\n Taille : 855,14 Go\n Version de BitLocker : Aucun\n État de la conversion : Intégralement déchiffré\n Pourcentage chiffré : 0,0%\n Méthode de chiffrement : Aucun\n État de la protection\xa0: Protection désactivée\n État du verrouillage : Déverrouillé\n Champ d?identification : Aucun\n Protecteurs de clés : Aucun trouvé\n\n',
|
|
157
|
+
'protectors': None
|
|
158
|
+
},
|
|
159
|
+
'D:': {
|
|
160
|
+
'status': 'Chiffrement de lecteur BitLocker\xa0: outil de configuration version 10.0.19041\nCopyright (C) 2013 Microsoft Corporation. Tous droits réservés.\n\nVolume D: [Étiquette inconnue]\n[Volume de données]\n\n Taille : Inconnu Go\n Version de BitLocker : 2.0\n État de la conversion : Inconnu\n Pourcentage chiffré : Inconnu%\n Méthode de chiffrement : XTS-AES 128\n État de la protection\xa0: Inconnu\n État du verrouillage : Verrouillé\n Champ d?identification : Inconnu\n Déverrouillage automatique : Désactivé\n Protecteurs de clés\xa0:\n Password\n Mot de passe numérique\n\n',
|
|
161
|
+
'protectors': 'Chiffrement de lecteur BitLocker\xa0: outil de configuration version 10.0.19041\nCopyright (C) 2013 Microsoft Corporation. Tous droits réservés.\n\nVolume D: [Étiquette inconnue]\nTous les protecteurs de clés\n\n Password :\n ID : {SOMEPASS-WORD-ICAN-NNOT-REMEMBERWELL}\n\n Mot de passe numérique :\n ID : {SOMEPASS-GUID-ICAN-NNOT-REMEMBERWELL}\n\n'
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
You may parse those or simply pretty print since print will not interpret special characters from a dict or multiple variables at once:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
result = windows_tools.bitlocker.get_bitlocker_full_status()
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
result = get_bitlocker_full_status()
|
|
173
|
+
for drive in result:
|
|
174
|
+
for designation, content in result[drive].items():
|
|
175
|
+
print(designation, content)
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Warning** bitlocker needs to be run as admin.
|
|
180
|
+
Running as non administrator will produce the following logs
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
Don't have permission to get bitlocker drive status for C:.
|
|
184
|
+
Don't have permission to get bitlocker drive protectors for C:.
|
|
185
|
+
Don't have permission to get bitlocker drive status for D:.
|
|
186
|
+
Don't have permission to get bitlocker drive protectors for D:.
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Output shall be
|
|
190
|
+
```
|
|
191
|
+
{
|
|
192
|
+
'C:': {
|
|
193
|
+
'status': None,
|
|
194
|
+
'protectors': None
|
|
195
|
+
},
|
|
196
|
+
'D:': {
|
|
197
|
+
'status': None,
|
|
198
|
+
'protectors': None
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
You can check that you have administrator rights with `windows_utils.users` module
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
### bitness
|
|
207
|
+
|
|
208
|
+
### file_utils
|
|
209
|
+
|
|
210
|
+
### impersonate
|
|
211
|
+
|
|
212
|
+
### installed_software
|
|
213
|
+
|
|
214
|
+
### logical_disk
|
|
215
|
+
|
|
216
|
+
### misc
|
|
217
|
+
|
|
218
|
+
### office
|
|
219
|
+
|
|
220
|
+
### powershell
|
|
221
|
+
|
|
222
|
+
### product_key
|
|
223
|
+
|
|
224
|
+
### registry
|
|
225
|
+
|
|
226
|
+
### securityprivilege
|
|
227
|
+
|
|
228
|
+
### server
|
|
229
|
+
|
|
230
|
+
### signtool
|
|
231
|
+
|
|
232
|
+
signtool is designed to make the windows executable signature as simple as possible.
|
|
233
|
+
Once the Windows SDK is installed on your machine, you can sign any executable with the following commands:
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
from windows_tools.signtool import SignTool
|
|
237
|
+
signer = SignTool()
|
|
238
|
+
signer.sign(r"c:\path\to\executable", bitness=64)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Note that current versions of `signtool.exe` that come with Windows 10 SDK automagically detect hardware EV certificate tokens like Safenet.
|
|
242
|
+
|
|
243
|
+
When using former certificate files in order to sign an executable, one should use the following syntax:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
from windows_tools.signtool import SignTool
|
|
247
|
+
signer = SignTool(certificate=r"c:\path\to\cert.pfx", pkcs12_password="the_certificate_file_password")
|
|
248
|
+
signer.sign(r"c:\path\to\executable", bitness=64)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
If the wrong certificate is used to sign, please open `certmgr.msc`, go to Private > Certificates and remove the certificate you don't want.
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
### updates
|
|
255
|
+
|
|
256
|
+
Windows updates can be retrieved via a COM object that talks to Windows Update service, via WMI requests or via registry entries.
|
|
257
|
+
All methods can return different results, so they are combined into one function.
|
|
258
|
+
|
|
259
|
+
Usage
|
|
260
|
+
```
|
|
261
|
+
import windows_tools.updates
|
|
262
|
+
|
|
263
|
+
result = windows_tools.updates.get_windows_updates(filter_duplicates=True, include_all_states=False)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
`result` will contain a list of dict like
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
[{
|
|
270
|
+
'kb': 'KB123456',
|
|
271
|
+
'date': '2021-01-01 00:01:02',
|
|
272
|
+
'title': 'Some update title',
|
|
273
|
+
'description': 'Some update description',
|
|
274
|
+
'supporturl': 'https://support.microsoft.com/someID',
|
|
275
|
+
'operation': 'Installation'
|
|
276
|
+
'result': 'Installed'
|
|
277
|
+
}, {
|
|
278
|
+
'kb': None,
|
|
279
|
+
'date': '2021-01-01 00:01:02',
|
|
280
|
+
'title': 'Windows 10 20H1 update',
|
|
281
|
+
'description': 'Pretty big system update',
|
|
282
|
+
'supporturl': 'https://support.microsoft.com/someID',
|
|
283
|
+
'operation': 'Installation'
|
|
284
|
+
'result': 'Installed'
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Using `filter_duplicates` will avoid returning multiple times the same KB from different sources.
|
|
290
|
+
This setting is enabled by default.
|
|
291
|
+
|
|
292
|
+
The parameter `include_all_states` set to True will include all updates, even those who failed to install or are superseeded.
|
|
293
|
+
|
|
294
|
+
### users
|
|
295
|
+
|
|
296
|
+
### virtualization
|
|
297
|
+
|
|
298
|
+
### windows_firewall
|
|
299
|
+
|
|
300
|
+
### wmi_queries
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# windows_tools
|
|
2
|
+
## Collection of useful python functions around Microsoft Windows
|
|
3
|
+
|
|
4
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
5
|
+
[](http://isitmaintained.com/project/netinvent/ofunctions "Percentage of issues still open")
|
|
6
|
+
[](https://codeclimate.com/github/netinvent/windows_tools/maintainability)
|
|
7
|
+
[](https://codecov.io/gh/netinvent/windows_tools)
|
|
8
|
+
[](https://github.com/netinvent/windows_tools/actions/workflows/windows.yaml)
|
|
9
|
+
[](https://github.com/netinvent/windows_tools/releases/latest)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
windows_tools is a set of various recurrent functions amongst
|
|
13
|
+
|
|
14
|
+
- antivirus: antivirus state and list of installed AV engines
|
|
15
|
+
- bitlocker: drive encryption status and protector key retrieval
|
|
16
|
+
- bitness: simple bitness identification
|
|
17
|
+
- file_utils: file ownership handling, NTFS & ReFS ACL handling, file listing with permission fixes
|
|
18
|
+
- impersonate: python Runas implementation
|
|
19
|
+
- installed_software: list of installed software from registry, 32 and 64 bits
|
|
20
|
+
- logical_disk: logical disk listing
|
|
21
|
+
- misc: basic time related functions to convert windows ticks into epoch / date strings
|
|
22
|
+
- office: microsoft Office version identification, works for click & run, O365 and legacy
|
|
23
|
+
- powershell: powershell wrapper to identify interpreter and run scripts or commands
|
|
24
|
+
- product_key: windows product key retrieval
|
|
25
|
+
- registry: registry 32 and 64 bit API
|
|
26
|
+
- securityprivilege: enable / disable various security privileges for user
|
|
27
|
+
- server: windows server identification
|
|
28
|
+
- signtool: Easily sign executables with Authenticode
|
|
29
|
+
- updates: get all installed windows updates based on COM, WMI and registry retrieval methods
|
|
30
|
+
- users: user lookup for SID/PySID/username
|
|
31
|
+
- virtualization: virtualization platform identification for guest
|
|
32
|
+
- windows_firewall: windows firewall state retrieval
|
|
33
|
+
- wmi_queries: windows WMI query wrapper, wmi timezone converters
|
|
34
|
+
|
|
35
|
+
It is compatible with Python 3.5+ and is tested on Windows only (obviously).
|
|
36
|
+
|
|
37
|
+
## Setup
|
|
38
|
+
|
|
39
|
+
You may install the whole `windows_tools` package or any subpackage using the following commands
|
|
40
|
+
```
|
|
41
|
+
pip install windows_tools
|
|
42
|
+
pip install windows_tools.<subpackage>
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### antivirus
|
|
49
|
+
|
|
50
|
+
The antivirus package tries to list installed Antivirus products via the SecurityCenter API (using WMI calls).
|
|
51
|
+
Since SecurityCenter API does not exist on Windows Servers, we also need to check for installed antivirus software using the uninstall registry keys.
|
|
52
|
+
These checks are more fuzzy, but allow to detect the following products:
|
|
53
|
+
|
|
54
|
+
- avast
|
|
55
|
+
- avira
|
|
56
|
+
- avg technologies
|
|
57
|
+
- bitdefender
|
|
58
|
+
- dr web
|
|
59
|
+
- eset
|
|
60
|
+
- f-secure
|
|
61
|
+
- g data software
|
|
62
|
+
- kaspersky
|
|
63
|
+
- mcafee
|
|
64
|
+
- panda security
|
|
65
|
+
- sophos
|
|
66
|
+
- trend micro
|
|
67
|
+
- malwarebytes
|
|
68
|
+
- vipre
|
|
69
|
+
- sentinel one
|
|
70
|
+
- cybereason
|
|
71
|
+
- cylance
|
|
72
|
+
|
|
73
|
+
On top of that list, it will detect any installed software containing "antivirus/antiviral/antimalware" in the name.
|
|
74
|
+
|
|
75
|
+
Please report back if your antivirus is not detected, so we can improve the fuzzy detection here.
|
|
76
|
+
|
|
77
|
+
Usage
|
|
78
|
+
```
|
|
79
|
+
import windows_tools.antivirus
|
|
80
|
+
|
|
81
|
+
result = windows_tools.antivirus.get_installed_antivirus_software()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`result` will contain a list of dict like
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
[{
|
|
88
|
+
'name': 'Windows Defender',
|
|
89
|
+
'version': None,
|
|
90
|
+
'publisher': None,
|
|
91
|
+
'enabled': False,
|
|
92
|
+
'is_up_to_date': True,
|
|
93
|
+
'type': 'Windows Defender / Security Essentials'
|
|
94
|
+
}, {
|
|
95
|
+
'name': 'Malwarebytes version 4.4.6.132',
|
|
96
|
+
'version': '4.4.6.132',
|
|
97
|
+
'publisher': 'Malwarebytes',
|
|
98
|
+
'enabled': None,
|
|
99
|
+
'is_up_to_date': None,
|
|
100
|
+
'type': None
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Warning**
|
|
106
|
+
Keys `enabled`, `is_up_to_date` and `type` are only filled via securityCenter API*.
|
|
107
|
+
Keys `version` and `publisher` are only filled via installed software list.
|
|
108
|
+
The only guaranteed filled key will always be `name`
|
|
109
|
+
|
|
110
|
+
### bitlocker
|
|
111
|
+
|
|
112
|
+
Bitlocker can only work on NTFS or ReFS formatted disks.
|
|
113
|
+
Bitlocker keys can only be retrieved on local disks.
|
|
114
|
+
|
|
115
|
+
#### Usage
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
import windows_tools.bitlocker
|
|
119
|
+
|
|
120
|
+
result = windows_tools.bitlocker.get_bitlocker_full_status()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`result` will contain a dict as follows containing raw strings from `manage-bde` windows tool:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
{
|
|
127
|
+
'C:': {
|
|
128
|
+
'status': 'Chiffrement de lecteur BitLocker\xa0: outil de configuration version 10.0.19041\nCopyright (C) 2013 Microsoft Corporation. Tous droits réservés.\n\nVolume C: [Windows ]\n[Volume du système d?exploitation]\n\n Taille : 855,14 Go\n Version de BitLocker : Aucun\n État de la conversion : Intégralement déchiffré\n Pourcentage chiffré : 0,0%\n Méthode de chiffrement : Aucun\n État de la protection\xa0: Protection désactivée\n État du verrouillage : Déverrouillé\n Champ d?identification : Aucun\n Protecteurs de clés : Aucun trouvé\n\n',
|
|
129
|
+
'protectors': None
|
|
130
|
+
},
|
|
131
|
+
'D:': {
|
|
132
|
+
'status': 'Chiffrement de lecteur BitLocker\xa0: outil de configuration version 10.0.19041\nCopyright (C) 2013 Microsoft Corporation. Tous droits réservés.\n\nVolume D: [Étiquette inconnue]\n[Volume de données]\n\n Taille : Inconnu Go\n Version de BitLocker : 2.0\n État de la conversion : Inconnu\n Pourcentage chiffré : Inconnu%\n Méthode de chiffrement : XTS-AES 128\n État de la protection\xa0: Inconnu\n État du verrouillage : Verrouillé\n Champ d?identification : Inconnu\n Déverrouillage automatique : Désactivé\n Protecteurs de clés\xa0:\n Password\n Mot de passe numérique\n\n',
|
|
133
|
+
'protectors': 'Chiffrement de lecteur BitLocker\xa0: outil de configuration version 10.0.19041\nCopyright (C) 2013 Microsoft Corporation. Tous droits réservés.\n\nVolume D: [Étiquette inconnue]\nTous les protecteurs de clés\n\n Password :\n ID : {SOMEPASS-WORD-ICAN-NNOT-REMEMBERWELL}\n\n Mot de passe numérique :\n ID : {SOMEPASS-GUID-ICAN-NNOT-REMEMBERWELL}\n\n'
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
You may parse those or simply pretty print since print will not interpret special characters from a dict or multiple variables at once:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
result = windows_tools.bitlocker.get_bitlocker_full_status()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
result = get_bitlocker_full_status()
|
|
145
|
+
for drive in result:
|
|
146
|
+
for designation, content in result[drive].items():
|
|
147
|
+
print(designation, content)
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Warning** bitlocker needs to be run as admin.
|
|
152
|
+
Running as non administrator will produce the following logs
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
Don't have permission to get bitlocker drive status for C:.
|
|
156
|
+
Don't have permission to get bitlocker drive protectors for C:.
|
|
157
|
+
Don't have permission to get bitlocker drive status for D:.
|
|
158
|
+
Don't have permission to get bitlocker drive protectors for D:.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Output shall be
|
|
162
|
+
```
|
|
163
|
+
{
|
|
164
|
+
'C:': {
|
|
165
|
+
'status': None,
|
|
166
|
+
'protectors': None
|
|
167
|
+
},
|
|
168
|
+
'D:': {
|
|
169
|
+
'status': None,
|
|
170
|
+
'protectors': None
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
You can check that you have administrator rights with `windows_utils.users` module
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
### bitness
|
|
179
|
+
|
|
180
|
+
### file_utils
|
|
181
|
+
|
|
182
|
+
### impersonate
|
|
183
|
+
|
|
184
|
+
### installed_software
|
|
185
|
+
|
|
186
|
+
### logical_disk
|
|
187
|
+
|
|
188
|
+
### misc
|
|
189
|
+
|
|
190
|
+
### office
|
|
191
|
+
|
|
192
|
+
### powershell
|
|
193
|
+
|
|
194
|
+
### product_key
|
|
195
|
+
|
|
196
|
+
### registry
|
|
197
|
+
|
|
198
|
+
### securityprivilege
|
|
199
|
+
|
|
200
|
+
### server
|
|
201
|
+
|
|
202
|
+
### signtool
|
|
203
|
+
|
|
204
|
+
signtool is designed to make the windows executable signature as simple as possible.
|
|
205
|
+
Once the Windows SDK is installed on your machine, you can sign any executable with the following commands:
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
from windows_tools.signtool import SignTool
|
|
209
|
+
signer = SignTool()
|
|
210
|
+
signer.sign(r"c:\path\to\executable", bitness=64)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Note that current versions of `signtool.exe` that come with Windows 10 SDK automagically detect hardware EV certificate tokens like Safenet.
|
|
214
|
+
|
|
215
|
+
When using former certificate files in order to sign an executable, one should use the following syntax:
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
from windows_tools.signtool import SignTool
|
|
219
|
+
signer = SignTool(certificate=r"c:\path\to\cert.pfx", pkcs12_password="the_certificate_file_password")
|
|
220
|
+
signer.sign(r"c:\path\to\executable", bitness=64)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
If the wrong certificate is used to sign, please open `certmgr.msc`, go to Private > Certificates and remove the certificate you don't want.
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### updates
|
|
227
|
+
|
|
228
|
+
Windows updates can be retrieved via a COM object that talks to Windows Update service, via WMI requests or via registry entries.
|
|
229
|
+
All methods can return different results, so they are combined into one function.
|
|
230
|
+
|
|
231
|
+
Usage
|
|
232
|
+
```
|
|
233
|
+
import windows_tools.updates
|
|
234
|
+
|
|
235
|
+
result = windows_tools.updates.get_windows_updates(filter_duplicates=True, include_all_states=False)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`result` will contain a list of dict like
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
[{
|
|
242
|
+
'kb': 'KB123456',
|
|
243
|
+
'date': '2021-01-01 00:01:02',
|
|
244
|
+
'title': 'Some update title',
|
|
245
|
+
'description': 'Some update description',
|
|
246
|
+
'supporturl': 'https://support.microsoft.com/someID',
|
|
247
|
+
'operation': 'Installation'
|
|
248
|
+
'result': 'Installed'
|
|
249
|
+
}, {
|
|
250
|
+
'kb': None,
|
|
251
|
+
'date': '2021-01-01 00:01:02',
|
|
252
|
+
'title': 'Windows 10 20H1 update',
|
|
253
|
+
'description': 'Pretty big system update',
|
|
254
|
+
'supporturl': 'https://support.microsoft.com/someID',
|
|
255
|
+
'operation': 'Installation'
|
|
256
|
+
'result': 'Installed'
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Using `filter_duplicates` will avoid returning multiple times the same KB from different sources.
|
|
262
|
+
This setting is enabled by default.
|
|
263
|
+
|
|
264
|
+
The parameter `include_all_states` set to True will include all updates, even those who failed to install or are superseeded.
|
|
265
|
+
|
|
266
|
+
### users
|
|
267
|
+
|
|
268
|
+
### virtualization
|
|
269
|
+
|
|
270
|
+
### windows_firewall
|
|
271
|
+
|
|
272
|
+
### wmi_queries
|