rapid7/metasploit-framework — pull request #4150 by OJ (2014-11-07 04:11:46+00:00)
Title: Add the getsid command, fix incognito

After a bit of back and forth over https://github.com/rapid7/metasploit-framework/issues/3787 I decided to go implement the `getsid` command that @Meatballs1 suggested.

This PR contains a single commit which has the following changes:

* Addition of the `getsid` function to `config`.
* Addition of the `is_system?` function to `config`.
* Addition of the `getsid` command to the Meterpreter command list.
* Fix the incognito issue where the check for system wasn't localisation friendly.

There may be other modules that I don't know about that could use this.

## Verification

- [ ] Pull the changes from the meterpreter PR https://github.com/rapid7/meterpreter/pull/102
- [ ] Verify that x64 and x86 both build cleanly
- [ ] Verify that `getuid` still works on both x86 and x64
- [ ] Check that `getsid` works on both x86 and x64
- [ ] Drop into ruby and validate that the `is_system?` function behaves on x86 and x64
- [ ] Make sure that incognito stuff still works as per https://github.com/rapid7/metasploit-framework/issues/3787

## Sample runs
### x86
Machine info:
```
meterpreter > sysinfo
Computer : WIN-S45GUQ5KGVK
OS : Windows 7 (Build 7601, Service Pack 1).
Architecture : x64 (Current Process is WOW64)
System Language : en_US
Meterpreter : x86/win32
```
Command not broken:
```
meterpreter > getuid
Server username: WIN-S45GUQ5KGVK\OJ
```
New command works as expected when _not_ `SYSTEM`:
```
meterpreter > getsid
Server SID: S-1-5-21-2676972102-3618304068-1989523545-1000
```
Check incognito still works (uses new `is_system?` function):
```
meterpreter > use incognito
Loading extension incognito...success.
meterpreter > list_tokens -u
[-] Warning: Not currently running as SYSTEM, not all tokens will be available
Call rev2self if primary process token is SYSTEM

Delegation Tokens Available
========================================
NT AUTHORITY\SYSTEM
WIN-S45GUQ5KGVK\OJ

Impersonation Tokens Available
========================================
No tokens available

```
New command works as expected when running as `SYSTEM`:
```
meterpreter > getsystem
...got system (via technique 1).
meterpreter > getsid
Server SID: S-1-5-18
meterpreter > list_tokens -u

Delegation Tokens Available
========================================
NT AUTHORITY\IUSR
NT AUTHORITY\LOCAL SERVICE
NT AUTHORITY\NETWORK SERVICE
NT AUTHORITY\SYSTEM
WIN-S45GUQ5KGVK\OJ

Impersonation Tokens Available
========================================
NT AUTHORITY\ANONYMOUS LOGON
```
### x86 (very similar to x86)
Machine info:
```
meterpreter > sysinfo
Computer : WIN-S45GUQ5KGVK
OS : Windows 7 (Build 7601, Service Pack 1).
Architecture : x64
System Language : en_US
Meterpreter : x64/win64
```
Command not broken:
```
meterpreter > getuid
Server username: WIN-S45GUQ5KGVK\OJ
```
New command works as expected when _not_ `SYSTEM`:
```
meterpreter > getsid
Server SID: S-1-5-21-2676972102-3618304068-1989523545-1000
```
Check incognito still works (uses new `is_system?` function):
```
meterpreter > use incognito
Loading extension incognito...success.
meterpreter > list_tokens -u
[-] Warning: Not currently running as SYSTEM, not all tokens will be available
Call rev2self if primary process token is SYSTEM

Delegation Tokens Available
========================================
NT AUTHORITY\SYSTEM
WIN-S45GUQ5KGVK\OJ

Impersonation Tokens Available
========================================
No tokens available

```
New command works as expected when running as `SYSTEM`:
```
meterpreter > getsystem
...got system (via technique 1).
meterpreter > getsid
Server SID: S-1-5-18
meterpreter > list_tokens -u

Delegation Tokens Available
========================================
NT AUTHORITY\IUSR
NT AUTHORITY\LOCAL SERVICE
NT AUTHORITY\NETWORK SERVICE
NT AUTHORITY\SYSTEM
WIN-S45GUQ5KGVK\OJ

Impersonation Tokens Available
========================================
NT AUTHORITY\ANONYMOUS LOGON
```