Skip to content

Commit

Permalink
[REDESIGN] Added file handlers. Prepare for Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav WEB committed Jan 9, 2017
1 parent a69f569 commit 761ccd7
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
logs/
opendoor.egg-info/
/dist/
/phpmailer.py
/syslog/exceptions.log
1 change: 0 additions & 1 deletion data/directories.dat
Original file line number Diff line number Diff line change
Expand Up @@ -18231,7 +18231,6 @@ pfs/
pftpl/
pfx/
pg/
pgadmin
pgadmin.log
pgadmin/
pgdcode/
Expand Down
3 changes: 3 additions & 0 deletions data/proxies.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
http://58.71.17.34:80
http://110.168.108.197:3128
https://213.24.60.52:8080
1 change: 0 additions & 1 deletion data/proxy.dat

This file was deleted.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description-file = README.md
[opendoor]
directories = data/directories.dat
excludes = data/exclusions.dat
proxy = data/proxy.dat
proxies = data/proxies.dat
subdomains = data/subdomains.dat
useragents = data/useragents.dat

Expand Down
18 changes: 16 additions & 2 deletions src/core/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from .exceptions import FileSystemError


class FileSystem:
"""FileSystem class"""

Expand All @@ -22,6 +21,21 @@ def is_exist(dir, filename):
else:
return True

@staticmethod
def readliner(filename, resolver, params, callback):
""" read txt file by line """

file = os.path.join(os.getcwd(), filename)
if not os.path.isfile(file):
raise FileSystemError("{0} is not a file ".format(file))
if not os.access(file, os.R_OK):
raise FileSystemError("Configuration file {0} can not be read. Setup chmod 0644".format(file))

with open(file, "r") as f_handler:
for i, line in enumerate(f_handler):
line = resolver(line, params)
callback(line)

@staticmethod
def read(filename):
""" read txt file """
Expand All @@ -32,7 +46,7 @@ def read(filename):
if not os.access(file, os.R_OK):
raise FileSystemError("Configuration file {0} can not be read. Setup chmod 0644".format(file))

with open(file) as f_handler:
with open(file, "r") as f_handler:
data = f_handler.readlines()
return data

Expand Down
2 changes: 1 addition & 1 deletion src/core/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import sys


class System:
"""System class"""

Expand Down Expand Up @@ -42,3 +41,4 @@ def __clean():

sys.stdout.write('\033[1K')
sys.stdout.write('\033[0G')

40 changes: 26 additions & 14 deletions src/lib/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
from src.lib import tpl
from src.lib.reader import Reader
from .config import Config
class Browser(Config, Reader):
from .debug import Debug
class Browser(Config, Reader, Debug):
"""Browser class"""

def __init__(self, params):

try:
self.debugger = None

Config.__init__(self, params)
Reader.__init__(self)
Debug.__init__(self)


except LibError as e:
Expand All @@ -30,25 +33,34 @@ def ping(self):
socket.ping(self._host, self._port)

tpl.info(key='online', host=self._host, port=self._port, ip=socket.get_ip_address(self._host))
tpl.info(key='scanning', host=self._host)

except SocketError as e:
raise LibError(e)

def scan(self):
def _process_directories(self, line):
""" process with directories list """

self._debug_line(line)
pass

def _process_subdomains(self, line):
""" process with subdomains list """

self._debug_line(line)
pass

def scan(self):
""" scan host with params """

print self._scan
print self._host
print self._port
print self._method
print self._threads
print self._delay
print self._timeout
print self._debug
print self._is_proxy
print self._is_indexof
print self._is_random_user_agent
self._debug_user_agents()
self._debug_proxy()
self._debug_list()

tpl.info(key='scanning', host=self._host)

self._get_list(self._scan,
params={'host' : self._host, 'port' : self._port, 'scheme' : self._scheme},
callback= getattr(self, '_process_{0}'.format(self._scan))
)
pass

7 changes: 4 additions & 3 deletions src/lib/browser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class Config:

def __init__(self, params):
""" read filtered input params """

self._default_scan = 'directories'
self._scan = params.get('scan')
self._scheme = params.get('scheme')
self._host = params.get('host')
self._port = params.get('port')
self._is_indexof = params.get('indexof')
Expand All @@ -17,10 +18,10 @@ def __init__(self, params):
self._delay = 0 if params.get('delay')is None else params.get('delay')
self._timeout = 0 if params.get('timeout')is None else params.get('timeout')
self._threads = params.get('threads')
self._debug = params.get('debug')
self._debug = 0 if params.get('debug')is None else params.get('debug')
self._is_proxy = params.get('tor')
self._is_random_user_agent = params.get('random_agent')
self._user_agent = 'Opendoor OWASP'
self._user_agent = 'Opera/9.0 (Windows NT 5.1; U; en)'



