This directory contains the artifacts for the 'On the Effectiveness of CFI in Practice' paper published at WOOT'24.
-
asaasa_graph.pyGenerates the graphs related to LLVM CFI.asa.pyMain analysis script and entry point.external_analysis.pyUsed by asa.py, angr-based analysis to extract targets from__cfi_check.gen_comparison_table.pyCode used to generate statistics in LLVM CFI-related tables from the paper.internal_analysis_ghidra.pyHeadless-ghidra script to collect CFI slowpath / icalls.internal_analysis.pyA wrapper callingrun_ghidra_headless.shto executeinternal_analysis_ghidra.py.pa_coverage.pyGenerates file with PA coverage information from.pklrun_ghidra_headless.shBash script to invoke GHDira.rust_analysis.pyUsed by asa.py, Rust symbol detection.shadow_stack_analysis.pyUsed by asa.py, check for shadow stack.
-
asa_results/Pre-generated data set resulting from asa.py. -
clangcontains the source code and Makefile for the TOCTOU bypass PoC exploiting a race condition in LLVM's CDSO CFI. Successful execution should look like this:$ ./timing_attack Allocation at: 7fb81e61f000 Target at: 7fb2dcf5ecc6 Shadow base at: 7fa81de1e000 this should not have happened.The last line indicates that the target function was successfully called.
To confirm that without the simulated attack, CFI would have prevent this call, comment out line 28 in
timing_attack.cpp. Execution should now look like this:$ ./timing_attack Allocation at: 7fa06501f000 Target at: 7f9b177419cc Shadow base at: 7f906481e000 [1] 97839 illegal hardware instruction ./timing_attack -
firmware_toolscontains scripts for extracting/mounting the different firmware files analysed in the paper. -
wcfgcontains scripts related to Windows CFG and XFG.enum_dll_suppressed.pyis used to enumerate DLLs with suppressed XFG-instrumented functions on a Windows system. Its use-case was to determine potential targets for the XFG bypass discussed in section5.3 Windows Study.enum_pa.pyUsed to enumerate which files use which PA instructions.enum_win.pyWindows main analysis script. Produceswin_analysis.pkl.filter_pa_instructions.pyScript to calculate statistics of PA usage based on the output ofenum_pa.py.win_analysis.pklResult fromenum_win.py.win_graph.pygenerates Figure 7 fromwin_analysis.pkl.win_stats.pygenerate stats inTable 4: Windows 11 Insider Preview CFI coveragefromwin_analysis.pkl.xfg_bypass.cppCode highlighting an issue with XFG hashes and suppressed functions. Seems to be fixed in recent VisualStudio versions.
- Install software requirements listed below
- Create and activate venv
- Install requirements.txt in it
- Prepare the firwmare to analyse:
- extract image
- (if applicable) un-sparse image
- (if applicable) unpack super.img
- mount system.img and different sub-images to some mount point
- Run the script, e.g., for GSI 14:
mkdir outdir python3 asa.py -p "Android-AARCH64" --rebase-ldpaths -e outdir/gsi_14.pkl -l "/system/system_ext/apex/com.android.runtime/lib64/bionic/:/system/system_ext/apex/com.android.i18n/lib64/:/system/system_ext/apex/com.google.android.art/lib64/:/system/system_ext/apex/com.google.android.os.statsd/lib64/:/system/system_ext/apex/com.google.android.adbd/lib64/:/system/system_ext/apex/com.google.android.media/lib64/:/system/system_ext/apex/com.google.android.tethering/lib64/:/system/system_ext/apex/com.google.android.resolv/lib64/" /mnt/gsi_14_bind/
- Prepare cache with PA data:
python3 pa_coverage.py outdir - Perform arbitrary analysis on result data. For examples, see the snippets below or the code in
gen_comparison_table.py(modifytarget_dirsas needed).
with open(join(target_dir, p), "rb") as f:
cfidata = list(pickle.load(f).values())
bins = [d for d in data if not d.is_library and "ko" not in d.trait and "oat" not in d.trait and "rust" not in d.trait]
libs = [d for d in data if d.is_library and "ko" not in d.trait and "oat" not in d.trait and "rust" not in d.trait]
kos = [d for d in data if "ko" in d.trait]
# get protected binaries
[b.path for b in bins if b.has_cfi_check]- Setup Windows guest with the target image (e.g., in VM) and python
- Install python on the guest
- Run
enum_win.pyinside the guest to obtain result data.
- python3
- Ghidra
run_ghidra_headless.shassumes installation to /opt/ghidra. It is advisable to raiseMAXMEMinghidra/support/analyzeHeadlessdepending on the available resources. - radare2
Used for batch analysis (r2pipe) - rizin
Used for batch analysis (for some functionality due to bugs in radare2) - bindfs
Used for re-mounting firmware accessible to users without root. - binutils-aarch64-linux-gnu Used to check for shadowstack instructions in aarch64 executables.