Skip to content

Commit

Permalink
Merge pull request #1114 from djv554/main
Browse files Browse the repository at this point in the history
Added a malware scanner
  • Loading branch information
UTSAVS26 authored Nov 8, 2024
2 parents 3f30953 + 61d08de commit cf01542
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Cybersecurity_Tools/Malware Scanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Simple Malware Scanner

## Overview

This is a simple malware scanner written in Python. It allows users to scan individual files or directories for known malware by comparing their hash values against a predefined list of malicious signatures. This tool is lightweight and designed to provide a basic level of malware detection using SHA-256 hash comparisons.

## Features

- **File Scanning**: Scan individual files for known malware by checking their hash values.
- **Directory Scanning**: Recursively scan all files within a directory to detect any potential malware.
- **Malware Detection**: Uses SHA-256 hashing to compare files against known malware signatures.
- **Logging**: Logs the results of the scans, including the files that were scanned and any malware detected.
- **Color-Coded Output**: Uses color-coded messages to indicate whether a file is clean or potentially malicious.
- **Easy to Use**: Simple command-line interface for scanning files or directories.

## Libraries Needed

To run the malware scanner, you'll need the following Python libraries:

1. **`hashlib`** (Python Standard Library) - Used for generating the SHA-256 hashes of files.
2. **`os`** (Python Standard Library) - Used to check file paths and traverse directories.
3. **`logging`** (Python Standard Library) - Used for logging scan results.
4. **`colorama`** - Used to display colored output in the terminal.

## Conclusion

This simple malware scanner provides a foundational tool for detecting known malware based on hash signatures. While it is not a complete antivirus solution, it can be useful for basic scanning tasks or as part of a larger security toolkit. It demonstrates how file integrity can be checked using hash comparisons and how malware signatures can be detected in a straightforward manner.
73 changes: 73 additions & 0 deletions Cybersecurity_Tools/Malware Scanner/malware_scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os
import hashlib
import logging
from colorama import Fore, Style

# Predefined malware signatures (hashes of known malware files)
MALWARE_SIGNATURES = {
"EICAR_Test_File": "275a021bbfb648aa3206d6e4d8c662c7e542c1686c5b167b2f832d83b1455a4f", # EICAR test file hash
}

# Setup logging
logging.basicConfig(filename='malware_scan.log', level=logging.INFO, format='%(asctime)s - %(message)s')

def get_file_hash(file_path):
"""Generate SHA-256 hash of a file."""
hasher = hashlib.sha256()
try:
with open(file_path, "rb") as file:
while chunk := file.read(8192):
hasher.update(chunk)
return hasher.hexdigest()
except OSError as e:
print(Fore.RED + f"Error reading file {file_path}: {e}" + Style.RESET_ALL)
return None

def log_scan_result(file_path, message):
"""Log scan result to a file."""
logging.info(f"{file_path}: {message}")

def scan_file(file_path):
"""Scan a file for known malware signatures."""
if not os.path.isfile(file_path):
print(Fore.RED + f"File '{file_path}' does not exist." + Style.RESET_ALL)
return

file_hash = get_file_hash(file_path)
if not file_hash:
return

for malware_name, signature in MALWARE_SIGNATURES.items():
if file_hash == signature:
print(Fore.RED + f"Alert! File '{file_path}' matches malware signature: {malware_name}" + Style.RESET_ALL)
log_scan_result(file_path, f"Malware found: {malware_name}")
return

print(Fore.GREEN + f"File '{file_path}' is clean." + Style.RESET_ALL)
log_scan_result(file_path, "Clean")

def scan_directory(directory_path):
"""Scan all files in a directory recursively."""
if not os.path.isdir(directory_path):
print(Fore.RED + f"Directory '{directory_path}' does not exist." + Style.RESET_ALL)
return

for root, dirs, files in os.walk(directory_path):
for file in files:
file_path = os.path.join(root, file)
scan_file(file_path)

def main():
print("Simple Malware Scanner")
choice = input("1: Scan a file, 2: Scan a directory: ")
if choice == "1":
file_path = input("Enter the path of the file to scan: ")
scan_file(file_path)
elif choice == "2":
directory_path = input("Enter the directory path to scan: ")
scan_directory(directory_path)
else:
print("Invalid choice")

if __name__ == "__main__":
main()
32 changes: 32 additions & 0 deletions Cybersecurity_Tools/Password Manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## **Password Manager**

### 🎯 **Goal**

The goal of the code is to create a simple, secure password manager that encrypts and stores passwords for various websites or services, ensuring they can be safely retrieved later. It checks the strength of passwords before storing them and allows users to manage their passwords using strong encryption techniques.

### 🧾 **Description**

This is a simple password manager built with Streamlit, allowing users to securely store, encrypt, and manage their passwords. The application uses AES encryption (via the `cryptography` library) to securely store passwords (in a passwords.txt file), and it includes functionality to generate encryption keys and check password strength before storing passwords. Users can add passwords, view stored passwords, and generate encryption keys all through an easy-to-use graphical interface.

