Skip to content

Commit 22d3f69

Browse files
authored
Merge branch 'x4nth055:master' into master
2 parents afd61d9 + db9e815 commit 22d3f69

File tree

647 files changed

+110777
-3209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

647 files changed

+110777
-3209
lines changed

README.md

Lines changed: 103 additions & 5 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [Bluetooth Device Scanning in Python](https://thepythoncode.com/article/build-a-bluetooth-scanner-in-python)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import bluetooth
2+
3+
# Major and Minor Device Class definitions based on Bluetooth specifications
4+
MAJOR_CLASSES = {
5+
0: "Miscellaneous",
6+
1: "Computer",
7+
2: "Phone",
8+
3: "LAN/Network Access",
9+
4: "Audio/Video",
10+
5: "Peripheral",
11+
6: "Imaging",
12+
7: "Wearable",
13+
8: "Toy",
14+
9: "Health",
15+
10: "Uncategorized"
16+
}
17+
18+
MINOR_CLASSES = {
19+
# Computer Major Class
20+
(1, 0): "Uncategorized Computer", (1, 1): "Desktop Workstation",
21+
(1, 2): "Server-class Computer", (1, 3): "Laptop", (1, 4): "Handheld PC/PDA",
22+
(1, 5): "Palm-sized PC/PDA", (1, 6): "Wearable computer",
23+
# Phone Major Class
24+
(2, 0): "Uncategorized Phone", (2, 1): "Cellular", (2, 2): "Cordless",
25+
(2, 3): "Smartphone", (2, 4): "Wired modem or voice gateway",
26+
(2, 5): "Common ISDN Access",
27+
# LAN/Network Access Major Class
28+
(3, 0): "Fully available", (3, 1): "1% to 17% utilized",
29+
(3, 2): "17% to 33% utilized", (3, 3): "33% to 50% utilized",
30+
(3, 4): "50% to 67% utilized", (3, 5): "67% to 83% utilized",
31+
(3, 6): "83% to 99% utilized", (3, 7): "No service available",
32+
# Audio/Video Major Class
33+
(4, 0): "Uncategorized A/V", (4, 1): "Wearable Headset", (4, 2): "Hands-free Device",
34+
(4, 3): "Microphone", (4, 4): "Loudspeaker", (4, 5): "Headphones", (4, 6): "Portable Audio",
35+
(4, 7): "Car audio", (4, 8): "Set-top box", (4, 9): "HiFi Audio Device",
36+
(4, 10): "VCR", (4, 11): "Video Camera", (4, 12): "Camcorder",
37+
(4, 13): "Video Monitor", (4, 14): "Video Display and Loudspeaker",
38+
(4, 15): "Video Conferencing", (4, 16): "Gaming/Toy",
39+
# Peripheral Major Class
40+
(5, 0): "Not Keyboard/Not Pointing Device", (5, 1): "Keyboard",
41+
(5, 2): "Pointing device", (5, 3): "Combo Keyboard/Pointing device",
42+
# Imaging Major Class
43+
(6, 0): "Display", (6, 1): "Camera", (6, 2): "Scanner", (6, 3): "Printer",
44+
# Wearable Major Class
45+
(7, 0): "Wristwatch", (7, 1): "Pager", (7, 2): "Jacket",
46+
(7, 3): "Helmet", (7, 4): "Glasses",
47+
# Toy Major Class
48+
(8, 0): "Robot", (8, 1): "Vehicle",
49+
(8, 2): "Doll / Action figure",
50+
(8, 3): "Controller", (8, 4): "Game",
51+
# Health Major Class
52+
(9, 0): "Undefined", (9, 1): "Blood Pressure Monitor",
53+
(9, 2): "Thermometer", (9, 3): "Weighing Scale",
54+
(9, 4): "Glucose Meter", (9, 5): "Pulse Oximeter",
55+
(9, 6): "Heart/Pulse Rate Monitor", (9, 7): "Health Data Display",
56+
(9, 8): "Step Counter", (9, 9): "Body Composition Analyzer",
57+
(9, 10): "Peak Flow Monitor", (9, 11): "Medication Monitor",
58+
(9, 12): "Knee Prosthesis", (9, 13): "Ankle Prosthesis",
59+
# More specific definitions can be added if needed
60+
}
61+
62+
def parse_device_class(device_class):
63+
major = (device_class >> 8) & 0x1F # divide by 2**8 and mask with 0x1F (take the last 5 bits)
64+
minor = (device_class >> 2) & 0x3F # divide by 2**2 and mask with 0x3F (take the last 6 bits)
65+
major_class_name = MAJOR_CLASSES.get(major, "Unknown Major Class")
66+
minor_class_key = (major, minor)
67+
minor_class_name = MINOR_CLASSES.get(minor_class_key, "Unknown Minor Class")
68+
return major_class_name, minor_class_name
69+
70+
71+
def scan_bluetooth_devices():
72+
try:
73+
discovered_devices = bluetooth.discover_devices(duration=8, lookup_names=True, lookup_class=True)
74+
print('[!] Scanning for Bluetooth devices...')
75+
print(f"[!] Found {len(discovered_devices)} Devices")
76+
for addr, name, device_class in discovered_devices:
77+
major_class, minor_class = parse_device_class(device_class)
78+
print(f"[+] Device Name: {name}")
79+
print(f" Address: {addr}")
80+
print(f" Device Class: {device_class} ({major_class}, {minor_class})")
81+
except Exception as e:
82+
print(f"[ERROR] An error occurred: {e}")
83+
84+
if __name__ == "__main__":
85+
scan_bluetooth_devices()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pybluez2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Create a Custom Wordlist in Python](https://thepythoncode.com/article/make-a-wordlist-generator-in-python)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Import the argparse module for handling command line arguments.
2+
# Import the itertools module for generating combinations.
3+
import argparse, itertools
4+
5+
6+
# Define a function to generate a wordlist based on given parameters.
7+
def generate_wordlist(characters, min_length, max_length, output_file):
8+
# Open the output file in write mode.
9+
with open(output_file, 'w') as file:
10+
# Iterate over the range of word lengths from min_length to max_length.
11+
for length in range(min_length, max_length + 1):
12+
# Generate all possible combinations of characters with the given length.
13+
for combination in itertools.product(characters, repeat=length):
14+
# Join the characters to form a word and write it to the file
15+
word = ''.join(combination)
16+
file.write(word + '\n')
17+
18+
19+
# Create an ArgumentParser object for handling command line arguments.
20+
parser = argparse.ArgumentParser(description="Generate a custom wordlist similar to crunch.")
21+
22+
# Define command line arguments.
23+
parser.add_argument("-c", "--characters", type=str, default="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
24+
help="Set of characters to include in the wordlist")
25+
parser.add_argument("-min", "--min_length", type=int, default=4, help="Minimum length of the words")
26+
parser.add_argument("-max", "--max_length", type=int, default=6, help="Maximum length of the words")
27+
parser.add_argument("-o", "--output_file", type=str, default="custom_wordlist.txt", help="Output file name")
28+
29+
# Parse the command line arguments.
30+
args = parser.parse_args()
31+
32+
# Call the generate_wordlist function with the provided arguments.
33+
generate_wordlist(args.characters, args.min_length, args.max_length, args.output_file)
34+
35+
# Print a message indicating the wordlist has been generated and saved.
36+
print(f"[+] Wordlist generated and saved to {args.output_file}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# [How to Implement the Caesar Cipher in Python](https://thepythoncode.com/article/implement-caesar-cipher-in-python)
2+
# [How to Crack the Caesar Cipher in Python](https://thepythoncode.com/article/how-to-crack-caesar-cipher-in-python)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys # The sys module for system-related operations.
2+
from colorama import Fore, init # Import the colorama for colored text
3+
4+
init() # Initialize the colorama library for colored text.
5+
6+
7+
def implement_caesar_cipher(message, key, decrypt=False):
8+
# Initialize an empty string to store the result.
9+
result = ""
10+
# Iterate through each character in the user's input message.
11+
for character in message:
12+
# Check if the character is an alphabet letter.
13+
if character.isalpha():
14+
# Determine the shift amount based. i.e the amount of times to be shifted e.g 2,3,4....
15+
shift = key if not decrypt else -key
16+
# Check if the character is a lowercase letter.
17+
if character.islower():
18+
# Apply Caesar cipher transformation for lowercase letters.
19+
result += chr(((ord(character) - ord('a') + shift) % 26) + ord('a'))
20+
else:
21+
# Apply Caesar cipher transformation for uppercase letters.
22+
result += chr(((ord(character) - ord('A') + shift) % 26) + ord('A'))
23+
else:
24+
# Preserve non-alphabet characters as they are.
25+
result += character
26+
return result # Return the encrypted or decrypted result.
27+
28+
29+
# Prompt the user to enter the text to be encrypted
30+
text_to_encrypt = input(f"{Fore.GREEN}[?] Please Enter your text/message: ")
31+
# Prompt the user to specify the shift length (the key).
32+
key = int(input(f"{Fore.GREEN}[?] Please specify the shift length: "))
33+
34+
35+
# Check if the specified key is within a valid range (0 to 25).
36+
if key > 25 or key < 0:
37+
# Display an error message if the key is out of range.
38+
print(f"{Fore.RED}[!] Your shift length should be between 0 and 25 ")
39+
sys.exit() # Exit the program if the key is invalid.
40+
41+
# Encrypt the user's input using the specified key.
42+
encrypted_text = implement_caesar_cipher(text_to_encrypt, key)
43+
44+
# Display the encrypted text.
45+
print(f"{Fore.GREEN}[+] {text_to_encrypt} {Fore.MAGENTA}has been encrypted as {Fore.RED}{encrypted_text}")
46+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Import colorama for colorful text.
2+
from colorama import Fore, init
3+
4+
init()
5+
6+
7+
# Define a function for Caesar cipher encryption.
8+
def implement_caesar_cipher(text, key, decrypt=False):
9+
# Initialize an empty string to store the result.
10+
result = ""
11+
12+
# Iterate through each character in the input text.
13+
for char in text:
14+
# Check if the character is alphabetical.
15+
if char.isalpha():
16+
# Determine the shift value using the provided key (or its negation for decryption).
17+
shift = key if not decrypt else -key
18+
19+
# Check if the character is lowercase
20+
if char.islower():
21+
# Apply the Caesar cipher encryption/decryption formula for lowercase letters.
22+
result += chr(((ord(char) - ord('a') + shift) % 26) + ord('a'))
23+
else:
24+
# Apply the Caesar cipher encryption/decryption formula for uppercase letters.
25+
result += chr(((ord(char) - ord('A') + shift) % 26) + ord('A'))
26+
else:
27+
# If the character is not alphabetical, keep it as is e.g. numbers, punctuation
28+
result += char
29+
30+
# Return the result, which is the encrypted or decrypted text
31+
return result
32+
33+
34+
# Define a function for cracking the Caesar cipher.
35+
def crack_caesar_cipher(ciphertext):
36+
# Iterate through all possible keys (0 to 25) as there 26 alphabets.
37+
for key in range(26):
38+
# Call the caesar_cipher function with the current key to decrypt the text.
39+
decrypted_text = implement_caesar_cipher(ciphertext, key, decrypt=True)
40+
41+
# Print the result, showing the decrypted text for each key
42+
print(f"{Fore.RED}Key {key}: {decrypted_text}")
43+
44+
45+
# Initiate a continuous loop so the program keeps running.
46+
while True:
47+
# Accept user input.
48+
encrypted_text = input(f"{Fore.GREEN}[?] Please Enter the text/message to decrypt: ")
49+
# Check if user does not specify anything.
50+
if not encrypted_text:
51+
print(f"{Fore.RED}[-] Please specify the text to decrypt.")
52+
else:
53+
crack_caesar_cipher(encrypted_text)
54+
55+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
colorama
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Check Password Strength with Python](https://thepythoncode.com/article/test-password-strength-with-python)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from zxcvbn import zxcvbn
2+
import pprint, getpass, sys
3+
4+
5+
def test_single_password():
6+
password = getpass.getpass("[?] Enter your password: ")
7+
result = zxcvbn(password)
8+
print(f"Value: {result['password']}")
9+
print(f"Password Score: {result['score']}/4")
10+
print(f"Crack Time: {result['crack_times_display']['offline_slow_hashing_1e4_per_second']}")
11+
print(f"Feedback: {result['feedback']['suggestions']}")
12+
#pprint.pp(result)
13+
14+
15+
def test_multiple_passwords(password_file):
16+
try:
17+
with open(password_file, 'r') as passwords:
18+
for password in passwords:
19+
result = zxcvbn(password.strip('\n'))
20+
print('\n[+] ######################')# for readability
21+
print(f"Value: {result['password']}")
22+
print(f"Password Score: {result['score']}/4")
23+
print(f"Crack Time: {result['crack_times_display']['offline_slow_hashing_1e4_per_second']}")
24+
print(f"Feedback: {result['feedback']['suggestions']}")
25+
#pprint.pp(result)
26+
27+
except Exception:
28+
print('[!] Please make sure to specify an accessible file containing passwords.')
29+
30+
31+
if len(sys.argv) == 2:
32+
test_multiple_passwords(sys.argv[1])
33+
elif len(sys.argv) == 1:
34+
test_single_password()
35+
else:
36+
print('Usage: python test_password_strength.py <file> (for a file containing passwords) or \
37+
\npython test_password_strength.py (for a single password.)')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
password
2+
1234567
3+
abc123cba159
4+
Sioplabxtre_9lTGCE
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zxcvbn
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Make a Clickjacking Vulnerability Scanner in Python](https://thepythoncode.com/article/make-a-clickjacking-vulnerability-scanner-with-python)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import requests, argparse
2+
3+
4+
# Function to check if a website is vulnerable to clickjacking.
5+
def check_clickjacking(url):
6+
try:
7+
# Add https:// schema if not present in the URL.
8+
if not url.startswith('http://') and not url.startswith('https://'):
9+
url = 'https://' + url
10+
11+
# Send a GET request to the URL.
12+
response = requests.get(url)
13+
headers = response.headers
14+
15+
# Check for X-Frame-Options header.
16+
if 'X-Frame-Options' not in headers:
17+
return True
18+
19+
# Get the value of X-Frame-Options and check it..
20+
x_frame_options = headers['X-Frame-Options'].lower()
21+
if x_frame_options != 'deny' and x_frame_options != 'sameorigin':
22+
return True
23+
24+
return False
25+
except requests.exceptions.RequestException as e:
26+
print(f"An error occurred while checking {url} - {e}")
27+
return False
28+
29+
# Main function to parse arguments and check the URL.
30+
def main():
31+
parser = argparse.ArgumentParser(description='Clickjacking Vulnerability Scanner')
32+
parser.add_argument('url', type=str, help='The URL of the website to check')
33+
parser.add_argument('-l', '--log', action='store_true', help='Print out the response headers for analysis')
34+
args = parser.parse_args()
35+
36+
url = args.url
37+
is_vulnerable = check_clickjacking(url)
38+
39+
if is_vulnerable:
40+
print(f"[+] {url} may be vulnerable to clickjacking.")
41+
else:
42+
print(f"[-] {url} is not vulnerable to clickjacking.")
43+
44+
if args.log:
45+
# Add https:// schema if not present in the URL for response printing.
46+
if not url.startswith('http://') and not url.startswith('https://'):
47+
url = 'https://' + url
48+
49+
print("\nResponse Headers:")
50+
response = requests.get(url)
51+
for header, value in response.headers.items():
52+
print(f"{header}: {value}")
53+
54+
if __name__ == '__main__':
55+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Crack the Affine Cipher in Python](https://thepythoncode.com/article/how-to-crack-the-affine-cipher-in-python)

0 commit comments

Comments
 (0)