-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_check_tdx.py
More file actions
177 lines (138 loc) · 5.42 KB
/
Copy path1_check_tdx.py
File metadata and controls
177 lines (138 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python3
"""
Step 0: Check TDX Status
Verifies that Intel TDX is active on this VM.
Run this first to confirm you're in a Confidential VM.
Author: GopeshK
License: MIT License
"""
import subprocess
import sys
import os
def print_banner():
print("""
╔══════════════════════════════════════════════════════════════════════╗
║ Intel TDX Status Check ║
║ Verify Confidential VM Configuration ║
╚══════════════════════════════════════════════════════════════════════╝
""")
def run_command(cmd, shell=True):
"""Run command and return output."""
try:
result = subprocess.run(
cmd,
shell=shell,
capture_output=True,
text=True,
timeout=10
)
return result.stdout.strip(), result.returncode
except Exception as e:
return str(e), 1
def check_dmesg_tdx():
"""Check kernel messages for TDX."""
print("[1/5] Checking kernel messages (dmesg)...")
output, rc = run_command("sudo dmesg 2>/dev/null | grep -i tdx | head -5")
if "guest" in output.lower() or "tdx" in output.lower():
print(f" ✅ TDX detected in kernel messages:")
for line in output.split('\n')[:3]:
print(f" {line}")
return True
else:
print(" ❌ No TDX messages found in dmesg")
return False
def check_cpuinfo():
"""Check CPU flags for TDX."""
print("\n[2/5] Checking CPU flags...")
output, rc = run_command("grep -o 'tdx[^ ]*' /proc/cpuinfo | head -1")
if output:
print(f" ✅ TDX CPU flag found: {output}")
return True
else:
# TDX guest may not show flag, check for other indicators
output2, _ = run_command("cat /proc/cpuinfo | grep 'model name' | head -1")
print(f" ℹ️ CPU: {output2.split(':')[-1].strip() if ':' in output2 else 'Unknown'}")
print(f" ⚠️ TDX flag not visible (normal for TDX guest)")
return None
def check_sys_firmware():
"""Check /sys/firmware for TDX."""
print("\n[3/5] Checking /sys/firmware...")
if os.path.exists("/sys/firmware/tdx"):
print(" ✅ /sys/firmware/tdx exists")
return True
output, rc = run_command("ls /sys/firmware/ 2>/dev/null")
print(f" ℹ️ Firmware entries: {output.replace(chr(10), ', ')}")
return False
def check_confidential_compute():
"""Check GCP metadata for confidential compute."""
print("\n[4/5] Checking GCP Confidential Compute metadata...")
cmd = """curl -s -H "Metadata-Flavor: Google" \
http://metadata.google.internal/computeMetadata/v1/instance/confidential-instance/enable \
2>/dev/null"""
output, rc = run_command(cmd)
if output.lower() == "true":
print(" ✅ GCP Confidential Compute: ENABLED")
return True
elif "not found" in output.lower() or rc != 0:
print(" ℹ️ GCP metadata not available (may not be on GCP)")
return None
else:
print(f" ❌ GCP Confidential Compute: {output}")
return False
def check_attestation():
"""Check if TDX attestation is available."""
print("\n[5/5] Checking TDX attestation device...")
devices = [
"/dev/tdx_guest",
"/dev/tdx-guest",
"/dev/tdx-attest"
]
for dev in devices:
if os.path.exists(dev):
print(f" ✅ Attestation device found: {dev}")
return True
print(" ⚠️ No TDX attestation device found")
print(" (Attestation may still work via different interface)")
return None
def main():
print_banner()
checks = {
"Kernel TDX": check_dmesg_tdx(),
"CPU Flags": check_cpuinfo(),
"Sys Firmware": check_sys_firmware(),
"GCP Confidential": check_confidential_compute(),
"Attestation": check_attestation()
}
print("\n" + "="*70)
print("SUMMARY")
print("="*70)
passed = sum(1 for v in checks.values() if v is True)
warned = sum(1 for v in checks.values() if v is None)
failed = sum(1 for v in checks.values() if v is False)
for name, result in checks.items():
if result is True:
status = "✅ PASS"
elif result is None:
status = "⚠️ WARN"
else:
status = "❌ FAIL"
print(f" {name:.<30} {status}")
print("")
if passed >= 2:
print("🔒 TDX APPEARS TO BE ACTIVE")
print(" Memory encryption is protecting this VM")
print("\n Proceed with the attack demo:")
print(" python 1_train_proprietary_model.py")
return 0
elif warned > failed:
print("⚠️ TDX STATUS UNCERTAIN")
print(" Some indicators present but not confirmed")
print(" Proceed with caution - attack demo may still work")
return 0
else:
print("❌ TDX NOT DETECTED")
print(" This VM may not have Confidential Computing enabled")
print(" Create VM with: --confidential-compute-type=TDX")
return 1
if __name__ == "__main__":
sys.exit(main())