text
stringlengths
1
93.6k
use_partial_update (bool): Whether to perform a partial refresh (default: True).
Raises:
Exception: If the display update fails.
"""
if stats is None:
stats = {"targets": 0, "vulns": 0, "exploits": 0, "files": 0}
try:
# Log the current state and refresh mode
logging.info(f"Updating display: state={state}, partial_refresh={use_partial_update}")
# Update workflow state and load corresponding image and message
state_manager.set_state(state)
image, xeno_message = state_manager.get_image_and_message_for_current_state()
prepared_image = self.prepare_image(image)
# Initialize the display in the correct mode
if use_partial_update:
# Partial refresh does not require reinitialization
logging.debug("Partial refresh mode: Skipping reinitialization.")
else:
# Full refresh requires initialization to default mode
self.initialize(partial_refresh=False)
# Combine the current status with the Xenomorph message
full_status = f"{current_status}\n{xeno_message}"
# Render layout and update display
layout = self.draw_layout(prepared_image, current_ssid=current_ssid,
current_status=full_status, stats=stats)
self.display_image(layout, use_partial_update=use_partial_update)
# Log success
logging.info(f"State updated successfully: {state}, partial_refresh={use_partial_update}")
except Exception as e:
logging.error(f"Failed to update display: {e}")
def run_scans(logger, wifi_manager, html_logger, display, state_manager):
"""
Perform the scanning and processing logic for the workflow.
Parameters:
logger (Logger): Logger for recording workflow progress.
wifi_manager (WiFiManager): Manages Wi-Fi connections.
html_logger (HTMLLogger): Generates HTML logs of scan results.
display (EPaperDisplay): Updates the e-paper display.
state_manager (ImageStateManager): Manages workflow states and images.
Workflow:
1. Initializes the display with default stats.
2. Loads Wi-Fi and SSH credentials.
3. Connects to Wi-Fi networks and performs scans.
4. Runs reconnaissance, vulnerability scans, and exploit testing.
5. Attempts file-stealing on discovered devices.
6. Updates the e-paper display dynamically with results.
Raises:
Exception: If any critical errors occur during scanning.
"""
stats = {"targets": 0, "vulns": 0, "exploits": 0, "files": 0} # Initialize stats
# Full refresh for the initial template
initialize_display_template(display, current_ssid="Not Connected", stats=stats)
wifi_credentials = load_wifi_credentials()
if not wifi_credentials:
logger.log("[ERROR] No Wi-Fi credentials loaded. Ensure the file exists in either config or root.")
return
ssh_credentials = load_ssh_credentials()
if not ssh_credentials:
logger.log("[ERROR] No SSH credentials loaded. Ensure the file exists in either config or root.")
return
connected_ssid = None # Track the currently connected SSID
for network in wifi_credentials:
ssid = network.get("SSID")
password = network.get("Password")
if not ssid or not password:
continue
# Skip reconnection if already connected to the same SSID
if connected_ssid == ssid:
logger.log(f"[INFO] Already connected to SSID: {ssid}. Skipping reconnection.")
else:
wifi_manager.disconnect_wifi()
for attempt in range(3):
# Partial refresh for connecting to Wi-Fi
update_display_state(
display,
state_manager,
"scanning",
current_ssid=ssid,
current_status="Connecting to Wi-Fi",