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

Function _set_module_options

MetasploitMCP.py:428–452  ·  view source on GitHub ↗

Sets options on a module object, performing basic type guessing.

(module_obj: Any, options: Dict[str, Any])

Source from the content-addressed store, hash-verified

426 raise MsfRpcError(f"Error retrieving module '{module_name}': {e}") from e
427
428async def _set_module_options(module_obj: Any, options: Dict[str, Any]):
429 """Sets options on a module object, performing basic type guessing."""
430 logger.debug(f"Setting options for module {getattr(module_obj, 'fullname', '')}: {options}")
431 for k, v in options.items():
432 # Basic type guessing
433 original_value = v
434 if isinstance(v, str):
435 if v.isdigit():
436 try: v = int(v)
437 except ValueError: pass # Keep as string if large number or non-integer
438 elif v.lower() in ('true', 'false'):
439 v = v.lower() == 'true'
440 # Add more specific checks if needed (e.g., for file paths)
441 elif isinstance(v, (int, bool)):
442 pass # Already correct type
443 # Add handling for other types like lists if necessary
444
445 try:
446 # Use lambda to capture current k, v for the thread
447 await asyncio.to_thread(lambda key=k, value=v: module_obj.__setitem__(key, value))
448 # logger.debug(f"Set option {k}={v} (original: {original_value})")
449 except (MsfRpcError, KeyError, TypeError) as e:
450 # Catch potential errors if option doesn't exist or type is wrong
451 logger.error(f"Failed to set option {k}={v} on module: {e}")
452 raise ValueError(f"Failed to set option '{k}' to '{original_value}': {e}") from e
453
454async def _execute_module_rpc(
455 module_type: str,

Calls 1

__setitem__Method · 0.80