Beispiel #1
0
def main(password):
    global counter
    sys.stdout.write ("[-] Trying : %s \n" % (password))
    sys.stdout.flush()
    file.write("[-] Trying : %s \n" % (str(password)))
    try:
        IMAP4 = imaplib.IMAP4_SSL(HOST, PORT)
            IMAP4.Email(email)
            IMAP4.Passwd(password)  
            IMAP4.quit()
            print "[+] enjoy !!!\n[+] Username : [%s]\n[+] Password : [%s]\n[+] Status : Found!" % (email, password)
            file.write("[+] enjoy !!!\n[+] Username : [%s]\n[+] Password : [%s]\n[+] Status : Found!" % (email, password))
            sys.exit(1)
        except Exception, e:
            pass 
def fetch_from_imap(conn: imaplib.IMAP4, *args, cmd='fetch', **kwargs) -> \
        Tuple[bytes, List[bytes]]:
    """Function which will call imaplib function but it always will check status
    of the executed command and will raise Exception if IMAP command failed

    :param conn: imaplib.IMAP4 object
    :param args:
    :param cmd: string
    :param kwargs:
    :return: Tuple[bytes, List[bytes]]
    """
    # first lets execute CHECK IMAP command. It will flush any pending
    # operation in session
    conn.check()
    status, data = getattr(conn, cmd)(*args, **kwargs)
    if status != 'OK':
        raise Exception('Failed to execute fetch command: {}'.format(data))
    return build_imap_response_line(data)
Beispiel #3
0
    def run(self, imap_obj: imaplib.IMAP4):
        """Executes CREATE imap command

        :param imap_obj:
        :return: name of created folder
        """
        typ, data = imap_obj.create(self.__folder_name)
        self.check_response(typ, data)
        return self.__folder_name
Beispiel #4
0
    def __init__(self, imap, uid):

        self.uid = ""
        self.parts = []
        self.ct = ""

        (t, d) = imap.uid("FETCH", uid, "(BODY)")
        if d[0] is None:
            raise IMAP4.error('No message with UID "%s" has been found' % uid)
        self._parse_body_desc(d[0])
def change_swa_settings(conn: imaplib.IMAP4, swa_options: dict):
    """Changes swa preference email or create a new one if message with
    preference does not exists.

    :param swa_options:
    :param conn: imaplib.IMAP4
    :return:
    """
    status, data = conn.select('#Scalix/Oddpost')
    if status != 'OK':
        raise Exception('Could not select folder #Scalix/Oddpost. '
                        'Imap response: {}'.format(data))

    orphan_uids = set()
    if not int(data[0]):
        #  there are no messages in mailbox fetching will fail so we will
        #  skip it
        email = create_preference_message()
    else:
        email, orphan_uids = find_swa_preference_email(conn)

    if not email:
        email = create_preference_message()

    # lets apply changes to the preferences
    for key, value in swa_options.items():
        find_option_and_change(email.preferences, key, value)

    # if we have UID for previous email jus tadd it to delete
    if email.uid:
        orphan_uids.add(email.uid)

    if orphan_uids:
        uids_del = b','.join([str(uid).encode() for uid in orphan_uids])
        status, data = conn.uid('STORE', uids_del.decode(), '+FLAGS',
                                '\\Deleted')
        if status != 'OK':
            warnings.warn(
                'Could not delete duplicate preference emails {}'
                '. Error {}.'.format(orphan_uids, data),
                RuntimeWarning
            )

    status, data = conn.append('#Scalix/Oddpost', '\\Seen',
                               imaplib.Time2Internaldate(time.time()),
                               email.as_bytes())
    if status != 'OK':
        if email.uid:
            conn.uid('STORE', email.uid, '-FLAGS', '\\Deleted')
        raise Exception('Could not save email. Error message {}'.format(data))

    conn.expunge()
Beispiel #6
0
    def backup_folder(self, folder):
        print('Backup:', folder)
        folder_name = '"%s"' % folder
        resp, info = self.server.select(folder_name)
        if resp != 'OK':
            raise IMAP4.error(info)

        filename = folder.replace('/', '.') + '.mbox'

        mbox = open(filename, 'w')
        resp, items = self.server.search(None, "ALL")
        numbers = items[0].split()
        for num in numbers:
            resp, data = self.server.fetch(num, "(BODY.PEEK[])")
            text = data[0][1].decode('iso-8859-1')
            message = email.message_from_string(text)
            mbox.write(message.as_string(unixfrom=True))
        mbox.close()
