1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-04-30 13:07:22 +02:00

160 Commits

Author SHA1 Message Date
OJ
719dbe2b51 PR tidy based on feedback
* Updated `thread_create` so that it has 3 parameters, and removed
  `thread_create3`.
* Updated all calls to `thread_create` and added the extra parameter of
  `NULL`.
* Fixed comment typo.
* Removed assignment where value is not used.
* Checked for `NULL` prior to setting the result.
* Undefined `DEBUGTRACE`.
2013-10-18 06:30:31 +10:00
OJ
3b40f1abd0 Command refactor for clean shutdown + inline calls
This work contains a bunch of changes around command dispatching. The
goals for this bit of work were to:

* Provide the ability for commands to be executed on the same thread as
  the server rather than always creating new threads and executing them on
  those threads.
* Have the means for _special_ commands, such as `exit` and `migrate` to
  shut down the server cleanly without having to rely on signalling across
  threads or by doing brutal thread termination via shared global handles.
  This should not only fix the dirty shutdown problem on Windows which
  leaves tasks dangling (or based on the prior attempt at fixing, crashing
  stuff as well), it should also help clean up the shutdown process in
  POSIX.

These changes hit a very important part of Meterpreter and so should be
reviewed with intense scrutnity. I expect this PR to garner a log of
critique and most likely a number of changes before being included in the
main line.

The `PacketDispatcher` was modified to include a new function pointer
called an `inline_handler`. This new member indicates that there's a
handler which should be invoked inline. While this sits alongside the
existing `handler`, they are actually mutually exclusive. If an
`inline_handler` is specified then the `handler` is ignored and it is
assumed that the command is intended to be handled inline. The signature
of the inline handler is different to the standard handler, and this is
why a new function pointer was added rather than a simple flag. Addition of
this parameter meant that the basic command structure changed, and that
obviously affects all of the extensions and their respective commands.
This changeset therefore updates each of those command declarations so
that they use the new macros that hide this detail.

Other things to be mindful of:

* This version of the code reads the command's `method` prior to invoking
  any other function, and after that the command itself is passed around to
  the threaded or non-threaded routes for invocation. An extra thread
  parameter was included as as result, and an overload for the
  `thread_create` function was added which supported this new parameter.
  This was named `thread_create3` because
  `thread_create_with_another_paramter` sounded a bit crap.
* The migration code, which originally had a `thread_kill` and an event
  wait once the new meterpreter session had been created, has been modified
  to not do any waiting at all. Instead it finishes execution as fast as
  possible and returns control to the server which should respond by
  shutting down in a clean way.
* Originally the code always attempted to call a command handler in the
  base command list and then, if found, would also call an "overload" in
  the extension commands list. From the investigation that I did, it
  appears that the overloaded methods did nothing in the base (they'd
  early out during invocation). As a result, the new way of doing things
  acts like a 'true' overload in that the extension commands are searched
  first, and if one is found this is the command that is executed. Any
  base commands with the same method name will not get executed. In the
  case where there is no extension command found, the base command list is
  then queried. If a command is found that command is instead invoked.
* The POSIX version still compiles cleanly, but I've never been able to
  build a version that runs on my machines. I'm not sure if there's a
  trick to getting POSIX builds to run, and if there is I don't know it.
  Whoever scrutinises this build should make sure that the POSIX version
  that they build can still run and (hopefully) exit cleanly.

I've added lots of documentation, but there's always room for improvement.

Hopefully this will fix the `*_tcp` side of Redmine 8438.

Bring on the feedback!
2013-10-17 22:36:49 +10:00
James Lee
12140d10b4 Land , doxygen 2013-10-16 19:44:03 -05:00
Tod Beardsley
1fc10a8664 Resolve PR conflict
Conflicts:
	.gitignore
2013-10-16 09:39:47 -05:00
OJ
2c865a4a37 Documented base.* and core.*
Big job, this documentation lark. Also modified the prototype the
packet_is_tlv_null_terminated function, which used to take a Packet
instance as well as the TLV, but never used the packet in its
implementation.
2013-10-15 16:14:39 +10:00
OJ
ea3b9155b2 Fix railgun multi functionality
The main issue with things being broken was because the calling
convention was not defaulting to "stdapi" and hence the call would
fail. Adding the default fixed it.

