├── groups ├── files │ ├── decrypted-file.txt │ └── received-file.gpg ├── server_ip ├── group_port.txt ├── temp.txt ├── group_server.py └── group_client.py ├── broadcasting ├── server_ip ├── temp.txt ├── commands.txt ├── files │ ├── decrypted-file.txt │ └── received-file.gpg ├── broadcasting_server.py └── broadcasting_client.py ├── screenshots ├── chat box.png ├── group client.png ├── group server.png ├── encrypted file.png ├── broadcasting client.png └── broadcasting server.png ├── Documents └── Major Project Report.pdf ├── support-files ├── get_ip.py ├── udp_client.py ├── client.py ├── server.py ├── udp_server.py └── run.py ├── new_features_to_add.md ├── .gitignore ├── chat ├── chat_server.py └── chat_client.py ├── README.md └── LICENSE /groups/files/decrypted-file.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /groups/server_ip: -------------------------------------------------------------------------------- 1 | 10.42.0.1 2 | -------------------------------------------------------------------------------- /broadcasting/server_ip: -------------------------------------------------------------------------------- 1 | 10.42.0.1 2 | -------------------------------------------------------------------------------- /broadcasting/temp.txt: -------------------------------------------------------------------------------- 1 | date 2 | date 3 | uptime 4 | 10.42.0.1 5 | -------------------------------------------------------------------------------- /broadcasting/commands.txt: -------------------------------------------------------------------------------- 1 | sudo apt-get update 2 | sudo apt get install vim -------------------------------------------------------------------------------- /groups/group_port.txt: -------------------------------------------------------------------------------- 1 | 9911 - Group A 2 | 9922 - Group B 3 | 9933 - Group C -------------------------------------------------------------------------------- /broadcasting/files/decrypted-file.txt: -------------------------------------------------------------------------------- 1 | date 2 | date 3 | uptime 4 | 10.42.0.1 5 | -------------------------------------------------------------------------------- /groups/temp.txt: -------------------------------------------------------------------------------- 1 | date 2 | date 3 | uptime 4 | sudo apt-get updaye 5 | 10.42.0.1 6 | -------------------------------------------------------------------------------- /screenshots/chat box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/screenshots/chat box.png -------------------------------------------------------------------------------- /screenshots/group client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/screenshots/group client.png -------------------------------------------------------------------------------- /screenshots/group server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/screenshots/group server.png -------------------------------------------------------------------------------- /groups/files/received-file.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/groups/files/received-file.gpg -------------------------------------------------------------------------------- /screenshots/encrypted file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/screenshots/encrypted file.png -------------------------------------------------------------------------------- /Documents/Major Project Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/Documents/Major Project Report.pdf -------------------------------------------------------------------------------- /screenshots/broadcasting client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/screenshots/broadcasting client.png -------------------------------------------------------------------------------- /screenshots/broadcasting server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/screenshots/broadcasting server.png -------------------------------------------------------------------------------- /broadcasting/files/received-file.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Colviz/Linux-based-secure-systems-manager/HEAD/broadcasting/files/received-file.gpg -------------------------------------------------------------------------------- /support-files/get_ip.py: -------------------------------------------------------------------------------- 1 | #This script print the output of arp -an in output file 2 | with open('server_ip','r') as f: #File opening in read mode, take input to output file as arp -e 3 | next(f) #Going to the next line (skipping the header row) 4 | for line in f: #Fetching content line by line 5 | print(line.split(' ')[0]) #Prints the first word of line -------------------------------------------------------------------------------- /support-files/udp_client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import socket 3 | 4 | UDP_IP = "" 5 | UDP_PORT = 5005 6 | 7 | sock = socket.socket(socket.AF_INET, # Internet 8 | socket.SOCK_DGRAM) # UDP 9 | sock.bind(('', UDP_PORT)) 10 | 11 | while True: 12 | data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes 13 | print "received message:", data 14 | -------------------------------------------------------------------------------- /support-files/client.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | def Main(): 4 | host = '127.0.0.1' 5 | port = 5000 6 | 7 | s = socket.socket() 8 | s.connect((host, port)) 9 | 10 | message = raw_input('-->') 11 | while message != 'q': 12 | s.send(message) 13 | data = s.recv(1024) 14 | print "server: " + str(data) 15 | message = raw_input('-->') 16 | 17 | s.close() 18 | 19 | if __name__ == '__main__': 20 | Main() 21 | -------------------------------------------------------------------------------- /support-files/server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | def get_my_ip(): 4 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 5 | s.connect(("8.8.8.8", 80)) 6 | return s.getsockname()[0] 7 | 8 | def Main(): 9 | host = get_my_ip() 10 | port = 5001 11 | 12 | s = socket.socket() 13 | s.bind((host, port)) 14 | 15 | s.listen(1) 16 | c,addr = s.accept() 17 | 18 | print "connection from : " + str(addr) 19 | 20 | while True: 21 | data = c.recv(1024) 22 | if not data: 23 | break 24 | print "client :" + str(data) 25 | 26 | data = raw_input('-->') 27 | print "sending " + str(data) 28 | c.send(data) 29 | c.close() 30 | if __name__ == '__main__': 31 | Main(); 32 | -------------------------------------------------------------------------------- /support-files/udp_server.py: -------------------------------------------------------------------------------- 1 | """ 2 | #Code for sending UDP message to a specific client 3 | 4 | import socket 5 | 6 | UDP_IP = "192.168.43.234" 7 | UDP_PORT = 5005 8 | MESSAGE = "Hello, rishabh!" 9 | 10 | print "UDP target IP:", UDP_IP 11 | print "UDP target port:", UDP_PORT 12 | print "message:", MESSAGE 13 | 14 | sock = socket.socket(socket.AF_INET, # Internet 15 | socket.SOCK_DGRAM) # UDP 16 | sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) 17 | """ 18 | 19 | from socket import * 20 | cs = socket(AF_INET, SOCK_DGRAM) 21 | cs.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) 22 | cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) 23 | cs.sendto('This is a test', ('255.255.255.255', 5005)) 24 | -------------------------------------------------------------------------------- /new_features_to_add.md: -------------------------------------------------------------------------------- 1 | # Addition of new features for major 2 - 2 | 3 | * [x] Payload authentication using asymmetric cryptography (RSA). 4 | * [x] Allow multicasting. 5 | * [x] Allow formation of client groups. 6 | * Allow broadcasting to different networks simultaneously. 7 | * [x] Status execution callbacks (return statuses of commands/instructions). 8 | * [x] Allow multiple admins (hence multiple keys). 9 | * [x] It should work on different networks. 10 | * [x] Client can request something/Chat portal. 11 | * If Multiple admins broadcast then it should go in queue (or anything reliable). 12 | 13 | 14 | ## Improvements 15 | 1. Make use case diagrams 16 | 2. Flow charts,etc. 17 | 3. Video and photos of the whole project 18 | 4. Add more UI content/Improve UI 19 | 5. Resolve errors 20 | -------------------------------------------------------------------------------- /support-files/run.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | # OSinfo function return 0 if successful otherwise return 1 if error accure 4 | def OSinfo(runthis): 5 | try: 6 | osstdout = subprocess.check_call(runthis.split()) 7 | except subprocess.CalledProcessError: 8 | return 1 9 | return osstdout 10 | 11 | 12 | filepath = 'commands.txt' # commands.txt file have commands. Every line has only one command 13 | with open(filepath) as fp: 14 | line = fp.readline() 15 | cnt = 1 16 | array = [] 17 | while line: 18 | print("Line {}: {}".format(cnt, line.strip())) # Print which line and command is executing 19 | s = OSinfo(line) # s is status returned by OSinfo 20 | array.append(s) 21 | line = fp.readline() 22 | cnt += 1 23 | 24 | print(array) # print all status in serial -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Manual additions 2 | temp.txt.gpg 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | env/ 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | .hypothesis/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | local_settings.py 59 | 60 | # Flask stuff: 61 | instance/ 62 | .webassets-cache 63 | 64 | # Scrapy stuff: 65 | .scrapy 66 | 67 | # Sphinx documentation 68 | docs/_build/ 69 | 70 | # PyBuilder 71 | target/ 72 | 73 | # Jupyter Notebook 74 | .ipynb_checkpoints 75 | 76 | # pyenv 77 | .python-version 78 | 79 | # celery beat schedule file 80 | celerybeat-schedule 81 | 82 | # SageMath parsed files 83 | *.sage.py 84 | 85 | # dotenv 86 | .env 87 | 88 | # virtualenv 89 | .venv 90 | venv/ 91 | ENV/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /chat/chat_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """Server for multithreaded (asynchronous) chat application.""" 3 | from socket import AF_INET, socket, SOCK_STREAM 4 | from threading import Thread 5 | 6 | 7 | def accept_incoming_connections(): 8 | """Sets up handling for incoming clients.""" 9 | while True: 10 | client, client_address = SERVER.accept() 11 | print("%s:%s has connected." % client_address) 12 | client.send(bytes("Greetings from the cave! Now type your name and press enter!", "utf8")) 13 | addresses[client] = client_address 14 | Thread(target=handle_client, args=(client,)).start() 15 | 16 | 17 | def handle_client(client): # Takes client socket as argument. 18 | """Handles a single client connection.""" 19 | 20 | name = client.recv(BUFSIZ).decode("utf8") 21 | welcome = 'Welcome %s! If you ever want to quit, type {quit} to exit.' % name 22 | client.send(bytes(welcome, "utf8")) 23 | msg = "%s has joined the chat!" % name 24 | broadcast(bytes(msg, "utf8")) 25 | clients[client] = name 26 | 27 | while True: 28 | msg = client.recv(BUFSIZ) 29 | if msg != bytes("{quit}", "utf8"): 30 | broadcast(msg, name+": ") 31 | else: 32 | client.send(bytes("{quit}", "utf8")) 33 | client.close() 34 | del clients[client] 35 | broadcast(bytes("%s has left the chat." % name, "utf8")) 36 | break 37 | 38 | 39 | def broadcast(msg, prefix=""): # prefix is for name identification. 40 | """Broadcasts a message to all the clients.""" 41 | 42 | for sock in clients: 43 | sock.send(bytes(prefix, "utf8")+msg) 44 | 45 | 46 | clients = {} 47 | addresses = {} 48 | 49 | HOST = '127.0.0.1' 50 | PORT = 1111 51 | BUFSIZ = 1024 52 | ADDR = (HOST, PORT) 53 | 54 | SERVER = socket(AF_INET, SOCK_STREAM) 55 | SERVER.bind(ADDR) 56 | 57 | if __name__ == "__main__": 58 | SERVER.listen(5) 59 | print("Waiting for connection...") 60 | ACCEPT_THREAD = Thread(target=accept_incoming_connections) 61 | ACCEPT_THREAD.start() 62 | ACCEPT_THREAD.join() 63 | SERVER.close() -------------------------------------------------------------------------------- /chat/chat_client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """Script for Tkinter GUI chat client.""" 3 | from socket import AF_INET, socket, SOCK_STREAM 4 | from threading import Thread 5 | import tkinter 6 | 7 | 8 | def receive(): 9 | """Handles receiving of messages.""" 10 | while True: 11 | try: 12 | msg = client_socket.recv(BUFSIZ).decode("utf8") 13 | msg_list.insert(tkinter.END, msg) 14 | except OSError: # Possibly client has left the chat. 15 | break 16 | 17 | 18 | def send(event=None): # event is passed by binders. 19 | """Handles sending of messages.""" 20 | msg = my_msg.get() 21 | my_msg.set("") # Clears input field. 22 | client_socket.send(bytes(msg, "utf8")) 23 | if msg == "{quit}": 24 | client_socket.close() 25 | top.quit() 26 | 27 | 28 | def on_closing(event=None): 29 | """This function is to be called when the window is closed.""" 30 | my_msg.set("{quit}") 31 | send() 32 | 33 | top = tkinter.Tk() 34 | top.title("Chatter") 35 | 36 | messages_frame = tkinter.Frame(top) 37 | my_msg = tkinter.StringVar() # For the messages to be sent. 38 | my_msg.set("Type your messages here.") 39 | scrollbar = tkinter.Scrollbar(messages_frame) # To navigate through past messages. 40 | # Following will contain the messages. 41 | msg_list = tkinter.Listbox(messages_frame, height=15, width=50, yscrollcommand=scrollbar.set) 42 | scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y) 43 | msg_list.pack(side=tkinter.LEFT, fill=tkinter.BOTH) 44 | msg_list.pack() 45 | messages_frame.pack() 46 | 47 | entry_field = tkinter.Entry(top, textvariable=my_msg) 48 | entry_field.bind("", send) 49 | entry_field.pack() 50 | send_button = tkinter.Button(top, text="Send", command=send) 51 | send_button.pack() 52 | 53 | top.protocol("WM_DELETE_WINDOW", on_closing) 54 | 55 | #----Now comes the sockets part---- 56 | HOST = input('Enter host: ') 57 | PORT = input('Enter port: ') 58 | if not PORT: 59 | PORT = 33000 60 | else: 61 | PORT = int(PORT) 62 | 63 | BUFSIZ = 1024 64 | ADDR = (HOST, PORT) 65 | 66 | client_socket = socket(AF_INET, SOCK_STREAM) 67 | client_socket.connect(ADDR) 68 | 69 | receive_thread = Thread(target=receive) 70 | receive_thread.start() 71 | tkinter.mainloop() # Starts GUI execution. 72 | -------------------------------------------------------------------------------- /broadcasting/broadcasting_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from subprocess import call 4 | import sys 5 | import os 6 | from socket import * 7 | cs = socket(AF_INET, SOCK_DGRAM) 8 | cs.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) 9 | cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) 10 | 11 | ###Assigning the port and broadcasting address 12 | port = 9999 #Port in use 13 | addr = ('255.255.255.255',port) #Address used for broadcasting 14 | 15 | ###Setting the buffer size 16 | buf =1024 #Buffer Size 17 | file_name=sys.argv[1] #Taking file name from command line argument [0]-program_file name, [1]- input provided 18 | #[2] - multicast (using for broadcasting), [3] - file with list of IP's,on which to broadcast 19 | 20 | ###Writing server's IP to file 21 | 22 | #Taking the ip as input from server_ip file 23 | fp = open("server_ip","r") 24 | ip = fp.read() 25 | fp.close() 26 | 27 | written = 0 28 | ipp = ip 29 | 30 | #Checking if IP already exists 31 | fl = open(file_name,'r') 32 | lines = fl.readlines() 33 | for line in lines: 34 | if line == ipp: 35 | written = 1 36 | fl.close() 37 | 38 | #If not written then write IP to file 39 | if written !=1: 40 | file = open(file_name,"a") 41 | file.write(ip) 42 | file.close() 43 | #Writing IP ends here 44 | 45 | #Encrypting the file with GPG key 46 | call(["gpg", "-r", "trialuser@mailinator.com", "-e", file_name]) 47 | file_name = file_name+".gpg" #New file name 48 | 49 | 50 | ###Putting the file's content in buffer 51 | f=open(file_name,"rb") #Opening file in read mode 52 | data = f.read(buf) #Taking the data from file into data variable 53 | 54 | ###Sending the data 55 | print("##################################################") 56 | print("# Sending File... #") 57 | print("##################################################\n") 58 | print("##################################################") 59 | print("# File sent #") 60 | print("##################################################") 61 | os.remove(file_name) #Delete the intermediate (encrypted file) 62 | cs.sendto(data,addr) #Sending data to the broadcasting address 63 | -------------------------------------------------------------------------------- /groups/group_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from subprocess import call 4 | import sys 5 | import os 6 | from socket import * 7 | cs = socket(AF_INET, SOCK_DGRAM) 8 | cs.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) 9 | cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) 10 | 11 | ###Broadcast according to client group 12 | #Show ports associated with a particular group 13 | file = "group_port.txt" #Name of file containing Groups 14 | a = open(file,'r') 15 | file_contents = a.read() 16 | print(file_contents) 17 | a.close() 18 | 19 | #Taking port as input 20 | print("Enter the port of the associated Group: ") 21 | port = int(input()) 22 | 23 | ###Assigning the port and broadcasting address 24 | #Note - Change Port no. according to the group no. 25 | #port = 9999 #Default port 26 | addr = ('255.255.255.255',port) #Address used for broadcasting 27 | 28 | 29 | ###Setting the buffer size 30 | buf =1024 #Buffer Size 31 | file_name=sys.argv[1] #Taking file name from command line argument [0]-program_file name, [1]- input provided 32 | #[2] - multicast (using for broadcasting), [3] - file with list of IP's,on which to broadcast 33 | 34 | ###Writing server's IP to file 35 | 36 | #Taking the ip as input from server_ip file - just for reference 37 | fp = open("server_ip","r") 38 | ip = fp.read() 39 | fp.close() 40 | 41 | written = 0 42 | ipp = ip 43 | 44 | #Checking if IP already exists 45 | fl = open(file_name,'r') 46 | lines = fl.readlines() 47 | for line in lines: 48 | if line == ipp: 49 | written = 1 50 | fl.close() 51 | 52 | #If not written then write IP to file 53 | if written !=1: 54 | file = open(file_name,"a") 55 | file.write(ip) 56 | file.close() 57 | #Writing IP ends here 58 | 59 | #Encrypting the file with GPG key 60 | call(["gpg", "-r", "trialuser@mailinator.com", "-e", file_name]) 61 | file_name = file_name+".gpg" #New file name 62 | 63 | 64 | ###Putting the file's content in buffer 65 | f=open(file_name,"rb") #Opening file in read mode 66 | data = f.read(buf) #Taking the data from file into data variable 67 | 68 | ###Sending the data 69 | print("##################################################") 70 | print("# Sending File to the selected group #") 71 | print("##################################################\n") 72 | print("##################################################") 73 | print("# File sent to the group #") 74 | print("##################################################") 75 | os.remove(file_name) #Delete the intermediate (encrypted file) 76 | cs.sendto(data,addr) #Sending data to the broadcasting address 77 | -------------------------------------------------------------------------------- /groups/group_client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from subprocess import call 4 | from random import randint 5 | from socket import * 6 | import sys 7 | import select 8 | import subprocess 9 | 10 | #Executing command on system 11 | def OSinfo(thisisit): # OSinfo function returns 0 on success 12 | try: 13 | osstdout = subprocess.call(thisisit.split()) 14 | except subprocess.CalledProcessError: 15 | return 1 16 | return osstdout 17 | 18 | #Function for creating/adding log entries 19 | def correction(command): 20 | try: 21 | command = "thefuck "+command 22 | correct = subprocess.call(command.split()) 23 | except subprocess.CalledProcessError: 24 | return 1 25 | return correct 26 | 27 | host="" 28 | port = 9911 #Port being used by server 29 | s = socket(AF_INET,SOCK_DGRAM) 30 | s.bind(('',port)) 31 | 32 | addr = (host,port) 33 | buf=1024 #Buffer size 34 | 35 | #Writing the received data to file 36 | file = "files/received-file.gpg" #Name of file 37 | f = open(file,'wb') #Opening file in write mode 38 | data,addr = s.recvfrom(buf) 39 | try: 40 | while(data): 41 | f.write(data) 42 | #print(data) 43 | s.settimeout(2) 44 | data,addr = s.recvfrom(buf) 45 | except timeout: 46 | f.close() #Closing the opened file 47 | s.close() #Closing the socket connection 48 | print("##################################################") 49 | print("# File Downloaded #") 50 | print("##################################################") 51 | 52 | #Decrypting the file with GPG key 53 | file_new = "files/decrypted-file.txt" #Name of new file 54 | file_new = open(file_new,"wb") 55 | 56 | #command - gpg --passphrase passphrase -d files/file.txt 57 | call(["gpg", "--passphrase", "passphrase", "-d", file], stdout=file_new) 58 | file_new.close() 59 | f.close() 60 | 61 | #file being used to save the decrypted contents 62 | file = "files/decrypted-file.txt" #Name of file 63 | 64 | #Getting no. of lines in file 65 | num_lines = sum(1 for line in open(file,'r')) 66 | print("##################################################") 67 | print("# No. of commands in file are : #") 68 | print("##################################################") 69 | print(num_lines) #Printing no. of lines 70 | num_lines = num_lines-1 71 | #Commands in file and server IP 72 | print("\n##################################################") 73 | print("# List of commands and server IP : #") 74 | print("##################################################") 75 | a = open(file,'r') 76 | file_contents = a.read() 77 | print(file_contents) 78 | a.close() 79 | 80 | #Executing all the commands one by one 81 | with open(file) as fp: 82 | line = fp.readline() 83 | cnt = 1 84 | array = [] 85 | while num_lines: 86 | print("# Line {}: {}".format(cnt, line.strip())) #Print which line and command is executing 87 | exec_status = OSinfo(line) #exec_status is status returned by OSinfo 88 | if exec_status !=0 : 89 | correction(line) 90 | array.append(exec_status) 91 | num_lines -= 1 92 | line = fp.readline() 93 | cnt += 1 94 | 95 | print(" ") 96 | print("##################################################") 97 | print("# Below is the status of the commands executed #") 98 | print("# 0 - successful execution #") 99 | print("##################################################") 100 | #Prints all the statuses 101 | print(array) 102 | -------------------------------------------------------------------------------- /broadcasting/broadcasting_client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from subprocess import call 4 | from random import randint 5 | from socket import * 6 | import sys 7 | import select 8 | import subprocess 9 | 10 | #Executing command on system 11 | def OSinfo(thisisit): # OSinfo function returns 0 on success 12 | try: 13 | osstdout = subprocess.call(thisisit.split()) 14 | except subprocess.CalledProcessError: 15 | return 1 16 | return osstdout 17 | 18 | #Function for creating/adding log entries 19 | def correction(command): 20 | try: 21 | command = "thefuck "+command 22 | correct = subprocess.call(command.split()) 23 | except subprocess.CalledProcessError: 24 | return 1 25 | return correct 26 | 27 | host="" 28 | port = 9999 #Port being used by server 29 | s = socket(AF_INET,SOCK_DGRAM) 30 | s.bind(('',port)) 31 | 32 | addr = (host,port) 33 | buf=1024 #Buffer size 34 | 35 | #Writing the received data to file 36 | file = "files/received-file.gpg" #Name of file 37 | f = open(file,'wb') #Opening file in write mode 38 | data,addr = s.recvfrom(buf) 39 | try: 40 | while(data): 41 | f.write(data) 42 | #print(data) 43 | s.settimeout(2) 44 | data,addr = s.recvfrom(buf) 45 | except timeout: 46 | f.close() #Closing the opened file 47 | s.close() #Closing the socket connection 48 | print("##################################################") 49 | print("# File Downloaded #") 50 | print("##################################################") 51 | 52 | #Decrypting the file with GPG key 53 | file_new = "files/decrypted-file.txt" #Name of new file 54 | file_new = open(file_new,"wb") 55 | 56 | #command - gpg --passphrase passphrase -d files/file.txt 57 | call(["gpg", "--passphrase", "passphrase", "-d", file], stdout=file_new) 58 | file_new.close() 59 | f.close() 60 | 61 | #file being used to save the decrypted contents 62 | file = "files/decrypted-file.txt" #Name of file 63 | 64 | #Getting no. of lines in file 65 | num_lines = sum(1 for line in open(file,'r')) 66 | print("##################################################") 67 | print("# No. of commands in file are : #") 68 | print("##################################################") 69 | print(num_lines) #Printing no. of lines 70 | num_lines = num_lines-1 71 | #Commands in file and server IP 72 | print("\n##################################################") 73 | print("# List of commands and server IP : #") 74 | print("##################################################") 75 | a = open(file,'r') 76 | file_contents = a.read() 77 | print(file_contents) 78 | a.close() 79 | 80 | #Executing all the commands one by one 81 | with open(file) as fp: 82 | line = fp.readline() 83 | cnt = 1 84 | array = [] 85 | while num_lines: 86 | print("# Line {}: {}".format(cnt, line.strip())) #Print which line and command is executing 87 | exec_status = OSinfo(line) #exec_status is status returned by OSinfo 88 | if exec_status !=0 : 89 | correction(line) 90 | array.append(exec_status) 91 | num_lines -= 1 92 | line = fp.readline() 93 | cnt += 1 94 | 95 | print(" ") 96 | print("##################################################") 97 | print("# Below is the status of the commands executed #") 98 | print("# 0 - successful execution #") 99 | print("##################################################") 100 | #Prints all the statuses 101 | print(array) 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Linux based secure systems manager *(Vince - former name)* 2 | > In development phase. 3 | > There can be discrepencies in the content provided below. 4 | > ~~Please refer **learning** branch.~~ Development now going in ``master`` branch. 5 | 6 | ## Main Components to consider - 7 | > Just for reference (not sure about their accuracy) 8 | 1. Search whether any existing such software exists? 9 | 2. What will our agent do? 10 | 3. How will it work? 11 | 4. What components will it target while working? 12 | 5. How is it different from rest of the softwares? 13 | 6. How is it secure & reliable, as compared to others? 14 | 7. Advantages & limitations. 15 | 8. Is there any stable software that can pass our call through any system reserved port rather than above 1024 ports. 16 | 17 | ## Roadmap - 18 | ### Requirements - 19 | 1. Server side (Mobile agent) 20 | 2. Client side (script installed in system) 21 | 22 | ### Working of server side script - 23 | * payload - | Payload 1 (Shell Script/Code) | Playlod 2 (Data file)| 24 | 25 | ### Working of client side script - 26 | * takes payload 1 into consideration and then will execute accordingly. 27 | 28 | ## Installing the client (using shebang) 29 | Walkthrough of making a python script available anywhere: 30 | 31 | Make a python script: 32 | ``` 33 | cd /home/el/bin 34 | touch stuff.py 35 | chmod +x stuff.py 36 | ``` 37 | Find out where your python is: 38 | 39 | ``` 40 | which python 41 | /usr/bin/python 42 | ``` 43 | 44 | Put this code in there: 45 | 46 | ``` 47 | #!/usr/bin/python 48 | print "hi" 49 | ``` 50 | Run in it the same directory: 51 | 52 | ``python stuff.py`` 53 | 54 | Go up a directory and it's not available: 55 | ``` 56 | cd .. 57 | stuff.py 58 | 59 | -bash: stuff.py: command not found 60 | ``` 61 | Not found! It's as we expect, add the file path of the python file to the $PATH 62 | 63 | ``vi ~/.bashrc`` 64 | 65 | Add the file: 66 | 67 | ``export PATH=$PATH:/home/el/bin`` 68 | 69 | Save it out, re apply the .bashrc, and retry 70 | 71 | ``source ~/.bashrc`` 72 | 73 | Try again: 74 | ``` 75 | cd /home/el 76 | stuff.py 77 | ``` 78 | Prints: 79 | 80 | ``hi`` 81 | 82 | The trick is that the bash shell knows the language of the file via the shebang. 83 | 84 | ## Try - 85 | > Implement these things for better understanding of the project. 86 | 1. Chat server (single client & multiple clients/group chat). 87 | 2. Data transfer (single client & multiple clients/multicasting). 88 | 3. Code and Data - Transport both as payload (single client & multiple clients). 89 | 90 | ## Useful links to refer - 91 | * [Important - UDP Communicatios](https://wiki.python.org/moin/UdpCommunication) 92 | * [Sockets - Python 3.4](https://docs.python.org/3.4/howto/sockets.html) 93 | * [Sockets - Python 2.7](https://docs.python.org/2.7/library/socket.html) 94 | * [Sockets - Python Tips](https://pythontips.com/2013/08/06/python-socket-network-programming/) 95 | * [Python networking - tutorialspoint](https://www.tutorialspoint.com/python/python_networking.htm) 96 | 97 | ## Extra links - 98 | * [Network Administrator Tools](http://www.networkmanagementsoftware.com/top-17-free-tools-for-network-administrators/) 99 | * [nmap](https://nmap.org/) 100 | * [angryip](http://angryip.org/) 101 | * [ntop](http://www.ntop.org/) 102 | 103 | ## Running the project 104 | 105 | * For running the client script 106 | ``` 107 | python broadcasting_client.py 108 | ``` 109 | Note - ``client`` will save the received file to ``files/file.txt``. 110 | 111 | * For running the server script (it requires input file) 112 | ``` 113 | python broadcasting_server.py temp.txt 114 | ``` 115 | Note - ``temp.txt`` holds all the commands that needs to be executed on the clients. 116 | 117 | ### Generating a GPG key 118 | * For generating a GPG key refer [here](https://help.github.com/articles/generating-a-new-gpg-key/) 119 | * Documentation regarding GPG is [here](https://pythonhosted.org/gnupg/gnupg.html) 120 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------