SmmLoader is a smm module used to load/unload smm standalone modules during runtime.
SmmLoader requires Visual studio 2019 or higher and EDK2. If you do not have it downloaded here is a guide for setting it up. After setting up edk2 you can compile SmmLoader:
- Open command line and head up to edk2 directory and prompt
edksetup.bat
- Clone SmmLoader repo
- Prompt
build -b RELEASE -a X64 -t VS2019 -p SmmLoader/SmmLoader.dsc
Now SmmLoader should have been succesfully built in edk2/Build/SmmLoader.
In order to get firmware image, you need to install chipsec and then run this command as administrator: python chipsec_util.py spi dump firmware.bin
To embed the SmmLoader in the firmware:
-
Download UefiTool version 0.28.0
-
Open your firmware image and find Volume Image Section where all SMM modules are located
-
Find last SMM module
-
Right click on it and select
Insert after...
-
Select either precompiled ffs or the one you have built, you can find it here
edk2/Build/SmmLoader/RELEASE_VS2019/FV/Ffs/1B68BD50-BE1D-43F4-9571-9276A02DE8D0SmmLoader/1B68BD50-BE1D-43F4-9571-9276A02DE8D0.ffs
-
Save the modified firmware image
Now in order to write firmware back to your flash memory:
-
Connect your SPI programmer (in my case it's Bus Pirate) to SPI Flash on your mother board
-
Use flashrom to writeback firmware by running command
flashrom -VV -p buspirate_spi:dev=COM3 -w infected_firmware.bin
-
Disconnect programmer
You need to install chipsec so you can communicate with SmmLoader by using SmmLoader.py (Administrator priviligaes required)
Supported commands:
- SmmLoader.py --load <smm_module_path> - loads a module (currently the maximum number of modules is 16)
- SmmLoader.py --unload <smm_module> - smm_module must be a file name + extension of file which was loaded using --loads command
- SmmLoader.py --info - Prints info about all loaded modules (works only if SmmLoader was compiled with DebugLibNvVar)
- SmmLoader.py --debug - Goes into infinite loop and prints debug messages (works only if SmmLoader was compiled with DebugLibNvVar)
If you want to create new module, you need to append it in SmmLoader.dsc and add StandaloneMmDriverEntryPoint
and MmServicesTableLib
library classes.
[Components]
YourModule/YourModule.inf {
<LibraryClasses>
StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
}
Or you can use SampleSmmModule as a template.
Issues and limitations:
- Smm module must be a of MM_STANDALONE module type because DXE_SMM_DRIVER needs an access to Boot services and Runtime services during execution of it's entrypoint, which are not avalible because we are at runtime. You can read more about differences between these two types of modules here.
- If you want to see debug output in SmmLoader.py, you need to compile your smm module with DebugLibNvVar as your DebugLib Library class (In SmmLoader.dsc it's seleceted as a default one).
- Be careful with calling DebugPrint inside SmiHandler, because in case of DebugLibNvVar, it uses SmmGetVariable/SmmSetVariable which reads and writes to the DebugBuffer, what can generate a smi that puts you in an infinite loop.
SmmLoader should work on every hardware and platform supported by chipsec.
SmmBackdoor by Cr4sh
SmmLoader is under GPLv2 license.