rapid7/metasploit-framework — pull request #4329 by zeroSteiner (2014-12-06 21:44:35+00:00)
Title: Error messages for the python meterpreter

This adds error messages for the Python meterpreter. Python exception names and Windows error numbers are caught and returned to the user to help them troubleshoot what might have gone wrong. This is an improvement over the current implementation which always returns an error number of 1 with no additional details.

Side note, Python 3.3 introduced some additional builtin exceptions. This means the same error-causing action may not always produce the same message depending on the version.

Testing procedure:
- [ ] Open a Python meterpreter session on Linux and do things to cause errors
- [ ] View an error message with the Python exception name
- [ ] Open a Python meterpreter session on Windows and do more things to cause errors
- [ ] View a Windows error message or a Python exception name depending on the error type

Examples:
Windows 7 Python 3.4
```
meterpreter > cat thisfiledoesnotexist
[-] stdapi_fs_stat: Operation failed: Python exception: FileNotFoundError
```

Windows 7 Python 2.7
```
meterpreter > cat thisfiledoesnotexist
[-] stdapi_fs_stat: Operation failed: Windows error: The system cannot find the file specified.
```

Linux Python 3.4
```
meterpreter > cat /etc/shadow
[-] core_channel_open: Operation failed: Python exception: PermissionError
```
Linux Python 3.1
```
meterpreter > cat /etc/shadow
[-] core_channel_open: Operation failed: Python exception: IOError
```