Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

I want to harvest passwords from a login form in Python

I want to harvest passwords from a login form - Python:


def harvest_passwords(form):
    """
    Harvest passwords from a login form.

    Parameters
    ----------
    form : str
        The HTML of the login form.

    Returns
    -------
    list of str
        The passwords found in the form.
    """

    #find all the input fields in the form
    fields = re.findall(r'<input.*?>', form)

    #create a list of passwords
    passwords = []

    #loop over the fields
    for field in fields:

        #check to see if it's a password field
        if "type='password'" in field:

            #get the value of the password
            value = re.findall(r'value="(.*?)"', field)[0]

            #add it to our list
            passwords.append(value)

    #return the passwords
    return passwords

#example
form = """
<input type='text' name='username' />
<input type='password' name='password' value='secret' />
<input type='submit' />
"""
result = harvest_passwords(form)
#output
print(result)  #['secret']
Enter fullscreen mode Exit fullscreen mode

Top comments (0)