├── DriverAnalyzer
├── src
│ ├── pch.cc
│ ├── utils
│ │ └── utils.h
│ ├── pch.h
│ ├── analyzer
│ │ ├── api
│ │ │ ├── MmMapIoSpace.cc
│ │ │ └── MmMapIoSpace.h
│ │ ├── disassembler.h
│ │ ├── disassembler.cc
│ │ └── analyzer.h
│ ├── data_types.h
│ └── main.cc
├── clang-format.bat
├── DriverAnalyzer.vcxproj.filters
├── .clang-format
└── DriverAnalyzer.vcxproj
├── .gitattributes
├── .gituhb_assets
├── MmMapIoSpace.png
└── MmMapIoSpaceJson.png
├── msvc-cleaner.bat
├── LICENSE
├── DriverAnalyzer.sln
├── readme.md
└── .gitignore
/DriverAnalyzer/src/pch.cc:
--------------------------------------------------------------------------------
1 | #include "pch.h"
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gituhb_assets/MmMapIoSpace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BehroozAbbassi/DriverAnalyzer/HEAD/.gituhb_assets/MmMapIoSpace.png
--------------------------------------------------------------------------------
/.gituhb_assets/MmMapIoSpaceJson.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BehroozAbbassi/DriverAnalyzer/HEAD/.gituhb_assets/MmMapIoSpaceJson.png
--------------------------------------------------------------------------------
/msvc-cleaner.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | echo.
4 | echo Removing files ...
5 | echo.
6 |
7 | del *.VC.db /s/q
8 | del *.bsc /s/q
9 | del *.pdb /s/q
10 | del *.iobj /s/q
11 | del *.ipdb /s/q
12 | del *.ilk /s/q
13 | del *.ipch /s/q
14 | del *.obj /s/q
15 | del *.sbr /s/q
16 | del *.tlog /s/q
17 | del *.suo /s/q
18 |
19 | echo.
20 | echo Removing build folders ...
21 | echo.
22 |
23 | for /d /r . %%d in (.vs __history Debug Release ipch build Intermediate x64) do (
24 |
25 | if exist "%%d" (
26 | rd /s/q "%%d"
27 | if not exist "%%d" ( echo [%%d] Removed! )
28 | echo.
29 | )
30 | )
31 |
32 | echo Done!
33 | pause
--------------------------------------------------------------------------------
/DriverAnalyzer/clang-format.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
4 | set clang_format=
5 |
6 | cls
7 |
8 | setlocal enableextensions enabledelayedexpansion
9 |
10 | for /f "tokens=*" %%i in ('%vswhere% -latest -find VC\Tools\LLVM\**\bin\clang-format.exe') do (
11 | echo clang-format found : %%i
12 | %%i --version
13 | set "clang_format="%%i""
14 | )
15 |
16 | for /r %%f in ( *.cc *.cpp *.hpp *.h *.c ) do (
17 | set file_path=%%~pf
18 |
19 | :: discard the third_party directory
20 | if /I "!file_path!"=="!file_path:third_party%=!" (
21 | echo formatting [%%f]
22 | call !clang_format! -i -style=file "%%f"
23 | )
24 | )
25 |
26 | endlocal
27 |
28 | echo Finish
29 | pause
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 BehroozAbbassi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/DriverAnalyzer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31825.309
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DriverAnalyzer", "DriverAnalyzer\DriverAnalyzer.vcxproj", "{92CD85E9-5155-414C-B605-DFFAA5375831}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Debug|x64.ActiveCfg = Debug|x64
17 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Debug|x64.Build.0 = Debug|x64
18 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Debug|x86.ActiveCfg = Debug|Win32
19 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Debug|x86.Build.0 = Debug|Win32
20 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Release|x64.ActiveCfg = Release|x64
21 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Release|x64.Build.0 = Release|x64
22 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Release|x86.ActiveCfg = Release|Win32
23 | {92CD85E9-5155-414C-B605-DFFAA5375831}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {F9E43B83-02AB-4CD0-858D-3A8FD4C92B70}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Driver Analyzer
2 |
3 | A static analysis tool that helps security researchers scan a list of Windows kernel drivers for common vulnerability patterns in drivers (CVE makers!)
4 |
5 | The generic scan is not robust. It just suggests the potential drivers, but you can write more complex scans for specific APIs. (There is one example in the code tree for [MmMapIoSpace](https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-mmmapiospace) API)
6 |
7 | For example, in the following picture, you can see a call to the `MmMapIoSpace` API and its first parameter that is controllable through `rcx` register (first argument in the `fastcall` calling convention), so this one has the potential to be a vulnerable call in the driver, you need to do more investigations manually by reversing the driver.
8 |
9 | In the end, if you can find a direct path from the `IOCTL` handler to this function call, congregates you have just found another stupid driver to be exploited.
10 |
11 |
12 | 
13 | 
14 |
15 |
16 | > Note that this project was part of a larger project, and I just separated it as a standalone tool, so there are some inconsistencies in the code style like namings!
17 |
18 | # How to build
19 |
20 | You need to have installed these dependencies.
21 |
22 | ```bat
23 | vcpkg.exe install cereal:x64- indows cereal:x86-windows
24 | vcpkg.exe install zydis:x64-windows zydis:x86-windows
25 | vcpkg.exe install cxxopts:x64-windows cxxopts:x86-windows
26 | vcpkg.exe install lief[pe]:x64-windows lief[pe]:x86-windows
27 | ```
28 |
29 |
30 | # Usage
31 |
32 | ```bat
33 | Usage:
34 | Vulnerable Driver Scanner [OPTION...]
35 |
36 | -i, --input arg Path of directory that contains Driver files (*.sys)
37 | -o, --output arg Full name of JSON report
38 | -b, --backup arg Path of backup directory to have a copy of suspicious
39 | driver files
40 | ```
--------------------------------------------------------------------------------
/DriverAnalyzer/DriverAnalyzer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 | Header Files
46 |
47 |
48 | Header Files
49 |
50 |
51 |
--------------------------------------------------------------------------------
/DriverAnalyzer/src/utils/utils.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace utils {
4 | struct Chrono
5 | {
6 | Chrono() :
7 | start(std::chrono::system_clock::now())
8 | {
9 | }
10 |
11 | void Start()
12 | {
13 | start = std::chrono::system_clock::now();
14 | }
15 |
16 | void Stop()
17 | {
18 | end = std::chrono::system_clock::now();
19 | }
20 |
21 | uint32_t GetElapsedTime() const
22 | {
23 | return std::chrono::duration_cast(end - start).count();
24 | }
25 |
26 | void PrintElapsedTime()
27 | {
28 | int elapsed_seconds = GetElapsedTime();
29 | std::time_t end_time = std::chrono::system_clock::to_time_t(end);
30 |
31 | std::cout << "finished computation at " << std::ctime(&end_time)
32 | << "elapsed time: " << elapsed_seconds << "s\n";
33 | }
34 |
35 | ~Chrono()
36 | {
37 | }
38 |
39 | private:
40 | std::chrono::time_point start, end;
41 | };
42 |
43 | inline std::string
44 | FormatFileSize(const size_t fileSize)
45 | {
46 | const int MAX_FILE_SIZE_BUFFER = 255;
47 | char szFileSize[MAX_FILE_SIZE_BUFFER];
48 | StrFormatByteSizeA(fileSize,
49 | szFileSize,
50 | MAX_FILE_SIZE_BUFFER);
51 |
52 | return szFileSize;
53 | }
54 |
55 | inline std::string
56 | GetFileName(const std::string & filePath)
57 | {
58 | std::filesystem::path path(filePath);
59 | return path.filename().string();
60 | }
61 |
62 | inline std::string
63 | GeFormattedtFileSize(const std::string & filePath)
64 | {
65 | auto fileSize = std::filesystem::file_size(filePath);
66 | return std::to_string(fileSize) + " (" + utils::FormatFileSize(fileSize) + ")";
67 | }
68 |
69 | template
70 | std::string
71 | IntToHex(T i)
72 | {
73 | std::stringstream stream;
74 | stream << "0x"
75 | << std::setfill('0') << std::setw(sizeof(T) * 2)
76 | << std::hex << i;
77 | return stream.str();
78 | }
79 |
80 | inline std::string
81 | str_tolower(std::string s)
82 | {
83 | std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); } // correct
84 | );
85 | return s;
86 | }
87 |
88 | } // namespace utils
--------------------------------------------------------------------------------
/DriverAnalyzer/src/pch.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | //
4 | // Windows API headers
5 | //
6 |
7 | #pragma region Win32 API Headers
8 |
9 | #define NOMINMAX
10 | //#define CINTERFACE
11 | #define _SCL_SECURE_NO_WARNINGS
12 | #define _CRT_SECURE_NO_WARNINGS
13 |
14 | #ifndef WIN32_LEAN_AND_MEAN
15 | # define WIN32_LEAN_AND_MEAN
16 | #endif
17 |
18 | #include
19 | #include
20 | #include
21 | #include "shlwapi.h"
22 | #pragma comment(lib, "Shlwapi.lib")
23 |
24 | #pragma endregion = > Win32 API Headers
25 |
26 | //
27 | // std headers
28 | //
29 |
30 | #pragma region C++ Standrad Headers
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include