Track Your Pixel: Stealthy Visitor Logging

Turning Invisible Pixels into Insightful Data

My script to track pixels

This Python script automates the setup of an Apache web server with PHP support. It installs necessary packages, configures a PHP script to log visitor IP addresses and serve an image, sets up URL redirection using `.htaccess`, manages log file creation and permissions, downloads a specific image to be served, updates Apache configuration, and restarts the Apache service.

  • 1

    Download my script

                
    apt update
    apt install nano kitty sudo wget git curl zsh
     
            
    wget https://github.com/4rji/bina/blob/10aeecc7198150b474379acf1a1efd235b5a58f8/binarios/pixeltrack
            
    python3 pixeltrack
    
    #working...
    Reiniciando Apache...
    Instalación y configuración completadas.
    sudo tail -f /var/log/image_access.log 
            
  • 2

    And now check the logs and visite the website IP/sss.png

                
    sudo tail -f /var/log/image_access.log
    IP: 123.29.107.163 - Date/Time: 2024-08-01 04:35:00
    IP: 186.70.11.113 - Date/Time: 2024-08-01 04:43:19 
            
    
            
    
            
  • 3

    Thats it. Simple.

    Code Example with Copy Functionality



    #!/usr/bin/python3
    import subprocess
    
    def install_packages():
        print("Instalando paquetes...")
        subprocess.run('sudo apt update', shell=True)
        subprocess.run('sudo apt install -y apache2 php libapache2-mod-php', shell=True)
        subprocess.run('sudo a2enmod rewrite', shell=True)
    
    def setup_php_script():
        print("Configurando save_ip.php...")
        php_content = """
    
    """
        subprocess.run(['sudo', 'tee', '/var/www/html/save_ip.php'], input=php_content.encode(), check=True)
        subprocess.run('sudo chown www-data:www-data /var/www/html/save_ip.php', shell=True)
        subprocess.run('sudo chmod 644 /var/www/html/save_ip.php', shell=True)
    
    def setup_htaccess():
        print("Configurando .htaccess...")
        htaccess_content = """
    RewriteEngine On
    # Redirige las solicitudes a sss.png al script PHP
    RewriteRule ^sss\\.png$ /save_ip.php [L]
    """
        subprocess.run(['sudo', 'tee', '/var/www/html/.htaccess'], input=htaccess_content.encode(), check=True)
        subprocess.run('sudo chmod 644 /var/www/html/.htaccess', shell=True)
    
    def setup_logs_and_permissions():
        print("Configurando logs y permisos...")
        subprocess.run('sudo touch /var/log/image_access.log', shell=True)
        subprocess.run('sudo chown www-data:www-data /var/log/image_access.log', shell=True)
        subprocess.run('sudo chmod 640 /var/log/image_access.log', shell=True)
    
    def download_and_setup_image():
        print("Descargando y configurando imagen...")
        image_url = "https://github.com/4rji/archivos-b/raw/c5cbc289fd6a8a9e5be86f11c62308ea17bea62d/pixel_blanco_invisible.png"
        image_path = '/var/www/html/sss.png'
        result = subprocess.run(f'sudo wget {image_url} -O {image_path}', shell=True)
        if result.returncode == 0:
            print(f'Imagen descargada correctamente: {image_path}')
            # Verificar permisos actuales
            subprocess.run(['ls', '-l', image_path], shell=True)
            # Cambiar propietario y permisos
            subprocess.run(f'sudo chown www-data:www-data {image_path}', shell=True)
            subprocess.run(f'sudo chmod 644 {image_path}', shell=True)
            # Verificar permisos después de cambios
            subprocess.run(['ls', '-l', image_path], shell=True)
        else:
            print(f'Error al descargar la imagen: {image_path}')
    
    def update_apache_config():
        print("Actualizando configuración de Apache...")
        config_block = """
    
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    
    """
        subprocess.run(['sudo', 'bash', '-c', f'echo "{config_block}" >> /etc/apache2/apache2.conf'], check=True)
    
    def restart_apache():
        print("Reiniciando Apache...")
        subprocess.run('sudo systemctl restart apache2', shell=True)
    
    def main():
        install_packages()
        setup_php_script()
        setup_htaccess()
        setup_logs_and_permissions()
        download_and_setup_image()
        update_apache_config()
        restart_apache()
        print("Instalación y configuración completadas.")
    
    if __name__ == "__main__":
        main()
    
    print("sudo tail -f /var/log/image_access.log")
  • Download