Skip to content

Commit

Permalink
Ported to python3 and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maurosoria committed Feb 3, 2015
1 parent 8e9f4b1 commit d13d185
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 107 deletions.
6 changes: 3 additions & 3 deletions lib/connection/__init__.py
Expand Up @@ -17,7 +17,7 @@
# Author: Mauro Soria


from Requester import *
from RequestException import *
from Response import *
from .Requester import *
from .RequestException import *
from .Response import *
pass
2 changes: 1 addition & 1 deletion lib/controller/__init__.py
Expand Up @@ -17,5 +17,5 @@
# Author: Mauro Soria


from Controller import *
from .Controller import *
pass
28 changes: 14 additions & 14 deletions lib/core/ArgumentsParser.py
Expand Up @@ -18,7 +18,7 @@



import ConfigParser
import configparser
from optparse import OptionParser, OptionGroup
from lib.utils.FileUtils import File
from lib.utils.FileUtils import FileUtils
Expand All @@ -37,32 +37,32 @@ def __init__(self, script_path):
if options.urlList != None:
with File(options.urlList) as urlList:
if not urlList.exists():
print "The file with URLs does not exist"
print("The file with URLs does not exist")
exit(0)
if not urlList.isValid():
print 'The wordlist is invalid'
print('The wordlist is invalid')
exit(0)
if not urlList.canRead():
print 'The wordlist cannot be read'
print('The wordlist cannot be read')
exit(0)
self.urlList = list(urlList.getLines())
elif options.url == None:
print 'Url target is missing'
print('Url target is missing')
exit(0)
else:
self.urlList = [options.url]
if options.extensions == None:
print 'No extension specified. You must specify at least one extension'
print('No extension specified. You must specify at least one extension')
exit(0)
with File(options.wordlist) as wordlist:
if not wordlist.exists():
print 'The wordlist file does not exist'
print('The wordlist file does not exist')
exit(0)
if not wordlist.isValid():
print 'The wordlist is invalid'
print('The wordlist is invalid')
exit(0)
if not wordlist.canRead():
print 'The wordlist cannot be read'
print('The wordlist cannot be read')
exit(0)
if options.httpProxy is not None:
if options.httpProxy.startswith('http://'):
Expand All @@ -75,8 +75,8 @@ def __init__(self, script_path):
try:
self.headers = dict((key.strip(), value.strip()) for (key, value) in (header.split(':', 1)
for header in options.headers))
except Exception, e:
print 'Invalid headers'
except Exception as e:
print('Invalid headers')
exit(0)
else:
self.headers = {}
Expand All @@ -85,7 +85,7 @@ def __init__(self, script_path):
self.useragent = options.useragent
self.cookie = options.cookie
if options.threadsCount < 1:
print 'Threads number must be a number greater than zero'
print('Threads number must be a number greater than zero')
exit(0)
self.threadsCount = options.threadsCount
if options.excludeStatusCodes is not None:
Expand Down Expand Up @@ -115,7 +115,7 @@ def __init__(self, script_path):
self.scanSubdirs = list(oset([subdir + "/" for subdir in self.scanSubdirs]))
else: self.scanSubdirs = None
if not self.recursive and options.excludeSubdirs is not None:
print '--exclude-subdir argument can only be used with -r|--recursive'
print('--exclude-subdir argument can only be used with -r|--recursive')
exit(0)
elif options.excludeSubdirs is not None:
self.excludeSubdirs = list(oset([subdir.strip() for subdir in options.excludeSubdirs.split(',')]))
Expand All @@ -138,7 +138,7 @@ def parseConfig(self):
config.read(configPath)

# General
self.threadsCount = config.safe_getint("general", "threads", 10, range(1, 50))
self.threadsCount = config.safe_getint("general", "threads", 10, list(range(1, 50)))
self.excludeStatusCodes = config.safe_get("general", "exclude-status", None)
self.redirect = config.safe_getboolean("general", "follow-redirects", False)
self.recursive = config.safe_getboolean("general", "recursive", False)
Expand Down
8 changes: 4 additions & 4 deletions lib/core/__init__.py
Expand Up @@ -17,8 +17,8 @@
# Author: Mauro Soria


