-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tdx memory_attack demo for Pentests (#273)
- Loading branch information
Showing
6 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
cczoo/penetration_testing/memory_attack/tdx/key_generator/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Key Generator Application Memory Attack | ||
|
||
## Introduction | ||
|
||
This application is generating keys in VM's memory. | ||
|
||
It will use the same code to run into Non-TDX VMs and TDX VMs, and perform memory attacks on them to verify the confidentiality of TDX VM memory. | ||
|
||
![](key_generator.svg) | ||
|
||
## Application Deployment | ||
|
||
1. Start Non-TDX or TDX VM (QEMU-KVM). | ||
|
||
2. Run app into VM. | ||
|
||
``` | ||
python3 -u ./key_generator.py | ||
``` | ||
## Hacker Memory Attack | ||
1. Dump VM's memory via gdb: | ||
``` | ||
rm -rf core.* | ||
gdb -ex "generate-core-file" -ex "set confirm off" -ex "quit" -p `pgrep -f qemu-kvm` | ||
``` | ||
2. Parse and find key from dumped file: | ||
``` | ||
strings ./core.* | grep -n uuid | ||
``` | ||
Corresponding output: | ||
- Non-TDX VM | ||
``` | ||
16152:{'uuid35139113': '3hf!tj9da9wbwy18', 'uuid16913511': 'ukb2tvdq@etii0@7', 'uuid06450037': 'vi#9qnxvr*rwbq61', 'uuid39123227': '%an$ggjd13jrf3p1', 'uuid42881267': 'g%wtfce&4h6&u$h6'} | ||
``` | ||
- TDX VM | ||
None output. |
26 changes: 26 additions & 0 deletions
26
cczoo/penetration_testing/memory_attack/tdx/key_generator/key_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import random, time | ||
|
||
kv_dict = {} | ||
|
||
key_choice = '1234567890' | ||
value_choice = '1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()' | ||
|
||
def gen_rand_chr(choice): | ||
return random.choice(choice) | ||
|
||
def gen_rand_str(choice, length): | ||
return ''.join([gen_rand_chr(choice) for _ in range(length)]) | ||
|
||
def generate_kv_pair(): | ||
kv = { | ||
"uuid" + gen_rand_str(key_choice, 8) : gen_rand_str(value_choice, 16) | ||
} | ||
kv_dict.update(kv) | ||
|
||
for _ in range(5): | ||
generate_kv_pair() | ||
|
||
print(kv_dict) | ||
|
||
while True: | ||
time.sleep(5) |
4 changes: 4 additions & 0 deletions
4
cczoo/penetration_testing/memory_attack/tdx/key_generator/key_generator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
documents/readthedoc/docs/source/Pentests/memory_attack/tdx/key_generator/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Key Generator Application Memory Attack | ||
|
||
## Introduction | ||
|
||
This application is generating keys in VM's memory. | ||
|
||
It will use the same code to run into Non-TDX VMs and TDX VMs, and perform memory attacks on them to verify the confidentiality of TDX VM memory. | ||
|
||
![](key_generator.svg) | ||
|
||
## Application Deployment | ||
|
||
1. Start Non-TDX or TDX VM (QEMU-KVM). | ||
|
||
2. Run app into VM. | ||
|
||
``` | ||
python3 -u ./key_generator.py | ||
``` | ||
## Hacker Memory Attack | ||
1. Dump VM's memory via gdb: | ||
``` | ||
rm -rf core.* | ||
gdb -ex "generate-core-file" -ex "set confirm off" -ex "quit" -p `pgrep -f qemu-kvm` | ||
``` | ||
2. Parse and find key from dumped file: | ||
``` | ||
strings ./core.* | grep -n uuid | ||
``` | ||
Corresponding output: | ||
- Non-TDX VM | ||
``` | ||
16152:{'uuid35139113': '3hf!tj9da9wbwy18', 'uuid16913511': 'ukb2tvdq@etii0@7', 'uuid06450037': 'vi#9qnxvr*rwbq61', 'uuid39123227': '%an$ggjd13jrf3p1', 'uuid42881267': 'g%wtfce&4h6&u$h6'} | ||
``` | ||
- TDX VM | ||
None output. |
Oops, something went wrong.