# worm0x1/h1j4ck architecture

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

- Interactive diagram: https://gitdiagram.com/worm0x1/h1j4ck
- Repository: https://github.com/worm0x1/h1j4ck

## Overview

##### Project type and purpose
- This is a Chrome browser extension built for educational demonstration of how malicious extensions can exfiltrate sensitive data.
- It consists of three files at the root:
- manifest.json – declares permissions, scripts, and extension metadata
- content.js – injected into web pages to capture credentials and cookies
- background.js – runs in the background, receives messages from content scripts, and forwards data to the attacker’s Telegram bot

##### File structure
- Top-level files only; no nested directories.
- manifest.json shows the extension’s architecture:
- “content_scripts” section → content.js runs in page context
- “background” section → background.js is the long-lived event handler
- content.js and background.js communicate via the Chrome messaging API.
- No build or deployment scripts—loading is manual via chrome://extensions.

##### README for architectural clues
- Extension monitors login forms on any website.
- Captured data (username/password + session cookies) is sent via HTTPS POST to the Telegram Bot API.
- The attacker views the exfiltrated data in a Telegram chat.

##### Main components
a. User’s Browser
- Chrome runtime hosting the extension
- Web pages (login form targets)
b. Chrome Extension
- Content Script (content.js) – DOM listener for form submissions + cookie capture
- Background Script (background.js) – handles outbound HTTP requests
- manifest.json – configuration (permissions: cookies, activeTab, webRequest, http://*/https://* for Telegram API)
c. External Service
- Telegram Bot API endpoint (api.telegram.org/bot<token>/sendMessage)
d. Attacker
- Telegram client receiving messages

##### Relationships and data flow
1. User navigates to a target site (e.g., bank.com).
2. content.js injects into the page, attaches to login form events.
3. On form submit: content.js reads form fields and document.cookie.
4. content.js sends a Chrome runtime message to background.js with the payload.
5. background.js composes an HTTPS request to the Telegram Bot API using the bot token and chat_id.
6. Telegram API responds; attacker views the message in their mobile/desktop Telegram client.

##### Architectural patterns and design principles
- Event-driven: content scripts react to DOM events; background script listens to messages.
- Separation of concerns:
- content.js handles sensing/extraction
- background.js handles network communication

##### Key technologies and libraries
- Chrome Extensions API (chrome.runtime.sendMessage, chrome.cookies)
- JavaScript ES6+ for logic
- HTTPS communication to Telegram

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef clientScript fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef config fill:#B0C4DE,stroke:#333,stroke-width:1px
    classDef external fill:#98FB98,stroke:#333,stroke-width:1px
    classDef attacker fill:#F08080,stroke:#333,stroke-width:1px
    classDef doc fill:#EEE8AA,stroke:#333,stroke-width:1px

    User["User’s Browser"]:::client
    WebPage["Web Page (login form)"]:::client

    subgraph "Chrome Extension"
        Manifest["manifest.json"]:::config
        Content["Content Script (content.js)"]:::clientScript
        Background["Background Script (background.js)"]:::clientScript
    end

    External["Telegram Bot API"]:::external
    Attacker["Attacker (Telegram client)"]:::attacker

    Documentation["README.md"]:::doc

    User -->|"navigates to site"| WebPage
    WebPage -->|"DOM submit event"| Content
    Content -->|"chrome.runtime.sendMessage (JSON payload)"| Background
    Background -->|"HTTPS POST to Telegram API"| External
    External -->|"Message via Bot"| Attacker

    Manifest -->|provides permissions| Content
    Manifest -->|provides permissions| Background

    Documentation -.-> Manifest

    click Manifest "https://github.com/worm0x1/h1j4ck/blob/main/manifest.json"
    click Content "https://github.com/worm0x1/h1j4ck/blob/main/content.js"
    click Background "https://github.com/worm0x1/h1j4ck/blob/main/background.js"
    click Documentation "https://github.com/worm0x1/h1j4ck/blob/main/README.md"
```
