MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / test_data_injection

Function test_data_injection

tests/security/test_access_control.py:199–236  ·  view source on GitHub ↗

Test data injection via API

(tester)

Source from the content-addressed store, hash-verified

197
198
199def 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
239def test_configuration_tampering(tester):

Callers 1

mainFunction · 0.85

Calls 6

SerialStudioClientClass · 0.90
configure_networkMethod · 0.80
recvMethod · 0.80
connectMethod · 0.45
closeMethod · 0.45
log_vulnerabilityMethod · 0.45

Tested by

no test coverage detected