def get_arguments(): # Get arguments and create link to server from optparse import OptionParser parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]") parser.add_option("-s", "--server",dest='server',help='IMAP server') parser.add_option("-p", "--port", dest='port', help='IMAP server port', type='int') parser.add_option("-x", "--ssl", dest='ssl', action="store_true", help='Use SSL') parser.add_option("-u", "--user", dest='user', help='IMAP user name') parser.add_option("-w", "--password", dest='password', help='IMAP password (Will prompt if not specified)') parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode") parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true", help="Don't actually do anything, just report what would be done") parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", help="Use a checksum of several mail headers, instead of the Message-ID") parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", help="Include the Message-ID (if any) in the -c checksum.") parser.add_option("-l", "--list", dest="just_list", action="store_true", help="Just list mailboxes") parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False) (options, args) = parser.parse_args() if (not options.server) or (not options.user): sys.stderr.write("\nError: Must specify server, user, password and at least one mailbox.\n\n") parser.print_help() sys.exit(1) if not options.password: options.password = getpass.getpass() return (options, args)
def get_arguments(args): # Get arguments and create link to server from optparse import OptionParser parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]") parser.add_option("-P", "--process",dest='process', help='IMAP process to access mailboxes') parser.add_option("-s", "--server",dest='server',help='IMAP server') parser.add_option("-p", "--port", dest='port', help='IMAP server port', type='int') parser.add_option("-x", "--ssl", dest='ssl', action="store_true", help='Use SSL') parser.add_option("-a", "--authuser", dest='authuser', help='IMAP admin user (e.g. for Zimbra)') parser.add_option("-u", "--user", dest='user', help='IMAP user name') parser.add_option("-w", "--password", dest='password', help='IMAP password (Will prompt if not specified)') parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode") parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true", help="Don't actually do anything, just report what would be done") parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", help="Use a checksum of several mail headers, instead of the Message-ID") parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", help="Include the Message-ID (if any) in the -c checksum.") parser.add_option("", "--no-close", dest='no_close', action="store_true", help='Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.') parser.add_option("-l", "--list", dest="just_list", action="store_true", help="Just list mailboxes") parser.set_defaults(verbose=False, ssl=False, dry_run=False, no_close=False, just_list=False) (options, mboxes) = parser.parse_args(args) if ((not options.server) or (not options.user)) and not options.process: sys.stderr.write("\nError: Must specify server, user, and at least one mailbox.\n\n") parser.print_help() sys.exit(1) if not options.password and not options.process: # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one. options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass() if options.use_id_in_checksum and not options.use_checksum: sys.stderr.write("\nError: If you use -m you must also use -c.\n") sys.exit(1) return (options, mboxes)
def get_arguments(args): # Get arguments and create link to server from optparse import OptionParser parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]") parser.add_option("-P", "--process",dest='process', help='IMAP process to access mailboxes') parser.add_option("-s", "--server",dest='server',help='IMAP server') parser.add_option("-p", "--port", dest='port', help='IMAP server port', type='int') parser.add_option("-x", "--ssl", dest='ssl', action="store_true", help='Use SSL') parser.add_option("-u", "--user", dest='user', help='IMAP user name') parser.add_option("-w", "--password", dest='password', help='IMAP password (Will prompt if not specified)') parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode") parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true", help="Don't actually do anything, just report what would be done") parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", help="Use a checksum of several mail headers, instead of the Message-ID") parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", help="Include the Message-ID (if any) in the -c checksum.") parser.add_option("", "--no-close", dest='no_close', action="store_true", help='Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.') parser.add_option("-l", "--list", dest="just_list", action="store_true", help="Just list mailboxes") parser.set_defaults(verbose=False, ssl=False, dry_run=False, no_close=False, just_list=False) (options, mboxes) = parser.parse_args(args) if ((not options.server) or (not options.user)) and not options.process: sys.stderr.write("\nError: Must specify server, user, and at least one mailbox.\n\n") parser.print_help() sys.exit(1) if not options.password and not options.process: # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one. options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass() if options.use_id_in_checksum and not options.use_checksum: sys.stderr.write("\nError: If you use -m you must also use -c.\n") sys.exit(1) return (options, mboxes)
def get_arguments(): from optparse import OptionParser parser = OptionParser(usage="%prog options ") parser.add_option("-f","--config", dest='config_file', help='Config File ') parser.add_option("-s","--src-server",dest='src_server',help='Source IMAP server') parser.add_option("-S","--dst-server",dest='dst_server',help='Destination IMAP server') parser.add_option("-p","--src-port", dest='src_port', help='Source IMAP server port', type='int') parser.add_option("-P","--dst-port", dest='dst_port', help='Destination IMAP server port', type='int') parser.add_option("-u","--src-user", dest='src_user', help='Source IMAP user') parser.add_option("-U","--dst-user", dest='dst_user', help='Destination IMAP user') parser.add_option("-w","--src-password", dest='src_password', help='Source IMAP password',type="string") parser.add_option("-W","--dst-password", dest='dst_password', help='Destination IMAP password',type="string") parser.add_option("-x", "--src-ssl", dest='src_ssl', action="store_true", help='Use SSL') parser.add_option("-X", "--dst-ssl", dest='dst_ssl', action="store_true", help='Use SSL') parser.add_option("-d","--start-date", dest='start_date',help='Start from date YYYYMMDD ') parser.add_option("-D","--end-date" , dest='end_date', help='End date YYYYMMDD') parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode") parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", help="Use a checksum of several mail headers, instead of the Message-ID") parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", help="Include the Message-ID (if any) in the -c checksum.") parser.add_option("-l", "--list", dest="just_list", action="store_true", help="Just list mailboxes on Source Server") parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False,src_port=143,dst_port=143) (options, args) = parser.parse_args() config = ConfigParser.ConfigParser() #Load Data from config file if options.config_file: config.read(options.config_file) for a in config.items("IMAPCopy"): setattr(options, a[0],a[1]) if (not options.start_date) or (not options.end_date): sys.stderr.write("\nError: Must specify Start and End dates. \n") parser.print_help() sys.exit(1) if options.just_list: if (not options.src_server) or (not options.src_user) : sys.stderr.write("\nError: Must specify src-server, src-users, src-passwords.\n") parser.print_help() sys.exit(1) else: if (not options.src_server) or (not options.dst_server) or (not options.src_user) or (not options.dst_user): sys.stderr.write("\nError: Must specify servers, users, passwords .\n\n") parser.print_help() sys.exit(1) return (options, args)
def parse_parameters(self, argv): parser = argparse.ArgumentParser() #================================================== # Input Files #================================================== filesgroup = parser.add_argument_group('input files') filesgroup.add_argument("-C", metavar="<config.txt>", dest="config_file", action='store', help="config file") filesgroup.add_argument("-U", metavar="<users.txt>", dest="usernamefile", action='store', help="file containing list of username") filesgroup.add_argument("-P", metavar="<passwords.txt>", dest="passwordfile", action='store', help="file containing list of passwords") filesgroup.add_argument( "--COMBINED", metavar="<username_passwords.txt>", dest="usernamepasswordfile", action='store', help="file containing list of username:password") filesgroup.add_argument( "--searchstringifile", metavar="<searchstrings.txt>", dest="searchstringfile", action='store', help="file containing list of search strings or regexes, 1 per line" ) #================================================== # Enable Flags #================================================== enablegroup = parser.add_argument_group('enable flags') enablegroup.add_argument("--emails", dest="downloademails", action='store_true', help="download any identified emails?") enablegroup.add_argument("--attachments", dest="downloadattachments", action='store_true', help="download any identified attachments?") enablegroup.add_argument("--contacts", dest="buildcontactlist", action='store_true', help="collect contact list?") #================================================== # Other Args #================================================== parser.add_argument("-s", metavar="<server>", dest="server", default="", action='store', help="target mail server ip or fqdn") parser.add_argument( "-t", metavar="<type of mail server>", dest="servertype", default="", action='store', help="valid choices are: IMAP, IMAPS, POP3, POP3S, OWA, EWS") parser.add_argument("-d", metavar="<domain>", dest="domain", action='store', help="domain name to phish") parser.add_argument("-u", metavar="<username>", dest="username", action='store', help="username") parser.add_argument("-p", metavar="<password>", dest="password", action='store', help="password") parser.add_argument("--searchstring", metavar="\"term1,term2,term3,...\"", dest="searchstring", action='store', help="list of search terms seperated by commas") parser.add_argument("-o", metavar="<output directory>", dest="outdir", action='store', help="directory to which to save any loot") parser.add_argument("-v", "--verbosity", dest="verbose", action='count', help="increase output verbosity") # parse args args = parser.parse_args() # convert parameters to values in the config dict self.config["verbose"] = args.verbose self.config["downloadattachments"] = args.downloadattachments self.config["downloademails"] = args.downloademails self.config["buildcontactlist"] = args.buildcontactlist self.config["searchstringfile"] = args.searchstringfile self.config["searchstring"] = args.searchstring self.config["server"] = args.server self.config["servertype"] = args.servertype self.config["domain"] = args.domain self.config["username"] = args.username self.config["usernamefile"] = args.usernamefile self.config["password"] = args.password self.config["passwordfile"] = args.passwordfile self.config["usernamepasswordfile"] = args.usernamepasswordfile if args.outdir: self.config["outdir"] = args.outdir if self.config["searchstring"]: self.config["searchterms"] = self.config["searchstring"].split(",") if Utils.isReadable(self.config["searchstringfile"]): with open(self.config["searchstringfile"]) as f: self.config["searchterms"] = f.read().splitlines() # validate we have required fields valid = True if (self.config["username"] and self.config["password"]) or ( Utils.isReadable(self.config["usernamefile"]) and Utils.isReadable(self.config["passwordfile"])) or ( Utils.isReadable(self.config["usernamepasswordfile"])): pass else: self.display.error( "Please enable at least one of the following parameters: --COMBINED or (-U and -P) or (-u and -p)" ) valid = False if (self.config["server"] and self.config["servertype"]): self.config["servertype"] = self.config["servertype"].lower() pass else: self.display.error("Please enable at both of: -s and -t") valid = False if not valid: parser.print_help() sys.exit(1)
if args.auto: if (args.list or args.month): print("Must not specify list and month when auto-generating!") sys.exit(1) if not os.path.isdir(args.destination): print( "Destination must be a directory, and exist, when auto-generating" ) sys.exit(1) else: if not (args.list and args.month and args.destination): print( "Must specify list, month and destination when generating a single mailbox" ) parser.print_help() sys.exit(1) # Arguments OK, now connect cfg = ConfigParser() cfg.read( os.path.join(os.path.realpath(os.path.dirname(sys.argv[0])), 'archives.ini')) try: connstr = cfg.get('db', 'connstr') except Exception: connstr = 'need_connstr' conn = psycopg2.connect(connstr) curs = conn.cursor()
def main(): """ Main routine. Args: None. Returns: None. """ usage = "%prog [options] [keyword]" + \ "\nVersion: {ver}".format(ver=__version__) parser = OptionParser(usage=usage) parser.add_option("-a", "--account", dest="account", help="The gmail account email address.") parser.add_option("-c", "--create", dest="create", help="Create contact from email.") parser.add_option("-e", "--edit", dest="edit", action="store_true", help="Edit contacts.") parser.add_option("-f", "--full-help", dest="full_help", action="store_true", help="Print full help and exit. Full help includes examples/notes.") parser.add_option('-m', '--mode', dest='mode', choices=('abook', 'email', 'long', 'short'), default='long', help="Mode. One of: 'abook', 'email', 'long', or 'short'. \ Default: 'long'") parser.add_option('-r', '--include-header', dest='print_status', action='store_true', default=False, help="Include a status header line. (Required for mutt)") parser.add_option('-s', '--sort', dest='sort', choices=('email', 'name'), default='email', help="Field to sort by. One of 'email' or 'name'. Default 'email'.") parser.add_option('-v', '--verbose', action='store_const', const=1, dest='verbose', help='Print messages to stdout.',) parser.add_option('--vv', action='store_const', const=2, dest='verbose', help='More verbose.') (options, args) = parser.parse_args() if options.verbose > 0: if options.verbose == 1: LOG.setLevel(logging.INFO) else: LOG.setLevel(logging.DEBUG) if options.full_help: parser.print_help() print print usage_full() exit(0) keyword = None if len(args) > 0: keyword = args[0] if options.account: email_addr = options.account else: email_addr = get_email_address() if not email_addr: msg = "Unable to determine google email account to login with." print >> sys.stderr, msg quit(1) password = get_password(email_addr) LOG.debug("email: {email} password: {pw}".format(email=email_addr, pw=password)) LOG.debug("Creating google contacts service.") gd_client = gdata.contacts.service.ContactsService() LOG.debug("Logging in.") gd_client.email = email_addr gd_client.password = password gd_client.source = 'dm-contacts-1' gd_client.ProgrammaticLogin() if options.edit: # All details are required for edit. Force long mode. options.mode = 'long' contact_set = Contacts(gd_client=gd_client) if options.create: contact_set.create_contact_from_file(options.create) else: contact_set.get() contact_set.filter(keyword) if options.edit: contact_set.edit() contact_set.update() else: contact_set.print_contacts(mode=options.mode, sort_by=options.sort, print_status=options.print_status)
def get_arguments(): # Get arguments and create link to server from optparse import OptionParser parser = OptionParser( usage="%prog [options] <mailboxname> [<mailboxname> ...]") parser.add_option("-s", "--server", dest='server', help='IMAP server') parser.add_option("-p", "--port", dest='port', help='IMAP server port', type='int') parser.add_option("-x", "--ssl", dest='ssl', action="store_true", help='Use SSL') parser.add_option("-u", "--user", dest='user', help='IMAP user name') parser.add_option("-w", "--password", dest='password', help='IMAP password (Will prompt if not specified)') parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode") parser.add_option( "-n", "--dry-run", dest="dry_run", action="store_true", help="Don't actually do anything, just report what would be done") parser.add_option( "-c", "--checksum", dest="use_checksum", action="store_true", help="Use a checksum of several mail headers, instead of the Message-ID" ) parser.add_option( "-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", help="Include the Message-ID (if any) in the -c checksum.") parser.add_option("-l", "--list", dest="just_list", action="store_true", help="Just list mailboxes") parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False) (options, args) = parser.parse_args() if (not options.server) or (not options.user): sys.stderr.write( "\nError: Must specify server, user, password and at least one mailbox.\n\n" ) parser.print_help() sys.exit(1) if not options.password: options.password = getpass.getpass() return (options, args)
help='smtp relay server hostname', metavar='STRING') parser.add_option('-p', '--port', dest='port', default='465', help='smtp relay port', metavar='STRING') parser.add_option('-t', '--type', dest='type', default='ssl', help='smtp connection type', metavar='plain|ssl|tls') parser.add_option('-U', '--username', dest='username', default='webermi', help='optional smtp username', metavar='STRING') parser.add_option('-P', '--password', dest='password', help='optional smtp password, leave blank for prompt', metavar='STRING') parser.add_option('-m', '--maildir', dest='maildir', default='mail', help='mailbox directory', metavar='DIR') (options, args) = parser.parse_args() if not options.host or not options.maildir or not options.type in ('plain', 'ssl', 'tls'): parser.print_help() sys.exit(1) if options.username and not options.password: import getpass options.password = getpass.getpass('Enter password for %s on %s: ' % (options.username, options.host)) mbox = mailbox.Maildir(options.maildir) mbox.lock() if options.type == 'ssl': conn = smtplib.SMTP_SSL(options.host, int(options.port)) else: conn = smtplib.SMTP(options.host, int(options.port)) if options.type == 'tls':
def parse_parameters(self, argv): parser = argparse.ArgumentParser() #================================================== # Input Files #================================================== filesgroup = parser.add_argument_group('input files') filesgroup.add_argument("-C", metavar="<config.txt>", dest="config_file", action='store', help="config file") filesgroup.add_argument("-U", metavar="<users.txt>", dest="usernamefile", action='store', help="file containing list of username") filesgroup.add_argument("-P", metavar="<passwords.txt>", dest="passwordfile", action='store', help="file containing list of passwords") filesgroup.add_argument("--COMBINED", metavar="<username_passwords.txt>", dest="usernamepasswordfile", action='store', help="file containing list of username:password") filesgroup.add_argument("--searchstringifile", metavar="<searchstrings.txt>", dest="searchstringfile", action='store', help="file containing list of search strings or regexes, 1 per line") #================================================== # Enable Flags #================================================== enablegroup = parser.add_argument_group('enable flags') enablegroup.add_argument("--emails", dest="downloademails", action='store_true', help="download any identified emails?") enablegroup.add_argument("--attachments", dest="downloadattachments", action='store_true', help="download any identified attachments?") enablegroup.add_argument("--contacts", dest="buildcontactlist", action='store_true', help="collect contact list?") #================================================== # Other Args #================================================== parser.add_argument("-s", metavar="<server>", dest="server", default="", action='store', help="target mail server ip or fqdn") parser.add_argument("-t", metavar="<type of mail server>", dest="servertype", default="", action='store', help="valid choices are: IMAP, IMAPS, POP3, POP3S, OWA, EWS") parser.add_argument("-d", metavar="<domain>", dest="domain", action='store', help="domain name to phish") parser.add_argument("-u", metavar="<username>", dest="username", action='store', help="username") parser.add_argument("-p", metavar="<password>", dest="password", action='store', help="password") parser.add_argument("--searchstring", metavar="\"term1,term2,term3,...\"", dest="searchstring", action='store', help="list of search terms seperated by commas") parser.add_argument("-o", metavar="<output directory>", dest="outdir", action='store', help="directory to which to save any loot") parser.add_argument("-v", "--verbosity", dest="verbose", action='count', help="increase output verbosity") # parse args args = parser.parse_args() # convert parameters to values in the config dict self.config["verbose"] = args.verbose self.config["downloadattachments"] = args.downloadattachments self.config["downloademails"] = args.downloademails self.config["buildcontactlist"] = args.buildcontactlist self.config["searchstringfile"] = args.searchstringfile self.config["searchstring"] = args.searchstring self.config["server"] = args.server self.config["servertype"] = args.servertype self.config["domain"] = args.domain self.config["username"] = args.username self.config["usernamefile"] = args.usernamefile self.config["password"] = args.password self.config["passwordfile"] = args.passwordfile self.config["usernamepasswordfile"] = args.usernamepasswordfile if args.outdir: self.config["outdir"] = args.outdir if self.config["searchstring"]: self.config["searchterms"] = self.config["searchstring"].split(",") if Utils.isReadable(self.config["searchstringfile"]): with open(self.config["searchstringfile"]) as f: self.config["searchterms"] = f.read().splitlines() # validate we have required fields valid = True if (self.config["username"] and self.config["password"]) or (Utils.isReadable(self.config["usernamefile"]) and Utils.isReadable(self.config["passwordfile"])) or (Utils.isReadable(self.config["usernamepasswordfile"])): pass else: self.display.error("Please enable at least one of the following parameters: --COMBINED or (-U and -P) or (-u and -p)") valid = False if (self.config["server"] and self.config["servertype"]): self.config["servertype"] = self.config["servertype"].lower() pass else: self.display.error("Please enable at both of: -s and -t") valid = False if not valid: parser.print_help() sys.exit(1)