How mcw0/dahuaconsole works
Project type and purpose
• This is a Python-based command-line interface (CLI) tool named “Dahua Console.”
• Its purpose is to connect to Dahua IP devices (cameras, DVRs) over various protocols, perform authentication (including exploit CVE methods), dump configuration or service data, subscribe to events, and optionally relay through SSH.
File structure
• Top-level files:
• Console.py – the main entry point and argument parser (CLI layer)
• connection.py – session/connection management
• net.py – raw network I/O (sockets, TCP/SSL)
• relay.py – SSH tunneling wrapper for connections
• servers.py – local server(s) if reverse connections or callbacks are needed
• dahua.py – high-level protocol API (commands, dumps, subscribe)
• dahua_logon_modes.py – implementations of all supported login modes
• events.py – event subscription and message handling
• eventviewer.py – interactive or formatted display of incoming events
• pwdmanager.py – password/credential hashing or transformations
• utils.py – shared helpers (JSON I/O, logging, hexdump, config file persistence)
• Console.json (generated at runtime) – saved host hashes/credentials
• Configuration: requirements.txt, .gitignore, LICENSE, README.md.
README for additional insights
• Lists all CLI arguments (--rhost, ‑-proto, ‑-logon, ‑-dump, ‑-events, etc.)
• Describes protocol choices: dhip, dvrip, HTTP(S), 3DES, onvif, loopback, etc.
• Mentions support for SSH relays, JSON dumps, test mode, debug modes.
• Highlights CVE-based exploit flows for authentication bypass.
a. Main components
1. CLI Layer (Console.py)
2. Argument Parser & Dispatcher
3. Core Engine
– Connection Manager (connection.py)
– Network I/O (net.py)
– SSH Relay (relay.py)
– Local Server (servers.py, for callback/event forwarding)
4. Protocol & Auth Modules
– Dahua Protocol API (dahua.py)
– Logon Modes (dahua_logon_modes.py)
5. Feature Modules
– Dump Service (methods in dahua.py)
– Event Subscription (events.py) + Event Viewer (eventviewer.py)
6. Utilities
– Password Manager (pwdmanager.py)
– Shared Helpers (utils.py)
– Config Persistence (dhConsole.json)
7. External Entities
– Target Dahua Device
– SSH Server (if using relay)
b. Relationships & interactions
• User invokes: Console.py → parses CLI args → passes to Core Engine
• Core Engine picks or opens connection via Connection Manager
– If relay URL set → instantiate SSH tunnel (relay.py) → forward net I/O
– Else → direct TCP/SSL socket (net.py)
• Engine selects logon mode implementation → authenticates via dahua_logon_modes.py
• Once authenticated → use dahua.py methods to run dumps or subscribe events
• Event subscription uses events.py → optionally spins up a local server (servers.py) → feeds into eventviewer.py
• All data (JSON dumps, logs, hexdumps) pass through utils.py for formatting, file I/O
c. Architectural patterns & design principles
– Modular separation by responsibility: CLI vs. Connection vs. Protocol vs. Features
– Strategy pattern for selectable “logon modes”
– Adapter-style network abstraction (net.py + relay.py)
– Single source of truth for configuration (JSON file)
– Dependency inversion: high-level engine depends on interface modules (not concrete sockets)
d. Key technologies, frameworks, libraries
– Python 3.x standard library (argparse, socket, ssl, subprocess)
– Paramiko or similar SSH client for relay.py (in requirements.txt)
– JSON for config and dumps
– Optional colorized CLI output (if any library in requirements)