# topotam/petitpotam architecture

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

- Interactive diagram: https://gitdiagram.com/topotam/petitpotam
- Repository: https://github.com/topotam/petitpotam

## Overview

##### Project Overview and Purpose
- This project is a Proof-of-Concept (PoC) security tool that forces Windows hosts to authenticate to other machines using vulnerabilities in the MS‑EFSRPC (and LSARPC) interfaces. It has two implementations:
– A Windows-targeted C++ implementation (built via Visual Studio, as seen in the solution, project files, and C++ source code).
– A Python version that relies on the Impacket library to perform similar coercion.
- Its core goal is to trigger Windows authentication without needing credentials against a Domain Controller.

##### Analyzing the File Structure
- Top-Level Files:
– PetitPotam.exe: The compiled C++ binary for Windows.
– PetitPotam.py: The Python script version.
– PetitPotam.sln: The Visual Studio solution file (along with accompanying project files and filters), indicating a structured C++ Windows application.
- Source and Support Files:
– The PetitPotam directory contains the main C++ source file and its project configuration.
– Additional header/source files (ms-dtyp.h, ms-efsrpc_c.c, etc.) provide implementations for EFSRPC and LSARPC protocols.
- README.md provides context on the attack vector, dependencies, and relevant protocols (EFSRPC and LSARPC).

##### Components
A. Core Components:
- Command-Line Interface (CLI) – Represents the user’s starting point where they execute either the C++ PoC or the Python script.
- PetitPotam PoC (C++):
- Visual Studio Build Environment: Represents the development and build process.
- Executable (PetitPotam.exe): The Windows binary implementing the MS‑EFSRPC call.
- Supporting Code: Source files (PetitPotam.cpp) and headers related to the EFSRPC and LSARPC protocols.
- PetitPotam PoC (Python):
- Python Script (PetitPotam.py): Implements the same functionality using the Impacket library.
- Dependency on Impacket: Denoted as an external module/library that supplies necessary network protocol support.
- External Dependencies:
- Windows RPC Library (Rpcrt4.lib) – Mentioned explicitly as a linker input.
- Named Pipes / RPC Endpoints – LSARPC and EFSRPC channels used to trigger the authentication on the target.
- Target Windows Host:
- Remote Machine: The system that will be coerced into authenticating by virtue of receiving an MS‑EFSRPC (or LSARPC) call.

B. Relationships and Data Flows:
- User triggers execution (via CLI) → calls either the C++ executable or Python script.
- The chosen implementation then constructs an RPC call using one of the named pipe interfaces (primarily LSARPC, also EFSRPC) to target a Windows host.
- The tool sends a crafted RPC request (using functions like EfsRpcOpenFileRaw) that forces the target to authenticate, with authentication details flowing back to a designated endpoint (the attacker’s machine).
- The project’s design shows a clear separation: one branch compiled as a native Windows application (using Visual Studio) and one implemented in Python with reliance on third-party networking libraries.

C. Technical and Architectural Patterns:
- Protocol Abstraction: Although it is a targeted PoC, there is a separation of responsibilities between constructing and sending the RPC calls and handling the network communication.
- External Library Integration: For the Python version, it is important to illustrate the role of the Impacket library in managing the network protocol details.

## Diagram (Mermaid)

```mermaid
flowchart TD
    cli["CLI Execution"]:::cli

    subgraph "C++ Implementation"
        vsbuild["Visual Studio Build Environment"]:::native
        cpplib["C++ Source & EFSRPC/LSARPC Code"]:::native
    end

    subgraph "Python Implementation"
        pyth["Python Script Implementation"]:::script
        impacket["Impacket Library"]:::dependency
    end

    rpcnode["RPC & Named Pipes Interface"]:::network
    targetnode["Target Windows Host"]:::target

    %% Relationships
    cli -->|"triggers"| vsbuild
    cli -->|"triggers"| pyth
    vsbuild -->|"compiles"| cpplib
    pyth -->|"utilizes"| impacket
    cpplib -->|"EfsRpcOpenFileRaw call"| rpcnode
    impacket -->|"RPC request"| rpcnode
    rpcnode -->|"forces authentication"| targetnode

    %% Click Events for CLI files
    click cli "https://github.com/topotam/petitpotam/blob/main/PetitPotam.exe"
    click cli "https://github.com/topotam/petitpotam/blob/main/PetitPotam.py"

    %% Click Events for C++ Visual Studio Build Environment files
    click vsbuild "https://github.com/topotam/petitpotam/blob/main/PetitPotam.sln"
    click vsbuild "https://github.com/topotam/petitpotam/blob/main/PetitPotam/PetitPotam.vcxproj"
    click vsbuild "https://github.com/topotam/petitpotam/blob/main/PetitPotam/PetitPotam.vcxproj.filters"
    click vsbuild "https://github.com/topotam/petitpotam/blob/main/PetitPotam/PetitPotam.vcxproj.user"

    %% Click Events for C++ Source Code and Supporting Files
    click cpplib "https://github.com/topotam/petitpotam/blob/main/PetitPotam/PetitPotam.cpp"
    click cpplib "https://github.com/topotam/petitpotam/blob/main/PetitPotam/ms-efsrpc_c.c"
    click cpplib "https://github.com/topotam/petitpotam/blob/main/PetitPotam/ms-dtyp.h"
    click cpplib "https://github.com/topotam/petitpotam/blob/main/PetitPotam/ms-dtyp_h.h"
    click cpplib "https://github.com/topotam/petitpotam/blob/main/PetitPotam/ms-efsrpc_h.h"

    %% Click Event for Python Script Implementation
    click pyth "https://github.com/topotam/petitpotam/blob/main/PetitPotam.py"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef native fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef script fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dependency fill:#32CD32,stroke:#000,stroke-width:2px;
    classDef network fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef target fill:#FF6347,stroke:#000,stroke-width:2px;
```
