forked from ickerwx/tcpproxy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjava_serializer.py
More file actions
37 lines (29 loc) · 1.22 KB
/
java_serializer.py
File metadata and controls
37 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import platform
if 'java' in platform.system().lower():
import java.io as io
from com.thoughtworks.xstream import XStream
class Module:
def __init__(self):
self.is_jython = 'java' in platform.system().lower()
self.name = 'java_serialization'
self.description = 'Serialization of XStream XML data' if self.is_jython else \
'serialization of XStream XML data (needs jython)'
def execute(self, *params):
data = params[0]
if not self.is_jython:
print '[!] This module can only be used in jython!'
return data
# Creating XStream object and creating Java object from XML structure
xs = XStream()
serial = xs.fromXML(data)
# writing created Java object to and serializing it with
# ObjectOutputStream
bos = io.ByteArrayOutputStream()
oos = io.ObjectOutputStream(bos)
oos.writeObject(serial)
# I had a problem with signed vs. unsigned bytes, hence the & 0xff
return "".join([chr(x & 0xff) for x in bos.toByteArray().tolist()])
if __name__ == '__main__':
print 'This module is not supposed to be executed alone!'