# a-d-team/grafanaexp architecture

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

- Interactive diagram: https://gitdiagram.com/a-d-team/grafanaexp
- Repository: https://github.com/a-d-team/grafanaexp

## Overview

##### Project Type and Purpose
- This project is a command-line exploitation tool implemented in Go.
- Its purpose is to auto-detect the Grafana vulnerability, retrieve plugins, secret keys, and decrypt the server-side database file to extract data_source information.
- There are two main commands: “exp” (to probe and exploit the vulnerability) and “decode” (to locally decrypt a downloaded database file).

##### File Structure
- Top-Level Files & Directories:
– “cmd” folder: Contains the main entry point (grafanaExp.go) that initializes CLI commands.
– “internal” folder: Houses modules for handling CLI flags, vulnerability exploitation logic (exp.go), constructing HTTP requests (req.go), and managing global variables (vars.go).
– “pkg/http” folder: Contains a comprehensive collection of HTTP-related tools and implementations. There are subdirectories for CGI, FCGI, cookiejar, HTTP trace, reverse proxy functions, and other HTTP utilities. These form the core of how the tool communicates with remote Grafana instances.
– Build script (build.sh) and dependency files (go.mod, go.sum) indicate that it’s built as a stand-alone Go binary with external dependency management.

##### Main Components
a. CLI Entry Layer:
- Component: Command-line interface (CLI)
- File: cmd/grafanaExp.go
- Responsibility: Parse command line arguments (exploit modes “exp” and “decode”) and initiate the corresponding workflow.

b. Internal Logic Layer:
- Components:
– Flag Parsing Module (internal/cliFlag.go)
– Exploitation Logic Module (internal/exp.go) – handles vulnerability detection, secret key retrieval, and output preparation.
– Request Builder Module (internal/req.go) and Variables Module (internal/vars.go) – these manage the construction and consistency of HTTP requests/data.
- Responsibility: Process input options, perform vulnerability checks, manage plugin detection, key extraction, and decrypt DB files when needed.

c. HTTP Communication and Utility Layer:
- Component: HTTP Package (pkg/http)
- Responsibilities:
– Managing HTTP communication with target servers.
– Handling specialized HTTP variants (CGI, FCGI, and file transports).
– Implementing client-server interactions along with testing and utility functions (found throughout pkg/http subdirectories such as cookiejar, httputil, and httptrace).
- Multiple sub-packages in pkg/http show that the design leverages the versatility of Go’s net/http functionalities and custom modifications (e.g., bypassing issues in transport implementations).

##### Data Flow and Interactions
- User Input →
– The user invokes the tool via the CLI with parameters (URL, plugin, DB file, key, etc.).
- CLI Manager (cmd/grafanaExp.go) →
– Routes the command to the correct internal module (either “exp” or “decode” command).
- Internal Processing (internal/) →
– Flag parsing reads and validates user input.
– The exploitation module (exp.go) orchestrates vulnerability detection, calls request-building functions (req.go), and uses global configuration values (vars.go).
- HTTP Communication (pkg/http) →
– Internal modules call upon HTTP utilities for sending crafted HTTP requests to the target Grafana server.
– Various HTTP sub-components (CGI, FCGI, etc.) interact depending on the nature of the vulnerability exploitation.
- Output Generation →
– The exploitation results (list of plugins, secret key, and database connection details) are collected and output to the console.
– In “decode” mode, similar steps are performed with local database file input and decryption logic to produce a clear output.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UCI["User CLI Input"]:::user
    CLI["CLI/Entry Point (cmd/grafanaExp.go)"]:::cli
    UCI -->|"providesCommandParameters"| CLI
    subgraph "Internal Processing"
        FP["Flag Parsing (internal/cliFlag.go)"]:::internal
        CLI -->|"parsesCommands"| FP

        EXP["Exploitation Logic (internal/exp.go)"]:::internal
        FP -->|"if_expCommand"| EXP

        RB["Request Builder (internal/req.go)"]:::internal
        EXP -->|"buildsHTTPRequest"| RB

        GV["Global Variables (internal/vars.go)"]:::internal
        EXP -->|"accessesGlobals"| GV

        DEC["Decode Workflow (local DB_decryption)"]:::internal
        FP -->|"if_decodeCommand"| DEC

        EXP -->|"outputsExploitResults"| OUT
        DEC -->|"outputsDecodeResults"| OUT
    end

    HTTP["HTTP Communication & Utilities (pkg/http)"]:::http
    RB -->|"sendsHTTPRequest"| HTTP
    HTTP -->|"returnsServerResponse"| EXP

    OUT["Output Console"]:::output

    %% Click Events
    click CLI "https://github.com/a-d-team/grafanaexp/blob/main/cmd/grafanaExp.go"
    click FP "https://github.com/a-d-team/grafanaexp/blob/main/internal/cliFlag.go"
    click EXP "https://github.com/a-d-team/grafanaexp/blob/main/internal/exp.go"
    click RB "https://github.com/a-d-team/grafanaexp/blob/main/internal/req.go"
    click GV "https://github.com/a-d-team/grafanaexp/blob/main/internal/vars.go"
    click HTTP "https://github.com/a-d-team/grafanaexp/tree/main/pkg/http"

    %% Styles
    classDef user fill:#A9DFBF, stroke:#239B56, stroke-width:2px;
    classDef cli fill:#AED6F1, stroke:#1F618D, stroke-width:2px;
    classDef internal fill:#F9E79F, stroke:#B7950B, stroke-width:2px;
    classDef http fill:#D7BDE2, stroke:#7D3C98, stroke-width:2px;
    classDef output fill:#F5CBA7, stroke:#784212, stroke-width:2px;
```
