msgpack / msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
http://msgpack.org
Apache License 2.0
832 stars 174 forks source link

Problem parsing returned data that does not happen in Ruby #11

Closed darkoperator closed 10 years ago

darkoperator commented 11 years ago

I'm using the library to write a automation module in PowerShell for Metasploit. The command for getting a list of sessions when received gets parsed in Ruby as:

>> rpc.call("session.list")
=> {1=>{"type"=>"meterpreter", "tunnel_local"=>"192.168.1.104:8080", "tunnel_peer"=>"192.168.1.183:1028", "via_exploit"=>"exploit/windows/smb/ms08_067_netapi", "via_payload"=>"payload/windows/meterpreter/reverse_tcp", "desc"=>"Meterpreter", "info"=>"NT AUTHORITY\\SYSTEM @ WIN2K3VMTEST", "workspace"=>"default", "session_host"=>"192.168.1.183", "session_port"=>445, "target_host"=>"192.168.1.183", "username"=>"carlos", "uuid"=>"zkzemzq5", "exploit_uuid"=>"mjqmtx7b", "routes"=>"", "platform"=>"x86/win32"}}

Now when I use msgpack.dll in both C# and PowerShell I get the following exception:

"Do not convert System.Byte (binary:0x1) MessagePackObject to MsgPack.MessagePackString."

Any clue what the error could be? I even tried it in python and it seemed to work fine with the python library. I compiled msgpack.dll using VS 2012

yfakariya commented 11 years ago

@darkoperator

Would you tell me what type did you deserialize stream to? If you deserialized stream as Dictionary<String, String>, for example, deserialization will fail because first key is numeric '1'.

darkoperator commented 11 years ago

Looks like the library I'm using it turning it into a Dictionary :) I will inform the author of it https://github.com/brandonprry/metasploit-sharp/blob/master/metasploit-sharp/MetasploitSession.cs#L110

darkoperator commented 11 years ago

I see that the methods in unpacking do not include unpacking to a Hashtable so as to keep the key/value structure but offer ILits and String, what would your recommendation be in this case given the structure?

yfakariya commented 11 years ago

You can use any of following to get raw key/value structures: 1) MessagePackSerializer.Create<Dictionary<MessagePackObject, MessagePackObject>>().Unpack... // returns Dictionary<MessagePackObject, MessagePackObject> 2) Unpacking.UnpackDictionary(...) // returns MessagePackDictionary(IDictionary<MessagePackObject,MessagePackObject>) 3) Unpacking.UnpackObject(...).AsDictionary(); // returns MessagePackDictionary 4) Unpacker.Data.AsDictionary(); // returns MessagePackDictionary

And you can cast MessagePackObject to various primitives.

Does it answer you?

yfakariya commented 10 years ago

Close because over 1year pasts.