rapid7/metasploit-framework — pull request #3085 by OJ (2014-03-11 05:00:48+00:00)
Title: Support service_control and new status field in service_query from Meterpreter

This code adds support for the new `service_control` feature in Meterpreter and also supports the status field that comes from the `service_query` function.

To modify the status of services the current session needs permissions. Here's an example without permissions:
```
meterpreter > service_query wmpnetworksvc

Name : wmpnetworksvc
Display : Windows Media Player Network Sharing Service
Account : NT AUTHORITY\NetworkService
Status : Running
Start Type : Manual
Path : "C:\Program Files\Windows Media Player\wmpnetwk.exe"
L.O. Group :
Interactive : No
DACL : D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)

meterpreter > service_control wmpnetworksvc stop
[-] extapi_service_control: Operation failed: Access is denied.
```
Here's a sample with permissions
```
meterpreter > service_query wmpnetworksvc

Name : wmpnetworksvc
Display : Windows Media Player Network Sharing Service
Account : NT AUTHORITY\NetworkService
Status : Running
Start Type : Manual
Path : "C:\Program Files\Windows Media Player\wmpnetwk.exe"
L.O. Group :
Interactive : No
DACL : D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)

meterpreter > service_control wmpnetworksvc stop
[+] Operation stop succeeded.
meterpreter > service_query wmpnetworksvc

Name : wmpnetworksvc
Display : Windows Media Player Network Sharing Service
Account : NT AUTHORITY\NetworkService
Status : Stopped
Start Type : Manual
Path : "C:\Program Files\Windows Media Player\wmpnetwk.exe"
L.O. Group :
Interactive : No
DACL : D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)
```
This works with `start`, `pause`, `resume`, `stop` and `restart`.

### Verification

- [ ] Querying services works on all platforms and gives the `status` field.
- [ ] `start` works (x86/x64)
- [ ] `pause` works (x86/x64)
- [ ] `resume` works (x86/x64)
- [ ] `stop` works (x86/x64)
- [ ] `restart` works (x86/x64)

Relies on this Meterpreter PR: https://github.com/rapid7/meterpreter/pull/77