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

Function test_logic_bombs

tests/security/test_exploit_techniques.py:508–551  ·  view source on GitHub ↗

Exploit state machine logic errors

(exploiter)

Source from the content-addressed store, hash-verified

506
507
508def test_logic_bombs(exploiter):
509 """Exploit state machine logic errors"""
510 print("\n[*] Testing logic bomb exploits...")
511
512 # Attack 1: Invalid state transitions
513 print(" - Forcing invalid state transitions...")
514
515 try:
516 with SerialStudioClient() as client:
517 # Try to export before connecting
518 client.command("csvExport.setEnabled", {"enabled": True})
519
520 # Try to disconnect before connecting
521 client.command("io.disconnect")
522
523 # Try to write data without device
524 import base64
525
526 data = base64.b64encode(b"INJECT").decode()
527 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
528 sock.connect((exploiter.host, exploiter.port))
529 msg = {"type": "raw", "id": str(uuid.uuid4()), "data": data}
530 sock.sendall(json.dumps(msg).encode() + b"\n")
531 sock.settimeout(2.0)
532 response = sock.recv(4096)
533 sock.close()
534
535 except Exception as e:
536 print(f" State validation: {e}")
537
538 # Attack 2: Rapid mode switching
539 print(" - Rapid operation mode switching...")
540
541 try:
542 with SerialStudioClient() as client:
543 for i in range(500):
544 mode = i % 3
545 client.configure_frame_parser(
546 start_sequence="/*",
547 end_sequence="*/",
548 operation_mode=mode,
549 )
550 except Exception as e:
551 print(f" Mode switching: {e}")
552
553
554def test_compression_bomb(exploiter):

Callers 1

mainFunction · 0.85

Calls 6

SerialStudioClientClass · 0.90
commandMethod · 0.80
recvMethod · 0.80
connectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected