├── README.md ├── admin └── main.py ├── client ├── bashHistory.py ├── browserHistory.py ├── data.py └── main.py ├── img ├── 1.PNG ├── 2.PNG └── 3.PNG └── server └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # Simple Live Data Collection Tool 2 | 3 | ![topology](https://github.com/omergunal/Simple-Live-Data-Collection/blob/master/img/1.PNG) 4 | 5 | ### How it works? 6 | 7 | - 1- Build server 8 | - 2- Connect with admin and client to server 9 | - 3- To collect information, send the request to the server through the admin, and then to the client 10 | 11 | ### Installation 12 | ```bash 13 | git clone https://github.com/LetsDefend/Simple-Live-Data-Collection 14 | ``` 15 | 16 | #### Server 17 | 18 | ```bash 19 | cd server 20 | python main.py 21 | ``` 22 | 23 | #### Admin 24 | 25 | ```bash 26 | cd admin 27 | python main.py 28 | ``` 29 | 30 | #### Client 31 | 32 | ```bash 33 | cd client 34 | python main.py 35 | ``` 36 | 37 | 38 | Change the "HOST" variable in main.py file 39 | 40 | 41 | ### Screenshots 42 | 43 | ![r2](https://github.com/omergunal/Simple-Live-Data-Collection/blob/master/img/2.PNG) 44 | ![r3](https://github.com/omergunal/Simple-Live-Data-Collection/blob/master/img/3.PNG) 45 | -------------------------------------------------------------------------------- /admin/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import socket 3 | import select 4 | 5 | def main(): 6 | 7 | host = "192.168.131.129" 8 | port = int(4444) 9 | 10 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 11 | s.settimeout(2) 12 | 13 | # connect to remote host 14 | try : 15 | s.connect((host, port)) 16 | except : 17 | print('Unable to connect') 18 | sys.exit() 19 | 20 | print('Connected to remote host') 21 | sys.stdout.write('>> '); sys.stdout.flush() 22 | 23 | while 1: 24 | socket_list = [sys.stdin, s] 25 | 26 | ready_to_read,ready_to_write,in_error = select.select(socket_list , [], []) 27 | 28 | for sock in ready_to_read: 29 | if sock == s: 30 | 31 | data = sock.recv(4096) 32 | if not data : 33 | print('\nDisconnected from server') 34 | sys.exit() 35 | else : 36 | sys.stdout.write(data) 37 | sys.stdout.write('>> '); sys.stdout.flush() 38 | 39 | else : 40 | msg = sys.stdin.readline() 41 | s.send(msg) 42 | sys.stdout.write('>> '); sys.stdout.flush() 43 | 44 | if __name__ == "__main__": 45 | 46 | sys.exit(main()) -------------------------------------------------------------------------------- /client/bashHistory.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | homedir = os.path.expanduser('~') 4 | history = open(homedir+"/.bash_history", 'r') 5 | 6 | for i in history: 7 | print(i) 8 | -------------------------------------------------------------------------------- /client/browserHistory.py: -------------------------------------------------------------------------------- 1 | import os 2 | import getpass 3 | import sqlite3 4 | 5 | 6 | username = getpass.getuser() 7 | directory = "" 8 | path = os.path.expanduser('~')+"/.mozilla/firefox/" 9 | files = os.listdir(path) 10 | 11 | 12 | for name in files: 13 | if ".default" in name: 14 | directory = name 15 | 16 | 17 | data_path = os.path.expanduser('~')+"/.mozilla/firefox/"+directory 18 | files = os.listdir(data_path) 19 | history_db = os.path.join(data_path, 'places.sqlite') 20 | c = sqlite3.connect(history_db) 21 | cursor = c.cursor() 22 | select_statement = "select moz_places.url, moz_places.visit_count from moz_places;" 23 | cursor.execute(select_statement) 24 | results = cursor.fetchall() 25 | 26 | 27 | for url, count in results: 28 | print(url) -------------------------------------------------------------------------------- /client/data.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | options = { 4 | "systemDate":"date", 5 | "osVersion":"cat /etc/issue", 6 | "kernelVersion":"uname -a", 7 | "uptime":"w", 8 | "userAccounts":"cat /etc/passwd", 9 | "groups":"cat /etc/group", 10 | "networkConnections":"netstat -anp", 11 | "loadedDrivers":"lsmod", 12 | "networkInterfaces":"ifconfig -a", 13 | "routingTable":"netstat rn", 14 | "browserHistory":"python3 browserHistory.py", 15 | "bashHistory":"python3 bashHistory.py" 16 | } 17 | 18 | 19 | def getData(command): 20 | command = command.split() 21 | data = subprocess.check_output(command) 22 | return(data) 23 | 24 | 25 | def getValue(command): 26 | value = getData(options[command]) 27 | return(value) 28 | -------------------------------------------------------------------------------- /client/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import socket 3 | import select 4 | from data import * 5 | 6 | 7 | def main(): 8 | 9 | host = "192.168.131.129" 10 | port = int(9009) 11 | 12 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 13 | s.settimeout(2) 14 | 15 | # connect to remote host 16 | try : 17 | s.connect((host, port)) 18 | except : 19 | print('Unable to connect') 20 | sys.exit() 21 | 22 | print('Connected to remote host') 23 | 24 | 25 | while 1: 26 | socket_list = [sys.stdin, s] 27 | 28 | ready_to_read,ready_to_write,in_error = select.select(socket_list , [], []) 29 | 30 | for sock in ready_to_read: 31 | if sock == s: 32 | data = sock.recv(4096) 33 | if not data : 34 | print('\nDisconnected from server') 35 | sys.exit() 36 | else: 37 | sys.stdout.write(data) 38 | try: 39 | if data.split()[2][0] == "!": 40 | command = data.split()[2][1:] 41 | value = getValue(command) 42 | s.send(str(value)) 43 | except: 44 | pass 45 | 46 | 47 | if __name__ == "__main__": 48 | sys.exit(main()) 49 | -------------------------------------------------------------------------------- /img/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LetsDefendio/Simple-Live-Data-Collection/bd4caf7e6016506d91468196f5bbae77540889a9/img/1.PNG -------------------------------------------------------------------------------- /img/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LetsDefendio/Simple-Live-Data-Collection/bd4caf7e6016506d91468196f5bbae77540889a9/img/2.PNG -------------------------------------------------------------------------------- /img/3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LetsDefendio/Simple-Live-Data-Collection/bd4caf7e6016506d91468196f5bbae77540889a9/img/3.PNG -------------------------------------------------------------------------------- /server/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import socket 3 | import select 4 | 5 | HOST = '192.168.131.129' 6 | SOCKET_LIST = [] 7 | RECV_BUFFER = 4096 8 | PORT = 4444 9 | 10 | def server(): 11 | 12 | server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 13 | server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 14 | server_socket.bind((HOST, PORT)) 15 | server_socket.listen(10) 16 | 17 | SOCKET_LIST.append(server_socket) 18 | 19 | print("Server started on port " + str(PORT)) 20 | 21 | while 1: 22 | 23 | ready_to_read,ready_to_write,in_error = select.select(SOCKET_LIST,[],[],0) 24 | 25 | for sock in ready_to_read: 26 | if sock == server_socket: 27 | sockfd, addr = server_socket.accept() 28 | SOCKET_LIST.append(sockfd) 29 | print("(%s, %s) connected" % addr) 30 | 31 | 32 | else: 33 | try: 34 | data = sock.recv(RECV_BUFFER) 35 | if data: 36 | broadcast(server_socket, sock, "\r" + '[' + str(sock.getpeername()) + '] ' + data) 37 | else: 38 | if sock in SOCKET_LIST: 39 | SOCKET_LIST.remove(sock) 40 | 41 | 42 | broadcast(server_socket, sock, "(%s, %s) is offline\n" % addr) 43 | 44 | except: 45 | broadcast(server_socket, sock, "(%s, %s) is offline\n" % addr) 46 | continue 47 | 48 | server_socket.close() 49 | 50 | 51 | def broadcast (server_socket, sock, message): 52 | for socket in SOCKET_LIST: 53 | if socket != server_socket and socket != sock : 54 | try : 55 | socket.send(message) 56 | print(message) 57 | except : 58 | socket.close() 59 | 60 | if socket in SOCKET_LIST: 61 | SOCKET_LIST.remove(socket) 62 | 63 | if __name__ == "__main__": 64 | sys.exit(server()) --------------------------------------------------------------------------------