1. Hashing Passwords:
import hashlib
def hash_password(password):
hashed_password = hashlib.sha256(password.encode()).hexdigest()
return hashed_password
# Example
password = "my_secure_password"
hashed_password = hash_password(password)
print("Hashed Password:", hashed_password)
#clcoding.com
Hashed Password: 2c9a8d02fc17ae77e926d38fe83c3529d6638d1d636379503f0c6400e063445f
2. Generating Random Passwords:
import random
import string
def generate_random_password(length=12):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for _ in range(length))
return password
# Example
random_password = generate_random_password()
print("Random Password:", random_password)
#clcoding.com
Random Password: zH7~ANoO:7#S
3. Network Scanning with Scapy:
from scapy.all import IP, ICMP, sr1
def ping(host):
packet = IP(dst=host)/ICMP()
response = sr1(packet, timeout=2, verbose=0)
if response:
return f"{host} is online"
else:
return f"{host} is offline"
# Example
host_to_scan = "example.com"
result = ping(host_to_scan)
print(result)
#clcoding.com
4. Web Scraping for Security Research:
import requests
from bs4 import BeautifulSoup
def scrape_security_news():
url = "https://example-security-news.com"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
headlines = soup.find_all('h2', class_='security-headline')
return [headline.text for headline in headlines]
# Example
security_headlines = scrape_security_news()
print("Security Headlines:", security_headlines)
#clcoding.com
5. Password Cracking Simulation:
import hashlib
def simulate_password_cracking(hashed_password, password_list):
for password in password_list:
if hashlib.sha256(password.encode()).hexdigest() == hashed_password:
return f"Password cracked: {password}"
return "Password not found"
# Example
hashed_password_to_crack = "d033e22ae348aeb5660fc2140aec35850c4da997"
common_passwords = ["password", "123456", "qwerty", "admin"]
result = simulate_password_cracking(hashed_password_to_crack, common_passwords)
print(result)
#clcoding.com
6. Secure File Handling:
import os
def secure_file_deletion(file_path):
with open(file_path, 'w') as file:
file.write(os.urandom(1024))
# Overwrite the file with random data
os.remove(file_path)
print(f"{file_path} securely deleted")
# Example
file_path_to_delete = "example.txt"
secure_file_deletion(file_path_to_delete)
#clcoding.com
0 Comments:
Post a Comment