While fixing this, I brought the mulit-call functionality up to speed
with the error message functionality, so the calls all return the
properly formatted error message.
2013-10-04 12:01:59 +10:00
James Lee
50b7557290 Land , Railgun error messages
See  and 
2013-10-01 16:39:01 -05:00
jvazquez-r7
07a45634bb Land , @OJ's fix for PIP_ADAPTER_PREFIX Length check 2013-09-26 17:46:32 -05:00
OJ
60b4a5778d Better fix for the XP SP0 problem
Thanks to @jvazquez-r7 doing some investigation we have a better solution
to this crash. This commit implements this fix and removes the need to
check the status of the memory that's being read.
2013-09-27 08:32:31 +10:00
Meatballs
1ed1fa6e94 Fix indent and nitpick 2013-09-19 20:22:45 +01:00
Meatballs
2182a891b6 Correct indent 2013-09-17 19:24:39 +01:00
Meatballs
4090e197aa Merge branch 'master' of github.com:rapid7/meterpreter into ip_resolv 2013-09-17 19:19:51 +01:00
Meatballs
4f1c2fe1ed Dont build in nix 2013-09-17 19:18:44 +01:00
OJ
8070ff7771 Possible fix for XP SP0 System process exploit crash
Exploitation of the System process on Windows XP SP0 resulted in crashes
when metepreter was enumerating network interfaces. It appears that the
System process isn't able to read from the address that contains prefixes
(stored in pPrefix in interfaces.c). In other cases, such as exploitation
of svchost.exe or via an msfpayload-generated exe, there was no such
crash. This is not an issue on later versions of Windows.

This crash happens in the current "production" version of Meterpreter that
was deployed with MSF v4.7.

The MS08-067 exploit targets the System process, and hence crashes.
The MS03-26 exploit targets svchost, and hence does not crash.

Checking the protection of the memory in each of those cases showed that
the MEM_COMMIT was set when not the System process, and was MEM_RESERVED
when it was. Sample runs can be seen here: http://pastebin.com/2WHqJ90A

This commit is an attempt to avoid this crash down the track, and it just
does a simple check to see if querying the area of memory for the current
process shows a state of MEM_COMMIT. If so, it carries on as per normal,
if not it uses the other legacy code path to traverse the network
interfaces.

With this "fix" in place I have not seen a crash at all on Windows XP,
Windows 7, Windows 8 and Windows 2012.
2013-09-16 23:14:10 +10:00
OJ
99771d367e Removal of more warnings in compilation 2013-09-15 00:06:49 +10:00
OJ
f0e7e0ec3c Add error message support to the railgun code
This code was lost in the transition when the meterpreter source was
removed from the metasploit-framework source. I'm pulling this in by
request of @dmaloney-r7 who originally requested this code be inculded
as part of https://github.com/rapid7/metasploit-framework/pull/740

I added an extra bit of code to free up memory that is allocated by the
call to FormatMessage and forced the ASCII-version (FormatMessageA) of
the call.
2013-09-13 06:15:48 +10:00
OJ
87031e0d00 Work towards a clean build
* Various code fixes to keep the compiler warnings down.
* Adjustments to project files.
2013-09-03 16:49:09 +10:00
OJ
8ae670cfaf Fix C++11 make_pair errors and U_CHAR problem
* make_pair() changed in C++11 so this change fixes the code so that the
  compiler doesn't complain any more.
* Compiler was also complaining about redefinition of U_CHAR. Undefining
  before redefining resolves the issue.
