Skip to content

Commit e00709c

Browse files
authored
Add files via upload
1 parent d45d246 commit e00709c

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

PrintNightmare_dll_check.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 2021-07-06 HV PrintNightmare dll check
2+
# a quick script to recursively scan for unsigned dll in %windir%\system32\spool\drivers
3+
4+
# According to https://github.com/afwu/PrintNightmare a successful PrintNightmare attack places a malicious dll in %windir%\system32\spool\drivers
5+
# These dll are most likely unsigned (neither AuthentiCode nor directly signed)
6+
7+
# VARIABLES
8+
# printer directory where attacks with dll occur / malicious dll are planted
9+
$srcpath = "$env:windir\system32\spool\drivers\*.dll"
10+
# output directory where to copy unsigned dll for further check with Sysinternals sigcheck.exe
11+
$2nd_check_path = "$PSScriptRoot\PrintNightmare_2nd_check_path"
12+
# get current date / time
13+
$now = Get-Date -Format "yyyyMMdd-HHmm"
14+
# logfile name
15+
$logfile = $PSScriptRoot + "\PrintNightmare_dll_check_" + $now + ".txt"
16+
17+
# create logfile
18+
Add-Content -Path $logfile -Value $now -Encoding UTF8
19+
Add-Content -Path $logfile -Value "script start" -Encoding UTF8
20+
Add-Content -Path $logfile -Value "" -Encoding UTF8
21+
22+
# create further check directory
23+
md $2nd_check_path
24+
25+
# search for unsigned dll (authenticode nor directly signed) and copy unsigned dll for further check
26+
gci -Path $srcpath -Recurse | Get-AuthenticodeSignature | Where-Object {$_.Status -eq "NotSigned"} | cpi -Destination $2nd_check_path
27+
28+
# if unsigned dll are detected
29+
if (Test-Path $2nd_check_path\*.dll)
30+
{
31+
$unsigned_dll_found=1
32+
# update logfile with name of unsigned dll(s)
33+
Add-Content -Path $logfile -Value "dll files without authenticode nor directly signed:" -Encoding UTF8
34+
gci $2nd_check_path | Add-Content -Path $logfile -Encoding UTF8
35+
Add-Content -Path $logfile -Value "" -Encoding UTF8
36+
# Check unsigned dll(s) with sigcheck and do external check with Virustotal.com; Internet connection required
37+
& $PSScriptRoot\sigcheck64.exe -accepteula -e -s -h -v -vt $2nd_check_path | Add-Content -Path $logfile -Encoding UTF8
38+
Add-Content -Path $logfile -Value "" -Encoding UTF8
39+
}
40+
else
41+
{
42+
# otherwise if all dll are signed
43+
$unsigned_dll_found=0
44+
Add-Content -Path $logfile -Value "all dll files provide authenticode or are directly signed" -Encoding UTF8
45+
Add-Content -Path $logfile -Value "NO suspicious dll files detetcted" -Encoding UTF8
46+
Add-Content -Path $logfile -Value "" -Encoding UTF8
47+
}
48+
# update logfile
49+
Add-Content -Path $logfile -Value "script end" -Encoding UTF8
50+
51+
# exit script; %errorcode% = 0 -> NO unsigned dll found; %errorcode% = 1 -> unsigned dll found!
52+
EXIT $unsigned_dll_found

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# PrintNightmare_dll_check.ps1
2+
3+
A quick PowerShell script to recursively scan for unsigned dll in %windir%\system32\spool\drivers.
4+
The scan path can be quickly changed within the script to any other location.
5+
6+
According to https://github.com/afwu/PrintNightmare a successful PrintNightmare attack places a malicious dll in %windir%\system32\spool\drivers.
7+
These dll are most likely unsigned (neither AuthentiCode nor directly signed) but this approach will also show up false-positives as well.
8+
9+
10+
Manual download of 3rd party tools
11+
----------------------------------
12+
13+
For licensing reasons we can't provide the script fully operational including sigcheck64.exe.
14+
Please manually download sigcheck64.exe from the offical Sysinternal website and place it next to PrintNightmare_dll_check.ps1.
15+
16+
|Download URL: | Extracted filename: |
17+
| ------------ | ------------------- |
18+
|https://download.sysinternals.com/files/Sigcheck.zip | SigCheck64.exe |
19+
20+
21+
Requirements
22+
------------
23+
-Download of Sysinternals Sigcheck.zip
24+
-Extracting of sigcheck64.exe from Sigcheck.zip
25+
-local user rights (Admin permission NOT required)
26+
-Internet connection for external check of unsigned dll with Virustotal.com (or remove the sigcheck parameters '-v -vt' to stay local)
27+
28+
29+
How to run
30+
----------
31+
1. place PrintNightmare_dll_check.ps1 to any directory where the executing user has write permission (e.g. C:\temp or C:\users\%username%\Documents)
32+
2. place sigcheck64.exe next to PrintNightmare_dll_check.ps1 in the same directory
33+
3. `cmd`
34+
4. `powershell.exe -executionpolicy bypass C:\path_to\PrintNightmare_dll_check.ps1`
35+
36+
37+
Returncode (%errorlevel%) of script
38+
-----------------------------------
39+
0 = NO unsigned dll found
40+
1 = unsigned dll found -> check logfile for more details
41+
42+
43+
Outputs of script
44+
-----------------
45+
logfile: C:\path_to\PrintNightmare_dll_check_YYYYMMDD-HHMM.txt
46+
copy of unsigned dlls: C:\path_to\PrintNightmare_2nd_check_path\
47+
48+
49+
Example of logfile - NO unsigned dll found
50+
------------------------------------------
51+
20210707-1142
52+
script start
53+
54+
all dll files provide authenticode or are directly signed
55+
NO suspicious dll files detetcted
56+
57+
script end
58+
59+
60+
Example of logfile - unsigned dll found
61+
---------------------------------------
62+
20210707-1138
63+
script start
64+
65+
dll files without authenticode nor directly signed:
66+
Vix64AllProductsDyn.dll
67+
68+
69+
Sigcheck v2.81 - File version and signature viewer
70+
Copyright (C) 2004-2021 Mark Russinovich
71+
Sysinternals - www.sysinternals.com
72+
73+
c:\test\printnightmare_2nd_check_path\Vix64AllProductsDyn.dll:
74+
Verified: Unsigned
75+
Link date: 14:15 30/04/2021
76+
Publisher: n/a
77+
Company: VMware, Inc.
78+
Description: VMware application library
79+
Product: VMware Workstation
80+
Prod version: 16.1.2 build-17966106
81+
File version: 16.1.2 build-17966106
82+
MachineType: 64-bit
83+
MD5: 22F4B8122EBE333200E833E05C2E357C
84+
SHA1: B858B78C22ECCF9B7DA408C297BB53FAEFED6426
85+
PESHA1: 5F20D482AE71A3B78CCF39D98991E2DA6F14DB6F
86+
PE256: 35AE6215FEAA28DB3A2F4CD5111CE61747481162B013DFCE3377EC4BE9748D0F
87+
SHA256: 985E8F96133B794A66CB1AF894AC5ED509AC3DE4A54DB73FD85C96505CC5D890
88+
IMP: 9FB9711F21857F89F61E06F13A427CA8
89+
VT detection: 0/73
90+
VT link: https://www.virustotal.com/gui/file/985e8f96133b794a66cb1af894ac5ed509ac3de4a54db73fd85c96505cc5d890/detection
91+
92+
script end
93+
94+
95+
How to test the script
96+
----------------------
97+
Copy any unsigned dll from any local installed app (from C:\Program Files) to C:\Windows\System32\spool\drivers and run the script.

0 commit comments

Comments
 (0)