问题
Without any encryption, if the recipient has the serialized Protobuf file but does not have the generated Protobuf class (they don't have access to the .proto file that define its structure), is it possible for them to get any data in the Protobuf file from the binary?
If they have access to a part of the .proto file (for example, just one related
message
in the file) can they get a part of that data out from the entire file while skipping other unknown parts?
回答1:
- yes, absolutely; the
protoc
tool can help with this (see:--decode_raw
), as can https://protogen.marcgravell.com/decode - so it should not be treated as "secure" at all - yes, absolutely - that's a key part built into the protocol that allows messages to be extensible such that they can decode the bits they understand and either ignore or just store (for round-trip or "extension" fields) the bits they don't understand
protobuf is not a security device; to someone with the right tools it is just as readable as xml or json, with the slight issue that it can be uncertain how to interpret some values; but: you can infer and guess and reverse engineer
回答2:
Ok, I have found this page https://developers.google.com/protocol-buffers/docs/encoding
The message discards all the names and is just a pair of key number and values. The generated class might offer some protection for safely reading these data and could not read unknown data. (Sure enough because the generated class was generated from known structure, .proto
file)
But if I am an attacker I could reference that Encoding page and try to figure out which area in the binary corresponds to which data. For example, varint might be easy to spot after changing some data. And proceed to write my own .proto
file to attack this unknown data or even a custom binary reader that can selectively read part of the binary.
来源:https://stackoverflow.com/questions/44799407/how-secure-the-protobuf-is-to-get-some-of-the-data-out