from FuzzerDictionary import *
from Fuzzer import *
from ArgumentsParser import *
from Path import *
from .FuzzerDictionary import *
from .Fuzzer import *
from .ArgumentsParser import *
from .Path import *
pass
2 changes: 1 addition & 1 deletion lib/output/CLIOutput.py
Expand Up @@ -101,7 +101,7 @@ def printStatusReport(self, path, response):
if path in self.checkedPaths:
self.mutexCheckedPaths.release()
return
except (KeyboardInterrupt, SystemExit), e:
except (KeyboardInterrupt, SystemExit) as e:
raise e
finally:
self.mutexCheckedPaths.release()
Expand Down
2 changes: 1 addition & 1 deletion lib/output/__init__.py
@@ -1,3 +1,3 @@
from CLIOutput import *
from .CLIOutput import *

pass
8 changes: 4 additions & 4 deletions lib/reports/__init__.py
Expand Up @@ -17,8 +17,8 @@
# Author: Mauro Soria


from BaseReport import *
from SimpleReport import *
from PlainTextReport import *
from JSONReport import *
from .BaseReport import *
from .SimpleReport import *
from .PlainTextReport import *
from .JSONReport import *
pass
4 changes: 2 additions & 2 deletions lib/test/__init__.py
Expand Up @@ -17,6 +17,6 @@
# Author: Mauro Soria


from ContentTester import *
from StatusTester import *
from .ContentTester import *
from .StatusTester import *
pass
22 changes: 11 additions & 11 deletions lib/utils/DefaultConfigParser.py
Expand Up @@ -17,49 +17,49 @@
# Author: Mauro Soria


import ConfigParser
import configparser

class DefaultConfigParser(ConfigParser.ConfigParser):
class DefaultConfigParser(configparser.ConfigParser):
def __init__(self):
ConfigParser.ConfigParser.__init__(self)
configparser.ConfigParser.__init__(self)


def safe_get(self, section, option, default, allowed=None):
try:
result = ConfigParser.ConfigParser.get(self, section, option)
result = configparser.ConfigParser.get(self, section, option)
if allowed is not None:
return result if result in allowed else default
else:
return result
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
except (configparser.NoSectionError, configparser.NoOptionError):
return default

def safe_getfloat(self, section, option, default, allowed=None):
try:
result = ConfigParser.ConfigParser.getfloat(self, section, option)
result = configparser.ConfigParser.getfloat(self, section, option)
if allowed is not None:
return result if result in allowed else default
else:
return result
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
except (configparser.NoSectionError, configparser.NoOptionError):
return default

def safe_getboolean(self, section, option, default, allowed=None):
try:
result = ConfigParser.ConfigParser.getboolean(self, section, option)
result = configparser.ConfigParser.getboolean(self, section, option)
if allowed is not None:
return result if result in allowed else default
else:
return result
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
except (configparser.NoSectionError, configparser.NoOptionError):
return default

def safe_getint(self, section, option, default, allowed=None):
try:
result = ConfigParser.ConfigParser.getint(self, section, option)
result = configparser.ConfigParser.getint(self, section, option)
if allowed is not None:
return result if result in allowed else default
else:
return result
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
except (configparser.NoSectionError, configparser.NoOptionError):
return default
2 changes: 1 addition & 1 deletion thirdparty/oset/__init__.py
@@ -1,3 +1,3 @@
"""Main Ordered Set module """

from pyoset import oset
from .pyoset import oset
34 changes: 14 additions & 20 deletions thirdparty/oset/_abc.py
Expand Up @@ -3,7 +3,7 @@

"""Partially backported python ABC classes"""

from __future__ import absolute_import


import sys
import types
Expand Down Expand Up @@ -65,7 +65,7 @@ def __new__(mcls, name, bases, namespace):
cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)
# Compute set of abstract method names
abstracts = set(name
for name, value in namespace.items()
for name, value in list(namespace.items())
if getattr(value, "__isabstractmethod__", False))
for base in bases:
for name in getattr(base, "__abstractmethods__", set()):
Expand All @@ -82,7 +82,7 @@ def __new__(mcls, name, bases, namespace):

def register(cls, subclass):
"""Register a virtual subclass of an ABC."""
if not isinstance(subclass, (type, types.ClassType)):
if not isinstance(subclass, type):
raise TypeError("Can only register classes")
if issubclass(subclass, cls):
return # Already a subclass
Expand All @@ -96,12 +96,12 @@ def register(cls, subclass):

def _dump_registry(cls, file=None):
"""Debug helper to print the ABC registry."""
print >> file, "Class: %s.%s" % (cls.__module__, cls.__name__)
print >> file, "Inv.counter: %s" % ABCMeta._abc_invalidation_counter
print("Class: %s.%s" % (cls.__module__, cls.__name__), file=file)
print("Inv.counter: %s" % ABCMeta._abc_invalidation_counter, file=file)
for name in sorted(cls.__dict__.keys()):
if name.startswith("_abc_"):
value = getattr(cls, name)
print >> file, "%s: %r" % (name, value)
print("%s: %r" % (name, value), file=file)

def __instancecheck__(cls, instance):
"""Override for isinstance(instance, cls)."""
Expand Down Expand Up @@ -171,9 +171,7 @@ def _hasattr(C, attr):
return hasattr(C, attr)


class Sized:
__metaclass__ = ABCMeta

class Sized(metaclass=ABCMeta):
@abstractmethod
def __len__(self):
return 0
Expand All @@ -186,9 +184,7 @@ def __subclasshook__(cls, C):
return NotImplemented


class Container:
__metaclass__ = ABCMeta

class Container(metaclass=ABCMeta):
@abstractmethod
def __contains__(self, x):
return False
Expand All @@ -201,9 +197,7 @@ def __subclasshook__(cls, C):
return NotImplemented


class Iterable:
__metaclass__ = ABCMeta

class Iterable(metaclass=ABCMeta):
@abstractmethod
def __iter__(self):
while False:
Expand Down Expand Up @@ -322,7 +316,7 @@ def _hash(self):
freedom for __eq__ or __hash__. We match the algorithm used
by the built-in frozenset type.
"""
MAX = sys.maxint
MAX = sys.maxsize
MASK = 2 * MAX + 1
n = len(self)
h = 1927868237 * (n + 1)
Expand Down Expand Up @@ -364,7 +358,7 @@ def pop(self):
"""Return the popped value. Raise KeyError if empty."""
it = iter(self)
try:
value = it.next()
value = next(it)
except StopIteration:
raise KeyError
self.discard(value)
Expand Down Expand Up @@ -453,7 +447,7 @@ def __reversed__(self):
def pop(self, last=True):
if not self:
raise KeyError('set is empty')
key = reversed(self).next() if last else iter(self).next()
key = next(reversed(self)) if last else next(iter(self))
self.discard(key)
return key

Expand All @@ -471,5 +465,5 @@ def __del__(self):
self.clear() # remove circular references

if __name__ == '__main__':
print(OrderedSet('abracadaba'))
print(OrderedSet('simsalabim'))
print((OrderedSet('abracadaba')))
print((OrderedSet('simsalabim')))
6 changes: 3 additions & 3 deletions thirdparty/oset/pyoset.py
Expand Up @@ -3,7 +3,7 @@

"""Partially backported python ABC classes"""

from __future__ import absolute_import


try:
from collections import MutableSet
Expand All @@ -12,7 +12,7 @@
from ._abc import MutableSet


KEY, PREV, NEXT = range(3)
KEY, PREV, NEXT = list(range(3))


class OrderedSet(MutableSet):
Expand Down Expand Up @@ -62,7 +62,7 @@ def __reversed__(self):
def pop(self, last=True):
if not self:
raise KeyError('set is empty')
key = reversed(self).next() if last else iter(self).next()
key = next(reversed(self)) if last else next(iter(self))
self.discard(key)
return key

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/oset/tests.py
Expand Up @@ -3,7 +3,7 @@

"""Partially backported python ABC classes"""

from __future__ import absolute_import


import doctest
import unittest
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/sqlmap/DynamicContentParser.py
Expand Up @@ -70,7 +70,7 @@ def findDynamicContent(firstPage, secondPage):
blocks.insert(0, None)
blocks.append(None)

for i in xrange(len(blocks) - 1):
for i in range(len(blocks) - 1):
prefix = firstPage[blocks[i][0]:blocks[i][0] + blocks[i][2]] if blocks[i] else None
suffix = firstPage[blocks[i + 1][0]:blocks[i + 1][0] + blocks[i + 1][2]] if blocks[i + 1] else None

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/sqlmap/__init__.py
@@ -1,3 +1,3 @@
from DynamicContentParser import *
from .DynamicContentParser import *

pass
2 changes: 1 addition & 1 deletion thirdparty/urllib3/_collections.py
Expand Up @@ -100,4 +100,4 @@ def clear(self):

def keys(self):
with self.lock:
return self._container.keys()
return list(self._container.keys())

0 comments on commit d13d185

Please sign in to comment.