rapid7/metasploit-framework — pull request #2443 by OJ (2013-10-01 07:30:07+00:00)
Title: Add error message support to railgun

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

This PR is the MSF side of https://github.com/rapid7/meterpreter/pull/26

Sample run:

[*] Started reverse handler on XXX.XXX.XXX.XXX:8000
[*] Starting the payload handler...
[*] Sending stage (784896 bytes) to 10.5.26.41
[*] Meterpreter session 1 opened (XXX.XXX.XXX.XXX:8000 -> XXX.XXX.XXX.XXX:1173) at 2013-10-01 17:13:56 +1000

meterpreter > irb
[*] Starting IRB shell
[*] The 'client' variable holds the meterpreter client

>> client.railgun.add_function('kernel32', 'DeleteFileA', 'BOOL', [['PCHAR', 'lpFileName', 'in']])
=> #
>> client.railgun.kernel32.DeleteFileA('C:\share\foo.txt')
=> {"GetLastError"=>0, "ErrorMessage"=>"The operation completed successfully.", "return"=>true}
>> client.railgun.kernel32.DeleteFileA('C:\share\foo.txt')
=> {"GetLastError"=>2, "ErrorMessage"=>"The system cannot find the file specified.", "return"=>false}
=> {"GetLastError"=>1813, "ErrorMessage"=>"The specified resource type cannot be found in the image file.", "return"=>6}
>> client.railgun.user32.MessageBoxA(0, 'Testing', 'This is testing too', 'MB_YESNO')
=> {"GetLastError"=>0, "ErrorMessage"=>"The operation completed successfully.", "return"=>7}

### Verification

- [ ] Check 32 and 64 bit meterpreter sessions.
- [ ] Validate both successful and unsuccessful API calls.
- [ ] Check in more than one lib (eg. `user32` and `kernel32`).