Upload all the older-stuff

This commit is contained in:
Daniel
2021-04-19 14:37:54 +01:00
parent 0e533d72bc
commit b9cb52b3e5
11 changed files with 622 additions and 0 deletions

View File

@ -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 = "<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()

View File

@ -0,0 +1,110 @@
import socket
import os
import tkinter
from PIL import ImageGrab
import time
SEPARATOR = "<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()
#-----------------------------------------

1
Controlled/log.txt Normal file
View File

@ -0,0 +1 @@
2021/03/31 09:47:47 Micro started

BIN
Controlled/screen.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

View File

@ -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 = "<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()