Modify subdomain sorting
This commit is contained in:
parent
5e2f5bb9d9
commit
09a2b9cdaf
45
sublist3r.py
45
sublist3r.py
|
@ -17,6 +17,7 @@ import multiprocessing
|
||||||
import threading
|
import threading
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
import socket
|
import socket
|
||||||
|
import functools
|
||||||
from subbrute import subbrute
|
from subbrute import subbrute
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
|
@ -78,6 +79,45 @@ def write_file(filename, subdomains):
|
||||||
for subdomain in subdomains:
|
for subdomain in subdomains:
|
||||||
f.write(subdomain+"\r\n")
|
f.write(subdomain+"\r\n")
|
||||||
|
|
||||||
|
def subdomain_cmp(d1, d2):
|
||||||
|
"""cmp function for subdomains d1 and d2.
|
||||||
|
|
||||||
|
This cmp function orders subdomains from the top-level domain at the right
|
||||||
|
reading left, then moving '^' and 'www' to the top of their group. For
|
||||||
|
example, the following list is sorted correctly:
|
||||||
|
|
||||||
|
[
|
||||||
|
'example.com',
|
||||||
|
'www.example.com',
|
||||||
|
'a.example.com',
|
||||||
|
'www.a.example.com',
|
||||||
|
'b.a.example.com',
|
||||||
|
'b.example.com',
|
||||||
|
'example.net',
|
||||||
|
'www.example.net',
|
||||||
|
'a.example.net',
|
||||||
|
]
|
||||||
|
|
||||||
|
"""
|
||||||
|
d1 = d1.split('.')[::-1]
|
||||||
|
d2 = d2.split('.')[::-1]
|
||||||
|
|
||||||
|
val = 1 if d1>d2 else (-1 if d1<d2 else 0)
|
||||||
|
if ((len(d1) < len(d2)) and
|
||||||
|
(d1[-1] == 'www') and
|
||||||
|
(d1[:-1] == d2[:len(d1)-1])):
|
||||||
|
val = -1
|
||||||
|
elif ((len(d1) > len(d2)) and
|
||||||
|
(d2[-1] == 'www') and
|
||||||
|
(d1[:len(d2)-1] == d2[:-1])):
|
||||||
|
val = 1
|
||||||
|
elif d1[:-1] == d2[:-1]:
|
||||||
|
if d1[-1] == 'www':
|
||||||
|
val = -1
|
||||||
|
elif d2[-1] == 'www':
|
||||||
|
val = 1
|
||||||
|
return val
|
||||||
|
|
||||||
class enumratorBase(object):
|
class enumratorBase(object):
|
||||||
def __init__(self, base_url, engine_name, domain, subdomains=None):
|
def __init__(self, base_url, engine_name, domain, subdomains=None):
|
||||||
subdomains = subdomains or []
|
subdomains = subdomains or []
|
||||||
|
@ -1033,7 +1073,10 @@ def main():
|
||||||
subdomains = search_list.union(bruteforce_list)
|
subdomains = search_list.union(bruteforce_list)
|
||||||
|
|
||||||
if subdomains:
|
if subdomains:
|
||||||
subdomains = sorted(subdomains)
|
subdomains = sorted(
|
||||||
|
subdomains,
|
||||||
|
key=functools.cmp_to_key(subdomain_cmp),
|
||||||
|
)
|
||||||
if savefile:
|
if savefile:
|
||||||
write_file(savefile, subdomains)
|
write_file(savefile, subdomains)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue