def cname(c_url):
    t = Terminal()
    try:
        result = dns.resolver.query(c_url, 'CNAME')
        for cnameval in result:
            return ' cname of ' + c_url + ' address:', cnameval.target
    except Exception as error2:
        print("---------------------------------------------------")
        print(t.bold_bright_red("[+] " + str(error2)))
        print("---------------------------------------------------")
Exemplo n.º 2
0
class testGroup(object):
    """TestGroup, group a number of testUnit, exec them and print the results"""
    def __init__(self,
                 name="",
                 terminal=None,
                 prefix="",
                 verbose=False,
                 align=0):
        self._tests = []
        self.name = name
        self.t = terminal
        self.prefix = prefix
        (self.t)
        if self.t == None:
            self.t = Terminal()
        self.results = []
        self.status_modules = {
            "success": 0,
            "total": 0,
            "warning": 0,
            "critical": 0,
            "failure": 0
        }
        self.success_text = self.t.green("success")
        self.failure_text = self.t.bright_red("failure")
        self.warning_text = self.t.bright_yellow("warning")
        self.critical_text = self.t.white_on_red("critical")
        self.verbose = verbose
        self.align = align

    def addTest(self, testUnit):
        self._tests.append(testUnit)
        return self

    def test(self):
        "Execute all tests, some options might exist at some point"
        module_success, module_total = 0, 0

        print(self.prefix + "+ Executing test group " +
              self.pretty_group(self.name))
        oldprefix = self.prefix
        self.prefix += "|  "
        self.results = []

        for test in self._tests:
            try:
                list_status, total, log_results = self.print_result(
                    test.test())
            except Exception as e:
                print(
                    self.t.bright_red(
                        "[ERROR] An unhandled error occured during the execution of the tests"
                    ))
                raise (e)
                # for l in e:
                #     print(l)
                list_status, total, log_results = self.print_result([])

            print(self.pretty_subtests(test.name, list_status, total))

            if list_status["success"] + list_status["warning"] == total:
                self.status_modules["success"] += 1
            self.status_modules["total"] += 1
            for log in log_results:
                print(log)
            self.results.append([self, SUCCESS_STATUS, ""])
        self.prefix = oldprefix

        print(
            self.pretty_group_result(self.status_modules,
                                     self.status_modules["total"]))
        return self.results

    def get_status(self):
        "Get the status of every module, if no test was run, should return an empty dict"
        return self.status_modules

    def print_result(self, table):
        "Get the array of success/failures and print according to the options (still none yet)"
        total = len(table)
        success = 0
        results_array = []
        nb = 0
        list_status = {"success": 0, "failure": 0, "warning": 0, "critical": 0}
        for item, status, infos in table:
            nb += 1
            if status == SUCCESS_STATUS:
                list_status["success"] += 1
            elif status == WARNING_STATUS:
                list_status["warning"] += 1
            elif status == CRITICAL_STATUS:
                list_status["critical"] += 1
            else:
                list_status["failure"] += 1
            if self.verbose or status != SUCCESS_STATUS:
                results_array.append(
                    self.pretty_result(status, nb, item, infos))
        return list_status, total, results_array

    def pretty_group_result(self, module_status, total):
        "Prettyfying the result of the batch of tests"
        bloc = self.prefix + "+ Done "
        return bloc + self.pretty_group(self.name) + self.pretty_dots(
            bloc, len(self.name)) + self.pretty_successrate(
                module_status, total)

    def pretty_name(self, item):
        "Just a pretty way of showing the name of a test"
        try:
            return item.__name__.strip("<>")
        except:
            return str(item)

    def pretty_subtests(self, name, success, total):
        "Pretty way of showing the result of the group of tests"
        bloc = self.prefix + "testing " + self.pretty_test(name)
        return bloc + self.pretty_dots(bloc) + self.pretty_successrate(
            success, total)

    def pretty_result(self, status, nb, item, infos):
        "Just a pretty way of showing the result of one test"
        bloc = self.prefix + " * " + " [" + str(nb) + "] " + self.pretty_name(
            item)
        if status == CRITICAL_STATUS:
            pbloc = self.prefix + " * " + " [" + str(
                nb) + "] " + self.t.bold_bright_red(self.pretty_name(item))
        else:
            pbloc = bloc
        return pbloc + self.pretty_dots(bloc) + self.pretty_status(
            status) + self.pretty_info(infos)

    def pretty_dots(self, bloc, padding=0):
        lenbloc = len(bloc) + padding
        if (self.align > lenbloc + 2):
            dots = "." * (self.align - lenbloc)
        else:
            dots = ".."
        return dots

    def pretty_info(self, infos):
        "Prettyfy the additional infos"
        if infos == "":
            return ""
        return self.t.italic(" (" + str(infos) + ")")

    def pretty_status(self, status):
        "Prettyfy the status of the test"
        if status == SUCCESS_STATUS:
            return self.success_text
        elif status == FAILURE_STATUS:
            return self.failure_text
        elif status == WARNING_STATUS:
            return self.warning_text
        else:
            return self.critical_text

    def pretty_group(self, name):
        "Prettify the name of the testGroup"
        return self.t.bold(name)

    def pretty_test(self, test):
        "Prettify the name of the testUnit"
        return test

    def pretty_successrate(self, success, total):
        warnings = ""
        if success["success"] == total:
            wrap = self.t.green
            txt = self.success_text
        elif success["success"] + success["warning"] == total:
            wrap = self.t.yellow
            txt = self.warning_text
            warnings = " ({} warnings)".format(str(success["warning"]))
        elif success["critical"] != 0:
            wrap = self.t.white_on_red
            txt = self.critical_text
        else:
            wrap = self.t.bright_red
            txt = self.failure_text
        return wrap(txt + " [" + str(success["success"] + success["warning"]) +
                    "/" + str(total) + "]" + warnings)

    def __str__(self):
        return self.name
