Introduction
Welcome to the Harvesting Public Information lab.
Open Source Intelligence (OSINT) is the practice of collecting information from publicly available sources. In cybersecurity, passive reconnaissance is the first step of any penetration test or vulnerability assessment. It involves gathering data about a target without directly interacting with their systems, ensuring that your activities remain undetected by the target's security monitoring.
The word "public" does not mean "harmless." Public data can still be extremely revealing when aggregated. One certificate log entry or one indexed page may seem unimportant on its own, but combined together they can expose naming conventions, business units, staging systems, and targetable employees.
In this lab, you will learn how to use theHarvester, a popular and powerful OSINT tool designed to gather emails, subdomains, hosts, employee names, open ports, and banners. You will collect this data from different public sources like search engines, PGP key servers, and public databases, entirely through passive public data collection.
Configure theHarvester
In this step, you will install and configure theHarvester on your Linux environment.
While theHarvester comes pre-installed on many security-focused Linux distributions (like Kali Linux), it needs to be installed manually on standard Ubuntu environments. We will install it directly from its official GitHub repository using the uv Python package manager, which is the recommended method by the tool's developers.
Tooling matters here because OSINT frequently depends on aggregating many external sources quickly. Doing that manually is possible, but automation helps you collect repeatable evidence and keep track of where each data point came from.
First, ensure you are in your project directory. This is where you will execute your commands and store your results.
cd ~/project
Next, run the following commands to install uv, clone the repository, and sync the dependencies:
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
git clone https://github.com/laramies/theHarvester.git
cd theHarvester
uv sync
Once the installation is complete, you can verify that the tool is correctly installed and accessible by checking its help menu. Since we used uv, we will run the tool through its virtual environment.
uv run theHarvester -h
You should see an output similar to the following, displaying the banner and usage instructions:
*******************************************************************
* _ _ _ *
* | |_| |__ ___ /\ /\__ _ _ ____ _____ ___| |_ ___ _ __ *
* | __| _ \ / _ \ / /_/ / _` | '__\ \ / / _ \/ __| __/ _ \ '__| *
* | |_| | | | __/ / __ / (_| | | \ V / __/\__ \ || __/ | *
* \__|_| |_|\___| \/ /_/ \__,_|_| \_/ \___||___/\__\___|_| *
* *
* theHarvester 4.6.0 *
* Coded by Christian Martorella *
* Edge-Security Research *
* cmartorella@edge-security.com *
* *
*******************************************************************
usage: theHarvester.py [-h] -d DOMAIN [-l LIMIT] [-S START] [-p] [-s] [--screenshot] [-v] [-e DNS_SERVER] [-t DNS_TLD] [-r] [-n] [-c] [-f FILENAME] [-b SOURCE]
...
Take a moment to read through the available flags. The most important ones for our lab are -d (to specify the target domain), -l (to limit the number of results), and -b (to specify the data source).
Scrape Search Engines for Emails
In this step, you will perform your first passive reconnaissance scan against a target domain.
We will use kali.org as our target domain for this educational exercise. To avoid getting blocked by search engine CAPTCHAs (which often happens when scraping Google or Bing from cloud environments), we will use crtsh as our data source. crtsh searches Certificate Transparency logs, which is a highly reliable method for discovering subdomains and associated public records.
Certificate Transparency is an important concept for beginners because it shows how internet security controls can also become reconnaissance sources. Public certificates improve ecosystem trust, but they also expose names that organizations may not realize they have published.
Run the following command to start the harvesting process. We will redirect the output of the command into a text file named scan_results.txt using the > operator. This allows us to save the data for later analysis.
uv run theHarvester -d kali.org -l 100 -b crtsh > ~/project/scan_results.txt
This command breaks down as follows:
uv run theHarvester: The tool we are using, executed via theuvvirtual environment.-d kali.org: Specifies the target domain.-l 100: Limits the search to 100 results to speed up the process.-b crtsh: Instructs the tool to use thecrtshdatabase as the source.> ~/project/scan_results.txt: Saves the terminal output to a file instead of printing it directly to the screen.
The scan might take a few moments to complete as it queries the external database. Once the command prompt returns, the scan is finished.
You can view the raw results of your scan by reading the contents of the file using the cat command:
cat ~/project/scan_results.txt
You will see the raw output generated by theHarvester, which includes the banner, the search progress, and the discovered hosts:
[*] Target: kali.org
[*] Searching crtsh.
[*] Hosts found: 28
---------------------
admin.kali.org
autopkgtest.kali.org
blog.kali.org
bugs.kali.org
cdimage.kali.org
...
Notice that the raw output contains a lot of formatting text (like [*] Target: and ---------------------). In the next step, we will clean this up.
Compile the Target Roster
In this step, you will extract the useful information from the raw OSINT data to create a clean list of targets.
Raw data gathered during reconnaissance often contains noise, such as tool banners, status messages, and duplicate entries. To make this data actionable for further security testing, we need to parse it into a clean "roster" or target list.
This cleaning step is part of analysis, not busywork. Security decisions become better once raw discovery is normalized into a list that can be reviewed, deduplicated, and passed safely into later tooling.
We will use standard Linux text processing tools to achieve this. The grep command is used to search for specific patterns within a file, and the sort command is used to organize the output.
Run the following command to extract only the lines containing our target domain (kali.org), remove any duplicates, and save the clean list to a new file named targets.txt:
grep "kali.org" ~/project/scan_results.txt | sort -u > ~/project/targets.txt
Here is how this command works:
grep "kali.org" ~/project/scan_results.txt: Scans the raw results file and outputs only the lines that contain the text "kali.org". This effectively filters out the tool banners and status messages.|(Pipe): Takes the output from thegrepcommand and passes it as input to the next command.sort -u: Sorts the incoming list alphabetically and the-u(unique) flag removes any duplicate entries.> ~/project/targets.txt: Saves the final, cleaned list into a new file.
Now, view your compiled target roster:
cat ~/project/targets.txt
Your output should now be a clean, alphabetical list of discovered subdomains, ready to be used in subsequent phases of a security assessment:
admin.kali.org
autopkgtest.kali.org
blog.kali.org
bugs.kali.org
cdimage.kali.org
docs.kali.org
forum.kali.org
http.kali.org
...
By mastering these basic command-line parsing techniques, you can efficiently handle large amounts of OSINT data gathered from various public sources.
Summary
In this lab, you successfully performed passive reconnaissance using automated OSINT tools. You started by installing and configuring theHarvester on your Linux environment. You then executed a targeted scan against a domain using public Certificate Transparency logs to discover external subdomains without directly interacting with the target. Finally, you utilized Linux command-line utilities like grep and sort to parse the raw output, filtering out noise and compiling a clean, actionable roster of targets. These foundational skills are essential for the initial information-gathering phase of any cybersecurity assessment.