2013-09-02 12:07:50 +10:00
Meatballs
071ff00a38 IPv6 resolution and remove nix 2013-06-20 22:29:49 +01:00
Meatballs
9b775f33d3 Add debug statements 2013-04-19 14:48:05 +02:00
Meatballs
b96062380c Use getaddrinfo 2013-04-19 11:06:52 +01:00
James Lee
7cafff29f5 Fix compilation on Linux
Doesn't work, but at least it compiles
2013-04-17 18:08:14 -05:00
James Lee
ee5efcfb58 whitespace 2013-04-17 17:43:33 -05:00
Meatballs
87dae3d449 Add file and project changes 2013-04-14 11:09:12 +01:00
Meatballs
85dc7cc96e Newline at EOF 2013-04-14 11:04:08 +01:00
Meatballs
aecf0b28d4 Final 2013-04-14 10:59:34 +01:00
Meatballs
0395a6cb3e correct indent 2013-04-11 21:10:55 +01:00
Meatballs
94de029ee2 Initial attempt 2013-04-07 23:04:54 +01:00
James Lee
d80547c656 Whitespace at EOL 2013-04-04 23:37:20 -05:00
James Lee
7cc29ff475 Landing , mv command 2013-04-04 23:12:26 -05:00
James Lee
2c812603e5 Whitespace 2013-04-04 22:33:15 -05:00
James Lee
0a5c4350cd Landing PR1, 64-bit in-mem execution 2013-04-04 22:04:24 -05:00
James Lee
b3c70642cb Use the same macro approach as stdcall
Gets rid of a ton of warnings at the expense of some slightly uglier
code.
2013-04-04 21:31:17 -05:00
James Lee
f7530f711b Default to stdcall if no convention is given
This keeps old API usage intact.
2013-04-04 20:57:19 -05:00
James Lee
4131c3bb4e Landing , Meatballs' fixes for cdecl in railgun 2013-04-04 20:40:11 -05:00
James Lee
8076989adf Fix precomp weirdness with audio and bmp2jpeg again 2013-04-04 20:37:15 -05:00
James Lee
4bf4125728 Add precomp.h to audio and bmp2jpeg
Makes it match all the other stuff in stdapi
2013-04-03 13:32:07 -05:00
Meatballs
23503bd3fa Merge remote branch 'origin/master' into railgun_cdecl_fix_clean 2013-03-29 13:01:37 +00:00
RageLtMan
035531c35c This commit adds in-memory substitution for x64
Initial commit of in-mem-exe.c modifications for Windows x64.
Initial boolean wrapper checks to see if the image supplied is a
valid 64bit PE and calls a 64bit injection function. wow64 not yet
implemented.

64bit execution is a bit tricky since we can't get the entrypoint
of the existing thread from ThreadContext.Eax and we need to make
sure that our images are properly aligned. The 64 bit mapper is
based on MemExec64 source code by Steve10120 [at] icode.org.

TODO:
Write wow64 based injector. Write conditional to check that
source and destination images are the same architecture and call
the arch appropriate injection method.
Write "Heaven's Gate" based injector for running x86 process in
x64 space.
2013-03-20 18:45:08 -04:00
RageLtMan
412fe9879b fix whitespace 2013-03-20 18:39:20 -04:00
RageLtMan
9ac6d93580 add meterpreter side of stdapi.fs.file.mv 2013-03-20 18:29:47 -04:00
James Lee
ceb6812b15 Add missing hook.dll
Hopefully the last obstacle to compiling on Windows.
2013-03-20 14:19:21 -05:00
Meatballs
167d7cc70e Correct railgun.c 2013-02-11 20:47:35 +00:00
Meatballs
fb8567e378 New clean pull 2013-02-11 20:46:15 +00:00
James Lee
7283131279 Initial source import from metasploit-framework 2012-11-19 16:46:07 -06:00
jlee-r7
964bae0c49 Initial commit 2012-11-19 14:40:03 -08:00
m m
b7a464292c I was pretty sure to have removed those fclose before 2012-09-12 13:11:24 -05:00
m m
c8b85f9587 fix netstat program name 2012-09-12 13:11:24 -05:00
m m
2860d0481e fix netstat program name 2012-09-12 13:11:24 -05:00
James Lee
e3915b99e4 Whitespace at EOL 2012-08-28 17:02:37 -05:00