Exemplo n.º 3
0
    try:
        url = "http://" + hostname
        response = requests.get(url)
        print(t.bold_bright_green("Requested Url" + ": "), url)
        print("\n")

        if len(response.history) > 0:
            if response.history[0].status_code == 301 or 302:
                print(
                    t.bold_bright_green("[+]HTTPS BYPASS Not Possible [" +
                                        str(response.status_code) + " ] " +
                                        " : "), response.url)
        else:
            print(
                t.bold_bright_red("[+]HTTPS BYPASSED [" +
                                  str(response.status_code) + " ] " + " : "),
                response.url)

    except Exception as e:
        print(e)

    with open('/var/www/html/output/response.txt', 'a') as f:
        print("\n\n", file=f)

    secure_response_headers = [
        'Strict-Transport-Security', 'Expect-CT', 'X-Frame-Options',
        'X-XSS-Protection', 'Cache-Control', 'Pragma',
        'Content-Security-Policy', 'Set-Cookie'
    ]
    print("\n")
    banner2 = t.bold_bright_yellow("******* Missing Response Headers *******")
def doSomethingWithResult(status, url):
    t = Terminal()
    if status == 200:
        print(t.bold_bright_white("[+] " + str(status) + "    " + url))
    else:
        print(t.bold_bright_red("[+] " + str(status) + "    " + url))
def upload_torrents():
  parser = ArgumentParser(description='Upload .torrent files to a Transmission server.')

  parser.add_argument('host', type=str, help='Transmission host[:port] (port defaults to 9091)')

  parser.add_argument('-u', '--user', type=str, default=getuser(), help='Transmission username (defaults to current user)')
  parser.add_argument('-d', '--directory', type=str, default='~/Downloads', help='directory to search for .torrent files (defaults to ~/Downloads)')
  parser.add_argument('-k', '--keep', action='store_true', help='do not trash .torrent files after uploading')

  args = parser.parse_args()
  t = Terminal()

  directory = Path(normpath(expanduser(expandvars(args.directory)))).resolve()
  print('\nScanning {} for {} files...'.format(t.bold(str(directory)), t.bold('.torrent')), end='')
  torrent_files = sorted(directory.glob('*.torrent'))
  if torrent_files:
    print(t.bold_bright_green(' Found {}'.format(len(torrent_files))))
  else:
    print(t.bold_bright_red(' None found'))
    return

  password = getpass('\n{}\'s password: '******':' in args.host:
      hostname, port = args.host.split(':')
      client = Client(address=hostname, port=port, user=args.user, password=password)
    else:
      client = Client(address=args.host, user=args.user, password=password)
    print(t.bold_bright_green('Connected'))
  except TransmissionError as e:
    print(t.bold_bright_red('Connection failed') + ' to Transmission at ' + t.bold(args.host))
    return

  uploaded, failed = [], []

  # pad the index so that the brackets are all vertically aligned
  width = len(str(len(torrent_files)))

  for i, f in enumerate(torrent_files):
    prefix = ('[{:>{width}}]').format(i + 1, width=width)
    print('\n' + t.bold(prefix + ' Uploading') + '\t' + f.name)
    try:
      torrent = client.add_torrent('file://' + str(f))
      uploaded.append(f)
      print(t.bold_bright_green(prefix + ' Started') + '\t' + t.bright_cyan(torrent.name))
    except TransmissionError as e:
      failed.append(f)
      print(t.bold_bright_red(prefix + ' Error') + '\t' + t.bright_black(str(e)))

  if not args.keep:
    # convert to list to force iteration
    trash = lambda f: send2trash(str(f))
    list(map(trash, uploaded))

  print('')

  if uploaded:
    print('{} file{} uploaded successfully{}'.format(
      t.bold_bright_green(str(len(uploaded))),
      's' if len(uploaded) != 1 else '',
      ' and moved to trash' if not args.keep else ''
    ))

  if failed:
    print('{} file{} failed to upload'.format(
      t.bold_bright_red(str(len(failed))),
      's' if len(failed) != 1 else ''
    ))