Code-Racing / brickyard

0 stars 0 forks source link

CONTRAST: 'MD5' hash algorithm used at BlacklistTest.java #97

Open valvolineford opened 4 years ago

valvolineford commented 4 years ago

Vulnerability ID: 7IV6-HNIL-OXQ2-5VL9

Application Name: AgentMessageGeneratorJava

Vulnerability Link: http://localhost:19080/Contrast/static/ng/index.html#/7c6cfec5-a187-4d5e-984a-d11d96d2ef63/applications/6394f24f-037b-43bb-8ac2-05fa5fb5d862/vulns/7IV6-HNIL-OXQ2-5VL9

What Happened?

The code:

com.contrastsecurity.agent.assess.test.blacklist.BlacklistTest$1#doStuff(), line 16

...obtained a handle to the hashing algorithm seen here, which is considered insecure:

digest = java.security.MessageDigest.getInstance("MD5")

What's the risk?

The application uses a hashing algorithm that has been established by researchers to be unsafe for protecting sensitive data with today's technology.

Recommendation

Cryptography is hard. There are lots of little mistakes you can make in your cryptosystem that can leak information, or worse - but choosing a known unsafe hashing algorithm can be a big mistake. This is why we wanted to alert you to the presence of a hashing algorithm being used that doesn't meet our standards.

Obviously, there are lots of times when a hashing algorithm like MD5 or SHA-1 is used in a way that doesn't represent realistic risk to your organization. However, if you find yourself needing to switch hashing algorithms, doing it in the code is very easy; data migration is a much bigger problem. Here's code that gets a MD5 digester, which is considered BROKEN by today's standards because it's not nearly as collision-resistant as once thought:

MessageDigest badDigester = MessageDigest.getInstance("MD5"); // Unsafe

The following code retrieves a SHA-256 cipher, which is considered MUCH STRONGER for many reasons (including a 256-bit hash, which is less likely to fall victim to a birthday attack): MessageDigest safeDigester = MessageDigest.getInstance("SHA-256"); // Safe!

Attacks against unsafe digests are more than theoretical; undirected collisions can be found on an average laptop in a few seconds. Directed collisions can be generated with relatively modest resources. That being said, all practical attacks would seem to require cryptographers of rare quality and the resources of a mid-large sized organization. Therefore, you should carefully decide how likely you are to face such an attack when estimating the severity of this issue. There is a common saying in cryptography (attributed to the NSA), "Attacks always get better; they never get worse." Make your cryptographic design accordingly!

First Event


Stack:
  java.security.MessageDigest.getInstance(MessageDigest.java:181)
  com.contrastsecurity.agent.assess.test.blacklist.BlacklistTest$1.doStuff(BlacklistTest.java:16)
  com.contrastsecurity.agent.assess.test.TestServlet.service(TestServlet.java:56)
  com.contrastsecurity.agent.assess.test.TestServlet.run(TestServlet.java:50)
  com.contrastsecurity.agent.assess.test.TestServlet.run(TestServlet.java:26)
  com.contrastsecurity.agent.assess.test.blacklist.BlacklistTest.testBlacklist(BlacklistTest.java:23)
  sun.reflect.NativeMethodAccessorImpl.invoke0()
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:498)
  junit.framework.TestCase.runTest(TestCase.java:176)
  junit.framework.TestCase.runBare(TestCase.java:141)
  junit.framework.TestResult$1.protect(TestResult.java:122)
  junit.framework.TestResult.runProtected(TestResult.java:142)
  junit.framework.TestResult.run(TestResult.java:125)
  junit.framework.TestCase.run(TestCase.java:129)
  junit.framework.TestSuite.runTest(TestSuite.java:252)
  junit.framework.TestSuite.run(TestSuite.java:247)
  org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
  org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
  org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
  org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
  org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
  org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
  org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

Last Event


Stack:
  java.security.MessageDigest.getInstance(MessageDigest.java:181)
  com.contrastsecurity.agent.assess.test.blacklist.BlacklistTest$1.doStuff(BlacklistTest.java:16)
  com.contrastsecurity.agent.assess.test.TestServlet.service(TestServlet.java:56)
  com.contrastsecurity.agent.assess.test.TestServlet.run(TestServlet.java:50)
  com.contrastsecurity.agent.assess.test.TestServlet.run(TestServlet.java:26)
  com.contrastsecurity.agent.assess.test.blacklist.BlacklistTest.testBlacklist(BlacklistTest.java:23)
  sun.reflect.NativeMethodAccessorImpl.invoke0()
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:498)
  junit.framework.TestCase.runTest(TestCase.java:176)
  junit.framework.TestCase.runBare(TestCase.java:141)
  junit.framework.TestResult$1.protect(TestResult.java:122)
  junit.framework.TestResult.runProtected(TestResult.java:142)
  junit.framework.TestResult.run(TestResult.java:125)
  junit.framework.TestCase.run(TestCase.java:129)
  junit.framework.TestSuite.runTest(TestSuite.java:252)
  junit.framework.TestSuite.run(TestSuite.java:247)
  org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
  org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
  org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
  org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
  org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
  org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
  org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

HTTP Request

GET http://acme.com/foo??foo=bar&id=23 HTTP/1.0 Host: acme.com

References

https://www.owasp.org/index.php/Cryptographic_Storage_Cheat_Sheet