theHarvester OSINT Tool

repository·master·Indexed 11 days ago

https://github.com/laramies/theharvester

An Open Source Intelligence (OSINT) tool used during reconnaissance in red team assessments or penetration tests. It gathers domain-related intelligence including names, emails, IPs, subdomains, and URLs using passive modules (search engines, certificate logs) and active modules (DNS brute force, screenshots). Supports a wide range of sources such as Shodan, Censys, and VirusTotal, and provides a REST API and CLI for data harvesting.

Tokens
8.9K
Snippets
33
Records
42
Agent score
97%

What's inside theHarvester

  1. Overview of theHarvester modules

    master

    theHarvester uses different types of modules to gather OSINT (Open Source Intelligence) data such as names, emails, IPs, subdomains, and URLs:

    • Passive modules: These gather data from public resources without directly interacting with the target infrastructure (e.g., search engines like baidu, brave, duckduckgo, or certificate transparency logs like crtsh).
    • Active modules: These interact more directly with the target, such as DNS brute force (dictionary enumeration) and Screenshots (capturing subdomains).
    • API-based modules: Many passive modules (e.g., censys, shodan, virustotal) require an API key to function. Some offer free tiers, while others require paid subscriptions.
  2. Install theHarvester using uv

    master

    To install and run theHarvester, ensure you have Python 3.12 or higher installed. The recommended installation method uses uv for dependency management.

    1. Install uv:
      curl -LsSf https://astral.sh/uv/install.sh | sh
    2. Clone the repository:
      git clone https://github.com/laramies/theHarvester
      cd theHarvester
    3. Install dependencies and create a virtual environment:
      uv sync
    4. Run the tool:
      uv run theHarvester
    curl -LsSf https://astral.sh/uv/install.sh | sh
    git clone https://github.com/laramies/theHarvester
    cd theHarvester
    uv sync
    uv run theHarvester
  3. Secure the /additional/* REST API routes

    master

    The theHarvester REST API includes optional /additional/* routes that are protected. To enable access to these routes, you must:

    1. Set the THEHARVESTER_API_KEY environment variable.
    2. Pass the same key value in the X-API-Key header of your requests.

    If the key is not configured, these routes will return a 503 status code.

  4. Configure DNS Resolvers with --dns-resolve

    master

    The --dns-resolve flag allows you to specify custom DNS resolvers. It supports three formats:

    1. A single IP address (e.g., 8.8.8.8).
    2. A comma-separated list of IP addresses (e.g., 1.1.1.1,8.8.8.8).
    3. A path to a file containing a list of resolvers (one per line).
    # Using a comma-separated list
    python -m theHarvester -d example.com -r "1.1.1.1,8.8.8.8"
    
    # Using a file containing resolvers
    python -m theHarvester -d example.com -r resolvers.txt
  5. Generate XML and JSON reports

    master

    theHarvester supports exporting gathered intelligence into structured XML and JSON formats.

    XML Report Format

    The XML report includes the command used, all discovered emails, hosts (with IP if available), and virtual hosts (vhosts).

    JSON Report Format

    The JSON report is a comprehensive dictionary containing:

    • cmd: The command line arguments used.
    • ips: A list of discovered IP addresses.
    • emails: A list of discovered email addresses.
    • hosts: A list of discovered hostnames/IPs.
    • vhosts: A list of virtual hosts.
    • interesting_urls: A list of URLs identified as interesting.
    • trello_urls: A list of Trello-related URLs.
    • asns: A list of Autonomous System Numbers.
    • twitter_people: A list of Twitter users found.
    • linkedin_people: A list of LinkedIn users found.
    • linkedin_links: A list of LinkedIn links.
    • people: A list of all people found.
    • takeover_results: Results from subdomain takeover checks.
    • shodan: Results from Shodan searches.
  6. Configure theHarvester via Docker Compose

    master

    When running theHarvester using Docker Compose, you can provide configuration files for API keys and proxies by mounting local files into the container. The service maps port 5000 on the host to port 80 inside the container.

    Volume Mappings

    To ensure the application uses your custom configurations, mount the following files:

    Local PathContainer Path (Root)Container Path (Etc)
    ./theHarvester/data/api-keys.yaml/root/.theHarvester/api-keys.yaml/etc/theHarvester/api-keys.yaml
    ./theHarvester/data/proxies.yaml/root/.theHarvester/proxies.yaml/etc/theHarvester/proxies.yaml

    Network

    The service is attached to a network named app_theHarvester_network.

    services:
      theharvester.svc.local:
        container_name: theHarvester
        volumes:
          - ./theHarvester/data/api-keys.yaml:/root/.theHarvester/api-keys.yaml
          - ./theHarvester/data/api-keys.yaml:/etc/theHarvester/api-keys.yaml
          - ./theHarvester/data/proxies.yaml:/etc/theHarvester/proxies.yaml
          - ./theHarvester/data/proxies.yaml:/root/.theHarvester/proxies.yaml
        build: .
        ports:
          - "5000:80"
    
    networks:
      default:
        name: app_theHarvester_network
  7. Configure API keys for theHarvester

    master

    TheHarvester uses an api-keys.yaml file to store credentials for various search engines. The engine searches for this file in the following order:

    1. ~/.theHarvester/api-keys.yaml
    2. /etc/theHarvester/api-keys.yaml
    3. /usr/local/etc/theHarvester/api-keys.yaml

    If the file is not found in these locations, the engine will attempt to create a default version in your home directory (~/.theHarvester/api-keys.yaml) using a template from the project's data directory.

    YAML Structure: The file must contain an apikeys top-level key. Some providers require a single key, while others require multiple fields (e.g., id and secret for Censys, or key and email for Fofa).

    apikeys:
      shodan:
        key: 'YOUR_SHODAN_KEY'
      censys:
        id: 'YOUR_CENSYS_ID'
        secret: 'YOUR_CENSYS_SECRET'
      fofa:
        key: 'YOUR_FOFA_KEY'
        email: 'YOUR_FOFA_EMAIL'
  8. Configure the THEHARVESTER_API_KEY environment variable

    master
    TheHarvester API uses the THEHARVESTER_API_KEY environment variable to store the valid credential for authentication. If this variable is not set, the API will return a 503 SERVICE UNAVAILABLE error. If the provided header does not match this value, the API will return a 401 UNAUTHORIZED error.
  9. Configure proxies via proxies.yaml

    master

    You can configure HTTP and SOCKS5 proxies by creating a proxies.yaml file in one of the standard configuration directories:

    • ~/.theHarvester/proxies.yaml
    • /etc/theHarvester/proxies.yaml
    • /usr/local/etc/theHarvester/proxies.yaml

    The AsyncFetcher class uses this file to resolve proxy URLs. It supports both http and socks5 types.

    http:
      - '1.2.3.4:8080'
      - '5.6.7.8:3128'
    socks5:
      - '1.2.3.4:1080'