Key Features
- **Password Encryption**: Encrypts and stores passwords securely.
- **Password Strength Validation**: Ensures the password is strong before storing it.
- **Password Viewing**: Decrypts and displays saved passwords when requested.
- **Key Generation**: Generates and stores a unique encryption key for secure password storage.
- **Cross-Platform**: Runs in a browser, supported across multiple platforms.


### 📚 **Libraries Needed**

The following Python libraries are required to run the project:

- **Streamlit**: For creating the web-based user interface.
- **Cryptography**: To provide AES encryption and decryption.
- **Re**: For regular expression-based password strength checking.
- **Getpass**: For securely handling password inputs (optional for CLI-based password entry).


### 📢 **Conclusion**

This password manager provides a secure and simple way to manage your passwords through encryption. By utilizing Streamlit, it offers a friendly graphical interface, making it easy for users to store and retrieve passwords securely. The application ensures password strength before encryption and allows easy key generation for security.

102 changes: 102 additions & 0 deletions Cybersecurity_Tools/Password Manager/password-manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import os
import re
import streamlit as st
from cryptography.fernet import Fernet
from getpass import getpass

# Load the encryption key
def load_key():
if not os.path.exists("key.key"):
st.error("Encryption key not found. Please generate a key first.")
return None
return open("key.key", "rb").read()

# Function to generate a new encryption key
def generate_key():
key = Fernet.generate_key()
with open("key.key", "wb") as key_file:
key_file.write(key)
st.success("Encryption key generated successfully!")

# Encrypt a password and save it to the file
def encrypt_password(website, username, password):
key = load_key()
if not key:
return

fernet = Fernet(key)
encrypted_password = fernet.encrypt(password.encode())

with open("passwords.txt", "a") as file:
file.write(f"{website},{username},{encrypted_password.decode()}\n")

st.success(f"Password for {website} saved successfully!")

# Decrypt and display the stored passwords
def view_passwords():
key = load_key()
if not key:
return

fernet = Fernet(key)

if not os.path.exists("passwords.txt"):
st.warning("No passwords found.")
return

with open("passwords.txt", "r") as file:
for line in file.readlines():
website, username, encrypted_password = line.strip().split(",")
decrypted_password = fernet.decrypt(encrypted_password.encode()).decode()
st.write(f"**Website**: {website} | **Username**: {username} | **Password**: {decrypted_password}")

# Function to check password strength
def check_password_strength(password):
if len(password) < 8:
return False, "Password too short. It should be at least 8 characters long."
if not re.search("[a-z]", password):
return False, "Password should contain at least one lowercase letter."
if not re.search("[A-Z]", password):
return False, "Password should contain at least one uppercase letter."
if not re.search("[0-9]", password):
return False, "Password should contain at least one digit."
if not re.search("[@#$%^&*!]", password):
return False, "Password should contain at least one special character (e.g., @, #, $, etc.)."
return True, "Password is strong."

# Streamlit app starts here
st.title("Password Manager")

# Main program
menu = ["Add Password", "View Passwords", "Generate Key", "Exit"]
choice = st.sidebar.selectbox("Menu", menu)

if choice == "Add Password":
st.subheader("Add New Password")

website = st.text_input("Enter the website name")
username = st.text_input("Enter the username")
password = st.text_input("Enter the password", type="password")

if st.button("Save Password"):
if website and username and password:
valid, message = check_password_strength(password)
if not valid:
st.warning(f"Password not strong enough: {message}")
else:
encrypt_password(website, username, password)
else:
st.warning("Please fill in all fields")

elif choice == "View Passwords":
st.subheader("View Stored Passwords")
view_passwords()

elif choice == "Generate Key":
st.subheader("Generate Encryption Key")
if st.button("Generate Key"):
generate_key()

elif choice == "Exit":
st.subheader("Thank you for using the Password Manager!")

4 changes: 4 additions & 0 deletions Project-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
* [Ids Ips](Cybersecurity_Tools/IDS_IPS%20Tool/ids_ips.py)
* Keylogger
* [Keylogger](Cybersecurity_Tools/Keylogger/keylogger.py)
* Malware Scanner
* [Malware Scanner](Cybersecurity_Tools/Malware%20Scanner/malware_scanner.py)
* Netwrok Packet Analyzer
* [Packet Analyzer](Cybersecurity_Tools/Netwrok%20Packet%20Analyzer/packet_analyzer.py)
* Pdf Malware Detection
Expand All @@ -420,6 +422,8 @@
* [Predict](Cybersecurity_Tools/PDF_Malware_Detection/predict.py)
* Packet-Sniffer
* [Packetsniffer](Cybersecurity_Tools/Packet-sniffer/packetsniffer.py)
* Password Manager
* [Password-Manager](Cybersecurity_Tools/Password%20Manager/password-manager.py)
* Password Strength Checker
* [Password Strength Checker](Cybersecurity_Tools/Password%20Strength%20Checker/password_strength_checker.py)
* Phishing Detection Tool
Expand Down

0 comments on commit cf01542

Please sign in to comment.