Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CC11001100 opened this issue Jan 25, 2024 · 2 comments
Closed

Comments

@CC11001100
Copy link

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:

URL u = new URL(null, url, handler); // URL to use as the Key

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:
Reflections.setFieldValue(u, "hashCode", -1); // During the put above, the URL's hashCode is calculated and cached. This resets that so the next time hashCode is called a DNS lookup will be triggered.

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
Copy link

UzJu commented Jan 25, 2024

mark

@frohoff
Copy link
Owner

frohoff commented Mar 31, 2024

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

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

@frohoff frohoff closed this as completed Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants