v0.5
This commit is contained in:
223
lib/request.py
223
lib/request.py
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#-------------------------------------------------------------------------------
|
||||
# Typo3 Enumerator - Automatic Typo3 Enumeration Tool
|
||||
# Copyright (c) 2014-2017 Jan Rude
|
||||
# Copyright (c) 2014-2020 Jan Rude
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -15,127 +15,120 @@
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/)
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
import re
|
||||
import os.path
|
||||
import json
|
||||
import requests
|
||||
from colorama import Fore
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
from colorama import Fore
|
||||
from lib.output import Output
|
||||
|
||||
class Request:
|
||||
"""
|
||||
This class is used to make all server requests
|
||||
"""
|
||||
@staticmethod
|
||||
def get_request(domain_name, path):
|
||||
"""
|
||||
All GET requests are done in this method.
|
||||
This method is not used, when searching for extensions and their Readmes/ChangeLogs
|
||||
There are three error types which can occur:
|
||||
Connection timeout
|
||||
Connection error
|
||||
anything else
|
||||
"""
|
||||
try:
|
||||
config = json.load(open('lib/config.json'))
|
||||
cookie = {config['cookie'].split('=')[0]:config['cookie'].split('=')[1]}
|
||||
r = requests.get(domain_name + path, timeout=config['timeout'], headers={'User-Agent' : config['agent']}, cookies=cookie, auth=(config['user'], config['pass']), verify=False)
|
||||
httpResponse = str((r.text).encode('utf-8'))
|
||||
headers = r.headers
|
||||
cookies = r.cookies
|
||||
status_code = r.status_code
|
||||
response = [httpResponse, headers, cookies, status_code]
|
||||
return response
|
||||
except requests.exceptions.Timeout:
|
||||
print(e)
|
||||
print(Fore.RED + '[x] Connection timed out' + Fore.RESET)
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print(e)
|
||||
print(Fore.RED + '[x] Connection error\n | Please make sure you provided the right URL' + Fore.RESET)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(Fore.RED + str(e) + Fore.RESET)
|
||||
def get_request(url):
|
||||
"""
|
||||
All GET requests are done in this method.
|
||||
This method is not used, when searching for extensions and their Readmes/ChangeLogs
|
||||
There are three error types which can occur:
|
||||
Connection timeout
|
||||
Connection error
|
||||
anything else
|
||||
"""
|
||||
config = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')))
|
||||
timeout = config['timeout']
|
||||
auth = config['auth']
|
||||
cookie = config['cookie']
|
||||
custom_headers = {'User-Agent' : config['User-Agent']}
|
||||
try:
|
||||
if cookie != '':
|
||||
name = cookie.split('=')[0]
|
||||
value = cookie.split('=')[1]
|
||||
custom_headers[name] = value
|
||||
response = {}
|
||||
if auth != '':
|
||||
r = requests.get(url, timeout=config['timeout'], headers=custom_headers, auth=(auth.split(':')[0], auth.split(':')[1]), verify=False)
|
||||
else:
|
||||
r = requests.get(url, timeout=config['timeout'], headers=custom_headers, verify=False)
|
||||
response['status_code'] = r.status_code
|
||||
response['html'] = r.text
|
||||
response['headers'] = r.headers
|
||||
response['cookies'] = r.cookies
|
||||
return response
|
||||
except requests.exceptions.Timeout:
|
||||
print(e)
|
||||
print(Fore.RED + '[x] Connection timed out' + Fore.RESET)
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print(e)
|
||||
print(Fore.RED + '[x] Connection error\n | Please make sure you provided the right URL' + Fore.RESET)
|
||||
exit(-1)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(Fore.RED + str(e) + Fore.RESET)
|
||||
|
||||
@staticmethod
|
||||
def head_request(domain_name, path):
|
||||
"""
|
||||
All HEAD requests are done in this method.
|
||||
HEAD requests are used when searching for extensions and their Readmes/ChangeLogs
|
||||
There are three error types which can occur:
|
||||
Connection timeout
|
||||
Connection error
|
||||
anything else
|
||||
"""
|
||||
try:
|
||||
config = json.load(open('lib/config.json'))
|
||||
r = requests.head(domain_name + path, timeout=config['timeout'], headers={'User-Agent' : config['agent']}, auth=(config['user'], config['pass']), allow_redirects=False, verify=False)
|
||||
status_code = str(r.status_code)
|
||||
if status_code == '405':
|
||||
print("WARNING, (HEAD) method not allowed!!")
|
||||
exit(-1)
|
||||
return status_code
|
||||
except requests.exceptions.Timeout:
|
||||
print(Fore.RED + '[x] Connection timed out' + Fore.RESET)
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print(Fore.RED + '[x] Connection aborted.\n Please make sure you provided the right URL' + Fore.RESET)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(Fore.RED + str(e) + Fore.RESET)
|
||||
def head_request(url):
|
||||
"""
|
||||
All HEAD requests are done in this method.
|
||||
HEAD requests are used when searching for extensions and their Readmes/ChangeLogs
|
||||
There are three error types which can occur:
|
||||
Connection timeout
|
||||
Connection error
|
||||
anything else
|
||||
"""
|
||||
|
||||
config = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')))
|
||||
timeout = config['timeout']
|
||||
auth = config['auth']
|
||||
cookie = config['cookie']
|
||||
custom_headers = {'User-Agent' : config['User-Agent']}
|
||||
try:
|
||||
if cookie != '':
|
||||
name = cookie.split('=')[0]
|
||||
value = cookie.split('=')[1]
|
||||
custom_headers[name] = value
|
||||
if auth != '':
|
||||
r = requests.head(url, timeout=config['timeout'], headers=custom_headers, auth=(auth.split(':')[0], auth.split(':')[1]), verify=False)
|
||||
else:
|
||||
r = requests.head(url, timeout=config['timeout'], headers=custom_headers, allow_redirects=False, verify=False)
|
||||
status_code = str(r.status_code)
|
||||
if status_code == '405':
|
||||
print('[x] WARNING: \'HEAD\' method not allowed!')
|
||||
exit(-1)
|
||||
return status_code
|
||||
except requests.exceptions.Timeout:
|
||||
print(Fore.RED + '[x] Connection timed out' + Fore.RESET)
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print(Fore.RED + '[x] Connection aborted.\n Please make sure you provided the right URL' + Fore.RESET)
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(Fore.RED + str(e) + Fore.RESET)
|
||||
|
||||
@staticmethod
|
||||
def interesting_headers(headers, cookies):
|
||||
"""
|
||||
This method searches for interesing headers in the HTTP response.
|
||||
Server: Displays the name of the server
|
||||
X-Powered-By: Information about Frameworks (e.g. ASP, PHP, JBoss) used by the web application
|
||||
X-*: Version information in other technologies
|
||||
Via: Informs the client of proxies through which the response was sent.
|
||||
be_typo_user: Backend cookie for TYPO3
|
||||
fe_typo_user: Frontend cookie for TYPO3
|
||||
"""
|
||||
found_headers = {}
|
||||
for header in headers:
|
||||
if header == 'server':
|
||||
found_headers['Server'] = headers.get('server')
|
||||
elif header == 'x-powered-by':
|
||||
found_headers['X-Powered-By'] = headers.get('x-powered-by')
|
||||
elif header == 'x-runtime':
|
||||
found_headers['X-Runtime'] = headers.get('x-runtime')
|
||||
elif header == 'x-version':
|
||||
found_headers['X-Version'] = headers.get('x-version')
|
||||
elif header == 'x-aspnet-version':
|
||||
found_headers['X-AspNet-Version'] = headers.get('x-aspnet-version')
|
||||
elif header == 'via':
|
||||
found_headers['Via'] = headers.get('via')
|
||||
try:
|
||||
typo_cookie = cookies['be_typo_user']
|
||||
found_headers['be_typo_user'] = typo_cookie
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
typo_cookie = cookies['fe_typo_user']
|
||||
found_headers['fe_typo_user'] = typo_cookie
|
||||
except:
|
||||
pass
|
||||
return found_headers
|
||||
|
||||
@staticmethod
|
||||
def version_information(domain_name, path, regex):
|
||||
"""
|
||||
This method is used for version search only.
|
||||
It performs a GET request, if the response is 200 - Found, it reads the first 400 bytes the response only,
|
||||
because usually the TYPO3 version is in the first few lines of the response.
|
||||
"""
|
||||
config = json.load(open('lib/config.json'))
|
||||
r = requests.get(domain_name + path, stream=True, timeout=config['timeout'], headers={'User-Agent' : config['agent']}, auth=(config['user'], config['pass']), verify=False)
|
||||
if r.status_code == 200:
|
||||
try:
|
||||
for content in r.iter_content(chunk_size=400, decode_unicode=False):
|
||||
regex = re.compile(regex)
|
||||
search = regex.search(str(content))
|
||||
version = search.groups()[0]
|
||||
return version
|
||||
except:
|
||||
return None
|
||||
def version_information(url, regex):
|
||||
"""
|
||||
This method is used for version search only.
|
||||
It performs a GET request, if the response is 200 - Found, it reads the first 400 bytes the response only,
|
||||
because usually the TYPO3 version is in the first few lines of the response.
|
||||
"""
|
||||
if regex is None:
|
||||
regex = '([0-9]+\.[0-9]+\.[0-9x][0-9x]?)'
|
||||
config = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')))
|
||||
timeout = config['timeout']
|
||||
auth = config['auth']
|
||||
cookie = config['cookie']
|
||||
custom_headers = {'User-Agent' : config['User-Agent']}
|
||||
if cookie != '':
|
||||
name = cookie.split('=')[0]
|
||||
value = cookie.split('=')[1]
|
||||
custom_headers[name] = value
|
||||
if auth != '':
|
||||
r = requests.get(url, stream=True, timeout=config['timeout'], headers=custom_headers, auth=(auth.split(':')[0], auth.split(':')[1]), verify=False)
|
||||
else:
|
||||
r = requests.get(url, stream=True, timeout=config['timeout'], headers=custom_headers, verify=False)
|
||||
if r.status_code == 200:
|
||||
try:
|
||||
for content in r.iter_content(chunk_size=400, decode_unicode=False):
|
||||
search = re.search(regex, str(content))
|
||||
version = search.group(1)
|
||||
r.close()
|
||||
return version
|
||||
except:
|
||||
r.close()
|
||||
return None
|
||||
Reference in New Issue
Block a user