# miladdiaz/mikrotikexploit architecture

> Architecture diagram of the GitHub repository miladdiaz/mikrotikexploit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/miladdiaz/mikrotikexploit
- Repository: https://github.com/miladdiaz/mikrotikexploit

## Overview

##### Project Type and Purpose
- This is a small open‑source, command‑line Python tool for scanning subnets or lists of IPv4 addresses to exploit a known RouterOS “Winbox” vulnerability and extract router credentials.
- The two entry‑point scripts are:
- loop.py – orchestrates command‑line parsing, IP range expansion, looping
- extract_user.py – implements the Winbox exploit (HTTP/SSL handshake via requests, parsing the response)

##### File Structure Analysis
- Top level:
- LICENSE, README.md – documentation
- extract_user.py – core exploit module
- loop.py – CLI interface and orchestration
- No “src/” or multi‑language layers—this is a single‑module, single‑language (Python 3) CLI tool.
- Dependencies:
- ipcalc – to expand IP ranges or parse CIDR
- requests – to send HTTP requests to Mikrotik Winbox port

##### Key Functional Components
a. CLI Interface (loop.py)
- Parses arguments: single IP, CIDR blocks, port override, input file.
- Invokes IP range generator (via ipcalc or simple list file).
- Feeds each IP+port to extract_user.py.
b. IP Range Generator
- External library “ipcalc” (or built‑in parsing) to expand CIDR to individual IPs.
c. Exploit Module (extract_user.py)
- Uses requests to connect to port 8291 (or override) on target RouterOS.
- Sends the Winbox‐protocol handshake & captures the “exported” user file.
- Parses and returns credentials or failure.
d. Output Handler
- loop.py captures the return from extract_user, writes to console or file.

##### External Dependencies & Services
- Third‑party Python packages: ipcalc, requests.
- Network endpoints: target RouterOS devices over TCP (Winbox port).

##### Relationships & Data Flow
1) User invokes loop.py with arguments
2) loop.py → IP Range Generator (ipcalc or file reader) → produces a stream of target IPs
3) For each IP: loop.py → extract_user.py (function call) → requests library → TCP connection to RouterOS
4) RouterOS responds with exported password data → extract_user parses → returns results
5) loop.py collects and prints or logs output

##### Architectural Patterns & Design Principles
- Single responsibility: loop.py for orchestration, extract_user.py for protocol logic.
- Dependency injection via function arguments (IP, port).
- Linear pipeline: input → generator → exploit → output.

##### Essential Elements
- Component labels, version of Python.
- Callouts for configuration (default port 8291, override -p).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Nodes
    CLI["User Input\n(CLI args,\nIP file)"]:::io
    loop["loop.py\n(Orchestration)"]:::local
    ipcalc["ipcalc\n(CIDR Expansion)"]:::lib
    extract["extract_user.py\n(Exploit Module)"]:::local
    requests["requests\n(HTTP/SSL)"]:::lib
    RouterOS["RouterOS Device\n(Target over TCP)"]:::network
    Output["Console/File\nOutput"]:::io
    subgraph "Documentation"
        README["README.md"]:::io
        LICENSE["LICENSE"]:::io
    end

    %% Flow
    CLI -->|"parse args"| loop
    loop -->|"invoke ipcalc"| ipcalc
    ipcalc -->|"IP stream"| loop
    loop -->|"call exploit"| extract
    extract -->|"HTTP/SSL handshake"| requests
    requests -->|"TCP/Winbox"| RouterOS
    RouterOS -->|"credential data"| extract
    extract -->|"result"| loop
    loop -->|"print/log"| Output

    %% Click events
    click loop "https://github.com/miladdiaz/mikrotikexploit/blob/master/loop.py"
    click extract "https://github.com/miladdiaz/mikrotikexploit/blob/master/extract_user.py"
    click README "https://github.com/miladdiaz/mikrotikexploit/blob/master/README.md"
    click LICENSE "https://github.com/miladdiaz/mikrotikexploit/tree/master/LICENSE"

    %% Styles
    classDef local fill:#AED6F1,stroke:#1F618D,stroke-width:2px
    classDef lib fill:#A9DFBF,stroke:#196F3D,stroke-width:2px
    classDef network fill:#D5D8DC,stroke:#616A6B,stroke-width:2px
    classDef io fill:#F9E79F,stroke:#B7950B,stroke-width:2px
```
