#!/usr/bin/env python # Author: St0rn (anbu-pentest.com) # # Use scapy # Usage: as_discover.py target port # # Autonomous System discovering (from yours to your target) by TCP Traceroute # from scapy.all import * import sys import os import socket import commands ips_list = list() asn = list() as_name = list() def tcp_traceroute(target, port): fail = 0 ttl = 1 while True: ans, unans = sr(IP(dst=target, ttl=ttl)/TCP(dport=int(port), flags="S"), timeout=2, verbose=0) if not ans: print "["+str(ttl)+"] "+"* * * * *" ips_list.append("filtred") ttl+=1 fail+=1 if fail == 10: break else: temp = ans[0] if temp[1].src == socket.gethostbyname(target): getname = commands.getoutput(str("host " + temp[1].src + " | cut -d' ' -f5")) print "["+str(ttl)+"] "+str(temp[1].src)+" ("+str(getname[0:(len(getname)-1)])+")" ips_list.append(temp[1].src) break else: getname = commands.getoutput(str("host " + temp[1].src + " | cut -d' ' -f5")) print "["+str(ttl)+"] "+str(temp[1].src)+" ("+str(getname[0:(len(getname)-1)])+")" ips_list.append(temp[1].src) ttl+=1 print "\nFinish with "+str(ttl)+" hop\n" def get_asn(ips): for ip in ips_list: if ip != "filtred": as_infos = scapy.as_resolvers.AS_resolver_multi().resolve(ip) asn.append(as_infos[0][1]) as_name.append(as_infos[0][2]) for info in asn: nb = asn.index(info) if "AS" in str(info): print str(info)+" ["+as_name[nb]+"]" else: print "AS"+str(info)+" ["+as_name[nb]+"]" os.system("cls" if os.name == "nt" else "clear") print "TCP Traceroute to %s\n" %(sys.argv[1]) tcp_traceroute(sys.argv[1],sys.argv[2]) print "AS Route to %s\n" %(sys.argv[1]) get_asn(ips_list)
St0rn