OSINT Automation with Python: Public Data Intelligence

OSINT Open Source Intelligence Reconnaissance Python Security

Open Source Intelligence (OSINT) involves collecting, analyzing, and synthesizing publicly accessible data to assess cybersecurity exposure, perform red team reconnaissance, and identify security risks before adversaries exploit them. Organizations often leak sensitive metadata through document properties, unredacted DNS zone records, and exposed cloud storage buckets.

Automating OSINT workflows with Python enables security analysts to audit public digital footprints at scale. In this practical guide, you will learn how to extract embedded Exif metadata from media files, automate DNS record enumeration, and query WHOIS registries programmatically.


OSINT Reconnaissance Categories and Python Tooling


Prerequisites & Installation

Pillow is used for Exif metadata extraction, and dnspython performs multi-record DNS resolution.

pip install pillow dnspython python-whois requests
Recon CategoryTarget Data PointPython LibraryDefensive Security Objective
Metadata ExtractionGPS coordinates, camera models, creation datesPillow (PIL.ExifTags)Sanitize public media before web publication to prevent geolocation leaks
DNS EnumerationA, MX, TXT, NS, and CNAME recordsdnspython (dns.resolver)Identify unlinked subdomains and dangling DNS takeover risks
Domain OwnershipRegistrar data, creation dates, nameserverspython-whoisDetect domain spoofing, typosquatting, and impersonation campaigns
HTTP Header AuditingServer versions, CSP, HSTS, X-Powered-Byrequests / urllibVerify security headers and prevent software version disclosure

Understanding Exif Metadata and Geolocation Extraction

Exchangeable Image File Format (Exif) metadata is automatically embedded in JPEG and TIFF images captured by smartphones and digital cameras. This metadata often includes precise GPS latitude and longitude coordinates, device serial numbers, and timestamps.

If employees upload event photos or facility images without stripping Exif headers, attackers can pinpoint exact physical office locations and device models.


Automating Image Exif Extraction and DNS Audit in Python

from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
import dns.resolver

# 1. Image Exif Metadata Extractor
def analyze_image_metadata(image_path: str):
    print(f"Auditing image metadata for: {image_path}...")
    try:
        image = Image.open(image_path)
        exif_raw = image._getexif()
        if not exif_raw:
            print("No Exif metadata found (image is clean).")
            return
            
        for tag_id, value in exif_raw.items():
            tag_name = TAGS.get(tag_id, tag_id)
            print(f"- {tag_name:25s}: {value}")
    except Exception as e:
        print(f"Error reading image metadata: {e}")

# 2. Automated DNS Reconnaissance
def query_dns_records(domain: str):
    print(f"\nQuerying DNS records for: {domain}...")
    record_types = ["A", "MX", "TXT", "NS"]
    
    for rtype in record_types:
        try:
            answers = dns.resolver.resolve(domain, rtype)
            print(f"[{rtype} Records]")
            for rdata in answers:
                print(f"  -> {rdata.to_text()}")
        except Exception:
            print(f"[{rtype} Records] None found or query timed out.")

if __name__ == "__main__":
    query_dns_records("ilabacademy.blogspot.com")

Defensive Countermeasures & Operational Security (OPSEC)

  • Automated Exif Stripping: Implement automated image processing pipelines using ImageMagick or Pillow to strip all Exif metadata before uploading assets to public cloud storage.
  • DNS Zone Transfer Restrictions: Configure authoritative DNS nameservers to disallow AXFR zone transfers to unauthenticated external IP addresses.
  • WHOIS Privacy Protection: Enable domain privacy guards to prevent administrative email addresses and phone numbers from being indexed in public registrars.

Frequently Asked Questions

Q: Is OSINT gathering legal?
A: Yes. OSINT focuses entirely on collecting publicly available information without exploiting systems or bypassing authentication boundaries.

Q: How do I sanitize images in Python?
A: You can strip metadata by opening the image with Pillow, creating a clean new image object, and saving it without the exif parameter.

Post a Comment

0 Comments