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

Executed PE Files do not return output #1

Closed
michaelweber opened this issue Jul 26, 2024 · 5 comments
Closed

Executed PE Files do not return output #1

michaelweber opened this issue Jul 26, 2024 · 5 comments

Comments

@michaelweber
Copy link
Collaborator

When we reflectively load another PE file, any hooks we've put in place to capture stdout/stderr go right out the window. The compiled executable will work fine, but if you want to make any decisions based off of the output of invoking the embedded PE file beyond return code this will need another solution.

@cookpoo78
Copy link

Same issue

@parzel
Copy link

parzel commented Feb 21, 2025

I ran into the same issue. The behavior stems from the no-consolation BOF and how it tries to redirect output. I was able to hotfix it and opened a ticket here with the details.

@michaelweber
Copy link
Collaborator Author

Holy crap - way to go @parzel! Gonna do some testing real quick and if that looks right then I'll build noconsolation with your hotfix and include it here until there's an official fix release.

I was losing my mind trying to run this thing down.

@parzel
Copy link

parzel commented Feb 22, 2025

Great. Let me know if it works, I had no issues so far. Here are the argBytes I am using (changed freeing libraries to z as per CNA and do not allocate console):

argBytes, err := lighthouse.PackArgs([]string{
	"Z" + peName, // Unicode PE Name
	"z" + peName, // ANSI PE Name
	"Z" + pePath, // Unicode PE Path
	"b" + hex.EncodeToString(executableBytes), // The actual PE to load
	"z",                                  // for local PE loading, we don't need it
	"i0",                                 // not doing local loading
	"i60",                                // 60 second timeout
	"i0",                                 // no headers
	"Z" + strings.Join(updatedArgs, " "), // Unicode Args
	"z" + strings.Join(updatedArgs, " "), // ANSI Args
	"z",                                  // Invoke default entry point method
	"i0",                                 // not using unicode
	"i0",                                 // we don't want to disable output
	"i0",                                 // allocating a console so we can capture output
	"i0",                                 // don't need to worry about closing handles
	"z",                                  // don't need to worry about freeing libraries
	"i1",                                 // don't need to worry about saving
	"i0",                                 // not listing PEs
	"z",                                  // not unloading any PEs
	"z",                                  // no need for us to have anything as our nick() for now
	"z" + "0",                            // timestamp doesn't matter
	"i0",                                 // linking to PEB
	"i0",                                 // unloading is fine
	"i0",                                 // do load all dependencies
	"z",                                  // load_all_deps_but DLL_A,DLL_B,DLL_C...
	"z",                                  // not using load_deps
	"z",                                  // not using search_paths
	"i1",                                 // running with -inthread
})

@michaelweber
Copy link
Collaborator Author

michaelweber commented Feb 22, 2025

Confirmed this works - I've pushed the fix. Got delayed because I ran into something stupid where I needed to use go to compress the BOF instead of just running gzip on the .o file - but we're good now.

Thanks again @parzel!

Going to close this issue for now but if anyone has issues with this please comment on it / open a new issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants