Projects STRLCPY cupp Commits ea6c152f
🤬
  • function for loading the configuration

  • Loading...
  • Mebus committed 5 years ago
    ea6c152f
    1 parent f48cdc50
  • ■ ■ ■ ■ ■ ■
    cupp.py
    skipped 32 lines
    33 33  import sys
    34 34  import os
    35 35  import ftplib
     36 +import functools
    36 37  import configparser
    37 38  import urllib.request, urllib.parse, urllib.error
    38 39  import gzip
    skipped 2 lines
    41 42   
    42 43  __author__ = "Muris Kurgas"
    43 44  __license__ = "GPL"
    44  -__version__ = "3.2.3-alpha"
     45 +__version__ = "3.2.4-alpha"
     46 + 
     47 +CONFIG = {}
     48 + 
     49 + 
     50 +def read_config(filename="cupp.cfg"):
     51 + """Read the given configuration file and update global variables to reflect
     52 + changes (CONFIG)."""
    45 53   
    46  -# Reading configuration file...
    47  -config = configparser.ConfigParser()
    48  -config.read(os.path.join(os.path.dirname(__file__), "cupp.cfg"))
     54 + # global CONFIG
    49 55   
    50  -years = config.get("years", "years").split(",")
    51  -chars = config.get("specialchars", "chars").split(",")
     56 + # Reading configuration file
     57 + config = configparser.ConfigParser()
     58 + config.read(filename)
     59 + 
     60 + CONFIG["global"] = {
     61 + "years": config.get("years", "years").split(","),
     62 + "chars": config.get("specialchars", "chars").split(","),
     63 + "numfrom": config.getint("nums", "from"),
     64 + "numto": config.getint("nums", "to"),
     65 + "wcfrom": config.getint("nums", "wcfrom"),
     66 + "wcto": config.getint("nums", "wcto"),
     67 + "threshold": config.getint("nums", "threshold"),
     68 + "alectourl": config.get("alecto", "alectourl"),
     69 + }
     70 + 
     71 + # 1337 mode configs, well you can add more lines if you add it to the
     72 + # config file too.
     73 + leet = functools.partial(config.get, "leet")
     74 + leetc = {}
     75 + letters = {"a", "i", "e", "t", "o", "s", "g", "z"}
    52 76   
    53  -numfrom = config.getint("nums", "from")
    54  -numto = config.getint("nums", "to")
     77 + for letter in letters:
     78 + leetc[letter] = config.get("leet", letter)
    55 79   
    56  -wcfrom = config.getint("nums", "wcfrom")
    57  -wcto = config.getint("nums", "wcto")
     80 + CONFIG["LEET"] = leetc
    58 81   
    59  -threshold = config.getint("nums", "threshold")
     82 + ftp_config = functools.partial(config.get, "downloader")
    60 83   
    61  -# 1337 mode configs, well you can add more lines if you add it to config file too.
    62  -# You will need to add more lines in two places in cupp.py code as well...
    63  -leet = {}
    64  -leet["a"] = config.get("leet", "a")
    65  -leet["i"] = config.get("leet", "i")
    66  -leet["e"] = config.get("leet", "e")
    67  -leet["t"] = config.get("leet", "t")
    68  -leet["o"] = config.get("leet", "o")
    69  -leet["s"] = config.get("leet", "s")
    70  -leet["g"] = config.get("leet", "g")
    71  -leet["z"] = config.get("leet", "z")
     84 + CONFIG["FTP"] = dict(
     85 + name=ftp_config("ftpname"),
     86 + url=ftp_config("ftpurl"),
     87 + path=ftp_config("ftppath"),
     88 + user=ftp_config("ftpuser"),
     89 + password=ftp_config("ftppass"),
     90 + )
    72 91   
    73 92   
    74  -# for concatenations...
     93 +def make_leet(x):
     94 + """convert string to leet"""
     95 + for letter, leetletter in CONFIG["LEET"].items():
     96 + x.replace(letter, leetletter)
     97 + return x
    75 98   
    76 99   
     100 +# for concatenations...
    77 101  def concats(seq, start, stop):
    78 102   for mystr in seq:
    79 103   for num in range(start, stop):
    skipped 1 lines
    81 105   
    82 106   
    83 107  # for sorting and making combinations...
    84  - 
    85  - 
    86 108  def komb(seq, start, special=""):
    87 109   for mystr in seq:
    88 110   for mystr1 in start:
    skipped 55 lines
    144 166   if not os.path.isfile(file_to_open):
    145 167   exit("Error: file " + file_to_open + " does not exist.")
    146 168   
     169 + chars = CONFIG["global"]["chars"]
     170 + years = CONFIG["global"]["years"]
     171 + numfrom = CONFIG["global"]["numfrom"]
     172 + numto = CONFIG["global"]["numto"]
     173 + wcto = CONFIG["global"]["wcto"]
     174 + wcfrom = CONFIG["global"]["wcfrom"]
     175 + threshold = CONFIG["global"]["threshold"]
     176 + 
    147 177   fajl = open(file_to_open, "r")
    148 178   listic = fajl.readlines()
    149 179   linije = 0
    skipped 20 lines
    170 200   conts = input(
    171 201   "> Do you want to concatenate all words from wordlist? Y/[N]: "
    172 202   ).lower()
    173  - conts = conts
     203 + 
    174 204   cont = [""]
    175 205   if conts == "y":
    176 206   for cont1 in listica:
    skipped 67 lines
    244 274   ) in (
    245 275   unique_lista
    246 276   ): # if you want to add more leet chars, you will need to add more lines in cupp.cfg too...
    247  - x = x.replace("a", a)
    248  - x = x.replace("i", i)
    249  - x = x.replace("e", e)
    250  - x = x.replace("t", t)
    251  - x = x.replace("o", o)
    252  - x = x.replace("s", s)
    253  - x = x.replace("g", g)
    254  - x = x.replace("z", z)
     277 + x = make_leet(x) # convert to leet
    255 278   unique_leet.append(x)
    256 279   
    257 280   unique_list = unique_lista + unique_leet
    skipped 81 lines
    339 362   
    340 363  def generate_wordlist_from_profile(profile):
    341 364   """ Generates a wordlist from a given profile """
     365 + 
     366 + chars = CONFIG["global"]["chars"]
     367 + years = CONFIG["global"]["years"]
     368 + numfrom = CONFIG["global"]["numfrom"]
     369 + numto = CONFIG["global"]["numto"]
     370 + wcto = CONFIG["global"]["wcto"]
     371 + wcfrom = CONFIG["global"]["wcfrom"]
    342 372   
    343 373   profile["spechars"] = []
    344 374   
    skipped 307 lines
    652 682   unique_lista
    653 683   ): # if you want to add more leet chars, you will need to add more lines in cupp.cfg too...
    654 684   
    655  - # transform to leet
    656  - for letter, leetletter in leet.items():
    657  - x.replace(letter, leetletter)
    658  - 
     685 + x = make_leet(x) # convert to leet
    659 686   unique_leet.append(x)
    660 687   
    661 688   unique_list = unique_lista + unique_leet
    skipped 8 lines
    670 697   """Download csv from alectodb and save into local file as a list of
    671 698   usernames and passwords"""
    672 699   
    673  - url = config.get("alecto", "alectourl")
     700 + url = CONFIG["global"]["alectourl"]
    674 701   
    675 702   print("\r\n[+] Checking if alectodb is not present...")
    676 703   if os.path.isfile("alectodb.csv.gz") == 0:
    skipped 37 lines
    714 741   """Implementation of -l switch. Download wordlists from ftp repository as
    715 742   defined in the configuration file."""
    716 743   
    717  - ftpname = config.get("downloader", "ftpname")
    718  - ftpurl = config.get("downloader", "ftpurl")
    719  - ftppath = config.get("downloader", "ftppath")
    720  - ftpuser = config.get("downloader", "ftpuser")
    721  - ftppass = config.get("downloader", "ftppass")
     744 + ftpname = CONFIG["FTP"]["name"]
     745 + ftpurl = CONFIG["FTP"]["url"]
     746 + ftppath = CONFIG["FTP"]["path"]
     747 + ftpuser = CONFIG["FTP"]["user"]
     748 + ftppass = CONFIG["FTP"]["password"]
    722 749   
    723 750   if os.path.isdir("dictionaries") == 0:
    724 751   os.mkdir("dictionaries")
    skipped 275 lines
    1000 1027  # the main function
    1001 1028  def main():
    1002 1029   """Command-line interface to the cupp utility"""
     1030 + 
     1031 + read_config()
    1003 1032   
    1004 1033   parser = get_parser()
    1005 1034   args = parser.parse_args()
    skipped 65 lines
Please wait...
Page is in error, reload to recover