jm33-m0 / emp3r0r

Linux/Windows post-exploitation framework made by linux user
https://infosec.exchange/@jm33
MIT License
1.24k stars 235 forks source link

Can I generate an agent in dll format #292

Closed fullfill13 closed 5 months ago

fullfill13 commented 5 months ago

Currently only able to generate windows agent in exe format, is it possible to add functionality?

jm33-m0 commented 5 months ago

This is not supported. However, there's project called exe_to_dll that might work.

fullfill13 commented 5 months ago

Thanks, but the converted dll file doesn't work!

jm33-m0 commented 5 months ago

Building agent as shared library is possible in Windows, I will implement it if I have time to work on it.

fullfill13 commented 5 months ago

Maybe I can merge main_windows.go and buildAgent.go into a C.go file , and compile it as a dll file, but that's too difficult

jm33-m0 commented 5 months ago

The biggest issue here is cross-building agent as DLL on Linux is quite impossible, perhaps it's an issue with Go itself (and the error is hard to debug).

My plan is to build a DLL stub (just like the exe), and add an option in gen_agent so it can be configured for use.

Maybe you can build the DLL on Windows with this command:

CGO_ENABLED=1 go build -buildmode=c-shared cmd/agent

And in main_windows.go, export the main function:

import "C"
//export main
func main() {}
jm33-m0 commented 5 months ago

This should work.

image

fullfill13 commented 5 months ago

i can generate main_windows and main_windows.h ,but not dll. May need to keep compiling? https://merlin-c2.readthedocs.io/en/latest/agent/dll.html

fullfill13 commented 5 months ago

and the dll is a DLL stub , Will buildAgent.go work with this stub?

jm33-m0 commented 5 months ago

i can generate main_windows and main_windows.h ,but not dll. May need to keep compiling? https://merlin-c2.readthedocs.io/en/latest/agent/dll.html

It's merlin-c2, which uses a very different approach to generate DLL. It won't work here. Have you tested the method I just posted?

and the dll is a DLL stub , Will buildAgent.go work with this stub?

Yes it will.

fullfill13 commented 5 months ago

I generated the stub dll file, but the last generated is still an exe, which is generated by buildAgent.go, I simply changed the suffix to dll, but then there is no export function, how do I start the dll?

fullfill13 commented 5 months ago

the stub dll has main export, but the final file does not have it

jm33-m0 commented 5 months ago

I simply changed the suffix to dll

Executable and shared library are two different things, changing file names don't change the file.

the stub dll has main export, but the final file does not have it

Why would it have exported functions? It's still an exe.

Right now the whole thing is being experimented on, it's not implemented so you won't be able to use emp3r0r to generate any DLLs.

jm33-m0 commented 5 months ago

Can you just wait until this feature is implemented?

fullfill13 commented 5 months ago

Of course, and I'm going to try it

jm33-m0 commented 5 months ago

image

Now the DLL seems to be working, I will test it further and fix the bugs.

fullfill13 commented 5 months ago

Why is the export function missing after the buildagent.go function reads the stub data, replaces some of the data and rewrites it?

jm33-m0 commented 5 months ago

It's not done yet. Right now I can only say the DLL file is working, agent configuration is not.

jm33-m0 commented 5 months ago

@fullfill13

2024-01-30_17-45

Here's the documentation: https://github.com/jm33-m0/emp3r0r/wiki/DLL-Agent