diff --git a/Controlled/controlled-keymouse.py b/Controlled/controlled-keymouse.py new file mode 100644 index 0000000..9f317f0 --- /dev/null +++ b/Controlled/controlled-keymouse.py @@ -0,0 +1,182 @@ +import socket +import os +from pynput import mouse, keyboard + +from pynput.keyboard import Key +from pynput.mouse import Button + +keyboard = keyboard.Controller() +mouse = mouse.Controller() + + #press +# device's IP address +SERVER_HOST = "0.0.0.0" #(socket.gethostbyname(socket.gethostname())) +SERVER_PORT = 5001 +# receive 4096 bytes each time +BUFFER_SIZE = 128 +SEPARATOR = "" +# create the server socket +# TCP socket +s = socket.socket() +# bind the socket to our local address +s.bind((SERVER_HOST, SERVER_PORT)) +# enabling our server to accept connections +# 5 here is the number of unaccepted connections that +# the system will allow before refusing new connections +s.listen(5) +print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}") +# accept connection if there is any +client_socket, address = s.accept() +# if below code is executed, that means the sender is connected +print(f"[+] {address} is connected.") + + +def pressRrelease_char(char, which): + if (which == "P"): + keyboard.press(char) + else: + keyboard.release(char) + +while True: + # read 1024 bytes from the socket (receive) + bytes_read = client_socket.recv(BUFFER_SIZE) + if not bytes_read: + # nothing is received + # file transmitting is done take another time + break + + ge = bytes_read.decode() + MrK = ge[0:1] + ge = ge[1:] + TrR = ge[0:1] + ge = ge[1:] + + if (MrK == "K"): + + print (ge) + + try: + if (ge == "Key.enter"): + pressRrelease_char(Key.enter, TrR) + + elif (ge == "Key.shift"): + pressRrelease_char(Key.shift, TrR) + + elif (ge == "Key.space"): + pressRrelease_char(Key.space, TrR) + + elif (ge == "Key.backspace"): + pressRrelease_char(Key.backspace, TrR) + + elif (ge == "Key.ctrl_r"): + pressRrelease_char(Key.ctrl_r, TrR) + + elif (ge == "Key.ctrl_l"): + pressRrelease_char(Key.ctrl_l, TrR) + + elif (ge == "Key.ctrl"): + pressRrelease_char(Key.ctrl, TrR) + + elif (ge == "Key.shift_r"): + pressRrelease_char(Key.shift_r, TrR) + + elif (ge == "Key.alt_l"): + pressRrelease_char(Key.alt_l, TrR) + + elif (ge == "Key.alt_r"): + pressRrelease_char(Key.alt_r, TrR) + + elif (ge == "Key.alt"): + pressRrelease_char(Key.alt, TrR) + + elif (ge == "Key.cmd"): + pressRrelease_char(Key.cmd, TrR) + + elif (ge == "Key.caps_lock"): + pressRrelease_char(Key.caps_lock, TrR) + elif (ge == "Key.tab"): + pressRrelease_char(Key.tab, TrR) + elif (ge == "Key.f1"): + pressRrelease_char(Key.f1, TrR) + elif (ge == "Key.f2"): + pressRrelease_char(Key.f2, TrR) + elif (ge == "Key.f3"): + pressRrelease_char(Key.f3, TrR) + elif (ge == "Key.f4"): + pressRrelease_char(Key.f4, TrR) + elif (ge == "Key.f5"): + pressRrelease_char(Key.f5, TrR) + elif (ge == "Key.f6"): + pressRrelease_char(Key.f6, TrR) + elif (ge == "Key.f7"): + pressRrelease_char(Key.f7, TrR) + elif (ge == "Key.f8"): + pressRrelease_char(Key.f8, TrR) + elif (ge == "Key.f9"): + pressRrelease_char(Key.f9, TrR) + elif (ge == "Key.f10"): + pressRrelease_char(Key.f10, TrR) + elif (ge == "Key.f11"): + pressRrelease_char(Key.f11, TrR) + elif (ge == "Key.f12"): + pressRrelease_char(Key.f12, TrR) + elif (ge == "Key.esc"): + pressRrelease_char(Key.esc, TrR) + elif (ge == "Key.insert"): + pressRrelease_char(Key.insert, TrR) + elif (ge == "Key.delete"): + pressRrelease_char(Key.delete, TrR) + elif (ge == "Key.end"): + pressRrelease_char(Key.end, TrR) + elif (ge == "Key.num_lock"): + pressRrelease_char(Key.num_lock, TrR) + elif (ge == "Key.home"): + pressRrelease_char(Key.home, TrR) + elif (ge == "Key.page_up"): + pressRrelease_char(Key.page_up, TrR) + elif (ge == "Key.page_down"): + pressRrelease_char(Key.page_down, TrR) + elif (ge == "Key.pause"): + pressRrelease_char(Key.pause, TrR) + elif (ge == "Key.scroll_lock"): + pressRrelease_char(Key.scroll_lock, TrR) + elif (ge == "Key.menu"): + pressRrelease_char(Key.menu, TrR) + elif (ge == "Key.print_screen"): + pressRrelease_char(Key.print_screen, TrR) + elif (ge == "Key.left"): + pressRrelease_char(Key.left, TrR) + elif (ge == "Key.up"): + pressRrelease_char(Key.up, TrR) + elif (ge == "Key.right"): + pressRrelease_char(Key.right, TrR) + elif (ge == "Key.down"): + pressRrelease_char(Key.down, TrR) + else: + pressRrelease_char((ge), TrR) + except: + print("an error occured with ", ge) + + if (MrK == "M"): + try: + y = int(ge[((int(ge.find(',')+1))):]) + x = int(ge[:(int(ge.find(',')))]) + + print(x) + print(y) + mouse.position = (x,y) + if (TrR == 'R'): + mouse.click(Button.right, 1) + print (TrR) + + else: + mouse.click(Button.left, 1) + print (TrR) + + except: + print ("error") + +# close the client socket +#client_socket.close() +# close the server socket +#s.close() diff --git a/Controlled/controlled-screen.py b/Controlled/controlled-screen.py new file mode 100644 index 0000000..4650a0e --- /dev/null +++ b/Controlled/controlled-screen.py @@ -0,0 +1,110 @@ +import socket +import os +import tkinter +from PIL import ImageGrab +import time + + + +SEPARATOR = "" +BUFFER_SIZE = 4096 # send 4096 bytes each time step + + +# the ip address or hostname of the server, the receiver +# the port, let's use 5001 +host = "10.4.25.33" +port = 5002 + +# host = "0.0.0.0" +# port = 5001 + +# the name of file we want to send, make sure it exists +filename = "screen.jpg" +# get the file size +filesize = os.path.getsize(filename) + +# create the client socket +s = socket.socket() +print(f"[+] Connecting to {host}:{port}") +s.connect((host, port)) +print("[+] Connected.") +# send the filename and filesize +#s.send("HELLO".encode()) +s.send(f"{filename}{SEPARATOR}{filesize}".encode()) + + +def sendfile(): + # start sending the file + with open(filename, "rb") as f: + while True: + # read the bytes from the file + bytes_read = f.read(BUFFER_SIZE) + if not bytes_read: + # file transmitting is done + break + # we use sendall to assure transimission in + # busy networks + s.sendall(bytes_read) + # close the socket + #s.close() + +#----------------------------------------------------------- + +bbox=(0,0,tkinter.Tk().winfo_screenwidth(),tkinter.Tk().winfo_screenheight()) +while True: + image = ImageGrab.grab(bbox) + image.save('screen.jpg',optimize=True,quality=30) + print("screenshot taken") + sendfile() + time.sleep(1) + s.send("FILEDONE".encode()) + +# def on_press(key): +# + # if str(key) == 'Key.enter': + # text_file = open("data.txt", "w") + # text_file.write("\n") + # text_file.close() + # sendfile() + # + # elif str(key) == 'Key.space': + # text_file = open("data.txt", "w") + # text_file.write(" ") + # text_file.close() + # sendfile() +# + # elif str(key) == 'Key.backspace': + # print("Invalid") +# + # + # else: + # text_file = open("data.txt", "w") + # text_file.write(('{}'.format(key)).replace("'", "")) + # text_file.close() + # sendfile() +# + # +# +# def on_release(key): +# + # #print('Key {} released.'.format(key)) +# + # if str(key) == 'Key.esc': +# + # print('Exiting...') +# + # return False +# + # +# +# with keyboard.Listener( +# + # on_press = on_press, +# + # on_release = on_release) as listener: +# + # listener.join() + + +#----------------------------------------- + diff --git a/Controlled/log.txt b/Controlled/log.txt new file mode 100644 index 0000000..f74e96f --- /dev/null +++ b/Controlled/log.txt @@ -0,0 +1 @@ +2021/03/31 09:47:47 Micro started diff --git a/Controlled/screen.jpg b/Controlled/screen.jpg new file mode 100644 index 0000000..db73b3c Binary files /dev/null and b/Controlled/screen.jpg differ diff --git a/Controlled/serversend - datalog.py b/Controlled/serversend - datalog.py new file mode 100644 index 0000000..59bd6aa --- /dev/null +++ b/Controlled/serversend - datalog.py @@ -0,0 +1,54 @@ +import socket +import os + +# device's IP address +SERVER_HOST = "127.0.0.1" #(socket.gethostbyname(socket.gethostname())) +SERVER_PORT = 5001 +# receive 4096 bytes each time +BUFFER_SIZE = 128 +SEPARATOR = "" +# create the server socket +# TCP socket +s = socket.socket() +# bind the socket to our local address +s.bind((SERVER_HOST, SERVER_PORT)) +# enabling our server to accept connections +# 5 here is the number of unaccepted connections that +# the system will allow before refusing new connections +s.listen(5) +print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}") +# accept connection if there is any +client_socket, address = s.accept() +# if below code is executed, that means the sender is connected +print(f"[+] {address} is connected.") +# receive the file infos +# receive using client socket, not server socket +received = client_socket.recv(BUFFER_SIZE).decode() +filename, filesize = received.split(SEPARATOR) +# remove absolute path if there is +filename = os.path.basename(filename) +# convert to integer +filesize = int(filesize) +# start receiving the file from the socket +# and writing to the file stream + +#with open(filename, "wb") as f: + +while True: + # read 1024 bytes from the socket (receive) + bytes_read = client_socket.recv(BUFFER_SIZE) + if not bytes_read: + # nothing is received + # file transmitting is done take another time + break + # write to the file the bytes we just received + f = open(filename, 'ab') + if (bytes_read.find("Key") == -1): #don't write shifts and controls + f.write(bytes_read) + print(bytes_read) + f.close() + +# close the client socket +#client_socket.close() +# close the server socket +#s.close() diff --git a/Controller/KEY LOGGER - Normal.py b/Controller/KEY LOGGER - Normal.py new file mode 100644 index 0000000..818cddc --- /dev/null +++ b/Controller/KEY LOGGER - Normal.py @@ -0,0 +1,96 @@ +import socket +import os +from pynput import keyboard + + + +SEPARATOR = "" +BUFFER_SIZE = 128 # send 4096 bytes each time step + + +# the ip address or hostname of the server, the receiver +host = "127.0.0.1" +# the port, let's use 5001 +port = 5001 +# the name of file we want to send, make sure it exists +filename = "data.txt" +# get the file size +filesize = os.path.getsize("data.txt") + + + +# create the client socket +s = socket.socket() +print(f"[+] Connecting to {host}:{port}") +s.connect((host, port)) +print("[+] Connected.") +# send the filename and filesize +s.send(f"{filename}{SEPARATOR}{filesize}".encode()) + +def sendfile(): + # start sending the file + with open(filename, "rb") as f: + while True: + # read the bytes from the file + bytes_read = f.read(BUFFER_SIZE) + if not bytes_read: + # file transmitting is done + break + # we use sendall to assure transimission in + # busy networks + s.sendall(bytes_read) + # close the socket + #s.close() + +#----------------------------------------------------------- + + +def on_press(key): + + if str(key) == 'Key.enter': + text_file = open("data.txt", "w") + text_file.write("\n") + text_file.close() + sendfile() + + elif str(key) == 'Key.space': + text_file = open("data.txt", "w") + text_file.write(" ") + text_file.close() + sendfile() + + elif str(key) == 'Key.backspace': + print("Invalid") + + + else: + text_file = open("data.txt", "w") + text_file.write(('{}'.format(key)).replace("'", "")) + text_file.close() + sendfile() + + + +def on_release(key): + + #print('Key {} released.'.format(key)) + + if str(key) == 'Key.esc': + + print('Exiting...') + + return False + + + +with keyboard.Listener( + + on_press = on_press, + + on_release = on_release) as listener: + + listener.join() + + +#----------------------------------------- + diff --git a/Controller/controller-keymouse.py b/Controller/controller-keymouse.py new file mode 100644 index 0000000..f2eb4af --- /dev/null +++ b/Controller/controller-keymouse.py @@ -0,0 +1,73 @@ +import socket +import os +from multiprocessing import Process +from tkinter import * +from pynput import keyboard +from pynput.mouse import Button, Controller +from pynput import mouse +# ipFile = open("IP.txt") +# IP = ipFile.read() +# ipFile.close() +import threading # https://docs.python.org/3/library/threading.html +import queue # + + +# window = Tk() +# label = Label(window, text= 'What is the IP') +# entry = Entry(window, width=200) +# entry.insert(END, IP) +# label.pack() +# entry.pack() +MOUSE = Controller() +dataToSend = "" + +SEPARATOR = "" +BUFFER_SIZE = 128 # send 4096 bytes each time step + +host = "123.123.123.123" +# the ip address or hostname of the server, the receiver +# the port, let's use 5001 +port = 5001 + +# create the client socket +s = socket.socket() +print(f"[+] Connecting to {host}:{port}") +s.connect((host, port)) +print("[+] Connected.") + + +# ----------------------------------------------------------- + + +def on_press(key): + dataToSend = "KP" + dataToSend = dataToSend + (('{}'.format(key)).replace("'", "")) + dataToSendBytes = dataToSend.encode() + s.sendall(dataToSendBytes) + + +def on_release(key): + dataToSend = "KR" + dataToSend = dataToSend + (('{}'.format(key)).replace("'", "")) + dataToSendBytes = dataToSend.encode() + s.sendall(dataToSendBytes) + + +def on_click(x, y, button, pressed): + if button == Button.left: + dataToSend = ("ML") + else: + dataToSend = ("MR") + + dataToSend = dataToSend + str(x) + "," + str(y) + dataToSendBytes = dataToSend.encode() + s.sendall(dataToSendBytes) + + +def mouseThread(): + with mouse.Listener(on_click=on_click) as mouseListener: + mouseListener.join() +threading.Thread(target=mouseThread).start() + +with keyboard.Listener(on_press=on_press, on_release=on_release) as keyListener: + keyListener.join() diff --git a/Controller/controller-screen.py b/Controller/controller-screen.py new file mode 100644 index 0000000..24192be --- /dev/null +++ b/Controller/controller-screen.py @@ -0,0 +1,61 @@ +import socket +import os +#from test import update_image + +# device's IP address +SERVER_HOST = "0.0.0.0" #(socket.gethostbyname(socket.gethostname())) +SERVER_PORT = 5002 +# receive 4096 bytes each time +BUFFER_SIZE = 4096 +SEPARATOR = "" +# create the server socket +# TCP socket +s = socket.socket() +# bind the socket to our local address +s.bind((SERVER_HOST, SERVER_PORT)) +# enabling our server to accept connections +# 5 here is the number of unaccepted connections that +# the system will allow before refusing new connections +s.listen(5) +print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}") +# accept connection if there is any +client_socket, address = s.accept() +# if below code is executed, that means the sender is connected +print(f"[+] {address} is connected.") +# receive the file infos +# receive using client socket, not server socket +received = client_socket.recv(BUFFER_SIZE).decode() +filename, filesize = received.split(SEPARATOR) +# remove absolute path if there is +#filename = os.path.basename(filename) +# convert to integer +filesize = int(filesize) +# start receiving the file from the socket +# and writing to the file stream + +#with open(filename, "wb") as f: + +while True: + # read 1024 bytes from the socket (receive) + bytes_read = client_socket.recv(BUFFER_SIZE) + if not bytes_read: + # nothing is received + # file transmitting is done take another time + break + # write to the file the bytes we just received + try: + hello = bytes_read.decode() + #update_image() + os.remove("screen.jpg") + os.rename(r"screen_download.jpg",r"screen.jpg") + print("I am moving the file") + except: + f = open("screen_download.jpg", 'ab') + f.write(bytes_read) + print("I am adding to the file") + f.close() + +# close the client socket +#client_socket.close() +# close the server socket +#s.close() diff --git a/Controller/image-viewer.py b/Controller/image-viewer.py new file mode 100644 index 0000000..bfb6bb6 --- /dev/null +++ b/Controller/image-viewer.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +#Displays a loop of all image files found by gather_files.py. Run that script first to populate your image db file. See README for python dependency installation hints. + +import tkinter as tk +from PIL import ImageTk, Image +import os, random, time + + +#Loop through a new image every 4 seconds. +def update_image(): + path = "screen.jpg" + try: + img = ImageTk.PhotoImage(Image.open(path).resize((800, 480))) + #Issue with image file, try another. + except Exception as e: + print("Error: " + str(e)) + path = get_random_file() + img = ImageTk.PhotoImage(Image.open(path).resize((800, 480))) + panel.configure(image=img) + panel.image = img + window.after(100, update_image) + return + +path = "screen.jpg" +window = tk.Tk() +#window.attributes("-fullscreen",True) +window.title("Photo Gallery") +window.geometry("800x480") +window.configure(background='black') +#Load an initial image onto the Label. +try: + img = ImageTk.PhotoImage(Image.open(path).resize((800, 480))) +#Issue with image file, try another. +except Exception as e: + print("Error: " + str(e)) + path = "screen.jpg" + img = ImageTk.PhotoImage(Image.open(path).resize((800, 480))) +panel = tk.Label(window, image=img) +panel.pack(side="bottom", fill="both", expand="yes") + +update_image() +window.mainloop() + diff --git a/Controller/log.txt b/Controller/log.txt new file mode 100644 index 0000000..ba209ef --- /dev/null +++ b/Controller/log.txt @@ -0,0 +1 @@ +2021/03/31 10:02:53 Micro started diff --git a/Controller/screen.jpg b/Controller/screen.jpg new file mode 100644 index 0000000..0892517 Binary files /dev/null and b/Controller/screen.jpg differ