News for hackers. Stuff that matters.
Re:The most dangerous code in the world by rolux on Wednesday October 24, 2012 @07:03PM (#4695470)
From the PDF linked in the article:

"Not the most interesting technically, but perhaps the most devastating (because of the ease of exploitation) bug is the broken certificate validation in the Chase mobile banking app on Android. Even a primitive network attacker—for example, someone in control of a malicious Wi-Fi access point—can exploit this vulnerability to harvest the login credentials of Chase mobile banking customers."

Re:The most dangerous code in the world by rolux on Wednesday October 24, 2012 @07:12PM (#4695500)
Further down in the PDF, the authors present the decompiled source of the Chase app:

  public final void checkServerTrusted(X509Certificate[]
      paramArrayOfX509Certificate, String paramString)
  {
    if ((paramArrayOfX509Certificate != null) && (
        paramArrayOfX509Certificate.length == 1))
      paramArrayOfX509Certificate[0].checkValidity();
    while (true)
    {
      return;
      this.a.checkServerTrusted(
          paramArrayOfX509Certificate, paramString);
    }
  }
Good to know this isn't used for anything critical, just for, um, mobile banking.
Re:The most dangerous code in the world by sukuriant on Wednesday October 24, 2012 @07:20PM (#4695530)
Okay. Please tell me I'm reading that wrong.

   void foo(X509Certificate[] a, String unused) {
     if( a != null && a.length == 1) a[0].checkValidity();
     while(true){
        return;
        /* never executed stuff */
        foo(a, unused);
     }
   }
X509Certificate.checkValidity()'s javadoc: http://docs.oracle.com/javase/1.5.0/docs/api/javax/security/...

Selections from above link:

Checks that the certificate is currently valid. It is if the current date and time are within the validity period given in the certificate.

  Throws:
  CertificateExpiredException - if the certificate has expired.
  CertificateNotYetValidException - if the certificate is not yet valid.
There has got to be more to their code than this. It does nothing useful except make sure a random certificate is not expired. If there is no certificate, it doesn't fail or return false or anything. What is this!?

Could this be a profiler-optimized set of code that really had a LOT more code to it? But then why would the bit of random junk after the return statement exist? Did no one do a proper code-review of this???

[edit: I used JavaSE 1.5 above; but I just checked Android's version and it looks to be the same, just less verbage in the docs.]

Re:The most dangerous code in the world by gardarh on Wednesday October 24, 2012 @07:48PM (#4695613)
It looks a lot like the output from an Android decompilation tool... which tends to return some weird stuff. That code segment would never compile (code immediately below a return/break/continue/etc. statement causes a compilation error).
Re:The most dangerous code in the world by Eduard on Wednesday October 24, 2012 @08:22PM (#4695725)
Can you elaborate here? Can you point to an example for some weird Android decompilation?
Re:The most dangerous code in the world by gardarh on Wednesday October 24, 2012 @08:33PM (#4695768)
Just run the dex2jar tool on any android .apk and view the results in jd-gui. I've looked at a few apk's and weirdness like the one noted above is quite common. The code is being reverse engineered from a .smali file and the reverse engineering process appears imperfect. Of course any const names would be stripped away from the decompiled code leaving hardcoded integers (such as the 0 in paramArrayOfX509Certificate[0].checkValidity() ).

I'm not saying that the conclusion of the article is wrong, I'm merely trying to explain why the code blob above looks so weird.

Re:The most dangerous code in the world by sukuriant on Wednesday October 24, 2012 @09:49PM (#4695977)
0 is the first element in the array; so, I bet that wasn't a constant, but honestly what the programmer did.

In either case, we have the bytecode; and shouldn't what is written above compile to the same bytecode?

Re:The most dangerous code in the world by jgeralnik on Thursday October 25, 2012 @04:44AM (#4696824)
Some code obfuscators will introduce illegal programming constructs. Most VMs will tolerate these but the decompiled source cannot be recompiled without fixing these. Not saying that's what happened here, but it is an option.
Re:The most dangerous code in the world by sukuriant on Thursday October 25, 2012 @05:45AM (#4696963)
So it is a very real possibility that an obfuscation technique that basically throws random bits of code with random extra params in another method and calls them at it would could have been used here. Interesting. It would certainly make more sense.
Re:The most dangerous code in the world by gardarh on Thursday October 25, 2012 @05:15AM (#4696881)
To demonstrate my point, try writing the following into C.java:

public class C { public int foo() { return 1; int b = 1 + 2; } }

Then compile it (javac C.java). You will get the following:

C.java:4: unreachable statement int b = 1 + 2; ^ C.java:5: missing return statement } ^ 2 errors

Therefore this code is not compileable, thus telling us that the initial code blob could never have run in the first place.

I'm not sure why the decompiler returns non-compiling java code, I just know it does.

Re:The most dangerous code in the world by iclelland on Wednesday October 24, 2012 @07:36PM (#4695576)
That almost hurts to look at -- It looks like a botched attempt at a recursive method to iterate through the array.

I can imagine some poor developer, unable to figure out why it seems to always throw a StackOverflowException, putting that return statement in in frustration, and forgetting about it.

Re:The most dangerous code in the world by ChuckMcM on Wednesday October 24, 2012 @07:55PM (#4695629)
Ouch, that is seriously yucky code.
Re:The most dangerous code in the world by rolux on Wednesday October 24, 2012 @07:28PM (#4695548)
The issue with the code above is the return statement, most likely inserted during development, with the good intention to remove it later, since the "bit of random junk" that follows would have validated the server's certificate.
Re:The most dangerous code in the world by sukuriant on Wednesday October 24, 2012 @07:42PM (#4695595)
But it doesn't. It's calling the exact same function. As your sibling comment remarked, it looked like someone really frustrated with why they were getting a stack-overflow error and gave up.
Re:The most dangerous code in the world by brown9-2 on Thursday October 25, 2012 @08:45AM (#4697357)
I'm not sure if things are different with the Android compiler, but javac will not compile code with an unreachable statement after a return like that.