commit 0b725735c9a88189f81303331195f25c95b210ac
parent c6d32c72998f64f029741416b7dc890748f067f1
Author: CO20328 <88075157+CO20328@users.noreply.github.com>
Date: Thu, 3 Aug 2023 10:48:35 +0530
Final
Diffstat:
7 files changed, 59 insertions(+), 153 deletions(-)
diff --git a/README.md b/README.md
@@ -1,25 +1,31 @@
# Remote Code and Command Execution
-A python implementation of remote code and command execution. Using the provided code you can connect 2 machines and remotely execute commands from one machine to another. It also features live video streaming/screen sharing. Which means that while executing commands on the remote machine you can see what change those executions are making.
+A python implementation of remote code/command execution. Using the code you can connect 2 machines and remotely execute commands from one machine to another. Initially implemented as telnet client, It also features live video streaming/screen sharing. Which means that while executing commands on the remote machine you can see what change those executions are making. **Batch scripts are used to file programs within programs**.
+# Video Demonstration
+Watch on youtube: [youtube link](https://youtu.be/2l4CWBmEw50)
+
+### Part 1
+https://github.com/abdulrahim2002/Remote-Code-Command-execution/assets/89011337/362e68f7-d01b-483f-99d9-5988dba84b22
+
+### Part 2
+https://github.com/abdulrahim2002/Remote-Code-Command-execution/assets/89011337/18361527-01f2-4a9d-8b83-0edd5ef8cf14
## Features
-* Live screen sharing
-* Remotely use server machine's keyboard.
+* **Live screen sharing**
+* Remotely **use** **server machine's keyboard**.
+ e.g. usage: you can open a text file on the remote machine. then you can write anything in that text file using !! before your text written in prompt. Once done you can save the file using !ctrl~s Command.
- e.g. usage: you can open a text file on the remote machine. then you can write anything in that text file using !! before your text written in prompt. Once done you can save the file using !Ctrl + S. Command.
+* Authentication. The server machine is secured by **OTP(one time password)** which is generated at runtime randomly.
+
+# Working
+The client machine sends commands to server machine, where they get executed, and the result is returned. The client machine can also **write something using server's keyboard**. The client's machine can also **send shortcuts** like ctrl+s(save) and win+d(jump to desktop), alt+tab(next program). The possibilities are endless, with what you can do with it.
-* Authentication. The server machine is secured by OTP(one time password) which is generated at runtime randomly.
## Authors
- [@amrindersingh](co20305@ccet.ac.in)
- [@abdulrahim2002](co20301@ccet.ac.in)
-
-
-## Documentation
-
-
diff --git a/__pycache__/utility.cpython-311.pyc b/__pycache__/utility.cpython-311.pyc
Binary files differ.
diff --git a/instructions.txt b/instructions.txt
@@ -0,0 +1,38 @@
+Instructions:
+
+# add contents
+echo Hello, World! >> my_file.txt
+
+type my_file.txt # display the contents
+
+# make a new file
+echo. > new.txt
+
+# to read contents
+type file.txt
+
+# notepad commands
+notepad file.txt # opens notepad
+
+# how to write:
+two write, type ! followed by text. To type next line character, type '~'
+
+examples:
+!hi`hi writes "hi\hi"
+
+# how to type shortcuts:
+start with !! then type keys seprated by ~ for example
+
+!!ctrl~s # save
+!!alt~f4 # close
+
+Note: dont leave any space
+
+keycodes:
+1. windows key: win
+2. control: ctrl
+3. shift: shift
+4. f4: f4
+
+# gcc command to compile code
+gcc -o output input.cd
+\ No newline at end of file
diff --git a/prog1.c b/prog1.c
@@ -0,0 +1,2 @@
+ #include <stdio.h>
+ int main() { printf("hello"); scanf("%d"); }
diff --git a/run.exe b/run.exe
Binary files differ.
diff --git a/telnetServer copy.py b/telnetServer copy.py
@@ -1,139 +0,0 @@
-import socket
-import threading
-import random
-import os
-import utility
-import subprocess
-
-parentDir = utility.getpath()
-
-# get server IP
-IP = utility.get_ip_address()
-PORT = 5566
-ADDR = (IP, PORT)
-SIZE = 1024
-FORMATmsg = "utf-8"
-
-u_name = [] # list of usernames
-u_addr = [] # list of ip addresses
-u_conn = [] # list of connections
-u_pin = [] # list of pins
-u_port = [] # list of ports
-
-
-# server functions
-def start():
- global server
-
- print(f"SERVER IP = {IP}\n")
- print("[STARTING] Server is starting...")
- server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server.bind(ADDR)
- server.listen()
- print(f"[LISTENING] Server is listening on {IP}:{PORT}")
-
-# broadcast connection list
-def broadcast(message):
- if message == 'LIST':
- for addr in u_conn:
- msg = str(u_name)
- msg = "[LIST] CONNECTION LIST: " + msg
- addr.send(msg.encode(FORMATmsg))
- msg = str(u_port)
- msg = "[LIST] CONNECTION LIST: " + msg
- addr.send(msg.encode(FORMATmsg))
- else:
- for addr in u_conn:
- addr.send(message.encode(FORMATmsg))
-
-# handle client connection
-def handle_client(conn, addr, u_name):
- print(f"[SERVER] [NEW CONNECTION] {u_name}:{addr} connected.")
-
- connected = True
- while connected:
- msg = conn.recv(SIZE).decode(FORMATmsg)
-
- print('[Incoming request]: ')
- print(f"[{u_name}:{addr}] {msg}") # print msg in server console
-
- print('Executing command...')
-
- result = executeCommand(msg)
-
- print(f'Output: {result}')
- broadcast(result)
-
- conn.close()
-
-# execute command and return output
-def executeCommand(command):
- result = os.popen(command).read()
- return result
-
-def startVideoStream():
- print('\nStarting video stream...')
-
- process = subprocess.Popen(['cmd', '/C', 'streamVideo.bat'], creationflags= subprocess.CREATE_NEW_CONSOLE)
- # exit_code = process.wait()
-
- print(f'Video Stream: Path: http://{IP}:5000')
-
-def main():
- utility.printUI()
- start()
- startVideoStream()
-
- temp_port = PORT+1
- while True:
- conn, addr = server.accept()
- while True:
- temp_name = conn.recv(SIZE).decode(FORMATmsg)
- print(f"[CLIENT] Username: {temp_name}")
- if temp_name in u_name:
- print("[SERVER] Username not accepted")
- conn.send("NOTACCEPTED!".encode(FORMATmsg))
- else:
- print("[SERVER] Username accepted")
- conn.send(temp_name.encode(FORMATmsg))
- break
-
- temp_pin = str(random.randint(1000, 9999))
- print(f"[AUTHENTICATING] Current Pin: {temp_pin}")
- msg_pin = conn.recv(SIZE).decode(FORMATmsg)
-
- if msg_pin != temp_pin:
- print("[SERVER] PIN not accepted")
- conn.send("try again".encode(FORMATmsg))
- continue
- else:
- print("[SERVER] PIN accepted")
- conn.send("!ACCEPTED".encode(FORMATmsg))
-
-
- conn.recv(SIZE).decode(FORMATmsg)
- conn.send(str(temp_port).encode(FORMATmsg))
-
- print(f"[SERVER] {temp_name} added to network")
-
-
- clientThread = threading.Thread(target=handle_client, args=(conn, addr, temp_name))
- clientThread.start()
-
-
- u_pin.append(temp_pin)
- u_name.append(temp_name)
- u_addr.append(addr)
- u_conn.append(conn)
- u_port.append(temp_port)
- temp_port += 1
-
- # broadcast connection list
- broadcast('LIST')
-
- print(f"\n[SERVER][ACTIVE CONNECTIONS] {threading.active_count() - 2}")
- pass
-
-
-if __name__ == "__main__":
- main()
-\ No newline at end of file
diff --git a/telnetServer.py b/telnetServer.py
@@ -6,8 +6,6 @@ import utility
import subprocess
import pyautogui
-
-
parentDir = utility.getpath()
# get server IP
@@ -72,6 +70,7 @@ def handle_client(conn, addr, u_name):
# if str == "exit()":
# exit()
if str[0]=="!" and str[1]!="!":
+ str = str.replace("`", "\n")
pyautogui.write(str[1:], interval = 0.05)
continue
if str[0]== '!' and str[1 == '!']:
@@ -82,7 +81,7 @@ def handle_client(conn, addr, u_name):
if len(spl)==2:
pyautogui.hotkey(spl[0], spl[1])
continue
-
+ # The effect is that calling hotkey('ctrl', 'shift', 'c') would perform a "Ctrl-Shift-C" hotkey/keyboard shortcut press
# result = executeCommand(msg)
Thr = threading.Thread(target=exec_cmd, args=(msg,))