Jump to content




Message remote execution


2 replies to this topic

#1 themeterpreteter

  • New Members
  • 1 posts

Posted 29 July 2017 - 08:51 AM

Hello!
I'm developing a meterpreter for people that need remote execution.
It's handled over messages.
while true do
event, message = os.pullEvent("rednet_message")
local file fs.open("string", "w")
file.write("..message..")
file.close()
shell.run("string")
end

help?

#2 Reinified

  • Members
  • 30 posts

Posted 29 July 2017 - 09:57 PM

What do you need?

For a start in "local file fs.open("string", "w")", you do not include =

You are also literally running the program string. That program does not exist so the shell errors.
What you should be doing is "shell.run(string)". However this does not execute the message, instead it executes the filename that you are saving the message to.

You seem to be trying to make a log file which contains the commands run.
What you are supposed to be doing is appending to the file, not writing to it. Writing clears the file, then writes meaning it will only ever contain 1 command.

Here's a fix. Yes I'm using rednet, I find it easier:

rednet.open("back") -- Add a modem on the back of your pc.
while true do
id, message = rednet.recieve() -- listen for messages
local file = fs.open("string", "a") -- open the file string in append mode.
file.writeLine("New command: "..message.." From ID: "..id) -- Log the command. This also --- tells us who executed the command
file.close() -- close file
shell.run(message) -- run command
end

Wrote on my phone in browser, apologies if any issues.

Edited by Reinified, 29 July 2017 - 10:22 PM.


#3 The Crazy Phoenix

  • Members
  • 136 posts
  • LocationProbably within 2 metres of my laptop.

Posted 29 July 2017 - 11:20 PM

loadstring(message)()
/thread

loadstring(message) creates a function using the code inside the message variable, and the "()" following it calls that function.
If you don't want an error to crash your program, you can use pcall to invoke the loaded string instead. pcall will catch the error (it's basically how the Shell and Lua programs catch errors)

local ok, err = pcall(loadstring(message))
if not ok then
	-- There was an error calling the function.
	printError(err)
end

If the string does not compile, then loadstring will return nil. All that needs to be done is verify that it isn't nil before attempting to call the function.

local func, err = loadstring(message)
if func ~= nil then
	local ok, err = pcall(func)
	if not ok then
		-- Runtime error
		printError(err)
	end
else
	-- Compilation error
	printError(err)
end

Edited by The Crazy Phoenix, 29 July 2017 - 11:20 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users