Ylianst / MeshAgent

MeshAgent used along with MeshCentral to remotely manage computers. Many variations of the background management agent are included as binaries in the MeshCentral project.
https://meshcentral.com
213 stars 84 forks source link

How to modify agent-installer.js #72

Closed ahghygy closed 3 years ago

ahghygy commented 3 years ago

Hi guys,

I find agent-installer.js is encryption in ILibDuktape_Polyfills.c

// agent-instaler: Refer to modules/agent-installer.js duk_peval_string_noresult(ctx, "addCompressedModule('agent-installer', Buffer.from('eJzdPWtT47iW36niP6ipuzdOd0igZ6q3LmzmFg3............QQbfFwZAwTRp8xYIB+JpV48j/D+W9YTI=', 'base64'));");

When I add a debug code in agent-installer.js in installService function, then rebuild MeshAgent.sln project process.stdout.write('This is test info');

my log is not output. So I want to know how to let agent-installer.js to the following contet 'eJzdPWtT47iW36niP6ipuzdOd0igZ6q3LmzmFg3............QQbfFwZAwTRp8xYIB+JpV48j/D+W9YTI=', 'base64'));

krayon007 commented 3 years ago

The easiest way is to just copy the js file into the same folder as the exe. When you run the exe, it will try to use the js files from the local path before using the one that is compressed.

krayon007 commented 3 years ago

After you make the changes you want, to compress it and add it back to the agent, just run the following command, with the updated js in the local path.

MeshAgent -exec "require('clipboard').nativeAddCompressedModule('agent-installer.js');process.exit();"

Then load up ILibDuktape_Polyfills.js in a text editor, and highlight the line to be changed, and paste.... (The previous command generates the whole C command and puts it into the clipboard. If you are doing this from linux, get rid of the process.exit(); from the previous command, because on linux the clipboard can only paste while the process that owns the buffer is alive.

ahghygy commented 3 years ago

Thank you very much. you really give me a quickly feedback, So a nother questions is when MeshService64.exe is update in mesh central, the previous client machines how to get the latest MeshService64.exe? I have stop mesh central, Then restart mesh central, I find all windows client machines have already get the lastest MeshService64.exe, But this method is not I want. Becasue it is need to stop mesh central,then start mesh central.

I don't want to stop mesh central, I want the mesh central can push the latest version of agent servie to all client machines without stop mesh central. Thansk again.

ahghygy commented 3 years ago

Hi Krayon007, When I copy the agent-installer.js into MeshService64.exe same folder, that is work for me , my self log is print. But I do not understand your second methond

  1. So how to compress js file? do you have a tool?
  2. where to exec the following command? MeshAgent -exec "require('clipboard').nativeAddCompressedModule('agent-installer.js');process.exit();"

    becasue I fiand MeshService64.exe only have the following parameter

image

  1. I cloud not find ILibDuktape_Polyfills.js in mesh agent project. So, where is this file?

could you give me a step by step instruction"

krayon007 commented 3 years ago

The -exec switch isn't shown in the --help list, as it's mostly for debugging purposes. You can run the command like the following:

MeshAgent -exec "require('clipboard').nativeAddCompressedModule('agent-installer');process.exit();"

The file you'll be editing is: MeshAgent/microscript/ILibDuktape_Polyfills.c You can search for agent-installer, as you'll be pasting/replacing with what the previous command puts in the clipboard.

krayon007 commented 3 years ago

When you run the command to compress the module, make sure the updated agent-installer.js file is in the same/current folder as the exe that you are running

ahghygy commented 3 years ago

Ok, thanks for you help. thanks again. I will have a try.

ahghygy commented 3 years ago

It is working now. thanks again. I will close it.

uwejan commented 1 year ago

After modifying, agent-installer.js I tried the following.

  1. compiles the agent. make linux ARCHID=6 DEBUG=1
  2. chmod +x meshagent_x86-64
  3. cp meshagent_x86-64 modules/
  4. cd modules/
  5. ./meshagent_x86-64 -exec "require('clipboard').nativeAddCompressedModule('agent-installer');process.exit();"
  6. Nothing shows on the terminal. The command runs and exists no output.
krayon007 commented 1 year ago

Let me fetch the instructions for you. I recently made some changes to make it easier to update these files. I'll verify the instructions on Linux as well.

uwejan commented 1 year ago

Yes. Please. That would be great.

krayon007 commented 1 year ago

I'm linking #167 since it's still open, and appears to be asking the same thing