A project for UFCD 9190: Introduction to Programming Applied to Cybersecurity
This project is part of UFCD 9190: Introduction to Programming Applied to Cybersecurity. It includes two main utilities:
syms.py: A script to identify and group duplicate files in a directory based on specific criteria.pycracker.py: A password-cracking utility designed to work with files formatted like/etc/shadow.
- Identify duplicate files by name.
- Group files by extension.
- Check for duplicate binary content (e.g., identical files).
- Use regex patterns to filter specific files.
- Cracks password hashes using a dictionary file.
- Supports multiple hashing algorithms like SHA-512, SHA-256, MD5, and bcrypt.
- Validates account statuses, ignoring locked or invalid accounts.
- Verbose output for better debugging and analysis.
The scripts demonstrate real-world applications of Python for file and cybersecurity tasks. They include proper error handling, support for multiple hashing schemes, and the ability to adapt to various input file structures.
To make the scripts executable, set the correct file permissions:
chmod 755 src/syms.py
chmod 755 src/pycracker.py
After setting the permissions, you can run the scripts directly:
./src/syms.py [OPTIONS] [DIR_PATH]
./src/pycracker.py [DICTIONARY] [PASSWORDS]
Alternatively, you can run the scripts using Python:
python src/syms.py
python src/pycracker.py
Here are some examples using the tests directory:
./src/syms.py -n tests
./src/syms.py -e tests
./src/syms.py -c tests
Find all files in tests starting with "test" or "Test" and ending with .txt:
./src/syms.py -r '^(test|Test).*\.txt$' tests
./src/syms.py --help
Run pycracker.py with a dictionary file and a shadow-like password file:
python src/pycracker.py ../tests/dict.txt ../tests/shadow.txt
Output:
[+] jgalamba : 'Lmxy20#a' (SHA-512)
[+] formando : 'abc' (SHA-256)
Use the -u flag to target a specific user:
python src/pycracker.py ../tests/dict.txt ../tests/shadow.txt -u jgalamba
Output:
[+] jgalamba : 'Lmxy20#a' (SHA-512)
Use the -v flag to see additional debug information:
python src/pycracker.py ../tests/dict.txt ../tests/shadow.txt -v
Output:
[!] Skipping user root: Account status is BLOCKED
[+] jgalamba : 'Lmxy20#a' (SHA-512)
python src/pycracker.py --help
This project uses a Python virtual environment for managing dependencies. Follow these steps:
python3 -m venv .venv
To activate the environment, run:
source .venv/bin/activate
.venv\Scripts\activate
To deactivate the environment:
deactivate
If the terminal is closed, navigate to the project directory and activate it again using the commands above.
If you encounter zsh: permission denied: .venv/bin/activate, follow these steps:
- Check permissions:
chmod +x .venv/bin/activate - Reactivate the environment:
source .venv/bin/activate - If the issue persists, recreate the virtual environment:
rm -rf .venv python3 -m venv .venv source .venv/bin/activate
After activating the virtual environment, install the dependencies:
pip install docopt passlib cryptography
To avoid conflicts, use the following command if needed:
python3 -m pip install passlib
Alternatively, you can install all dependencies from the requirements.txt file:
pip install -r requirements.txt
To maintain code quality and ensure consistent formatting, the following tools are recommended:
- Black: A Python code formatter that enforces PEP 8 compliance.
pip install black - Flake8: A Python linter for checking code style and potential errors.
pip install flake8
To apply Black and check linting, use the following commands:
# Format all files with Black
black .
# Check for linting issues with Flake8
flake8 .
In addition to syms.py, the repository includes the pycracker.py utility, which is currently under development. This script aims to perform password cracking using dictionaries and hash comparisons. Stay tuned for its progress!
For an optimized development experience in VS Code, we recommend the following extensions:
- Python: Provides IntelliSense, debugging, and tool integration. Install via:
code --install-extension ms-python.python - Pylance: Adds enhanced IntelliSense and type-checking. Install via:
code --install-extension ms-python.vscode-pylance
Project-specific recommendations are included in the .vscode/extensions.json file.
Made with β€οΈ for UFCD 9190.