StackZero
  • Homepage
  • Cryptography and Privacy
  • Ethical Hacking
  • Reverse Engineering
  • Contacts
  • About Me
No Result
View All Result
StackZero
No Result
View All Result

How to Easily Create a zip password cracker in Just Seconds!

May 19, 2022
in Cryptography and Privacy
0 0
How to Easily Create a zip password cracker in Just Seconds!
0
SHARES
505
VIEWS
Share on FacebookShare on Twitter

If you’ve ever forgotten a password for a zip file, you know how frustrating it can be.
There’s no need to worry anymore because in this article we’ll show you how to crack a zip password using a dictionary attack.
Usually, zip files are protected with very simple passwords.
With a dictionary attack, you can use a list of common passwords to try and guess the password for a zip file. This is a very effective method, and it’s easy to do. So let’s get started to code our zip password cracker!

Table of Contents

Toggle
  • Prerequisites
  • The code
  • The main method
  • How to launch zip password cracker
  • Conclusion and improvements
  • Further readings

Prerequisites

In order to complete the project you just need:

  • Python
  • pyzipper library
  • progress library
  • A good wordlist (Check on Google or look here)

You don’t need anything more, so we can start with the code.

The code

Imports:

from optparse import OptionParser
import pyzipper
from progress.bar import Bar

Auxiliary methods

def get_wordlist(wordlist_file):
    with open(wordlist_file, 'r') as f:
        return f.read().split('\n')

The first method gets the wordlist from a file and saves it into a file (if the list is too big, think to use a generator).

def extract(file_name):

    with pyzipper.AESZipFile(file_name, 'r') as f:
        f.extractall(pwd = bytes(p, 'utf-8'))

This is the method that extracts the file.

The main method

if __name__ == "__main__":



    parser = OptionParser()
    parser.add_option("-f", "--file", dest="filename",
                        help="compressed file", metavar="FILE")
    parser.add_option("-w", "--wordlist", dest="wordlist", 
                        help="Select the wordlist", metavar="WORDLIST")

    (options, args) = parser.parse_args()
    print(options.wordlist)
    for p in Bar('Processing').iter(get_wordlist(options.wordlist)):
        try:
            extract(options.filename)
            print(f"\n[+] Password found: {p}")
            break
        except RuntimeError as e:
            pass

The first part is just an argument’s parsing, easy to understand.
The extract generates an Exception in case of failure, so into the for loop we try the extract until it doesn’t throw the RuntimeException.

How to launch zip password cracker

Let’s see the complete code:

from optparse import OptionParser
import pyzipper
from progress.bar import Bar

def get_wordlist(wordlist_file):
    with open(wordlist_file, 'r') as f:
        return f.read().split('\n')


def extract(file_name):

    with pyzipper.AESZipFile(file_name, 'r') as f:
        f.extractall(pwd = bytes(p, 'utf-8'))       

if __name__ == "__main__":

    parser = OptionParser()
    parser.add_option("-f", "--file", dest="filename",
                        help="compressed file", metavar="FILE")
    parser.add_option("-w", "--wordlist", dest="wordlist", 
                        help="Select the wordlist", metavar="WORDLIST")

    (options, args) = parser.parse_args()
    print(options.wordlist)
    for p in Bar('Processing').iter(get_wordlist(options.wordlist)):
        try:
            extract(options.filename)
            print(f"\n[+] Password found: {p}")
            break
        except RuntimeError as e:
            pass

After saving our script in a file called main.py we can launch it with the following command:

python3 main.py -f test.zip -w wordlist.dic

The output will be something similar to this:

Processing |########################        | 21168/27608
[+] Password found: roland

Conclusion and improvements

With this project, you can see how easy is an attack on a zip password-protected file, so try to use the most secure ones for your important files.

You can also try to make some improvements, you could add numbers to the ends, or maybe you can merge words from two files.

Further readings

If you liked to write the zip password cracker in python, you may want to read those articles:

  • Write subdomain scanner in python
  • Create a network scanner in python
How to easily change your Windows Mac Address in Python
Trending
How to easily change your Windows Mac Address in Python

Tags: attackbruteforcecrackdictionaryenumerationpasswordpythonpyzipperwordlistzip
Previous Post

How to easily encrypt file in Python

Next Post

How to Hide Messages in Pictures with Python: Steganography

Next Post
How to Hide Messages in Pictures with Python: Steganography

How to Hide Messages in Pictures with Python: Steganography

You might also like

Cryptographic functions

Cryptographic Hash Functions in Python: Secure Your Data Easily

November 3, 2024
Malware Obfuscation Techniques: All That You Need To Know

Malware Obfuscation Techniques: All That You Need To Know

March 25, 2024
How To Do Process Enumeration: An Alternative Way

How To Do Process Enumeration: An Alternative Way

March 4, 2024
How To Do DLL Injection: An In-Depth Cybersecurity Example

How To Do DLL Injection: An In-Depth Cybersecurity Example

February 8, 2024
Process Injection By Example: The Complete Guide

Process Injection By Example: The Complete Guide

January 24, 2024
How To Build Your Own: Python String Analysis for Malware Insights

How To Build Your Own: Python String Analysis for Malware Insights

November 10, 2023

StackZero

StackZero is a specialized technical blog dedicated to the realm of cybersecurity. It primarily provides insightful articles and comprehensive tutorials designed to educate readers on developing security tools. The blog encompasses a broad spectrum of subjects, starting from the foundational principles of cryptography and extending to more sophisticated areas such as exploitation and reverse engineering. This makes StackZero an invaluable resource for both beginners and professionals in the field of cybersecurity.
The blog covers a wide range of topics, from the basics of cryptography to the more advanced topics of exploitation and reverse engineering.

Tags

application security blind sqli blind sql injection bruteforce c cesar cipher command injection cryptography ctf cybersecurity debugging dom-based xss dvwa ethical-hacking ethical hacking exploitation file inclusion gdb hacking injection javascript malware malware analysis malware evasion network-security pentesting lab picoctf pico ctf python reflected xss reverse engineering sql sqli sql injection static analysis stored xss substitution substitution cipher vulnerable application web application security web exploitation web security windows windows api xss
  • About Me
  • Contacts
  • HomePage
  • Opt-out preferences
  • Privacy Policy
  • Terms and Conditions

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
No Result
View All Result
  • Homepage
  • Cryptography and Privacy
  • Ethical Hacking
  • Reverse Engineering
  • Contacts
  • About Me