49 changes: 49 additions & 0 deletions src/lib/browser/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""Debug classes """

from src.core import sys
from src.lib import tpl

class Debug:
"""Debug class"""

def __init__(self):
if 0 < self._debug:
tpl.debug(key='debug', level=self._debug)
pass


def _debug_user_agents(self):
if 0 >= self._debug:
pass
else:
if True is self._is_random_user_agent:
tpl.debug(key='random_browser')
else:
tpl.debug(key='browser', browser=self._user_agent)


def _debug_proxy(self):
if 0 >= self._debug:
pass
else:
if True is self._is_proxy:
tpl.debug(key='proxy')

def _debug_list(self):
if 0 >= self._debug:
pass
else:
if self._default_scan is self._scan:
tpl.debug(key='directories')
else :
tpl.debug(key='subdomains')


def _debug_line(self, line):
if 0 >= self._debug:
tpl.line(line)
else:
tpl.info(line)

2 changes: 1 addition & 1 deletion src/lib/package/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def __proxies_count():

try :
config = filesystem.readcfg(Config.params['cfg'])
filename = config.get('opendoor', 'proxy')
filename = config.get('opendoor', 'proxies')
count = filesystem.read(filename).__len__()

return count
Expand Down
3 changes: 2 additions & 1 deletion src/lib/reader/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
class Config:
"""Config class"""

setup = 'setup.cfg'
setup = 'setup.cfg'
port = 80
104 changes: 72 additions & 32 deletions src/lib/reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Reader class"""

from random import randrange
from .config import Config
from src.core import filesystem
from src.core import FileSystemError
Expand All @@ -13,15 +14,10 @@ class Reader():

def __init__(self):

self.config = self.__load_config()
self.__config = self.__load_config()
self.__useragents = []
self.__proxies = []

# try:
# self.config = self.get_config()
# except ConfigParser.ParsingError as e:
# sys.exit(Log.error(e.message))
#
# self.__useragents = self.get_file_data('useragents')
# self.__proxy = self.get_file_data('proxy')
# self.__directories = self.get_file_data('directories')
# self.__subdomains = self.get_file_data('subdomains')

Expand All @@ -36,29 +32,73 @@ def __load_config():
raise LibError(e)


def _get_random_user_agent(self):
""" get random user agent from user-agents list"""

if not len(self.__useragents):
self.__useragents = filesystem.read(self.__config.get('opendoor','useragents'))

# def get_file_data(self, target):
# """ Get target file data"""
#
# file_path = self.config.get('opendoor', target)
# file = os.path.join(os.getcwd(), file_path)
# if not os.path.isfile(file):
# sys.exit(Log.error("{0} is not a file".format(file)))
# if not os.access(file, os.R_OK):
# sys.exit(Log.error("{0} file can not be read. Setup chmod 0644 ".format(file)))
# with open(file) as f_handler:
# data = f_handler.readlines()
# return data
#
# def get_random_user_agent(self):
# """ Get random user agent from user-agents list"""
#
# index = randrange(0, len(self.__useragents))
# return self.__useragents[index].rstrip()
#
# def get_random_proxy(self):
# """ Get random proxy from proxy list"""
#
# index = randrange(0, len(self.__proxy))
# return self.__proxy[index].rstrip()
index = randrange(0, len(self.__useragents))
return self.__useragents[index].strip()

def _get_random_proxy(self):
""" get random proxy from proxy list"""

if not len(self.__proxies):
self.__proxies = filesystem.read(self.__config.get('opendoor', 'proxies'))

index = randrange(0, len(self.__proxies))
return self.__proxies[index].strip()

def _get_list(self, list, params, callback):
""" read list """

dirlist = self.__config.get('opendoor', list)
filesystem.readliner(dirlist, resolver=getattr(self, '_{0}__line'.format(self._scan)),
params=params,
callback=callback)


def _subdomains__line(self, line, params):
""" resolve subdomains line"""

line = line.strip("\n")
line.strip('/')

host = params.get('host')
port = params.get('port')

if 'www.' in host:
host = host.replace("www.", "")

if Config.port is port:
port = ''
else:
port = ':{0}'.format(port)

return "{scheme}{sub}.{host}{port}".format(
scheme=params.get('scheme'),
host=host,
port=port,
sub=line,
)

def _directories__line(self, line, params):
""" resolve directories line """

line = line.strip("\n")
line.lstrip('/')

port = params.get('port')

if Config.port is port:
port = ''
else:
port = ':{0}'.format(port)

return "{scheme}{host}{port}/{uri}".format(
scheme=params.get('scheme'),
host=params.get('host'),
port=port,
uri=line,
)
8 changes: 7 additions & 1 deletion src/lib/tpl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ class Config:
'use_log' : 'Use --log param to store your scan results',
'logged' : 'The {host} has been stored. Press ENTER to rescan or CTRL+C to exit: ',
'online': 'Server {host}:{port} ({ip}) is online!',
'scanning': 'Scanning {host} ...'
'scanning': 'Scanning {host} ...',
'debug': 'Starting debug level {level} ...',
'browser': 'Fetching user-agent: {browser}',
'directories': 'Read directories list by line',
'subdomains': 'Read subdomains list by line',
'random_browser': 'Fetching random user-agent per request...',
'proxy': 'Fetching proxies...'
}

browser = {
Expand Down
Loading

0 comments on commit 761ccd7

Please sign in to comment.