Test data injection via API
(tester)
| 197 | |
| 198 | |
| 199 | def test_data_injection(tester): |
| 200 | """Test data injection via API""" |
| 201 | print("\n[*] Testing data injection capabilities...") |
| 202 | |
| 203 | # Test 1: Check if we can inject raw data to device |
| 204 | print(" - Testing raw data injection...") |
| 205 | |
| 206 | try: |
| 207 | import base64 |
| 208 | |
| 209 | with SerialStudioClient() as client: |
| 210 | # Try to configure network driver |
| 211 | client.configure_network(host="127.0.0.1", port=9999, socket_type="tcp") |
| 212 | |
| 213 | # Try to send raw data |
| 214 | malicious_data = b"INJECTED_DATA\r\n" |
| 215 | encoded = base64.b64encode(malicious_data).decode() |
| 216 | |
| 217 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 218 | sock.connect((tester.host, tester.port)) |
| 219 | |
| 220 | msg = {"type": "raw", "id": str(uuid.uuid4()), "data": encoded} |
| 221 | |
| 222 | sock.sendall(json.dumps(msg).encode() + b"\n") |
| 223 | sock.settimeout(2.0) |
| 224 | response = sock.recv(4096) |
| 225 | sock.close() |
| 226 | |
| 227 | if b"success" in response or b"bytesWritten" in response: |
| 228 | tester.log_vulnerability( |
| 229 | "HIGH", |
| 230 | "Data Injection", |
| 231 | "Unauthenticated raw data injection to device", |
| 232 | ) |
| 233 | print(" Successfully injected raw data") |
| 234 | |
| 235 | except Exception as e: |
| 236 | print(f" Data injection blocked or failed: {e}") |
| 237 | |
| 238 | |
| 239 | def test_configuration_tampering(tester): |
no test coverage detected