Projects STRLCPY geneva Commits 1a1a8783
🤬
  • Small cleanup http-plugin/client.py No semantic changes

  • Loading...
  • VwCSXg committed 2 years ago
    1a1a8783
    1 parent 3c1c963c
  • ■ ■ ■ ■ ■ ■
    plugins/http/client.py
    skipped 2 lines
    3 3  """
    4 4   
    5 5  import argparse
    6  -import logging
    7 6  import os
    8  -import random
    9 7  import socket
    10  -import sys
    11  -import time
    12  -import traceback
    13 8  import urllib.request
     9 +import requests
    14 10   
    15  -import requests
     11 +from plugins.plugin_client import ClientPlugin
    16 12   
    17 13  socket.setdefaulttimeout(1)
    18 14   
    19  -import external_sites
    20  -import actions.utils
    21  - 
    22  -from plugins.plugin_client import ClientPlugin
    23  - 
    24 15  BASEPATH = os.path.dirname(os.path.abspath(__file__))
    25 16   
    26 17   
    skipped 19 lines
    46 37   parser = argparse.ArgumentParser(description='HTTP Client', prog="http/client.py")
    47 38   
    48 39   parser.add_argument('--host-header', action='store', default="", help='specifies host header for HTTP request')
    49  - parser.add_argument('--injected-http-contains', action='store', default="", help='checks if injected http response contains string')
     40 + parser.add_argument('--injected-http-contains', action='store',
     41 + default="", help='checks if injected http response contains string')
    50 42   
    51 43   args, _ = parser.parse_known_args(command)
    52 44   args = vars(args)
    skipped 17 lines
    70 62   # If we've been given a non-standard port, append that to the URL
    71 63   port = args.get("port", 80)
    72 64   if port != 80:
    73  - url += ":%s" % str(port)
     65 + url += f":{str(port)}"
    74 66   
    75 67   if args.get("bad_word"):
    76  - url += "?q=%s" % args.get("bad_word")
     68 + url += f"?q={args.get('bad_word')}"
    77 69   
    78  - injected_http = args.get("injected_http_contains")
    79 70   try:
    80 71   res = requests.get(url, allow_redirects=False, timeout=3, headers=headers)
    81 72   logger.debug(res.text)
    82 73   # If we need to monitor for an injected response, check that here
    83  - if injected_http and injected_http in res.text:
     74 + if args.get("injected_http_contains") and args.get("injected_http_contains") in res.text:
    84 75   fitness -= 90
    85 76   else:
    86 77   fitness += 100
    87  - except requests.exceptions.ConnectTimeout as exc:
     78 + except requests.exceptions.ConnectTimeout:
    88 79   logger.exception("Socket timeout.")
    89 80   fitness -= 100
    90  - except (requests.exceptions.ConnectionError, ConnectionResetError) as exc:
     81 + except (requests.exceptions.ConnectionError, ConnectionResetError):
    91 82   logger.exception("Connection RST.")
    92 83   fitness -= 90
    93 84   except urllib.error.URLError as exc:
    94 85   logger.debug(exc)
    95  - fitness += -101
     86 + fitness -= 101
    96 87   # Timeouts generally mean the strategy killed the TCP stream.
    97 88   # HTTPError usually mean the request was destroyed.
    98 89   # Punish this more harshly than getting caught by the censor.
    99 90   except (requests.exceptions.Timeout, requests.exceptions.HTTPError) as exc:
    100 91   logger.debug(exc)
    101  - fitness += -120
     92 + fitness -= 120
    102 93   except Exception:
    103 94   logger.exception("Exception caught in HTTP test to site %s.", url)
    104  - fitness += -100
     95 + fitness -= 100
    105 96   return fitness * 4
    106 97   
Please wait...
Page is in error, reload to recover