def main(dst, dst_port, sport, bandwidth="%d" % (1024 * 1024), ttl=20):
    iface, src, _ = networking.get_route(dst)
    dst_port = int(dst_port)
    bandwidth = bandwidth.lower()
    if bandwidth.endswith("m"): bandwidth = float(bandwidth[ : -1]) * 1024 * 1024
    elif bandwidth.endswith("k"): bandwidth = float(bandwidth[ : -1]) * 1024
    elif bandwidth.endswith("b"): bandwidth = float(bandwidth[ : -1])
    else: bandwidth = float(bandwidth)

    if ROOT_USER_ID == os.geteuid():
        sniffer = networking.create_sniffer(iface, src, dst)
        probe = UdpPacketDropProbe(src, int(sport), dst, dst_port, int(ttl), sniffer, bandwidth=bandwidth)
        sniffer.start_sniffing()
        probe.poke()
        time.sleep(2)
        sniffer.stop_sniffing()
        report = probe.peek()
    else:
        probe = UdpPacketDropProbe(src, int(sport), dst, dst_port, int(ttl), sniffer=None, bandwidth=bandwidth)
        probe.poke()
        time.sleep(2)
        report = probe.peek()
    packets = report.pop('PACKETS')
    # print(report)

    router_hit = defaultdict(int)
    for pkt_id, router_ip in report["ROUTER_IP"].items():
        router_hit[router_ip] += 1
    return router_hit
Esempio n. 2
0
def main(dst, sport, ttl):
    iface, src, _ = networking.get_route(dst)
    if ROOT_USER_ID == os.geteuid():
        sniffer = networking.create_sniffer(iface, src, dst)
        probe = TcpPacketDropProbe(src, int(sport), dst, 80, int(ttl), sniffer)
        sniffer.start_sniffing()
        probe.poke()
        time.sleep(2)
        sniffer.stop_sniffing()
        report = probe.peek()
    else:
        probe = TcpPacketDropProbe(src,
                                   int(sport),
                                   dst,
                                   80,
                                   int(ttl),
                                   sniffer=None)
        probe.poke()
        time.sleep(2)
        report = probe.peek()
    packets = report.pop('PACKETS')
    print(report)
    for mark, packet in packets:
        formatted_packet = packet.sprintf(
            '%.time% %IP.src% -> %IP.dst% %TCP.flags%')
        print('[%s] %s' % (mark, formatted_packet))
Esempio n. 3
0
def main(dst, ttl, probe_type_code='HTTP', waits_for_syn_ack=False):
    probe_types = list_probe_types()
    probe_type = probe_types[probe_type_code]
    iface, src, _ = networking.get_route(dst)
    dport = probe_type.get_default_dport()
    if ROOT_USER_ID == os.geteuid():
        sniffer = networking.create_sniffer(iface, src, dst)
        probe = probe_type(
            src, SPORT, dst, dport, int(ttl), sniffer,
            waits_for_syn_ack=waits_for_syn_ack)
        sniffer.start_sniffing()
        probe.poke()
        time.sleep(2)
        sniffer.stop_sniffing()
        report = probe.peek()
    else:
        probe = probe_type(src, SPORT, dst, dport, int(ttl), sniffer=None)
        probe.poke()
        time.sleep(2)
        report = probe.peek()
    packets = report.pop('PACKETS')
    print(report)
    for mark, packet in packets:
        formatted_packet = packet.sprintf('%.time% %IP.src% -> %IP.dst% %TCP.flags%')
        print('[%s] %s' % (mark, formatted_packet))
Esempio n. 4
0
def main(dst, ttl):
    iface, src, _ = networking.get_route(dst)
    if ROOT_USER_ID == os.geteuid():
        sniffer = networking.create_sniffer(iface, src, dst)
        probe = DnsWrongAnswerProbe(src, SPORT, dst, DPORT, int(ttl), sniffer)
        sniffer.start_sniffing()
        probe.poke()
        time.sleep(2)
        sniffer.stop_sniffing()
        report = probe.peek()
    else:
        probe = DnsWrongAnswerProbe(src, SPORT, dst, DPORT, int(ttl), sniffer=None)
        probe.poke()
        time.sleep(2)
        report = probe.peek()
        report.pop('ROUTER_IP')
    report.pop('PACKETS')
    print(report)
Esempio n. 5
0
def main(dst, sport, ttl):
    iface, src, _ = networking.get_route(dst)
    if ROOT_USER_ID == os.geteuid():
        sniffer = networking.create_sniffer(iface, src, dst)
        probe = TcpPacketDropProbe(src, int(sport), dst, 80, int(ttl), sniffer)
        sniffer.start_sniffing()
        probe.poke()
        time.sleep(2)
        sniffer.stop_sniffing()
        report = probe.peek()
    else:
        probe = TcpPacketDropProbe(src, int(sport), dst, 80, int(ttl), sniffer=None)
        probe.poke()
        time.sleep(2)
        report = probe.peek()
    packets = report.pop('PACKETS')
    print(report)
    for mark, packet in packets:
        formatted_packet = packet.sprintf('%.time% %IP.src% -> %IP.dst% %TCP.flags%')
        print('[%s] %s' % (mark, formatted_packet))