Beispiel #7
0
    def fetch2file(self, imap, part, filename=None):

        (t, d) = imap.uid("fetch", self.uid, "(BODY.PEEK[%i])" % (part + 1))
        if (t != "OK") or (len(d[0]) != 2):
            raise IMAP4.error("could not retrieve part %s/%i" % (self.uid, part + 1))

        msg = d[0][1]
        msg = base64.decodestring(msg)
        if filename is None:
            out_file = os.tmpfile()
        else:
            out_file = open(filename, "w+")

        out_file.write(msg)
        out_file.seek(0)

        if filename is None:
            return out_file
        else:
            out_file.close()
            return None
Beispiel #8
0
    def __init__(self, host = '', port = IMAP4_TLS_PORT,
                 username=None, password=None, sharedKey=None,
                 certChain=None, privateKey=None,
                 cryptoID=None, protocol=None,
                 x509Fingerprint=None,
                 x509TrustList=None, x509CommonName=None,
                 settings=None):
        """Create a new IMAP4_TLS.

        For client authentication, use one of these argument
        combinations:
         - username, password (SRP)
         - username, sharedKey (shared-key)
         - certChain, privateKey (certificate)

        For server authentication, you can either rely on the
        implicit mutual authentication performed by SRP or
        shared-keys, or you can do certificate-based server
        authentication with one of these argument combinations:
         - cryptoID[, protocol] (requires cryptoIDlib)
         - x509Fingerprint
         - x509TrustList[, x509CommonName] (requires cryptlib_py)

        Certificate-based server authentication is compatible with
        SRP or certificate-based client authentication.  It is
        not compatible with shared-keys.

        The caller should be prepared to handle TLS-specific
        exceptions.  See the client handshake functions in
        L{tlslite.TLSConnection.TLSConnection} for details on which
        exceptions might be raised.

        @type host: str
        @param host: Server to connect to.

        @type port: int
        @param port: Port to connect to.

        @type username: str
        @param username: SRP or shared-key username.  Requires the
        'password' or 'sharedKey' argument.

        @type password: str
        @param password: SRP password for mutual authentication.
        Requires the 'username' argument.

        @type sharedKey: str
        @param sharedKey: Shared key for mutual authentication.
        Requires the 'username' argument.

        @type certChain: L{tlslite.X509CertChain.X509CertChain} or
        L{cryptoIDlib.CertChain.CertChain}
        @param certChain: Certificate chain for client authentication.
        Requires the 'privateKey' argument.  Excludes the SRP or
        shared-key related arguments.

        @type privateKey: L{tlslite.utils.RSAKey.RSAKey}
        @param privateKey: Private key for client authentication.
        Requires the 'certChain' argument.  Excludes the SRP or
        shared-key related arguments.

        @type cryptoID: str
        @param cryptoID: cryptoID for server authentication.  Mutually
        exclusive with the 'x509...' arguments.

        @type protocol: str
        @param protocol: cryptoID protocol URI for server
        authentication.  Requires the 'cryptoID' argument.

        @type x509Fingerprint: str
        @param x509Fingerprint: Hex-encoded X.509 fingerprint for
        server authentication.  Mutually exclusive with the 'cryptoID'
        and 'x509TrustList' arguments.

        @type x509TrustList: list of L{tlslite.X509.X509}
        @param x509TrustList: A list of trusted root certificates.  The
        other party must present a certificate chain which extends to
        one of these root certificates.  The cryptlib_py module must be
        installed to use this parameter.  Mutually exclusive with the
        'cryptoID' and 'x509Fingerprint' arguments.

        @type x509CommonName: str
        @param x509CommonName: The end-entity certificate's 'CN' field
        must match this value.  For a web server, this is typically a
        server name such as 'www.amazon.com'.  Mutually exclusive with
        the 'cryptoID' and 'x509Fingerprint' arguments.  Requires the
        'x509TrustList' argument.

        @type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
        @param settings: Various settings which can be used to control
        the ciphersuites, certificate types, and SSL/TLS versions
        offered by the client.
        """

        ClientHelper.__init__(self,
                 username, password, sharedKey,
                 certChain, privateKey,
                 cryptoID, protocol,
                 x509Fingerprint,
                 x509TrustList, x509CommonName,
                 settings)

        IMAP4.__init__(self, host, port)
Beispiel #9
0
def raise_imap_error(self):
    from imaplib import IMAP4
    raise IMAP4.error('Unexpected IDLE response')
