Project Documentation
π 1. Overview
Project Overview
The SystemHijack project is a modular Windows reconnaissance tool designed to collect system data, hunt for credential files, encrypt the report, and exfiltrate it via multiple channels. The project is built using Node.js and utilizes only built-in Node.js libraries, with zero dependencies required at runtime. The tool is designed to masquerade as a fake npm install process, providing a stealthy way to gather system information.
Core Functionality
The project's core functionality can be broken down into several key components. The first component is the reconnaissance phase, which collects system data such as OS information, CPU details, memory usage, user information, environment variables, and machine GUID. The second component is the file hunting phase, which scans for credential files such as .env files, SSH keys, and AWS credentials. The third component is the exfiltration phase, which encrypts the collected data and sends it to multiple channels, including GitHub, Discord, and Pastebin.
Tech Stack
The project's tech stack is primarily based on Node.js, with a focus on utilizing built-in libraries to minimize dependencies. The project uses JavaScript as the primary programming language and takes advantage of Node.js's built-in modules such as os, fs, and child_process. The project also uses the crypto module for encryption and decryption purposes.
Tech Stack at a Glance
| Category | Technology | Purpose |
|---|---|---|
| Programming Language | JavaScript | Primary programming language |
| Runtime Environment | Node.js | Built-in libraries and modules |
| Module System | CommonJS | Module resolution and loading |
| Encryption | Crypto | Encryption and decryption of collected data |
| Exfiltration | GitHub API, Discord Webhook, Pastebin API | Exfiltration of collected data to multiple channels |
| Configuration | JSON | Configuration files for storing settings and credentials |
State Management and Styling
The project does not appear to use any specific state management libraries or frameworks. Instead, it relies on Node.js's built-in modules and JavaScript's built-in data structures to manage state. The project also does not seem to have any specific styling or UI components, as it is designed to run as a command-line tool.
Database Libraries
The project does not use any database libraries, as it does not require a database to store collected data. Instead, the project relies on encrypting and exfiltrating the collected data to multiple channels.
Security and Safety
The project takes several security and safety measures to ensure that it does not cause harm to the system or compromise sensitive information. The project includes safety checks to detect VMs, debuggers, and other potential security threats. The project also includes a dry-run mode that allows users to test the tool without actually collecting or exfiltrating any data. Additionally, the project includes auto-cleanup features that remove any artifacts or traces of the tool's execution.
Conclusion
In conclusion, the SystemHijack project is a sophisticated Windows reconnaissance tool that collects system data, hunts for credential files, and exfiltrates the collected data to multiple channels. The project is built using Node.js and utilizes only built-in Node.js libraries, with a focus on minimizing dependencies and ensuring security and safety. The project's tech stack is primarily based on JavaScript, Node.js, and built-in modules, with a focus on encryption, exfiltration, and configuration management.
π 2. Project Structure
Codebase File Structure Analysis
File Structure Table
| Category | Sub-folder | Key Responsibility |
|---|---|---|
| Configuration | . | Project configuration files (.eslintrc.js, .gitignore, jsconfig.json, package-lock.json, package.json) |
| Documentation | . | Project README file (README.md) |
| Application | src/app | Main application logic (config.js, exfil.js, orchestrator.js, uploader.js) |
| File Management | src/files | File-related operations (crud.js, envHunter.js, secretHunter.js) |
| Monitoring | src/monitor | System monitoring (watcher.js) |
| Reporting | src/report | Report generation (generator.js) |
| System Information | src/system | System information gathering (cpu.js, debugDetect.js, env.js, machineId.js, memory.js, persist.js, processes.js, software.js, system.js, user.js, vmDetect.js, wifi.js) |
| Utilities | src/utils | Reusable utility functions (crypto.js, errors.js, execAsync.js, logger.js, retry.js, safe.js) |
| Testing | tests | Unit tests for application logic and utilities |
| Tools | tools | Additional tools and scripts (encode-creds.js) |
Architectural Patterns
The codebase appears to be using a modular, service-oriented architecture. The application logic is separated into distinct categories, each with its own set of responsibilities. This suggests a Modular Monolith architecture, where the application is divided into smaller, independent modules that work together to form the overall system.
The use of separate folders for application logic, file management, monitoring, reporting, and system information gathering implies a Layered Architecture. Each layer has a specific responsibility, and they are stacked on top of each other to form the overall system.
The presence of utility functions in the src/utils folder suggests the use of a Utility Layer pattern, where reusable functions are extracted from the application logic and placed in a separate layer for easy access and reuse.
The Clean Architecture pattern is also evident, as the application logic is separated from the infrastructure and presentation layers. The src/app folder contains the application logic, while the src/system folder contains the system information gathering logic, which can be considered as part of the infrastructure layer.
The Single Responsibility Principle (SRP) is also applied, as each file and folder has a single, well-defined responsibility. This makes the codebase more maintainable, scalable, and easier to understand.
However, the codebase could benefit from a more explicit separation of concerns between the application logic and the infrastructure layer. The use of interfaces and dependency injection could also improve the modularity and testability of the codebase.
Overall, the codebase has a clear and organized structure, with a focus on modularity, reusability, and separation of concerns. With some additional refinement and attention to detail, the codebase could be even more maintainable, scalable, and efficient.
ποΈ 3. Architecture & Data Flow
SystemHijack Deep Architecture Analysis
1. Deep-Dive Architecture Reasoning
1.1. Core Design Principles
SystemHijack is a modular reconnaissance tool disguised as a fake npm install process. It follows defense-in-depth, zero-dependency, and safety-first principles. The architecture is designed to:
- Masquerade as a legitimate npm process to evade detection.
- Collect system and credential data in parallel with minimal footprint.
- Persist via registry and scheduled tasks (auto-cleaned on exit).
- Exfiltrate via multiple channels (GitHub, Discord, Pastebin) with retry logic.
- Ensure safety via dry-run mode, cleanup hooks, and graceful degradation.
1.2. Module Interactions & Advanced Design Patterns
1.2.1. Entry Point: src/index.js
- Acts as the Orchestrator and Facade.
- Parses CLI flags (
--dry-run,--cleanup). - Initiates the fake npm install UI (masquerading).
- Triggers safety checks (VM/debugger detection).
- Coordinates Phase 1 (Recon), Phase 2 (Persistence), Phase 3 (Exfil).
- Registers exit handlers (
process.on('exit'),SIGINT,SIGTERM) for auto-cleanup.
1.2.2. Phase 1: Reconnaissance (src/app/orchestrator.js)
- Strategy Pattern: Uses
Promise.allSettled()to run 8 parallel collectors (CPU, Memory, User, Environment, WiFi, Software, Processes, System). - Decorator Pattern: Wraps each collector in
safe()to handle errors gracefully (e.g.,safe(() => os.cpus())). - Observer Pattern: Collectors emit data into a shared report object (
report = {}). - File Hunting: Uses
src/files/envHunter.jsandsrc/files/secretHunter.jsto recursively scan for.envfiles and secrets (SSH keys, AWS credentials, etc.).- Symlink Protection: Uses
fs.realpathSync()to avoid loops. - Size Limits: Skips files >100KB to avoid performance issues.
- Symlink Protection: Uses
1.2.3. Phase 2: Persistence (src/system/persist.js)
- Chain of Responsibility: Attempts multiple persistence methods in order:
- Copy Project: Copies the entire project to
~/.windows-update/(masquerading as a Windows update). - Registry Run Key: Writes to
HKCU\Software\Microsoft\Windows\CurrentVersion\Run(auto-removed on exit). - Scheduled Task: Falls back to
schtasks /createif registry fails (auto-removed on exit).
- Copy Project: Copies the entire project to
- Template Method Pattern: Uses
cleanupArtifacts(dryRun)to remove traces (registry, task, files).
1.2.4. Phase 3: Exfiltration (src/app/exfil.js)
- Strategy Pattern: Shuffles exfil channels (GitHub, Discord, Pastebin) to avoid detection.
- Retry Pattern: Uses
src/utils/retry.js(exponential backoff) for failed uploads. - Encryption: Uses
src/utils/crypto.js(AES-256-GCM) to encrypt the report before exfil. - Connectivity Check: Pre-validates internet access via
src/system/debugDetect.js(HEAD requests togithub.com,google.com).
1.2.5. Anti-Analysis & Obfuscation
- VM Detection:
src/system/vmDetect.jschecks for VM files, MAC prefixes, and RAM/CPU heuristics. - Debugger Detection:
src/system/debugDetect.jschecksNODE_OPTIONS, process timing, and running debuggers. - String Obfuscation: Credentials are XOR-encrypted at rest (
src/app/config.js) and decrypted at runtime usingMachineGuid. - User-Agent Spoofing: Uses Chrome 125 UA in HTTP requests.
1.2.6. Safety & Cleanup
- Dry-Run Mode: Skips persistence and exfil (only writes
system-report.jsonlocally). - Auto-Cleanup: Exit handlers remove registry keys, scheduled tasks, and copied files.
- AbortController: All OS commands (e.g.,
execAsync) have timeouts to prevent hangs.
1.3. Key Design Patterns Summary
| Pattern | Usage | Example |
|---|---|---|
| Facade | index.js hides complexity of phases. | index.js β orchestrator.js β collectors. |
| Strategy | Exfil channels, persistence methods. | exfil.js shuffles channels. |
| Decorator | safe() wraps collectors. | safe(() => os.cpus()). |
| Observer | Collectors emit to report. | report.cpu = safe(() => os.cpus()). |
| Chain of Responsibility | Persistence methods. | Registry β Task β Copy. |
| Retry | Exfil uploads. | retry(async () => uploader.upload()). |
| Template Method | Cleanup logic. | cleanupArtifacts(dryRun). |
2. Data Flow & State Transitions
| Origin | Action | Logic Handler | Resulting State |
|---|---|---|---|
src/index.js | Parse CLI flags (--dry-run, --cleanup) | process.argv | dryRun = true/false, cleanup = true/false |
src/index.js | Start fake npm install UI | console.log + setInterval | Fake progress bar displayed |
src/index.js | Run safety checks | vmDetect.js, debugDetect.js | isVM = false, isDebugger = false |
src/index.js | Execute Phase 1 (Recon) | orchestrator.js β Promise.allSettled() | report = { system, cpu, memory, user, env, wifi, software, processes } |
src/app/orchestrator.js | Run file hunters | envHunter.js, secretHunter.js | report.envFiles, report.secrets |
src/app/orchestrator.js | Execute Phase 2 (Persistence) | persist.js β copyProject(), setRegistry(), createTask() | ~/.windows-update/ exists, registry key added, task created |
src/app/orchestrator.js | Execute Phase 3 (Exfil) | exfil.js β shuffleChannels() β uploader.js | Report encrypted and uploaded to GitHub/Discord/Pastebin |
src/app/orchestrator.js | Register exit handlers | process.on('exit'), SIGINT, SIGTERM | Auto-cleanup triggered on exit |
src/system/persist.js | Cleanup artifacts | cleanupArtifacts(dryRun) | Registry key removed, task deleted, ~/.windows-update/ removed (if dryRun = false) |
src/index.js | --cleanup flag | cleanupArtifacts(true) | All traces removed |
3. Mermaid.js Architecture Diagram
4. Critical Observations
- Zero Dependencies: Uses only Node.js built-ins (
fs,os,child_process, etc.). - OPSEC Considerations:
- Shuffled exfil channels.
- Auto-cleanup on exit.
- String obfuscation.
- Safety Mechanisms:
- Dry-run mode.
- AbortController timeouts.
- Symlink protection.
- Testing:
- 102 tests with mocked OS commands.
- No side effects in test mode.
5. Potential Improvements
- Win32 API Integration: Replace
reg querywithwin32apifor faster registry reads. - AMSI Bypass: Add runtime obfuscation for evading antivirus.
- Report Compression: Use
zlibto reduce exfil size. - Cross-Platform WiFi Parsing: Expand beyond Windows/macOS/Linux.
This architecture exemplifies modularity, defense-in-depth, and safety-first design in a reconnaissance tool. The use of advanced patterns (Strategy, Decorator, Chain of Responsibility) ensures maintainability and extensibility.
π System Architecture Diagram
π οΈ 4. Function Breakdowns
.eslintrc.js
| Function/Export Name | Parameters | Logic Description | Impact |
|---|---|---|---|
| module.exports | Exports the ESLint configuration | Defines the ESLint rules for the project | |
| env | { node: true, es2022: true } | Specifies the environments in which the code will run | Enables Node.js and ES2022 syntax support |
| extends | ["eslint:recommended"] | Extends the recommended ESLint configuration | Applies the recommended ESLint rules to the project |
| parserOptions | { ecmaVersion: "latest", sourceType: "script" } | Configures the parser options | Sets the ECMAScript version to the latest and the source type to script |
| rules | { "no-unused-vars": ["warn", { argsIgnorePattern: "^", varsIgnorePattern: "^" }], ... } | Defines the ESLint rules | Warns about unused variables, disallows var, prefers const, and more |
| ignorePatterns | ["node_modules/", "workspace/"] | Specifies the directories to ignore | Excludes the node_modules and workspace directories from ESLint checks |
jsconfig.json
| Function/Export Name | Parameters | Logic Description | Impact |
|---|---|---|---|
| compilerOptions | { module: "commonjs", ... } | Configures the compiler options | Sets the module system to CommonJS, the module resolution to Node.js, and more |
| ignoreDeprecations | "6.0" | Ignores deprecations | Suppresses deprecation warnings for Node.js 6.0 |
| target | "es2022" | Specifies the target ECMAScript version | Sets the target ECMAScript version to ES2022 |
| checkJs | true | Enables JavaScript checking | Enables type checking for JavaScript files |
| strict | false | Disables strict mode | Disables strict mode for the project |
| noImplicitAny | false | Disables implicit any type checking | Disables implicit any type checking for the project |
| strictNullChecks | true | Enables strict null checks | Enables strict null checks for the project |
| noEmit | true | Disables code emission | Disables code generation for the project |
| skipLibCheck | true | Skips library checks | Skips type checking for libraries |
| include | ["src/**/*.js"] | Specifies the files to include | Includes all JavaScript files in the src directory |
| exclude | ["node_modules", "workspace"] | Specifies the files to exclude | Excludes the node_modules and workspace directories from the project |
README.md
| Function/Export Name | Parameters | Logic Description | Impact |
|---|---|---|---|
| npm install | Installs the project dependencies | Sets up the project dependencies | |
| npm test | Runs the project tests | Executes the project tests | |
| npm run dry-run | Runs the project in dry-run mode | Runs the project in dry-run mode, without any side effects | |
| npm start | Starts the project | Starts the project in normal mode | |
| node src/index.js --cleanup | Cleans up the project artifacts | Removes the project artifacts, including the HKCU Run key, scheduled task, and more | |
| npm run lint | Runs the project linter | Executes the project linter, checking for code quality and syntax issues | |
Note that the README.md file does not contain any executable code, but rather serves as a documentation and instruction guide for the project. |
The src/index.js file, which is the entry point of the project, is not provided in the given context. However, based on the project architecture described in the README.md file, it can be inferred that this file orchestrates the entire project, including the fake npm install UI, safety checks, and execution of the various project phases.
Here is a high-level breakdown of the src/index.js file, based on the provided context:
src/index.js
| Function/Export Name | Parameters | Logic Description | Impact |
|---|---|---|---|
| main | Orchestrates the project execution | Runs the fake npm install UI, performs safety checks, and executes the project phases | |
| safetyChecks | Performs safety checks, including VM detection and debugger detection | Ensures the project is running in a safe environment | |
| executePhases | Executes the project phases, including system information collection, file hunting, and exfiltration | Collects system information, hunts for files, and exfiltrates data | |
| buildReport | Builds the project report | Creates a report based on the collected system information and file hunting results | |
| cleanupArtifacts | dryRun | Cleans up the project artifacts, including the HKCU Run key, scheduled task, and more | Removes the project artifacts, with an option to skip deletion in dry-run mode |