Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.pyc
build/
dist/
Sublist3r.egg-info/
2 changes: 1 addition & 1 deletion subbrute/subbrute.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def extract_hosts(data, hostname):

#Return a list of unique sub domains, sorted by frequency.
#Only match domains that have 3 or more sections subdomain.domain.tld
domain_match = re.compile("([a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*)+")
domain_match = re.compile(r"([a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*)+")
def extract_subdomains(file_name):
#Avoid re-compilation
global domain_match
Expand Down
34 changes: 26 additions & 8 deletions sublist3r.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def no_color():


def banner():
print("""%s
print(r"""%s
____ _ _ _ _ _____
/ ___| _ _| |__ | (_)___| |_|___ / _ __
\___ \| | | | '_ \| | / __| __| |_ \| '__|
Expand Down Expand Up @@ -283,7 +283,7 @@ def __init__(self, domain, subdomains=None, q=None, silent=False, verbose=True):

def extract_domains(self, resp):
links_list = list()
link_regx = re.compile('<cite.*?>(.*?)<\/cite>')
link_regx = re.compile('<cite.*?>(.*?)</cite>')
try:
links_list = link_regx.findall(resp)
for link in links_list:
Expand Down Expand Up @@ -340,7 +340,7 @@ def extract_domains(self, resp):
links2 = link_regx2.findall(resp)
links_list = links + links2
for link in links_list:
link = re.sub("<(\/)?b>", "", link)
link = re.sub("<(/)?b>", "", link)
if not link.startswith('http'):
link = "http://" + link
subdomain = urlparse.urlparse(link).netloc
Expand Down Expand Up @@ -436,7 +436,7 @@ def extract_domains(self, resp):
links_list = links + links2

for link in links_list:
link = re.sub('<(\/)?strong>|<span.*?>|<|>', '', link)
link = re.sub('<(/)?strong>|<span.*?>|<|>', '', link)
if not link.startswith('http'):
link = "http://" + link
subdomain = urlparse.urlparse(link).netloc
Expand Down Expand Up @@ -638,13 +638,31 @@ def req(self, req_method, url, params=None):

def get_csrftoken(self, resp):
csrf_regex = re.compile('<input type="hidden" name="csrfmiddlewaretoken" value="(.*?)">', re.S)
token = csrf_regex.findall(resp)[0]
return token.strip()
try:
token = csrf_regex.findall(resp)[0]
return token.strip()
except (IndexError, TypeError):
# Try alternative CSRF token patterns
alt_csrf_regex = re.compile('<input[^>]*name=["\']csrfmiddlewaretoken["\'][^>]*value=["\'](.*?)["\']', re.S)
try:
token = alt_csrf_regex.findall(resp)[0]
return token.strip()
except (IndexError, TypeError):
if self.verbose:
self.print_("%s%s: Could not extract CSRF token" % (R, self.engine_name))
return ""

def enumerate(self):
self.lock = threading.BoundedSemaphore(value=70)
resp = self.req('GET', self.base_url)
token = self.get_csrftoken(resp)

# If no token found, skip DNSdumpster enumeration
if not token:
if self.verbose:
self.print_("%s%s: Skipping enumeration due to missing CSRF token" % (R, self.engine_name))
return self.live_subdomains

params = {'csrfmiddlewaretoken': token, 'targetip': self.domain}
post_resp = self.req('POST', self.base_url, params)
self.extract_domains(post_resp)
Expand All @@ -655,7 +673,7 @@ def enumerate(self):
return self.live_subdomains

def extract_domains(self, resp):
tbl_regex = re.compile('<a name="hostanchor"><\/a>Host Records.*?<table.*?>(.*?)</table>', re.S)
tbl_regex = re.compile('<a name="hostanchor"></a>Host Records.*?<table.*?>(.*?)</table>', re.S)
link_regex = re.compile('<td class="col-md-4">(.*?)<br>', re.S)
links = []
try:
Expand Down Expand Up @@ -895,7 +913,7 @@ def main(domain, threads, savefile, ports, silent, verbose, enable_bruteforce, e
enable_bruteforce = True

# Validate domain
domain_check = re.compile("^(http|https)?[a-zA-Z0-9]+([\-\.]{1}[a-zA-Z0-9]+)*\.[a-zA-Z]{2,}$")
domain_check = re.compile(r"^(http|https)?[a-zA-Z0-9]+([-\.]{1}[a-zA-Z0-9]+)*\.[a-zA-Z]{2,}$")
if not domain_check.match(domain):
if not silent:
print(R + "Error: Please enter a valid domain" + W)
Expand Down