Find patterns of vulnerabilities on Windows in order to find 0-day and write exploits of 1-days. We use Microsoft security updates in order to find the patterns
Find patterns of vulnerabilities on Windows in order to find 0-day and write exploits of 1-days. We use Microsoft security updates in order to find the patterns
Find patterns of vulnerabilities on Windows in order to find 0-day and write exploits of 1-days. We use Microsoft security updates in order to find the patterns.
There are 2 main goals for this repo:
In order to detect all the patch patterns and find 0-days, it is required to do the following steps:
cve_correlation.py) - Automatically download all the Windows updates from Microsoft catalog.
Our focus is in security only updates (aka Windows 8.1), extracts them and correlate them with windows vulnerabilities published in Microsoft's website. msu_patch_extractor.py) - Apply delta-patches, create an executable's folder that contains all the versions of a single file.auto_patchdiff.py) - Compare all the changes made in the security updates using Bindiff tool.rank_changes.py) - Analyze the executables, and the changes made by Microsoft and store the
changes into a single DBextract_cg.py) - After you analyzed and found interesting functions, use this tool to extract
call graph in order to detect
which functions are calling to the vulnerable function you found or which
functions the function you found is calling cross binariesYou can skip steps 1-4 if you'll use the generated DB found in release, see TL DR
The required dependencies on the PC are
pywin32pathlib2pefilepygmentsrequestsbs4lxmleasydict cachetoolsfuzzywuzzyrpycsarkbeautifulsoup4pyenchantPyGithubpefileFor optimizations:
python-Levenshteindotnet tool install --global ilspycmdFIDL - interactions with ida decompiler https://github.com/fireeye/FIDL/tree/master
see known issues to fix it's bug manuallysark - ida api wrapper https://github.com/tmr232/Sarkrpyc - execute rpc on ida process NtObjectManager to install run the command Install-Module "NtObjectManager" -ForceIt is recommended to execute the following codes one by one because there are dependencies between the output of one script to another.
Some of the scripts can take more than 2 days to execute. please be caution.
By default all the output files of all the codes below writes into the ./logs/ folder.
For analysis of all the patches - follow the steps below.
If you only want to generate cross binaries graphs or find patterns in binaries without patch-diffing, go straight to step 5, and use Generic FS flag.
cve_correlation.py - downloads the security updates from the internet, extracts them and correlate the changes to the
CVEs.
Common arguments:
--msuDownload, -m Is download the .msu files, Windows security updates--outputMsuName -o path to the which the MSU will be downloaded to--doExtract, -x Extract msu content to msuExtractedPath folderExecution time: about 30-60 minutes
This step has 2 sub-steps:
msu_patch_extractor.py with the arguments:--path-winsxs - location of the winsxs you downloaded in the previous sub-step--path-executables - folder that contains all the executable versions (symlinks)--path-kb-folder - folder that contains all the KBs (MSUs), the same path as in the previous step.--include-base-files - if you want to include base files, it can add noise to the results,
but you'll have more results.--path-extract-msu - The path you extracted the msu files in the previous stepThe output of the script will be the path of the executables, and it will extract all the MSU files in the KB folder.
If you'll use --path-winsxs it will include base version of all the files in WinSXS.
Execution time about 30-60 minutes
auto_patchdiff.py - Generate all the diffs between all the patches common arguments:
--path-executables - pass the same argument as you pass to the script msu_patch_extractor.py--path-diffs - a folder the script will generate all the information about, this folder will weight a lot--skip-fails - if some diff failed it will not terminate the program
the diffs between executables found in executables folderThe output of the code will be written to --path-diffs, this folder will be HUGE, 150+ GB.
It contains all files required for bindiff to compare all the versions.
Execution time about 48-36 hours
rank_changes.py - Classify all the changes or patterns from existing directory tree.
The output of this code is an SQL DB with all the features
There are 2 main options on which directory trees we can execute it on:
All the configurations can bypass using arguments or changing the file: config/default_config.json
Common parameters:
--path-diff - Path to the root folder of binary-diffed generated by step 4 --path-executables - The path to the executables folder or any folder inside it (for example only x64 executables)--generic-filesystem - path-executables points to generic filesystem and non-standard file-system,
(file-system not built by msu_patch_extractor)--continue-execution - continue execution from a specific PE if for some reason the last execution was stopped in the middle.To execute with additional features that takes more time:
--include-cg - Is include call graph features (takes lots of time)--include-cg-metadata - Is scrape information from external sources for the call graph graphs (MSDN and github)--extract-additional-params - extract additional params to the DB, unrelated to call graph.You might need to update the file config/default_config.json specially the object features.pe.cve_link.db_location
(just close the features object there and you'll see the important configurations).
Execution time about 72+ hours (Can be over 4 days If you use all the additional features)
extract_cg.py - Generate a call graph from or to any function across
the entire Windows OS. In order to use it, it is required to add few flags to rank_changes.py.
So it will extract all the required information.
The output of the code is .graphml represent the call graph, you can view it using any software designed to display graphs. The best program we found was cytoscape
Complicated arguments:
--path-api-set - Path to the mapping file of the api-set
mapping that will be used external dlls, You can use the example mappings found
in: config/windows_*_apisets_mapping or to generate that yourself--unsafe-xrefs - Include in the graph dynamic xrefs, such as GetProcAddress - it might be
ambiguous and linked to another PE--direction-cfg-from - Is generate the graph from or to the chosen function, if selected - generate CF from the function.--generic-fs - If the DB was generated from a generic FS, regular directory tree and not the FS generated by
msu_patch_extractor.py.Dependencies.exe -apisets Dependencies and copy
the stdout to the configuration .\config\windows\apisets_mapping file.Execution time about 5 minutes
For view the patterns found without changes - use the DB found in releases. It contains only the patterns of Windows 8.1 until the date it was released.
Execute the following commands, and you'll get the DB with all the changes
.\logs is going to weight 20 GB+-.python cve_correlation.py -m --msuExtractedPath E:\tests\extracted_path --dbPath E:\tests\db.db -x --outputMsuName E:\tests\msupython msu_patch_extractor.py -v --path-winsxs E:\windows8\Windows\winsxs --path-executables "E:\tests\executables" --path-kb-folder "E:\tests\msu" --path-extract-msu "E:\tests\extracted_path" -t 3 --include-base-filespython auto_patchdiff.py --path-executables "E:\tests\executables\amd64" --path-diffs E:\tests\diffs --skip-failsdefault_config.json edit the object `featuresNo open issues yet, or sync has not completed.