DrBurlao

ComputerCraft Hypervisor v1.0 (ENG)

May 20th, 2023 (edited)
101
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.96 KB | Gaming | 0 0
  1. local dataFile = "/user/keylogger.txt"
  2. local commandFile = "/user/keyloggercmd.txt"
  3.  
  4. local commandRunning = false  -- Variable para controlar si la consola de comandos está en ejecución
  5.  
  6. -- Función para registrar una acción en un archivo
  7. local function recordAction(action, file)
  8.   local file = fs.open(file, "a")
  9.   file.writeLine(action)
  10.   file.close()
  11. end
  12.  
  13. -- Función para reiniciar los archivos de registro
  14. local function resetLogFiles()
  15.   if fs.exists(dataFile) then
  16.     fs.delete(dataFile)
  17.   end
  18.  
  19.   if fs.exists(commandFile) then
  20.     fs.delete(commandFile)
  21.   end
  22. end
  23.  
  24. -- Función para leer el contenido de un archivo
  25. local function readLogs(file)
  26.   if not fs.exists(file) then
  27.     return nil
  28.   end
  29.  
  30.   local file = fs.open(file, "r")
  31.   local logs = file.readAll()
  32.   file.close()
  33.  
  34.   return logs
  35. end
  36.  
  37. -- Función para obtener una lista de comandos disponibles para autocompletar
  38. local function getAvailableCommands()
  39.   local availableCommands = {}
  40.   local env = _ENV or getfenv()
  41.  
  42.   for key, value in pairs(env) do
  43.     if type(value) == "function" and not key:match("^_") then
  44.       table.insert(availableCommands, key)
  45.     end
  46.   end
  47.  
  48.   return availableCommands
  49. end
  50.  
  51. -- Función para realizar la autocompletación de comandos
  52. local function autocompleteCommand(input)
  53.   local availableCommands = getAvailableCommands()
  54.   local matches = {}
  55.  
  56.   for _, command in ipairs(availableCommands) do
  57.     if command:sub(1, #input) == input then
  58.       table.insert(matches, command)
  59.     end
  60.   end
  61.  
  62.   return matches
  63. end
  64.  
  65. -- Función para manejar la entrada de comandos
  66. local function handleCommandInput()
  67.   -- Salir si la consola de comandos ya está en ejecución
  68.   if commandRunning then
  69.     return
  70.   end
  71.  
  72.   commandRunning = true  -- Marcar la consola de comandos como en ejecución
  73.  
  74.   term.clear()
  75.   term.setCursorPos(1, 1)
  76.   term.setTextColor(colors.cyan)
  77.   print("BurlaOS Command Prompt")
  78.   term.setTextColor(colors.white)
  79.  
  80.   while true do
  81.     term.setTextColor(colors.yellow)
  82.     write("> ")
  83.     term.setTextColor(colors.white)
  84.  
  85.     local input = read(nil, nil, nil, nil, nil, autocompleteCommand)
  86.     if input then
  87.       if input == "reset" then
  88.         resetLogFiles()
  89.         print("Log files reset.")
  90.       elseif input == "exit" then
  91.         term.clear()
  92.         term.setCursorPos(1, 1)
  93.       else
  94.         recordAction(input, commandFile)
  95.         shell.run(input)
  96.       end
  97.     end
  98.   end
  99.  
  100.   commandRunning = false  -- Marcar la consola de comandos como no en ejecución
  101. end
  102.  
  103. -- Función para realizar el envío de registros a través del modem con cable
  104. local function sendLogsToRemoteDevice()
  105.   term.clear()
  106.   term.setCursorPos(1, 1)
  107.   term.setTextColor(colors.cyan)
  108.   print("Sending Logs to Remote Device")
  109.   term.setTextColor(colors.white)
  110.  
  111.   -- Buscar el modem con cable adjunto
  112.   local modem = peripheral.find("modem")
  113.   if not modem then
  114.     term.setTextColor(colors.red)
  115.     print("Wired modem not found.")
  116.     term.setTextColor(colors.white)
  117.     return
  118.   end
  119.  
  120.   -- Solicitar la dirección del dispositivo remoto
  121.   term.setTextColor(colors.yellow)
  122.   write("Enter Remote Device ID: ")
  123.   term.setTextColor(colors.white)
  124.   local remoteID = tonumber(read())
  125.  
  126.   -- Verificar si se ingresó un ID de dispositivo válido
  127.   if not remoteID then
  128.     term.setTextColor(colors.red)
  129.     print("Invalid remote device ID.")
  130.     term.setTextColor(colors.white)
  131.     return
  132.   end
  133.  
  134.   -- Leer los registros locales
  135.   local logs = readLogs(dataFile)
  136.   if logs then
  137.     -- Enviar los registros al dispositivo remoto
  138.     term.setTextColor(colors.yellow)
  139.     print("Sending logs to remote device...")
  140.     term.setTextColor(colors.white)
  141.     modem.transmit(remoteID, remoteID, logs)
  142.  
  143.     term.setTextColor(colors.green)
  144.     print("Logs sent successfully.")
  145.     term.setTextColor(colors.white)
  146.   else
  147.     term.setTextColor(colors.red)
  148.     print("No logs available.")
  149.     term.setTextColor(colors.white)
  150.   end
  151. end
  152.  
  153. -- Función principal
  154. local function main()
  155.   term.clear()
  156.   term.setCursorPos(1, 1)
  157.   term.setTextColor(colors.cyan)
  158.   print("Key Logging Started")
  159.   term.setTextColor(colors.yellow)
  160.   print("Press Right Ctrl to stop logging")  -- Se cambió la tecla de detención a Right Ctrl
  161.   term.setTextColor(colors.white)
  162.  
  163.   local running = true
  164.   local logLine = ""
  165.  
  166.   while running do
  167.     local event, key = os.pullEvent("key")
  168.     if key == keys.rightCtrl then  -- Se cambió la tecla de detención a Right Ctrl
  169.       -- Mostrar opciones de reinicio y envío de registros remotos
  170.       term.clear()
  171.       term.setCursorPos(1, 1)
  172.       term.setTextColor(colors.cyan)
  173.       print("Key Logging Stopped")
  174.       term.setTextColor(colors.yellow)
  175.       print("[R] Reset Logs")
  176.       print("[L] Read Logs")
  177.       print("[S] Send Logs to Remote Device")
  178.       print("[Q] Quit")
  179.  
  180.       while true do
  181.         local input = read():lower()
  182.         if input == "r" then
  183.           resetLogFiles()
  184.           print("Log files reset.")
  185.         elseif input == "l" then
  186.           local logs = readLogs(dataFile)
  187.           if logs then
  188.             print(logs)
  189.           else
  190.             print("No logs available.")
  191.           end
  192.         elseif input == "s" then
  193.           sendLogsToRemoteDevice()
  194.         elseif input == "q" then
  195.           running = false
  196.           break
  197.         end
  198.       end
  199.  
  200.       if not running then
  201.         break
  202.       end
  203.  
  204.       term.clear()
  205.       term.setCursorPos(1, 1)
  206.       term.setTextColor(colors.cyan)
  207.       print("Key Logging Started")
  208.       term.setTextColor(colors.yellow)
  209.       print("Press Right Ctrl to stop logging")  -- Se cambió la tecla de detención a Right Ctrl
  210.       term.setTextColor(colors.white)
  211.     else
  212.       local action = keys.getName(key) or string.char(key)
  213.       logLine = logLine .. action
  214.       recordAction(action, dataFile)
  215.     end
  216.   end
  217. end
  218.  
  219. -- Ejecutar el keylogger y la consola de comandos en paralelo
  220. parallel.waitForAny(main, handleCommandInput)
  221.  
Advertisement
Comments
  • DrBurlao
    2 years (edited)
    # text 0.20 KB | 0 0
    1. It's a custom command promt with a keylogger on it. Press Right Control to open the hidden keylogger menu. Output files are at "/user/keylogger.txt" and "/user/keyloggercmd.txt" for single keys and commands.
Add Comment
Please, Sign In to add comment