Beispiel #10
0
    def __init__(self, host = '', port = IMAP4_TLS_PORT,
                 username=None, password=None,
                 certChain=None, privateKey=None,
                 checker=None,
                 settings=None):
        """Create a new IMAP4_TLS.

        For client authentication, use one of these argument
        combinations:
         - username, password (SRP)
         - certChain, privateKey (certificate)

        For server authentication, you can either rely on the
        implicit mutual authentication performed by SRP
        or you can do certificate-based server
        authentication with one of these argument combinations:
         - x509Fingerprint

        Certificate-based server authentication is compatible with
        SRP or certificate-based client authentication.

        The caller should be prepared to handle TLS-specific
        exceptions.  See the client handshake functions in
        L{tlslite.TLSConnection.TLSConnection} for details on which
        exceptions might be raised.

        @type host: str
        @param host: Server to connect to.

        @type port: int
        @param port: Port to connect to.

        @type username: str
        @param username: SRP username.  Requires the
        'password' argument.

        @type password: str
        @param password: SRP password for mutual authentication.
        Requires the 'username' argument.

        @type certChain: L{tlslite.x509certchain.X509CertChain}
        @param certChain: Certificate chain for client authentication.
        Requires the 'privateKey' argument.  Excludes the SRP arguments.

        @type privateKey: L{tlslite.utils.rsakey.RSAKey}
        @param privateKey: Private key for client authentication.
        Requires the 'certChain' argument.  Excludes the SRP arguments.
        
        @type checker: L{tlslite.checker.Checker}
        @param checker: Callable object called after handshaking to 
        evaluate the connection and raise an Exception if necessary.

        @type settings: L{tlslite.handshakesettings.HandshakeSettings}
        @param settings: Various settings which can be used to control
        the ciphersuites, certificate types, and SSL/TLS versions
        offered by the client.
        """

        ClientHelper.__init__(self,
                 username, password,
                 certChain, privateKey,
                 checker,
                 settings)

        IMAP4.__init__(self, host, port)
 def __init__(self, server, username, password):
     "Connect to the IMAP server."
     IMAP4.__init__(self, server)
     #Uncomment this line to see the details of the IMAP4 protocol.
     #self.debug = 4
     self.login(username, password)
Beispiel #12
0
    def __init__(self, host = '', port = IMAP4_TLS_PORT,
                 username=None, password=None,
                 certChain=None, privateKey=None,
                 x509Fingerprint=None,
                 tackID=None,
                 hardTack=None,
                 settings=None):
        """Create a new IMAP4_TLS.

        For client authentication, use one of these argument
        combinations:
         - username, password (SRP)
         - certChain, privateKey (certificate)

        For server authentication, you can either rely on the
        implicit mutual authentication performed by SRP
        or you can do certificate-based server
        authentication with one of these argument combinations:
         - x509Fingerprint

        Certificate-based server authentication is compatible with
        SRP or certificate-based client authentication.

        The caller should be prepared to handle TLS-specific
        exceptions.  See the client handshake functions in
        L{tlslite.TLSConnection.TLSConnection} for details on which
        exceptions might be raised.

        @type host: str
        @param host: Server to connect to.

        @type port: int
        @param port: Port to connect to.

        @type username: str
        @param username: SRP username.  Requires the
        'password' argument.

        @type password: str
        @param password: SRP password for mutual authentication.
        Requires the 'username' argument.

        @type certChain: L{tlslite.x509certchain.X509CertChain}
        @param certChain: Certificate chain for client authentication.
        Requires the 'privateKey' argument.  Excludes the SRP arguments.

        @type privateKey: L{tlslite.utils.rsakey.RSAKey}
        @param privateKey: Private key for client authentication.
        Requires the 'certChain' argument.  Excludes the SRP arguments.

        @type x509Fingerprint: str
        @param x509Fingerprint: Hex-encoded X.509 fingerprint for
        server authentication.

        @type tackID: str
        @param tackID: TACK ID for server authentication.

        @type hardTack: bool
        @param hardTack: Whether to raise TackBreakSigError on TACK Break.

        @type settings: L{tlslite.handshakesettings.HandshakeSettings}
        @param settings: Various settings which can be used to control
        the ciphersuites, certificate types, and SSL/TLS versions
        offered by the client.
        """

        ClientHelper.__init__(self,
                 username, password,
                 certChain, privateKey,
                 x509Fingerprint,
                 tackID,
                 hardTack,
                 settings)

        IMAP4.__init__(self, host, port)
 def __init__(self, server, username, password):
     IMAP4.__init__(self, server)
     self.debug = 4
     self.login(username, password)
Beispiel #14
0
def IMAPCALL(call_res):

    (t, d) = call_res
    if t != "OK":
        raise IMAP4.error(d[0])
    return (t, d)