jborean93 / pypsrp

PowerShell Remoting Protocol for Python
MIT License
324 stars 49 forks source link

Update messages.py #161

Closed 3gstudent closed 1 year ago

3gstudent commented 1 year ago

Hi Jordan,

When we connect to the Exchange Powershell, the output command results are incomplete.

Here is the my test code:

wsman = WSMan(server=host, username=username, password=password, port=80, path="PowerShell", ssl=False, auth="kerberos", cert_validation=False)     
with wsman, RunspacePool(wsman, configuration_name="Microsoft.Exchange") as pool:
    ps = PowerShell(pool)                  
    ps.add_cmdlet("Get-Mailbox").add_parameter("-Identity", "administrator")
    output = ps.invoke()
    print("[+] OUTPUT:\n%s" % "\n".join([str(s) for s in output]))

This is the output:

1

In fact, the complete result is as follows:

2

So I rewrite the messages.py to output more complete results.

This is the new output:

3

jborean93 commented 1 year ago

I'm not sure why this is needed, you are doing str(output) which is simply going to get the <ToString> value of the output object which will of course not have all the properties that were returned in the string value.

It sounds like you want to combine output.adapted_properties and output.extended_properties on each of the output objects and then format them the way you wish. Unfortunately the UX is pretty poor for dealing with these complex objects but it shouldn't need a manual check in the deserializer code.

3gstudent commented 1 year ago

Yes, I want to combine the output and get the complete result. Is there a better way to combine output?

jborean93 commented 1 year ago

You would need to go through the adapted_properties and extended_properties of the output object(s). This will contain the keys you are looking for and can be formatted how you wish.

3gstudent commented 1 year ago

OK. Thanks for your advice.