rapid7/metasploit-framework — pull request #4302 by zeroSteiner (2014-12-03 02:05:56+00:00)
Title: Fix getuid for the python meterpreter

Currently on non-Windows systems the ```getpass.getuser()``` function provides the username for ```stdapi_sys_config_getuid```. However this function will return an incorrect value when specific environment variables are set (LOGNAME, USER, LNAME, or USERNAME). This PR attempts to fix this by preferring the ```pwd``` module when it is available which will lookup the correct username based on the UID.

This also fixes an error with ```stdapi_sys_config_getenv``` when used on Python 3 due to a different implementation of the string ```translate``` method.

Verification steps:
- [ ] Set one of the environment variables specified ```export LOGNAME=groot```
- [ ] Open a python meterpreter session
- [ ] Verify that ```getuid``` returns the correct username and **not** the value of environment variable
- [ ] Verify that the ```getenv``` command works as expected from Python 3.x

Example output:
```
msf-git (S:0 J:0) exploit(handler) > exploit

[*] [2014.12.02-21:02:04] Started HTTP reverse handler on http://0.0.0.0:8080/
[*] [2014.12.02-21:02:04] Starting the payload handler...
[*] [2014.12.02-21:02:08] 192.168.90.1:40161 Request received for /QDrI...

meterpreter > getuid
Server username: steiner
meterpreter > getenv LOGNAME

Environment Variables
=====================

Variable Value
-------- -----
LOGNAME groot

meterpreter >
```