frohoff / ysoserial

A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.
http://frohoff.github.io/appseccali-marshalling-pickles/
MIT License
7.77k stars 1.76k forks source link

Hello, I have some confusion about the code implementation of URLDNS #213

Closed CC11001100 closed 7 months ago

CC11001100 commented 9 months ago

Thank you for such an excellent open source project, I have some confusion about the code implementation of URLDNS,

A custom URLStreamHandler was used here to block DNS resolution: https://github.com/frohoff/ysoserial/blob/2874a69f6127fd3b3f078461741910423a6b1376/src/main/java/ysoserial/payloads/URLDNS.java#L56 But it also affects the hash code of the URL, causing the hash code obtained by the URL to be inconsistent with the original hash code: image The hashcode of the URL obtained at this point appears to be true, but in reality it is not: image The true hashcode should be: image Subsequently, the hashcode cache in the URL was reset through reflection: https://github.com/frohoff/ysoserial/blob/2874a69f6127fd3b3f078461741910423a6b1376/src/main/java/ysoserial/payloads/URLDNS.java#L59 This reflection looks quite troublesome because it also involves compatibility issues with the JDK version and introduces a dedicated library:

        <dependency>
            <groupId>com.nqzero</groupId>
            <artifactId>permit-reflect</artifactId>
            <version>0.3</version>
        </dependency>

My question is, since the hashcode needs to be cleaned up, why not just rewrite the hashcode method of URLStreamHandler in SilentURLStreamHandler and directly return -1? This way, the implementation is simpler and there is no need to consider compatibility issues image Anyway, the hashcode is different from the original one. As for whether the hashcode of the key in HashMap is -1 or 12345678, it doesn't seem to be that important anymore?

Thank you again for bringing such an excellent project, and I hope you have time to help me clarify.

UzJu commented 9 months ago

mark

frohoff commented 7 months ago

Please use the discussions feature for questions or troubleshooting not related to a bug.

https://github.com/frohoff/ysoserial/discussions