<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <generator uri="http://jekyllrb.com" version="3.9.5">Jekyll</generator>
  
  
  <link href="https://serializethoughts.com/feed.xml" rel="self" type="application/atom+xml" />
  <link href="https://serializethoughts.com/" rel="alternate" type="text/html" hreflang="en" />
  <updated>2024-07-04T08:04:23+00:00</updated>
  <id>https://serializethoughts.com/</id>

  
    <title type="html">serializethoughts</title>
  

  
    <subtitle>Serializing thought objects!</subtitle>
  

  
    <author>
        <name>Vikas Gupta</name>
      
      
    </author>
  

  
  
    <entry>
      
      <title type="html">Recovering dProtect’s Obfuscated Strings Using Katalina in an Android App</title>
      
      
      <link href="https://serializethoughts.com/2024/07/03/katalina-dprotect-string-obfuscation" rel="alternate" type="text/html" title="Recovering dProtect's Obfuscated Strings Using Katalina in an Android App" />
      
      <published>2024-07-03T10:32:22+00:00</published>
      <updated>2024-07-03T10:32:22+00:00</updated>
      <id>https://serializethoughts.com/2024/07/03/katalina-dprotect-string-obfuscation</id>
      <content type="html" xml:base="https://serializethoughts.com/2024/07/03/katalina-dprotect-string-obfuscation">&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; &lt;em&gt;In an Android app, strings obfuscated using dProtect can be recovered by Dalvik code emulation using Katalina.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time To Read:&lt;/strong&gt; 5 min&lt;/p&gt;

&lt;h2 id=&quot;katalina&quot;&gt;Katalina&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/huuck/Katalina&quot;&gt;Katalina&lt;/a&gt; is a Dalvik bytecode emulation tool. Katalina implements a sandbox in Python and executes one dalvik instructions at a time for emulation. As highlighted by the author, such approach is useful in dealing with obfuscated code, especially in recovering obfuscated strings.&lt;/p&gt;

&lt;p&gt;String obfuscation is a highly effective technique used by both, malwares and genuine applications to slow down reverse engineering attempts. For instance, lack of visible strings can deter many automated static analysis tools and slows down manual attempts, forcing the attacker to perform dynamic analysis. The app authors can further implement various anti-dynamic analysis techniques to prolong the time to reverse engineer the app.&lt;/p&gt;

&lt;p&gt;To put Katalina to test, I created an obfuscated application using dProtect. &lt;a href=&quot;https://github.com/open-obfuscator/dprotect&quot;&gt;dProtect&lt;/a&gt; is an open source obfuscation tool for Android. It is an extension of Proguard and offers code obfuscation for Java and Kotlin, along with symbol obfuscation feature from Proguard.&lt;/p&gt;

&lt;h2 id=&quot;dprotect-string-obfuscation&quot;&gt;dProtect String Obfuscation&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/darvincisec/DetectMagiskHide&quot;&gt;DetectMagiskHide&lt;/a&gt; is used. Following dProtect configuration is used to enable string obfuscation, along with other techniques:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-keep,allowobfuscation class com.** { *; }

-obfuscations *
-obfuscate-strings      class com.darvin.security.** { *; }
-obfuscate-arithmetic   class com.darvin.security.** { *; }
-obfuscate-constants    class com.darvin.security.** { *; }
-obfuscate-control-flow class com.darvin.security.** { *; }

-repackageclasses
-allowaccessmodification
-flattenpackagehierarchy
-useuniqueclassmembernames
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Post obfuscation, the code is transformed to following:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AppZygotePreload&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ZygotePreload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
 
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1959339100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1532247175&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;496329810&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648423&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1290985939&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;139648832&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1345075629&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;618995181&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
 
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;StringBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;StringBuilder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1532247175&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;charAt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;charAt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;496366473&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;charAt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;charAt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1290935852&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((~(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;496366473&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;496366473&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;charAt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;charAt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;496366473&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((~(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;496366473&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))))));&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((~(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((~(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84648422&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jArr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;139648834&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
 
    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// android.app.ZygotePreload&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doPreload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;ApplicationInfo&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;applicationInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;applicationInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SDK_INT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1959339073&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;loadLibrary&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;鞵鞻鞭鞱鞩鞻韰鞰鞺鞰&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.loadLibrary()&lt;/code&gt; expects a string input and dProtect has obfuscated the original string passed to this function. The original string is recovered during the runtime by calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a(&quot;鞵鞻鞭鞱鞩鞻韰鞰鞺鞰&quot;)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we closely analyze the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt;, the code is self-contained in the class, which means all the dependencies and logic required to execute this function is present in the same class. &lt;strong&gt;There is no dependency on any other class. Such scenarious are perfect to handle using emulation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On using Katalina, the original string &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;native-lib&lt;/code&gt; can be easily recovered:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python3 Katalina/main.py -v classes.dex -x 'Lcom/darvin/security/AppZygotePreload;-&amp;gt;a(Ljava/lang/String;)Ljava/lang/String;' '鞵鞻鞭鞱鞩鞻韰鞰鞺鞰'     
 
// --- output ----
...
INFO     String created: Lcom/darvin/security/AppZygotePreload;.a(LL) -&amp;gt; native-lib
INFO     String created: native-lib
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;patching-katalina&quot;&gt;Patching Katalina&lt;/h2&gt;

&lt;p&gt;The existing implementation of Katalina does not handle all array use-cases properly (and mentioned in the Readme). dProtect’s code is using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aget-wide&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;aput-wide&lt;/code&gt; instructions, and to handle them it required patching Katalina. The patched code is available &lt;a href=&quot;https://github.com/su-vikas/Katalina&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      
        <category term="Obfuscation" />
      
        <category term="Android" />
      
        <category term="Dex" />
      
        <category term="Java" />
      
        <category term="Emulation" />
      

      
        <summary type="html">TL;DR: In an Android app, strings obfuscated using dProtect can be recovered by Dalvik code emulation using Katalina.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Poking around with FRIDA’s Java enumerateClassLoaders</title>
      
      
      <link href="https://serializethoughts.com/2021/05/07/frida-java-classloaders" rel="alternate" type="text/html" title="Poking around with FRIDA's Java enumerateClassLoaders" />
      
      <published>2021-05-07T08:17:22+00:00</published>
      <updated>2021-05-07T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2021/05/07/frida-java-classloaders</id>
      <content type="html" xml:base="https://serializethoughts.com/2021/05/07/frida-java-classloaders">&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; &lt;em&gt;In Android, if classes are loaded by using non-default classloader, FRIDA will not be able to hook it. By using enumerateClassLoaders() API one can get the other classloaders used by the program and use them to hook Java classes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time To Read:&lt;/strong&gt; 5 min&lt;/p&gt;

&lt;h2 id=&quot;java-classloaders&quot;&gt;Java Classloaders&lt;/h2&gt;

&lt;p&gt;In Java, a &lt;a href=&quot;https://en.wikipedia.org/wiki/Java_Classloader&quot;&gt;Classloader&lt;/a&gt; is a part of Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. By doing so, the Java run time does not need to know about files and file systems as this is delegated to the classloader. This concept is very much applicable with Dalvik bytecode for Android as well.&lt;/p&gt;

&lt;p&gt;Often malwares and obfuscation tools change the default behaviour of class loading in Android. By default all the classes to be loaded are present in the classes.dex file and are loaded using the default &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dalvik.system.PathClassLoader&lt;/code&gt; classloader. But Android offers other classloaders too, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dalvik.system.InMemoryDexClassLoader&lt;/code&gt;, using which one can load a dex (containing Java classes) file from the memory.&lt;/p&gt;

&lt;h2 id=&quot;frida&quot;&gt;FRIDA&lt;/h2&gt;

&lt;p&gt;FRIDA will throw error while trying to hook a class not loaded using the default classloader. To this problem, FIRDA provides a easy solution via &lt;a href=&quot;https://frida.re/docs/javascript-api/#java&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java.enumerateClassLoaders()&lt;/code&gt;&lt;/a&gt; API. You can iterate over the classloaders and use them by using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Java.ClassFactory.get(loader)&lt;/code&gt; API. Once the new loader is set, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.use()&lt;/code&gt; API can be used to get the desired class and hook it.&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;Java&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;enumerateClassLoaders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onMatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;loader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;Java&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classFactory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;loader&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;loader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;TestClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;// Hook the class if found, else try next classloader.&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;TestClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Java&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;com.example.TestClass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;TestClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;testMethod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;implementation&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
                    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;[+] Inside test method&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;includes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ClassNotFoundException&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;
                    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; You are trying to load encrypted class, trying next loader&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onComplete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      
        <category term="Android" />
      
        <category term="Frida" />
      

      
        <summary type="html">TL;DR: In Android, if classes are loaded by using non-default classloader, FRIDA will not be able to hook it. By using enumerateClassLoaders() API one can get the other classloaders used by the program and use them to hook Java classes.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Solving iOS UnCrackable 1 Crackme Without Using an iOS Device</title>
      
      
      <link href="https://serializethoughts.com/2019/10/28/solving-mstg-crackme-angr" rel="alternate" type="text/html" title="Solving iOS UnCrackable 1 Crackme Without Using an iOS Device" />
      
      <published>2019-10-28T08:17:22+00:00</published>
      <updated>2019-10-28T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2019/10/28/solving-mstg-crackme-angr</id>
      <content type="html" xml:base="https://serializethoughts.com/2019/10/28/solving-mstg-crackme-angr">&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; iOS UnCrackable Level 1 crackme application can be solved without using an iOS device using Angr’s dynamic execution engine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time To Read:&lt;/strong&gt; 5 min&lt;/p&gt;

&lt;p&gt;OWASP MSTG &lt;a href=&quot;https://github.com/OWASP/owasp-mstg/tree/master/Crackmes/iOS/Level_01&quot;&gt;UnCrackable Level 1 Crackme App&lt;/a&gt; is an iOS crackme application. The goal of the crackme is to find a secret string hidden somewhere inside the application. There are multiple ways to solve the crackme using Frida, or a debugger, or even by manually reversing the native code. In this post I will solve the challenge using Angr’s dynamic execution engine. With the current approach, by using static analysis assisted with dynamic execution, the crackme can be &lt;strong&gt;solved without needing an iOS device.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To perform static analysis, multiple tools are available - Ghidra, R2 or IDA Pro. The application code is not obfuscated and can be easily followed in any of these tools. I am using Ghidra in this post.&lt;/p&gt;

&lt;p&gt;The application gives a message “Verification Failed” when a wrong input is provided to it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/owasp_mstg_angr_ios_app_wrong_input.png &quot; alt=&quot;Verification Failed Message&quot; height=&quot;650&quot; width=&quot;400&quot; /&gt;&lt;/p&gt;

&lt;p&gt;On searching the binary for this string, it is found in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;buttonClick&lt;/code&gt; function. The message is displayed after a comparison operation using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isEqualToString&lt;/code&gt;. The comparison is being performed between the input string and the value of a label marked as &lt;em&gt;hidden&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/owasp_mstg_angr_ghidra_buttonclick_decompiled.png&quot; alt=&quot;Decompilation of buttonClick function&quot; title=&quot;Decompilation of buttonClick function&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To find the secret string, we need to find the value of this label. Further, on analysing the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;viewDidLoad&lt;/code&gt;, the value of the label is being set using the return value of the function at offset &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x1000080d4&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/owasp_mstg_angr_ghidra_viewdidload_decompile.png&quot; alt=&quot;Decompilation of viewDidLoad function&quot; title=&quot;Decompilation of viewDidLoad function&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Shifting our attention to function at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x1000080d4&lt;/code&gt;, there are multiple sub-function calls, and return values from each of these sub-functions is stored at an index of an array at address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x10000dbf0&lt;/code&gt;. This array is the hidden string we are looking for! Each of the above sub-functions are not too complicated, but nevertheless require some manual effort to reverse them and obtain the eventual hidden string.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/owasp_mstg_angr_ghidra_native_disassembly.png&quot; alt=&quot;Decompilation of function at 0x1000080d4&quot; title=&quot;Decompilation of function at 0x1000080d4&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The function at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x1000080d4&lt;/code&gt; or any of its sub-functions are self contained, i.e, there are no library calls or system calls; we can easily run this code in any emulator like Unicorn or its likes. Angr is a reverse engineering framework with multiple features and one of them being to dynamically execute code. For using dynamic execution feature of Angr, we need to identify and pass the points in the program from where we want to emulate the code and the addresses where the eventual secret string generated. In this case, the function at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x1000080d4&lt;/code&gt; is the function we want to emulate and the return value is the information we are interested in. The return value is a pointer to the hidden string.&lt;/p&gt;

&lt;p&gt;The eventual Angr script looks as following:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;angr&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;claripy&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Load the binary by creating angr project.
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;project&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;angr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Project&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'uncrackable.arm64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Pass the address of the function to the callable
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;project&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;callable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x1000080d4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Get the return value of the function
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;ptr_secret_string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;claripy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;backends&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;concrete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;convert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Address of the pointer to the secret string: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;hex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ptr_secret_string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Extract the value from the pointer to the secret string
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;secret_string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result_state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ptr_secret_string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;concrete&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Secret String: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;secret_string&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;solve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Angr &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Project&lt;/code&gt; is the basic building block, and must needed to access any functionality of Angr. Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;callable&lt;/code&gt; API we inform the Angr engine to execute the code from the offset &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x1000080d4&lt;/code&gt;, and the return value post &lt;em&gt;concrete&lt;/em&gt; execution (dynamic execution is also called concrete execution) is captured in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ptr_secret_string&lt;/code&gt;. The value stored in the pointer is accessed using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;result_state&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This solution is also contributed to the &lt;a href=&quot;https://github.com/OWASP/owasp-mstg&quot;&gt;OWASP MSTG&lt;/a&gt; and with some more details on reverse engineering part.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">TL;DR: iOS UnCrackable Level 1 crackme application can be solved without using an iOS device using Angr’s dynamic execution engine.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">RageAgainstTheCage - Revisting Android adb setuid Exhaustion Attack</title>
      
      
      <link href="https://serializethoughts.com/2019/10/28/revisting-rageagainstthecage" rel="alternate" type="text/html" title="RageAgainstTheCage - Revisting Android adb setuid Exhaustion Attack" />
      
      <published>2019-10-28T08:17:22+00:00</published>
      <updated>2019-10-28T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2019/10/28/revisting-rageagainstthecage</id>
      <content type="html" xml:base="https://serializethoughts.com/2019/10/28/revisting-rageagainstthecage">&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; &lt;em&gt;adb setuid exhaustion attack&lt;/em&gt; (aka RageAgainstTheCage) was present in Android 1.6 to 2.2. During &lt;em&gt;adb&lt;/em&gt; initialisation, while dropping its privileges there is no check for &lt;em&gt;setuid&lt;/em&gt; syscall’s return value. This can be exploited by causing a race condition by creating RLIMIT_NPROC processes and killing &lt;em&gt;adb&lt;/em&gt;, on &lt;em&gt;adb&lt;/em&gt; restart &lt;em&gt;setuid&lt;/em&gt; syscall might fail and can lead to &lt;em&gt;adb&lt;/em&gt; continue running with root privileges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time To Read:&lt;/strong&gt; 5 min&lt;/p&gt;

&lt;p&gt;In 2010 Sebastian Krahmer discovered a vulnerability in the implementation of &lt;em&gt;adb&lt;/em&gt; for Android 1.6 to 2.2 versions. The vulnerability is - &lt;em&gt;adb&lt;/em&gt; fails to check &lt;em&gt;setuid&lt;/em&gt; return code and this can be caused to fail by a shell user already having RLIMIT_NPROC processes. The vulnerability in itself is very simple, unlike many other vulnerabilities which require various memory gymnastics to exploit. Apart from the simplicity, the vulnerability gives us a good insight into some of the Linux kernel working and also a good lesson for the developers.&lt;/p&gt;

&lt;h1 id=&quot;rlimit_nproc&quot;&gt;RLIMIT_NPROC&lt;/h1&gt;

&lt;p&gt;To understand the working of this exploit, we need to understand how resource allocation works in Linux. Linux uses &lt;em&gt;getrlimit()&lt;/em&gt; and &lt;em&gt;setrlimit()&lt;/em&gt; system calls to get and set resource limits for a process. Some of the process resources are: virtual memory size, CPU time a process can consume etc, a list is available at &lt;a href=&quot;http://man7.org/linux/man-pages/man2/setrlimit.2.html&quot;&gt;&lt;em&gt;getrlimit&lt;/em&gt; man page&lt;/a&gt;. In this case we are interested in RLIMIT_NPROC resource. This resources was introduced to protect against a &lt;a href=&quot;https://en.wikipedia.org/wiki/Fork_bomb&quot; title=&quot;fork bomb&quot;&gt;fork bomb&lt;/a&gt;. As per the man page:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;This is a limit on the number of extant process (or, more precisely on Linux, threads) for the real user ID of the calling process.  So long as the current number of processes belonging to this process’s real user ID is greater than or equal to this limit, fork(2) fails with the error EAGAIN.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;vulnerability&quot;&gt;Vulnerability&lt;/h1&gt;

&lt;p&gt;When Android Debug Bridge (&lt;em&gt;adb&lt;/em&gt;) is started, there are multiple tasks need to be performed before &lt;em&gt;adb&lt;/em&gt; is available to the user. To accomplish these tasks, &lt;em&gt;adb&lt;/em&gt; is launched with root privileges and once all the initialisation is complete, it drops its privileges. Linux system call &lt;em&gt;setuid&lt;/em&gt; is used to lower the privileges. The main cause of the vulnerability is, in Android 1.6 to 2.2, &lt;em&gt;adb&lt;/em&gt; does not check the return value of this &lt;em&gt;setuid&lt;/em&gt; syscall while lowering its privileges.&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// setuid call in adb &lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;setgid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AID_SHELL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;setuid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AID_SHELL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When &lt;em&gt;setuid&lt;/em&gt; is called, the kernel checks if the number of processes for that non-root user set by administrator is not crossed (i.e RLIMIT_NPROC). If this non-root user already has RLIMIT_NPROC processes running, then &lt;em&gt;setuid&lt;/em&gt; call will fail.&lt;/p&gt;

&lt;p&gt;If we can somehow reach this RLIMIT_NPROC processes and then make &lt;em&gt;adb&lt;/em&gt; restart, the kernel will prevent the &lt;em&gt;adb&lt;/em&gt; to lower its privileges. Since, &lt;em&gt;adb&lt;/em&gt; does not check the &lt;em&gt;setuid&lt;/em&gt; return value, it will continue to execute with root privileges. To accomplish this, we can launch multiple dummy processes and reach RLIMIT_NPROC process limit for the user. Then kill &lt;em&gt;adb&lt;/em&gt;, which will cause &lt;em&gt;adbd&lt;/em&gt; to restart &lt;em&gt;adb&lt;/em&gt;. While relaunching &lt;em&gt;adb&lt;/em&gt;, it causes a race condition between &lt;em&gt;adb&lt;/em&gt; and the processes we launched to spawn the last RLIMIT_NPROC process. If our dummy process is launched, &lt;em&gt;setuid&lt;/em&gt; for &lt;em&gt;adb&lt;/em&gt; will fail, and in this case it will continue running with root privileges.&lt;/p&gt;

&lt;p&gt;Multiple dummy processes can be launched using the following code:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(;;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x743C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;fix&quot;&gt;Fix&lt;/h1&gt;

&lt;p&gt;One obvious fix for this vulnerability is to check the return value of &lt;em&gt;setuid&lt;/em&gt;. But it seems non-checking of &lt;em&gt;setuid&lt;/em&gt; return value is a common mistake with grave consequences. In the past, &lt;em&gt;sendmail capabilities bug&lt;/em&gt; was caused by the same programming malpractice. The common occurrence of this programming pattern has lead to discussion within Linux Kernel community to fix it in the Kernel itself, discussed in this excellent &lt;a href=&quot;https://lwn.net/Articles/451985/&quot;&gt;LWN article&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;https://thesnkchrmr.wordpress.com/2011/03/24/rageagainstthecage/&lt;/li&gt;
  &lt;li&gt;https://lwn.net/Articles/451985/&lt;/li&gt;
&lt;/ol&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">TL;DR: adb setuid exhaustion attack (aka RageAgainstTheCage) was present in Android 1.6 to 2.2. During adb initialisation, while dropping its privileges there is no check for setuid syscall’s return value. This can be exploited by causing a race condition by creating RLIMIT_NPROC processes and killing adb, on adb restart setuid syscall might fail and can lead to adb continue running with root privileges.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Differentiate an ELF executable from a shared library</title>
      
      
      <link href="https://serializethoughts.com/2019/06/29/elf-pic-pie" rel="alternate" type="text/html" title="Differentiate an ELF executable from a shared library" />
      
      <published>2019-06-29T08:17:22+00:00</published>
      <updated>2019-06-29T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2019/06/29/elf-pic-pie</id>
      <content type="html" xml:base="https://serializethoughts.com/2019/06/29/elf-pic-pie">&lt;p&gt;&lt;strong&gt;Time To Read:&lt;/strong&gt; 5 min&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; A position independent ELF executable is compiled as a shared library to achieve position independent code. The OS is able to differentiate between the two by checking for PT_INTERP segment, which is present in executable and not in a shared library.&lt;/p&gt;

&lt;p&gt;All modern operating systems support Address Space Layout Randomization, ASLR, as part of defense in depth approach, to make it harder for an attacker to reliably jump to a memory location while exploiting a vulnerability, like bufferoverflows. To effectively use ASLR, the code should be compiled as position independent, i.e code can be loaded at any address in the memory. Shared libraries are always compiled as position independent, while in the past (before ASLR) an ELF executable was always loaded at a fixed address.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/pic-pie-readelf-lib.png&quot; alt=&quot;ELF library&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/pic-pie-readelf-ssh.png&quot; alt=&quot;ELF executable&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For an executable to utilize ASLR, OS should be able to load executable at any address in the memory. Such executable is often referred as PIE (position independent executable). To make an executable PIE, the solution lies in reusing the existing implementation of how a shared library is compiled. In a nutshell, it turns out to be quite simple to create a PIE: a PIE is simply an executable shared library. This can be verified by checking the ELF filetype using &lt;em&gt;readelf&lt;/em&gt; command. Both shared library and PIE are: &lt;em&gt;DYN (Shared object file)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Since both files have same ELF filetype, it raises the question how to determine if a given ELF binary is a shared library or an executable. The answer unsurprisingly lies in the fact how the OS differentiates between the two. As it is evident from above, ELF filetype cannot be used anymore to differentiate between the two, the OS need to look for some other hints.&lt;/p&gt;

&lt;p&gt;A quick read through on how an ELF file is &lt;a href=&quot;https://lwn.net/Articles/631631/&quot;&gt;loaded by the kernel and executed&lt;/a&gt; gives us the hint. If you are interested in learning the gory details, the article is highly recommended, while for the others, the hint is in “The code now loops over the program header entries, checking for an interpreter (PT_INTERP) …”. As it turns out &lt;strong&gt;PT_INTERP&lt;/strong&gt; is an ELF segment which contains the path name of the interpreter used to execute a file. And this &lt;strong&gt;PT_INTERP&lt;/strong&gt; segment is the answer to our problem. An ELF executable file has this segment while a shared library will not. This can be verified using readelf as shown in the screenshots below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/pic-pie-readelf-segment-lib.png&quot; alt=&quot;ELF segments in library&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/pic-pie-readelf-segment-ssh.png&quot; alt=&quot;ELF segments in executable&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To sumamrize, an ELF executable is made to be position independent by compiling it like a shared library, and to make this shared library executable you just need to give it a &lt;em&gt;PT_INTERP&lt;/em&gt; segment and appropriate startup code.&lt;/p&gt;

&lt;p&gt;Some other information I discovered and might be interesting for further experimentation is, an ELF executable and shared library are so closely similar that with some hacking you can make an executable work as a shared library. This is discussed by &lt;a href=&quot;https://lief.quarkslab.com/doc/latest/tutorials/08_elf_bin2lib.html&quot;&gt;Romain Thomas&lt;/a&gt; on how to achieve this using &lt;a href=&quot;https://github.com/lief-project/LIEF&quot;&gt;LIEF&lt;/a&gt;. Also, Ian Lance in &lt;a href=&quot;https://www.airs.com/blog/archives/549&quot;&gt;Piece of PIE&lt;/a&gt; discusses about how similar ELF position independent executable and shared library are.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">Time To Read: 5 min</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Bypassing Android FLAG_SECURE using FRIDA</title>
      
      
      <link href="https://serializethoughts.com/2018/10/07/bypassing-android-flag_secure-using-frida" rel="alternate" type="text/html" title="Bypassing Android FLAG_SECURE using FRIDA" />
      
      <published>2018-10-07T08:17:22+00:00</published>
      <updated>2018-10-07T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2018/10/07/bypassing-android-flag_secure-using-frida</id>
      <content type="html" xml:base="https://serializethoughts.com/2018/10/07/bypassing-android-flag_secure-using-frida">&lt;p&gt;Since Android 5 via MediaProjection API, Android allows screen capturing and screen sharing using third party applications. I won’t be going in detail of how this API work and what are its various security implications.  This article by &lt;a href=&quot;https://wwws.nightwatchcybersecurity.com/2016/04/13/research-securing-android-applications-from-screen-capture/&quot;&gt;Nightwatch Cybersecurity&lt;/a&gt; summarizes it very succinctly.&lt;/p&gt;

&lt;p&gt;The important point to keep in mind is, to protect sensitive applications from screen capturing and sharing is to set &lt;a href=&quot;https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_SECURE&quot;&gt;FLAG_SECURE&lt;/a&gt; flag for that respective screen.&lt;/p&gt;

&lt;p&gt;Recently I came across an Android application using this very  FLAG_SECURE flag to prevent from screen capturing or sharing. I wrote a simple FRIDA script to bypass this check and it is very straightforward.  The script I used is below:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/36410f67c9e0127961ae344010c4c0ef.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;There is an &lt;a href=&quot;https://github.com/veeti/DisableFlagSecure&quot;&gt;XPosed module&lt;/a&gt; as well which performs exactly same thing.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">Since Android 5 via MediaProjection API, Android allows screen capturing and screen sharing using third party applications. I won’t be going in detail of how this API work and what are its various security implications. This article by Nightwatch Cybersecurity summarizes it very succinctly.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Frida, Magisk and SELinux</title>
      
      
      <link href="https://serializethoughts.com/2018/07/23/frida-magisk-selinux" rel="alternate" type="text/html" title="Frida, Magisk and SELinux" />
      
      <published>2018-07-23T08:17:22+00:00</published>
      <updated>2018-07-23T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2018/07/23/frida-magisk-selinux</id>
      <content type="html" xml:base="https://serializethoughts.com/2018/07/23/frida-magisk-selinux">&lt;p&gt;While using Frida 12.x with Magisk v16.3+, I came across the problem that Frida is not able to spawn applications on Android. In logcat one can see the SELinux error:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;avc: denied { sigchld } for scontext=u:r:zygote:s0 tcontext=u:r:magisk:s0 tclass=process permissive=0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I am not sure from the problem has started, is it Magisk, which does perform some tinkering with SELinux or is it new version of Frida. I have not open a bug with either projects yet, as I am not sure.&lt;/p&gt;

&lt;p&gt;But for those stuck with this problem, the solution is to use magiskpolicy, which is installed along with magisk. Just go to the terminal and add this policy:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;magiskpolicy --live &quot;allow zygote magisk process *&quot;
magiskpolicy --live &quot;allow system_server magisk process *&quot;
magiskpolicy --live &quot;allow radio magisk process *&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In case someone knows the root cause I would be more than happy to know.&lt;/p&gt;

&lt;p&gt;UPDATE:&lt;/p&gt;

&lt;p&gt;It seems others also have come across problems related to SELinux and FRIDA, like https://github.com/frida/frida-core/issues/123. The recommended solution is to set SELinux to Permissive mode. In case you don’t want to do that, as some applications do check for SELinux status and do not work if set to Permissive mode, then use the commands above, as a workaround.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">While using Frida 12.x with Magisk v16.3+, I came across the problem that Frida is not able to spawn applications on Android. In logcat one can see the SELinux error:</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Bypassing anti-debugger check in iOS Applications</title>
      
      
      <link href="https://serializethoughts.com/2018/01/23/bypassing-anti-debugger-check-in-ios-applications" rel="alternate" type="text/html" title="Bypassing anti-debugger check in iOS Applications" />
      
      <published>2018-01-23T08:17:22+00:00</published>
      <updated>2018-01-23T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2018/01/23/bypassing-anti-debugger-check-in-ios-applications</id>
      <content type="html" xml:base="https://serializethoughts.com/2018/01/23/bypassing-anti-debugger-check-in-ios-applications">&lt;p&gt;&lt;strong&gt;Expected Reading Time&lt;/strong&gt;: 5 Mins&lt;/p&gt;

&lt;p&gt;While pentesting mobile applications, very often you will come across applications implementing myriads of anti-reversing techniques. Specially while performing dynamic analysis, it is imperative to disable these checks. To make the bypassing these checks more daunting, some applications heavily obfuscate the binaries. In this post, we will look into bypassing one of the anti-debugging technique for iOS applications and using IDAPython script to automate patching of the binary. The idea presented in this post is really simple, and many readers might have been already using it, for others here is another idea to add to your armory.&lt;/p&gt;

&lt;h1 id=&quot;ptrace&quot;&gt;Ptrace&lt;/h1&gt;

&lt;p&gt;iOS under the hood runs a XNU kernel. The XNU kernel do implement ptrace() system call, but it is not potent enough when compared to Unix and Linux implementations. On the other hand, XNU kernel exposes another interface via Mach IPC to perform debugging. In this post we won’t be comparing between the two mechanisms, in fact we will only talk about one feature of ptrace syscall, PT_DENY_ATTACH. It is a fairly well known among the iOS application hackers, and among the most frequently encountered anti-debugging technique in iOS applications.&lt;/p&gt;

&lt;p&gt;Before getting into the details of bypassing the check, lets first try to understand briefly what exactly does PT_DENY_ATTACH do. Although, there is ample literature available on the Internet discussing PT_DENY_ATTACH in various depths, but &lt;a href=&quot;https://www.amazon.com/Mac-Hackers-Handbook-Charlie-Miller/dp/0470395362&quot;&gt;The Mac Hacker’s Handbook&lt;/a&gt; defines it most succinctly.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;PT_DENY_ATTACH
This request is the other operation used by the traced process; it allows a process that is not currently being traced to deny future traces by its parent. All other arguments are ignored. If the process is currently being traced, it will exit with the exit status of ENOTSUP; otherwise, it sets a flag that denies future traces. An attempt by the parent to trace a process which has set this flag will result in the segmentation violation in the parent.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To rephrase it, using ptrace with PT_DENY_ATTACH, it ensures that no other debugger can attach to the calling process; even if an attempt is made to attach a debugger, the process exits.&lt;/p&gt;

&lt;p&gt;It is important to know that ptrace() is not part of public API on iOS. As per the &lt;a href=&quot;http://(https//developer.apple.com/documentation/), use of non-public API is prohibited and use of them may lead to rejection of the app from the AppStore&quot;&gt;AppStore publishing policy&lt;/a&gt;. Because of this, developers don’t call ptrace()   directly in the code, instead its called via obtaining ptrace() function pointer using dlsym. Programmatically it looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-objective-c&quot;&gt;#import %3Csys/types.h&amp;gt;
#import typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data);
void anti_debug() {
ptrace_ptr_t ptrace_ptr = (ptrace_ptr_t)dlsym(RTLD_SELF, &quot;ptrace&quot;); ptrace_ptr(31, 0, 0, 0); // PTRACE_DENY_ATTACH = 31
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The dis-assembly of the binary implementing this approach looks like following:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/ptrace-original.png&quot; alt=&quot;ptrace original&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To break down whats happening in the binary, at 0x19086 dlsym() is called with “ptrace” as the 2nd argument (register R1, offset 0x19084) to the function. The return value, in register R0 is moved to register R6 at offset 0x1908A. Eventually at offset 0x19098, the pointer value in register R6 is called using BLX R6 instruction. In this case, to disable ptrace() call, all we need to do is to replace the instruction BLX R6 (0xB0 0x47 in Little Endian) with NOP (0x00 0xBF in Little Endian) instruction. &lt;a href=&quot;http://armconverter.com/&quot;&gt;Armconverter.com&lt;/a&gt; is a handy tool for conversion between bytecode and instruction mnemonics. The code after patching looks like following:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/call-ptrace.png&quot; alt=&quot;call_ptrace&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This can be done manually easily if there is only one or a few calls to ptrace, but this turns tedious once such calls are made multiple times across the binary.&lt;/p&gt;

&lt;h1 id=&quot;idapython-script&quot;&gt;IDAPython Script&lt;/h1&gt;
&lt;p&gt;IDAPython script can be leveraged to perform this task automatically. I wrote one such script to automate the task for the binary dis-assembly shown above.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/06b6837a0f8b66a7a0a33f4ed719510a.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;The script is quite self explanatory, but if something is not clear, feel free to drop a comment below for further clarification.&lt;/p&gt;

&lt;p&gt;To conclude, there are many other anti-debugging approaches available for iOS, the one discussed here is the most commonly found in the iOS applications. Using such techniques to slow down the attackers is fine, but solely depending on such techniques for the security of an application is not at all advisable. Such techniques can be part of the defense in depth approach, but should not be the only defense.&lt;/p&gt;

&lt;p&gt;Keep hacking :)&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">Expected Reading Time: 5 Mins</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Working of LD_PRELOAD for Android Applications and its anti-RE Technique</title>
      
      
      <link href="https://serializethoughts.com/2017/04/01/working-of-ld_preload-for-android-applications-and-its-anti-re-technique" rel="alternate" type="text/html" title="Working of LD_PRELOAD for Android Applications and its anti-RE Technique" />
      
      <published>2017-04-01T08:17:22+00:00</published>
      <updated>2017-04-01T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2017/04/01/working-of-ld_preload-for-android-applications-and-its-anti-re-technique</id>
      <content type="html" xml:base="https://serializethoughts.com/2017/04/01/working-of-ld_preload-for-android-applications-and-its-anti-re-technique">&lt;p&gt;&lt;em&gt;Have you ever checked the parent process of an Android application launched using “wrap” system property set with LD_PRELOAD value? It’s not Zygote!!!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expected Reading Time&lt;/strong&gt;: 10 mins&lt;/p&gt;

&lt;p&gt;There are multiple tools and methodology available for reverse engineering an Android application. In this post, I am not exploring various RE techniques available, instead look into how one such technique works in case of Android applications. &lt;strong&gt;LD_PRELOAD&lt;/strong&gt; is a functionality of dynamic linker present across all Linux distributions, giving precedence to library passed to be searched first for symbols. It is not a RE technique per se, but I have used it often for such purposes and hence I classify it as a RE technique which one should know.&lt;/p&gt;

&lt;p&gt;Many Linux users will be aware of how LD_PRELOAD works in case of native binaries. For the starters, there are many good blogs available and I will leave it as an assignment. As a side note, knowledge of how dynamic linkers work is always handy for reverse engineering assignments.&lt;/p&gt;

&lt;p&gt;In case of a simple native binary compiled to run on Android, LD_PRELOAD works as for other Linux systems. Things get interesting once you intend to use LD_PRELOAD for an Android application. If you simply set the LD_PRELOAD env variable and then try to launch the application, it will not work. Rather you need to perform some Android trickery to make it work for an application. For example, we want to load libpreload.so using LD_PRELOAD for application with package name com.foo.bar. We need to perform following steps:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Push the library to the device.  &lt;em&gt;adb push libpreload.so /data/local/tmp/libpreload.so&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;Set system property:  &lt;em&gt;setprop wrap.com.foo.bar LD_PRELOAD=/data/local/tmp/libpreload.so&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note, in last step the property name is  “wrap” prefixed to the application’s package name.&lt;/p&gt;

&lt;p&gt;Now if you launch the application, the library &lt;em&gt;libpreload.so&lt;/em&gt; will be searched first by the dynamic linker for symbols. (In recent Android versions, one need to disable SELinux to make this work, as &lt;em&gt;libpreload.so&lt;/em&gt; does not have SELinux context assigned, because of which the library is not loaded and whole process exits on such an error.) The above work around is neither a hidden feature nor a newly added feature. Many of us might have used it several times in the past.&lt;/p&gt;

&lt;p&gt;After knowing how to make it work practically, lets try to understand what is actually happening internally, and why we need to perform these extra steps. Some might have already guessed, it is because of Zygote process creation model used in Android. As covered previously on this blog as well, an Android application is launched by forking a Zygote process. Argument being,  in order to save time while launching an application, Android coldstarts a process during OS startup, from which applications can be forked when required. This process is initialized with all necessary libraries required to run an Android application, and remains in sleep state. When a request to launch an application is received, this Zygote process is simply forked and used there on.&lt;/p&gt;

&lt;p&gt;Since, Zygote process is initialized well before launching the application, setting LD_PRELOAD env variable before launching an application will cause no change in symbol search order for linker. Thus, to enable LD_PRELOAD functionality, Android needs a work around.&lt;/p&gt;

&lt;p&gt;Lets revisit how an application launch request is passed to Zygote. When user makes a request to launch an application,  a request is sent to /dev/socket/zygote. On receiving request, Zygote forks itself and launches the application in the child process. As per this mechanism all the application’s, as expected, will have &lt;strong&gt;Zygote as the parent process&lt;/strong&gt;. But in case of LD_PRELOAD scenario, a slight different code path is taken.&lt;/p&gt;

&lt;p&gt;Code listening at &lt;em&gt;/dev/socket/zygote&lt;/em&gt; runs in a loop, referred as ‘select loop’ in code. On receiving request, &lt;em&gt;runOnce()&lt;/em&gt; in &lt;a href=&quot;http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/com/android/internal/os/ZygoteConnection.java#142&quot;&gt;ZygoteConnection&lt;/a&gt;  is called. In this function, many checks and operations are performed, one such check is to check if “wrap” system property set for the given application’s package name.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;runOnce&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ZygoteInit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MethodAndArgsCaller&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;applyUidSecurityPolicy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parsedArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peerSecurityContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;applyRlimitSecurityPolicy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parsedArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peerSecurityContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;applyInvokeWithSecurityPolicy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parsedArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peerSecurityContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;applyseInfoSecurityPolicy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parsedArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peerSecurityContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;checkTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;zygoteConnection.runOnce: apply security policies&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;applyDebuggerSystemProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parsedArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;applyInvokeWithSystemProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parsedArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;checkTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;zygoteConnection.runOnce: apply security policies&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If it is set, it extracts the value of the property. It is important that, a system property name cannot be more than 31 chars, and if package name is more than 31 chars, it need to be truncated to 31 chars.&lt;/p&gt;

&lt;p&gt;After extracting the value, execApplication() in &lt;a href=&quot;http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/com/android/internal/os/WrapperInit.java#97&quot;&gt;WrapperInit&lt;/a&gt; is called. In this function, a command string is constructed with required parameters, to launch application via &lt;strong&gt;/system/bin/app_process&lt;/strong&gt;  (Zygote) directly. The shell arguments, LD_PRELOAD in this case, is appended in this command string. This command is executed using &lt;strong&gt;/system/bin/sh&lt;/strong&gt;. Thus, making &lt;strong&gt;/system/bin/sh as the parent process to the finally launched application&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;execApplication&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;invokeWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;niceName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targetSdkVersion&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;FileDescriptor&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pipeFd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;StringBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;StringBuilder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invokeWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; /system/bin/app_process /system/bin --application&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;niceName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; '--nice-name=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;niceName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; com.android.internal.os.WrapperInit &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pipeFd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pipeFd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getInt&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;targetSdkVersion&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;Zygote&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;appendQuotedShellArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;Zygote&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execShell&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This very fact, that parent process for such an application is not Zygote, can be used as an anti-RE technique. If application’s parent is not Zygote, then application can change its behavior or exit, preventing application analysis.&lt;/p&gt;

&lt;p&gt;Keep hacking :)&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">Have you ever checked the parent process of an Android application launched using “wrap” system property set with LD_PRELOAD value? It’s not Zygote!!!</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Intercepting HTTPS Traffic of Android Nougat Applications</title>
      
      
      <link href="https://serializethoughts.com/2016/09/10/905" rel="alternate" type="text/html" title="Intercepting HTTPS Traffic of Android Nougat Applications" />
      
      <published>2016-09-10T08:17:22+00:00</published>
      <updated>2016-09-10T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2016/09/10/905</id>
      <content type="html" xml:base="https://serializethoughts.com/2016/09/10/905">&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; To intercept network traffic for Android 7.0 targeted applications, introduce a res/xml/network_security_config.xml file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expected Reading Time&lt;/strong&gt;: 5 mins&lt;/p&gt;

&lt;p&gt;In this post I am exploring the new security feature of Android 7.0, which by default makes applications to not to trust “user” installed CA certificates (non-admin), and how to bypass this new security feature.  I started with the feeling that it might not be easy to find a way past these checks, but it panned out to be quite straightforward and much less technical than expected.&lt;/p&gt;

&lt;p&gt;Android 7.0 (Nougat) has introduced many &lt;a href=&quot;http://android-developers.blogspot.sg/2016/09/security-enhancements-in-nougat.html&quot;&gt;new security features&lt;/a&gt; to harden the OS. The changes ranges from low level stuff like using more of Linux Seccomp, having File based encryption, to making mediaserver more secure by compartmentalization and compiler level checks for integer overflows. Among all these changes, Android 7.0 also &lt;a href=&quot;http://android-developers.blogspot.sg/2016/07/changes-to-trusted-certificate.html&quot;&gt;changed&lt;/a&gt; the default trust level of installed CA certificates for the applications.&lt;/p&gt;

&lt;p&gt;In Android Nougat, the default trusted CA certificates by the applications has changed. In the earlier versions of Android, by default the application apart from trusting the “system” installed CA certificates, it also used to trust the “user” added CA certificates as well. For example, while using some MITM proxy like mitmproxy, burp etc, you can simply install the proxy’s certificate on Android device/emulator and then you can intercept and observe the network traffic in clear text. But from Android 7.0 onwards, the default behaviour has been altered and the “user” installed certificates won’t be trusted anymore by the applications. Thus, intercepting  application’s traffic using a proxy will not be possible out of the box.&lt;/p&gt;

&lt;p&gt;So how to observe the network traffic for the applications targeting Android 7.0? Apparently, Google has not provided any simple switch in settings menu, which can be toggled and apps start trusting user installed CA certs. So it means we need to get our hands dirty.&lt;/p&gt;

&lt;p&gt;So with a task in hand, I picked up an open source Android application and compiled with target SDK Level 24 (for Android 7.0). I prepared a release build and installed on a device running Android 7.0. I used mitmproxy for the job to intercept network traffic. And to no surprises, the application was not able to connect and reported no internet connectivity.&lt;/p&gt;

&lt;p&gt;As the adage goes, RTFD, lo and behold, the hint is there in the same &lt;a href=&quot;http://android-developers.blogspot.sg/2016/07/changes-to-trusted-certificate.html&quot;&gt;blog post&lt;/a&gt;. For ease of setting network security configuration, Android provides a network security configuration file, while lets you to “customize network security settings in a safe, declarative configuration file without modifying app code”. So that is all needed. We need to decompile the application using apktool and introduce a network_security_config.xml (shown below) file at res/xml folder of the application.  Recompile the application with apktool again, sign it using jarsigner and we are good to go.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;network-security-config&amp;gt;  
      &amp;lt;base-config&amp;gt;  
            &amp;lt;trust-anchors&amp;gt;  
                &amp;lt;!-- Trust preinstalled CAs --&amp;gt;  
                &amp;lt;certificates src=&quot;system&quot; /&amp;gt;  
                &amp;lt;!-- Additionally trust user added CAs --&amp;gt;  
                &amp;lt;certificates src=&quot;user&quot; /&amp;gt;  
           &amp;lt;/trust-anchors&amp;gt;  
      &amp;lt;/base-config&amp;gt;  
 &amp;lt;/network-security-config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once this file is created, also update the &lt;em&gt;AndroidManifest.xml&lt;/em&gt; file to reflect the above changes.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;manifest ... &amp;gt;
    &amp;lt;application android:networkSecurityConfig=&quot;@xml/network_security_config&quot;
                    ... &amp;gt;
        ...
    &amp;lt;/application&amp;gt;
&amp;lt;/manifest&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For the better understanding, I highly recommend to read the &lt;a href=&quot;http://android-developers.blogspot.sg/2016/07/changes-to-trusted-certificate.html&quot;&gt;original blog&lt;/a&gt; and the security config &lt;a href=&quot;https://developer.android.com/training/articles/security-config.html&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the end it turned out to be quite trivial than expected, but nevertheless requires few extra steps now to intercept an applications traffic. This technique might be not be needed immediately, as most applications will still be targeting at least Android 4.4 for now, for which the user added CA certificate are still trusted.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">TL;DR To intercept network traffic for Android 7.0 targeted applications, introduce a res/xml/network_security_config.xml file.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Bypassing SSL Pinning in Android Applications</title>
      
      
      <link href="https://serializethoughts.com/2016/08/18/bypassing-ssl-pinning-in-android-applications" rel="alternate" type="text/html" title="Bypassing SSL Pinning in Android Applications" />
      
      <published>2016-08-18T08:17:22+00:00</published>
      <updated>2016-08-18T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2016/08/18/bypassing-ssl-pinning-in-android-applications</id>
      <content type="html" xml:base="https://serializethoughts.com/2016/08/18/bypassing-ssl-pinning-in-android-applications">&lt;p&gt;It is a common practice for Android and iOS applications’ developers to implement SSL Pinning in order to make reverse engineering of the apps difficult. As per &lt;a href=&quot;https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning&quot;&gt;OWASP&lt;/a&gt;, SSL Pinning can be defined as the process of associating a host (in this case the app), with their expected X509 certificate or public key. Applications communicating over HTTPS and using SSL Pinning makes it non-trivial to perform Man-In-The-Middle attack and grab the network traffic in clear text using the proxy tools. For further reading about SSL Pinning, I would recommend &lt;a href=&quot;https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning&quot;&gt;OWASP article&lt;/a&gt; to get started with.&lt;/p&gt;

&lt;p&gt;In this post, I will be looking into the steps involved in bypassing SSL Pinning checks for an Android application and show how we can patch the application binaries in order to intercept the traffic. For this post I am using Facebook Messenger (FBM) application as an example.&lt;/p&gt;

&lt;h1 id=&quot;ssl-pinning-in-android&quot;&gt;SSL Pinning In Android&lt;/h1&gt;
&lt;p&gt;SSL Pinning in case of Android can be performed either in the Java layer, using the Android API, or in the native C/C++ layer. Lets look into each of the cases one at a time:&lt;/p&gt;

&lt;h2 id=&quot;java-layer&quot;&gt;Java Layer&lt;/h2&gt;

&lt;p&gt;To implement SSL Pinning, Android API exposes multiple functions to do so.  Android developer &lt;a href=&quot;https://developer.android.com/training/articles/security-ssl.html&quot;&gt;website&lt;/a&gt; provides a good overview about the topic.  In order to bypass the SSL Pinning in Java layer one can use existing tools or can patch the APK file manually.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Xposed Framework&lt;/strong&gt;: If the device is rooted, one can install Xposed Framework and use one of the multiple modules available to disable SSL Pinning. One such module is SSL Unpinning. Using the module is straight forward and I would leave the details of usage to the readers to figure out.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Manual Patching&lt;/strong&gt;:  Xposed Framework requires the device to be rooted. In such a case we cannot use the tools discussed above to bypass the SSL checks. In such a situation we can patch the APK file manually. Patching the file manually requires some extra effort, but given the abundance of exiting tools, this can be done with ease. The steps involved are following:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;Decompile the application using Apktool or any other similar tool. Apktool gives Smali code for the application.&lt;/li&gt;
  &lt;li&gt;Patch the relevant functions in the Smali code.&lt;/li&gt;
  &lt;li&gt;Compile the application back using apktool, sign it using jarsign and run zipalign over it.&lt;/li&gt;
  &lt;li&gt;Installed the patched APK generated above.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The above approach is discussed in detail in this &lt;a href=&quot;http://blog.dewhurstsecurity.com/2015/11/10/mobile-security-certificate-pining.htm&quot;&gt;blog post&lt;/a&gt;. Hence, I will refrain from duplicating the information and recommend you to read it there.&lt;/p&gt;

&lt;h2 id=&quot;native-layer&quot;&gt;Native Layer&lt;/h2&gt;

&lt;p&gt;Now enters a bit more challenging part. If the above approaches fail, you can fairly be confident that the SSL Pinning checks are being performed in the native layer. FBM is doing exactly same. To make things a bit obscure, the FBM application do have SSL Pinning logic in Java layer as well, but patching it does not work.&lt;/p&gt;

&lt;p&gt;To get started, simply run APKTool and get the decompiled/unzipped version of the APK. If you look in the lib folder, there are 6 native libraries.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/fb_libs.png&quot; alt=&quot;FB Libraries&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After exploring these libraries using IDA Pro, to my surprise, none was having network related code. Which entailed more research is required to find the relevant code. If you look into these existing native libraries, you will find there is logic for xz decoding and logic for loading more native libraries. Also, if you go on and install the application and after the first usage, you will find that the &lt;em&gt;/data/data/com.facebook.orca&lt;/em&gt; directory have a folder &lt;em&gt;lib-xzs&lt;/em&gt;, which contains another 30+ libraries.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/libliger.png&quot; alt=&quot;libliger&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So now the work is cut out clearly, we have to look into these libraries to find the network code. After evaluating each library using IDAPro, the code for SSL Pinning was found in libliger-native.so. There are many functions corresponding to SSL Pinning and network in this library. On seeing the various functions,  proxygen::SSLVerification::verifyWithMetrics() seems to be an easy target to fix. The function performs a comparison of the certificate received against the desired certificate embedded/pinned in the application and returns true or false. The pseudocode is shown below:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/verifywithmetrics1.jpg&quot; alt=&quot;VerifywithMetrics&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Dynamic Patching&lt;/strong&gt;: Dynamic library can be patched by performing dynamic injection and patching the function during the runtime. &lt;a href=&quot;https://github.com/crmulliner/adbi&quot;&gt;ADBI&lt;/a&gt; and &lt;a href=&quot;https://frida.re&quot;&gt;FRIDA&lt;/a&gt; are the two frameworks that provide such functionality. After some fiddling around with the above mentioned tools,  in both the cases FBM was crashing whenever an injection is made. Whether it was a security defense mechanism or instability of the process post injection, I left this unexplored for the time being. A note to the readers, to use these framework you need a rooted device.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Native Library Patching&lt;/strong&gt;: Given the dynamic injection is causing frequent crashes, patching the binary manually and reloading it again seems to be the only other option to go with. I used IDAPro to patch the binary. At the offset  0x0006732E patch code from 0xB948 (CBNZ R0, loc_6744) to 0xB9B8 (CBNZ R0, loc_6760). Where the block at loc_6760 is responsible for setting the return value, variable ‘result’, to always true. To get more understanding how the ARMv7 instructions represented at the bit level, read this &lt;a href=&quot;http://stackoverflow.com/questions/9279451/armv7-word-patch-cbnz&quot;&gt;answer&lt;/a&gt;. After patching, replace the libliger-native.so file in /data/data/com.facebook.orca/lib-xzs with the new one, restart the application and now you can intercept the traffic.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before patching library looks like following: 
&lt;img src=&quot;/assets/images/before_patching.jpg&quot; alt=&quot;before_patching&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After patching: 
&lt;img src=&quot;/assets/images/patched.jpg&quot; alt=&quot;After Patching&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Recently, there was another &lt;a href=&quot;https://eaton-works.com/2016/07/31/reverse-engineering-and-removing-pokemon-gos-certificate-pinning/&quot;&gt;blog post&lt;/a&gt; discussing patching of Android application (Pokemon Go app) to bypass SSL Pinning and I would recommend to read that one as well. The approach taken in that post is slightly different, as each application has different implementation.&lt;/p&gt;

&lt;p&gt;Keep hacking :)&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">It is a common practice for Android and iOS applications’ developers to implement SSL Pinning in order to make reverse engineering of the apps difficult. As per OWASP, SSL Pinning can be defined as the process of associating a host (in this case the app), with their expected X509 certificate or public key. Applications communicating over HTTPS and using SSL Pinning makes it non-trivial to perform Man-In-The-Middle attack and grab the network traffic in clear text using the proxy tools. For further reading about SSL Pinning, I would recommend OWASP article to get started with.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Linux Thread is a Standard Process</title>
      
      
      <link href="https://serializethoughts.com/2016/07/16/linux-threads-are-standard-process" rel="alternate" type="text/html" title="Linux Thread is a Standard Process" />
      
      <published>2016-07-16T08:17:22+00:00</published>
      <updated>2016-07-16T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2016/07/16/linux-threads-are-standard-process</id>
      <content type="html" xml:base="https://serializethoughts.com/2016/07/16/linux-threads-are-standard-process">&lt;p&gt;As per &lt;a href=&quot;https://en.wikipedia.org/wiki/Thread_(computing)&quot;&gt;Wikipedia&lt;/a&gt;, a computing thread is defined as “the smallest sequence of programmed instructions that can be managed independently by a scheduler”. And further goes on to say, the implementation of threads and processes differs between operating systems, but in most cases a thread is a component of a process. A process can have multiple threads within a shared memory address space of the process.  In this article, I won’t be going into the nitty-gritty of threads. There are many good resources available on the Internet discussing various details of threads. Rather I would like to focus on an important aspect of threads specifically in Linux kernel.&lt;/p&gt;

&lt;p&gt;While discussing Linux internals with a senior developer, he mentioned that in case of Linux kernel, there is no difference between a process and a thread. Intrigued by the fact, I started looking into kernel’s source, aided by the excellent book on Linux kernel, &lt;a href=&quot;https://www.amazon.com/Linux-Kernel-Development-Robert-Love/dp/0672329468&quot;&gt;Linux Kernel Development&lt;/a&gt;, by Robert Love.&lt;/p&gt;

&lt;p&gt;Coming on to the topic, in Linux, there is no separate data structure defining a thread. A thread and a process have the same data structure. Also, a thread is created exactly in the same way as a normal process is created, i.e by calling fork or vfork() (which eventually calls clone() system call). Although, in case of a thread, while making clone() system call some extra flags are passed. These extra flags specify the resources which are to be shared. A typical call looks like:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the address space, filesystem resources, file descriptors, and signal handlers are shared.&lt;/p&gt;

&lt;p&gt;For the readers who want to delve more into the internal working, &lt;em&gt;struct task_struct&lt;/em&gt; contains information about a process, defined in &lt;em&gt;&amp;lt;linux/sched.h&amp;gt;&lt;/em&gt;. The field &lt;em&gt;unsigned int&lt;/em&gt; flags stores all the flag related information. These flags, help specify the behaviour of the new process and detail what resources the parent and child will share. List of other clone flags can also be found in linux/sched.h.&lt;/p&gt;

&lt;p&gt;For completeness, in case of Microsoft Windows, kernel have explicit support for kernels and also referred as lighweight process. For Windows, a thread is an abstraction which provides  a lighter, quicker execution than the heavy process. The pros and cons of the two approaches requires more deep understanding of the two, and will be a much bigger post than this one.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">As per Wikipedia, a computing thread is defined as “the smallest sequence of programmed instructions that can be managed independently by a scheduler”. And further goes on to say, the implementation of threads and processes differs between operating systems, but in most cases a thread is a component of a process. A process can have multiple threads within a shared memory address space of the process. In this article, I won’t be going into the nitty-gritty of threads. There are many good resources available on the Internet discussing various details of threads. Rather I would like to focus on an important aspect of threads specifically in Linux kernel.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Security Implications of Zygote Process Creation Model in Android</title>
      
      
      <link href="https://serializethoughts.com/2016/05/25/security-implications-of-zygote-process-creation-model" rel="alternate" type="text/html" title="Security Implications of Zygote Process Creation Model in Android" />
      
      <published>2016-05-25T08:17:22+00:00</published>
      <updated>2016-05-25T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2016/05/25/security-implications-of-zygote-process-creation-model</id>
      <content type="html" xml:base="https://serializethoughts.com/2016/05/25/security-implications-of-zygote-process-creation-model">&lt;p&gt;In the &lt;a href=&quot;https://serializethoughts.com/2016/04/15/android-zygote/&quot;&gt;previous post&lt;/a&gt; I discussed about the Zygote process creation model in Android OS and importance of having different process creation model than a linux process in a mobile device. Before getting into the technical specifics, it is advisable to freshen the concept pertaining to Linux process creation and ASLR.&lt;/p&gt;

&lt;p&gt;In  Zygote process creation model, a process template is created on the system startup, having the Dalvik VM (DVM) instance initialized and also other essential libraries loaded. When an application launch request is received, this template process is forked and application is loaded into it, saving significant time by avoiding loading of libraries and in instantiating DVM on every launch. Also, Linux COW (copy-on-write) helps in reducing global memory usage. But this trade-off have a major security implication.&lt;/p&gt;

&lt;p&gt;Zygote process creation model causes two types of  memory  layout  sharing  on  Android,  which  undermine  the effectiveness of ASLR. Firstly, the code of an application is always loaded at the exact same memory location across different runs even when  ASLR  is  present;  and  secondly,  all  running apps  inherit  the  commonly  used  libraries  from  the  Zygote process (including the libc library) and thus share the same virtual memory mappings of these libraries. If an attacker is able to get the memory mapping information for one process, he can easily predict for the target process (as both share same mappings for Zygote loaded libraries). Thus developing ROP attacks becomes very easy, in spite of having ASLR. For more details, read this excellent article by Copperhead team.&lt;/p&gt;

&lt;p&gt;After understanding the pros and cons of the approach, it must raise the curiosity that how can it be fixed without breaking the existing applications. To start with, one approach is to switch to Linux style process creation model, i.e, fork and exec, rather than creating a template and keep forking it subsequently. This approach fixes the security issue, but raises the very issue for which Zygote model was created. We will revisit this approach again at the end and re-evaluate its applicability in light of new performance enhancements measures introduced in Android.&lt;/p&gt;

&lt;p&gt;Another approach to fix the security issue with Zygote process creation model was proposed by &lt;a href=&quot;http://wenke.gtisc.gatech.edu/papers/morula.pdf&quot;&gt;Lee et. al. in this paper&lt;/a&gt;. They name their approach as Morula process creation model. Why it is called Morula is left as an exercise for the readers.&lt;/p&gt;

&lt;h1 id=&quot;morula-process-creation-model&quot;&gt;Morula Process Creation Model:&lt;/h1&gt;

&lt;p&gt;In this approach, a template process performs the common and time-consuming initialisation tasks beforehand.  The whole process is divided into 2 steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Preparation Phase&lt;/strong&gt;: initiated by the Activity Manager. A preparation request is made to the Zygote process, when the system is idle or lightly occupied. The Zygote process forks a child, which immediately call a exec() to establish a new memory image with a fresh randomized layout. Then, the new process constructs DVM instance and loads all shared libraries and common Android classes, which would tremendously prolong the app launch time if not done in advance. Now the Morula process is fully created, waiting for the request to start an app. Multiple Morula process can be created in order to accommodate a flurry of requests to start several apps. If these newly created process is not used immediately, the  process enters the sleep mode and awakened only when needed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Transition Phase&lt;/strong&gt;: When the Activity Manager requests an app launch, the request is routed through Zygote process first, where a decision is made regarding if the app should be started in a Morula process or in a fork of the Zygote process. Having this option allows the Morula model to be backward compatible with the Zygote model, in order to carry out an optimization strategy. Depending on the configuration, using either of the process the application is launched.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From Android 4.4.4 onward, Google was previewing a new runtime environment instead of Dalvik, called ART. From Android 5.0 it was fully deployed and considered to be faster than previous Dalvik VM. Factoring in the advances made by ART, Copperhead experimented with fork and exec approach in their Copperhead OS. As per their &lt;a href=&quot;https://copperhead.co/blog/2015/05/11/aslr-android-zygote&quot;&gt;findings&lt;/a&gt;, “The Morula proof of concept code has some issues like file descriptor leaks and needs to be ported to Lollipop. It’s much less important now that ART has drastically improved start-up time without the zygote.” To conclude, with ART, fork and exec approach is not as slow as compared with Dalvik runtime. For security paranoid users, a small performance glitch should not be a big barrier.&lt;/p&gt;

&lt;p&gt;It is highly recommended to read both, the Morula paper and blog by Copperhead to understand the nitty-gritty of the topic. And for the hackers out their, patch for implementing Morula is available &lt;a href=&quot;https://github.com/lifeasageek/morula&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">In the previous post I discussed about the Zygote process creation model in Android OS and importance of having different process creation model than a linux process in a mobile device. Before getting into the technical specifics, it is advisable to freshen the concept pertaining to Linux process creation and ASLR.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Android Zygote</title>
      
      
      <link href="https://serializethoughts.com/2016/04/15/android-root-detection-techniques" rel="alternate" type="text/html" title="Android Zygote" />
      
      <published>2016-04-15T08:17:22+00:00</published>
      <updated>2016-04-15T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2016/04/15/android-root-detection-techniques</id>
      <content type="html" xml:base="https://serializethoughts.com/2016/04/15/android-root-detection-techniques">&lt;p&gt;In this post I will discuss about a very interesting piece of Android Operating System. If you have worked with Android, you might have run the &lt;em&gt;ps&lt;/em&gt; command and might have observed that all applications have same parent PID (PPID). Android takes an unconventional approach to spawn processes, which ensure application startup is snappy. The process from which all the Android applications are derived is called Zygote. So in the screenshot below, all the applications have PPID of 1914, which is the PID of Zygote. In the rest of the post, I will talk about what is the need of Zygote, how does it come into existence and some discussion about Zygote in general.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/android_zygote.png&quot; alt=&quot;android_zygote&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;need-of-zygote&quot;&gt;Need of Zygote?&lt;/h1&gt;

&lt;p&gt;In a typical Linux process, when a process is started - by forking parent process, it goes through various setup steps, including loading of libraries and resources. The details are out of scope for this post. This process setup consumes time and on our beefy desktops, it is hardly noticeable. But in case of Android, not all devices are high spec and this process setup is noticeable to end user. As a workaround to normalize the process startup times on various devices, Android coldstarts a process during OS startup, from which applications can be forked when required. This process is called &lt;strong&gt;Zygote&lt;/strong&gt;.&lt;/p&gt;

&lt;h1 id=&quot;zygote-startup&quot;&gt;Zygote Startup&lt;/h1&gt;

&lt;p&gt;After the Android device is turned on, and following all booting up steps, then init system starts, and run &lt;em&gt;/init.rc&lt;/em&gt; file to setup various environment variables, mount points, start native daemons etc. There are many resources available on the internet discussing about Android bootup process and init system as well, and thus bypassed in this post. While executing init.rc, that Zygote is started. There is no binary directly corresponding to Zygote, instead it is started by a binarycalled app_process. Corresponding line in init.rc can be found here.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;app_process&lt;/em&gt; firstly starts Android Runtime, which in turn starts Dalvik VM of the system, and finally Dalvik VM invokes Zygote’s &lt;a href=&quot;https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/os/ZygoteInit.java#575&quot;&gt;main()&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Zygote initilization can be simplified into following steps:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Register Zygote socket (listens for connections on /dev/socket/zygote) for requests to start new apps&lt;/li&gt;
  &lt;li&gt;preload all java classes&lt;/li&gt;
  &lt;li&gt;preload resources&lt;/li&gt;
  &lt;li&gt;start system server (not covered in this post)&lt;/li&gt;
  &lt;li&gt;open socket&lt;/li&gt;
  &lt;li&gt;listen to connections&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;zygote-socket&quot;&gt;Zygote Socket&lt;/h1&gt;

&lt;p&gt;As mentioned above, zygote opens up a socket, &lt;em&gt;/dev/socket/zygote&lt;/em&gt;, and listens on it for requests to start new applicationss. On receiving a request, it simply forks itself and launches the new requested application. So now the new application have Dalvik VM already loaded, including other necessary libraries and resources, and can start with execution straight away.&lt;/p&gt;

&lt;p&gt;One feature of Linux is important to understand over here, Copy-on-Write (COW) policy for forks. Forking in Linux involves creating a new process, which is an exact copy of the parent process. With COW, Linux doesn’t actually copy anything. On the contrary, it just maps the pages of the new process over to those of the parent process and makes copies only when the new process writes to a page. Thus, saving significant amount of memory and setup time as well. To add, in case of Android, these pages are never written, as the libraries are mostly immutable and hardly changed over the process lifetime.&lt;/p&gt;

&lt;p&gt;If you want to learn more details, with corresponding code, &lt;a href=&quot;http://allenlsy.com/android-kernel-3/&quot;&gt;this is an excellent resource.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In upcoming post I will discuss about the security implications of having Zygote model and various existing alternative workarounds.&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">In this post I will discuss about a very interesting piece of Android Operating System. If you have worked with Android, you might have run the ps command and might have observed that all applications have same parent PID (PPID). Android takes an unconventional approach to spawn processes, which ensure application startup is snappy. The process from which all the Android applications are derived is called Zygote. So in the screenshot below, all the applications have PPID of 1914, which is the PID of Zygote. In the rest of the post, I will talk about what is the need of Zygote, how does it come into existence and some discussion about Zygote in general.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">TLS Sequence Numbers</title>
      
      
      <link href="https://serializethoughts.com/2016/02/09/tls-sequence-numbers" rel="alternate" type="text/html" title="TLS Sequence Numbers" />
      
      <published>2016-02-09T08:17:22+00:00</published>
      <updated>2016-02-09T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2016/02/09/tls-sequence-numbers</id>
      <content type="html" xml:base="https://serializethoughts.com/2016/02/09/tls-sequence-numbers">&lt;p&gt;When talking about SSL/TLS most of the discussion centers around the ciphersuites, the types of messages or other complex cryptographical aspects. But there are many subtle things embedded in the protocol, which are often skipped or not discussed generally. One such thing is sequence numbers. Like in TCP, a sequence number for messages is also maintained in SSL/TLS protocol and one gets to know only is he/she delve into the RFCs.&lt;/p&gt;

&lt;p&gt;In case of SSL/TLS, sequence number is a simple count of messages sent and received. This is maintained implicitly i.e, not sent in the messages explicitly. The protocol requires to maintain a separate sequence number counter for read and write sessions respectively.&lt;/p&gt;

&lt;p&gt;A touch of history,  sequence numbers were not used in the SSLv1, and were introduced in SSLv2 only.  Thus making SSLv1 prone to replay attacks (against which sequence numbers protect).&lt;/p&gt;

&lt;p&gt;The question arises, if sequence number for a connection is maintained, and given that it is not explicitly transmitted, then how it is useful? To answer, sequence numbers are used in the MAC. To prevent message replay or modification attacks, the MAC is computed using the MAC secret, the sequence number, the message length, the message contents, and two fixed character strings. When either side calculate the MAC for a given message, if sequence number does not correspond to the current message, then message authentication will fail, and the receiver will demand the sender to re-send the message.&lt;/p&gt;

&lt;p&gt;From RFC 6101 states following about how sequence number should be calculated and also what data type should be used. Note that by using int64, chances of overflow are minimized.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Each party maintains separate sequence numbers for transmitted and received messages for each connection. When a party sends or receives a change cipher spec message, the appropriate sequence number is set to zero.  Sequence numbers are of type uint64 and may not exceed 2^64-1.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To summarize, the sequence number provides protection against attempts to delete or reorder messages.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References:&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;https://tools.ietf.org/html/rfc6101#page-14&lt;/li&gt;
  &lt;li&gt;https://security.stackexchange.com/questions/55667/tls-sequence-number#&lt;/li&gt;
  &lt;li&gt;SSL and TLS Theory and practice by Rolf Oppliger&lt;/li&gt;
&lt;/ol&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">When talking about SSL/TLS most of the discussion centers around the ciphersuites, the types of messages or other complex cryptographical aspects. But there are many subtle things embedded in the protocol, which are often skipped or not discussed generally. One such thing is sequence numbers. Like in TCP, a sequence number for messages is also maintained in SSL/TLS protocol and one gets to know only is he/she delve into the RFCs.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">iOS Solid State NAND Storage</title>
      
      
      <link href="https://serializethoughts.com/2015/11/21/ios-solid-state-nand-storage" rel="alternate" type="text/html" title="iOS Solid State NAND Storage" />
      
      <published>2015-11-21T08:17:22+00:00</published>
      <updated>2015-11-21T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2015/11/21/ios-solid-state-nand-storage</id>
      <content type="html" xml:base="https://serializethoughts.com/2015/11/21/ios-solid-state-nand-storage">&lt;p&gt;There is not much literature available on how does NAND storage of Apple’s iDevices is like. While reading “Hacking and Securing iOS Applications” by Jonathan Zdziarski, I came across how does the NAND storage looks like until iOS 5. As a note on caution, it is very possible that this structure has been changed in the subsequent iOS versions.&lt;/p&gt;

&lt;p&gt;Knowing the structure of storage is an important step in order to understand how encryption works in iOS. The text below is verbatim from the book.
The NAND is divided into six separate slices:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;BOOT&lt;/strong&gt;: Block zero is referred to as the BOOT block of the NAND, and contains a copy of Apple’s low level boot loader.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;PLOG&lt;/strong&gt;: Block 1 is referred to as effaceable storage, and is designed as a storage locker for encryption keys and other data that needs to be quickly wiped or updated. The PLOG is where three very important keys are stored, which you’ll learn about in this chapter: the BAGI, Dkey, and EMF! keys. This is also where a security epoch is stored, which caused iOS 4 firmware to seemingly brick devices if the owner attempted a downgrade of the firmware.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;NVM&lt;/strong&gt;: Blocks 2–7 are used to store the NVRAM parameters set for the device.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;FIRM&lt;/strong&gt;: Blocks 8–15 store the device’s firmware, including iBoot (Apple’s second stage boot loader), the device tree, and logos.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;FSYS&lt;/strong&gt;: Blocks 16–4084 (and higher, depending on the capacity of the device) are used for the filesystem itself. This is the filesystem portion of NAND, where the operating system and data are stored. The filesystem for both partitions is stored here.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;RSRV&lt;/strong&gt;: The last 15 blocks of the NAND are reserved.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If there is any recent material on this topic, please let me know by commenting below.&lt;/p&gt;

&lt;p&gt;Keep Hacking :D&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">There is not much literature available on how does NAND storage of Apple’s iDevices is like. While reading “Hacking and Securing iOS Applications” by Jonathan Zdziarski, I came across how does the NAND storage looks like until iOS 5. As a note on caution, it is very possible that this structure has been changed in the subsequent iOS versions.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">Detecting Microsoft HTTP.sys Vulnerability</title>
      
      
      <link href="https://serializethoughts.com/2015/11/12/detecting-microsoft-http-sys-vulnerability" rel="alternate" type="text/html" title="Detecting Microsoft HTTP.sys Vulnerability" />
      
      <published>2015-11-12T08:17:22+00:00</published>
      <updated>2015-11-12T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2015/11/12/detecting-microsoft-http-sys-vulnerability</id>
      <content type="html" xml:base="https://serializethoughts.com/2015/11/12/detecting-microsoft-http-sys-vulnerability">&lt;p&gt;On April 14th, 2015 patch Tuesday, Microsoft released a patch for a remote code execution vulnerability in HTTP.sys module of Windows. The vulnerability affected all versions of windows, ranging from Windows 7 to Windows servers. Microsoft’s bulletin &lt;a href=&quot;https://technet.microsoft.com/en-us/library/security/ms15-034.aspx&quot;&gt;MS15-034&lt;/a&gt; talked about the vulnerability only in brief and left the details to be revealed only by reverse engg the patch. It was a race against time for people to patch their servers and for attackers to reverse engineer the patch to zero-down on the exact vulnerability. The vulnerability was assigned &lt;a href=&quot;http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-1635&quot;&gt;CVE-2015-1635&lt;/a&gt;. In this blog we will see what is HTTP.sys is and how to detect the vulnerability. Understandably the fix was to apply Microsoft’s patch.&lt;/p&gt;

&lt;h1 id=&quot;what-is-httpsys&quot;&gt;What is HTTP.sys?&lt;/h1&gt;

&lt;p&gt;HTTP.sys is a kernel-module which is a HTTP listener. Prior to HTTP.sys, windows used Windows Socket API (Winsock), a user-mode component, to receive HTTP requests. Having HTTP listener in kernel have following advantages [1]:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Kernel-mode caching&lt;/strong&gt;: Requests for cached responses are served without switching to user mode.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kernel-mode request queuing&lt;/strong&gt;: Requests cause less overhead in context switching because the kernel forwards requests directly to the correct worker process. If no worker process is available to accept a request, the kernel-mode request queue holds the request until a worker process picks it up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more details on working and advantages of HTTP.sys, visit [2].&lt;/p&gt;

&lt;h1 id=&quot;vulnerability&quot;&gt;Vulnerability&lt;/h1&gt;

&lt;p&gt;The vulnerability exists in the parsing of the Range Header [3] of the HTTP request sent to the server. By sending Range header’s value as &lt;em&gt;bytes=0-18446744073709551615&lt;/em&gt;, triggers a buffer overflow and this can be used as a test to detect HTTP.sys vulnerability on a server.&lt;/p&gt;

&lt;p&gt;Following curl command can be used for testing:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; www.example.com &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Host: irrelevant&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Range: bytes=0-18446744073709551615&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If response is “HTTP Error 400. The request has an invalid header name.”, then the server is patched, any other response apart from this indicate the server is still vulnerable.&lt;/p&gt;

&lt;p&gt;Sending following request will cause Blue Screen of Death (BSoD) and thus causing Denial-of-Service.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; www.example.com/iis-85.png &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Host: irrelevant&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Range: bytes=20-18446744073709551615&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As per comments on Hacker News [4], the vulnerability affects only those server on which “Output Cache” or “Enable Kernal Caching” is checked.&lt;/p&gt;

&lt;p&gt;There is ready to use tool available on &lt;a href=&quot;https://github.com/xPaw/HTTPsys/blob/master/index.php&quot;&gt;Github&lt;/a&gt; for testing your server for HTTP.sys vulnerability.&lt;/p&gt;

&lt;p&gt;This attack is similar to Range-attack on Apache servers, causing Denial of service [5].&lt;/p&gt;

&lt;p&gt;Keep Hacking :).&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References:&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;https://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/a2a45c42-38bc-464c-a097-d7a202092a54.mspx?mfr=true&lt;/li&gt;
  &lt;li&gt;http://www.codeproject.com/Articles/437733/Demystify-http-sys-with-HttpSysManager&lt;/li&gt;
  &lt;li&gt;https://tools.ietf.org/html/rfc7233#section-3.1&lt;/li&gt;
  &lt;li&gt;https://news.ycombinator.com/item?id=9380889&lt;/li&gt;
  &lt;li&gt;http://seclists.org/fulldisclosure/2011/Aug/175&lt;/li&gt;
  &lt;li&gt;https://security.stackexchange.com/questions/86201/does-http-sys-vulnerability-affect-windows-not-running-any-webservers&lt;/li&gt;
  &lt;li&gt;https://isc.sans.edu/forums/diary/MS15034+HTTPsys+IIS+DoS+And+Possible+Remote+Code+Execution+PATCH+NOW/19583/&lt;/li&gt;
  &lt;li&gt;https://www.reddit.com/r/netsec/comments/32n3m2/cve20151635_rce_in_windows_httpsys/&lt;/li&gt;
  &lt;li&gt;https://stackoverflow.com/questions/22598350/how-exactly-does-http-sys-work&lt;/li&gt;
&lt;/ol&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">On April 14th, 2015 patch Tuesday, Microsoft released a patch for a remote code execution vulnerability in HTTP.sys module of Windows. The vulnerability affected all versions of windows, ranging from Windows 7 to Windows servers. Microsoft’s bulletin MS15-034 talked about the vulnerability only in brief and left the details to be revealed only by reverse engg the patch. It was a race against time for people to patch their servers and for attackers to reverse engineer the patch to zero-down on the exact vulnerability. The vulnerability was assigned CVE-2015-1635. In this blog we will see what is HTTP.sys is and how to detect the vulnerability. Understandably the fix was to apply Microsoft’s patch.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">How Cuckoo Filters Can Improve Existing Approximate Matching Techniques</title>
      
      
      <link href="https://serializethoughts.com/2015/11/01/how-cuckoo-filter-can-improve-existing-approximate-matching-techniques" rel="alternate" type="text/html" title="How Cuckoo Filters Can Improve Existing Approximate Matching Techniques" />
      
      <published>2015-11-01T08:17:22+00:00</published>
      <updated>2015-11-01T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2015/11/01/how-cuckoo-filter-can-improve-existing-approximate-matching-techniques</id>
      <content type="html" xml:base="https://serializethoughts.com/2015/11/01/how-cuckoo-filter-can-improve-existing-approximate-matching-techniques">&lt;p&gt;If you have used &lt;a href=&quot;https://virustotal.com&quot;&gt;VirusTotal&lt;/a&gt;, in additional information tab you will find a field for &lt;strong&gt;ssdeep&lt;/strong&gt;. It is intriguing what this field represents among hashing functions SHA1, SHA256 and MD5. &lt;strong&gt;ssdeep&lt;/strong&gt; is a approximate matching algorithm (AMA). NIST define &lt;a href=&quot;http://www.nsrl.nist.gov/Documents/ApproxMatchSP3-20130802.pdf&quot;&gt;approximate matching algorithms&lt;/a&gt; as:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;Approximate matching is a technique for identifying similarities between or among digital objects, such as files, storage media, or network streams, which do not match exactly&quot;.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In simple words, given two files, having certain degree of similarity, for example, two word files with second file being copy of first except a paragraph. Traditional hash functions can only tell about the exact similarity, but cannot provide degree or a confidence score out of 100 of how similar the files are.&lt;/p&gt;

&lt;p&gt;AMA are used extensively in forensics investigation as they provide easy way to compare a hard disk against whitelisted or blacklisted corpus of files. Over past few years many AMA have been proposed. &lt;strong&gt;ssdeep&lt;/strong&gt; was the first, followed by &lt;strong&gt;sdhash&lt;/strong&gt; and &lt;strong&gt;mrsh-v2&lt;/strong&gt;. In between, some other algorithms were also proposed, but they suffered with one shortcoming or other. All of the above algorithms use &lt;a href=&quot;https://en.wikipedia.org/wiki/Bloom_filter&quot;&gt;Bloom filters&lt;/a&gt; as their basic building block. In short, Bloom filter is a probabilistic data structure for performing set membership query efficiently. In this post I will not go into details of internal working of  AMA nor of Bloom filter, but talk about an alternative of Bloom filter, namely &lt;a href=&quot;https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf&quot;&gt;Cuckoo filter&lt;/a&gt;. Cuckoo filter is modification of Cuckoo hashing approach to construct a data structure suitable for set membership determination. Cuckoo filter excel over Bloom filter on following parameters:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Cuckoo filter has better lookup performance&lt;/li&gt;
  &lt;li&gt;Cuckoo filter has better space efficiency than Bloom filter, when false positive rate desired is &amp;lt; 3%.&lt;/li&gt;
  &lt;li&gt;Unlike Bloom filter, Cuckoo filter supports deleting stored items dynamically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In one of my recent works, I have used Cuckoo filter instead of Bloom filter in &lt;strong&gt;mrsh-v2&lt;/strong&gt; and was able to achieve significant performance gain. The final results can be summarized as:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In simple runtime performance, there is a gain of 37%.&lt;/li&gt;
  &lt;li&gt;Size of final fingerprints generated is halved.&lt;/li&gt;
  &lt;li&gt;Memory usage is 8th of approach with Bloom filter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This work was presented at &lt;a href=&quot;http://d-forensics.org/&quot;&gt;ICDF2C-2015&lt;/a&gt;, which took place on 6th October in Seoul, South Korea, titled &lt;a href=&quot;http://link.springer.com/chapter/10.1007/978-3-319-25512-5_4#page-1&quot;&gt;How Cuckoo Filter Can Improve Existing Approximate Matching Techniques&lt;/a&gt; (&lt;a href=&quot;/assets/docs/icdf2c.pdf&quot;&gt;pdf&lt;/a&gt;). The work was adjudged with best paper award by the committee.&lt;/p&gt;

&lt;p&gt;In next coming posts I will try to cover what are approximate matching algorithms in detail and probably also look into each of these algorithms.&lt;/p&gt;

&lt;p&gt;Keep hacking!!&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">If you have used VirusTotal, in additional information tab you will find a field for ssdeep. It is intriguing what this field represents among hashing functions SHA1, SHA256 and MD5. ssdeep is a approximate matching algorithm (AMA). NIST define approximate matching algorithms as:</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">How to Detect a Drupal Installation</title>
      
      
      <link href="https://serializethoughts.com/2014/11/18/how-to-detect-a-drupal-installation" rel="alternate" type="text/html" title="How to Detect a Drupal Installation" />
      
      <published>2014-11-18T08:17:22+00:00</published>
      <updated>2014-11-18T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2014/11/18/how-to-detect-a-drupal-installation</id>
      <content type="html" xml:base="https://serializethoughts.com/2014/11/18/how-to-detect-a-drupal-installation">&lt;p&gt;On 15th October Drupal project disclosed a severely critical vulnerability &lt;a href=&quot;https://www.drupal.org/SA-CORE-2014-005&quot;&gt;SA-CORE-2014-005&lt;/a&gt; in Drupal core. Durpal is one of the most commonly used Content Management System (CMS), apart from Wordpress and Joomla. CMS helps in organizing and storing files of a website.&lt;/p&gt;

&lt;p&gt;The vulnerability affects Drupal version 7.x, before 7.32, and &lt;a href=&quot;https://www.drupal.org/drupalsa05FAQ&quot;&gt;some deployments of 6.x&lt;/a&gt;. An SQL injection vulnerability is present in Drupal’s abstraction API layer and an unauthenticated user can easily exploit it. More details about the vulnerability are available at &lt;a href=&quot;https://www.drupal.org/PSA-2014-003&quot;&gt;PSA-2014-003&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Lets look into some signatures which can be used to detect a Drupal installation:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;CHANGELOG.txt&lt;/strong&gt;: A default Drupal installation will have a CHANGELOG.txt file present in the root folder of the website. The presence of this file helps in couple of ways, firstly, it affirms presence of Drupal CMS and secondly helps in extracting the version of the Drupal running on the website. One can check Drupal’s website to check how does this work.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;HTTP Expire header&lt;/strong&gt;: A default Drupal installation have value of ‘Sun, 19 Nov 1978 05:00:00 GMT’ for expires header. It is fairly a good signature as not many servers will keep exactly this value.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/expire_header.jpg&quot; alt=&quot;Expire header in case of a Drupal installation&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;X-Generator HTTP Header&lt;/strong&gt;:  A default installation also sends a ‘X-Generator’ header in the HTTP response with value ‘Drupal 7 (http://drupal.org)’ .&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Looking for Drupal modules&lt;/strong&gt;: In case above mentioned methods are disabled by the server admin (which is very likely), one can scan for Drupal specific plugins. An exhaustive list is available &lt;a href=&quot;https://github.com/Dionach/CMSmap/blob/master/data/drupal_plugins.txt&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;determining-version&quot;&gt;Determining Version&lt;/h1&gt;

&lt;p&gt;Above methods, apart from CHANGELOG.txt, can only give us only a yes/no. But if one need to go a bit further and wants to determine the version of Drupal running??&lt;/p&gt;

&lt;p&gt;To solve this problem, one can use the fact that Drupal is an open source tool. Clone the Drupal code and look for the file which is most changed across various versions. One would prefer to look for javascript or css files, as these will be easy to fetch and unlikely to be changed by the website developer. In my short research I found using modules/color/color.js is a nice place to start with. Generate a SHA-1 hash of color.js across various versions of Drupal, then fetch this file from the website and hash and check against an already generated hash table to determine the version, or at least a range. You can practice this technique &lt;a href=&quot;https://www.drupal.org/modules/color/color.js&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Will update this post in case I find some more signatures. If you know one and would like to share, please leave it in the comments below.&lt;/p&gt;

&lt;p&gt;Keep hacking !! :D&lt;/p&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">On 15th October Drupal project disclosed a severely critical vulnerability SA-CORE-2014-005 in Drupal core. Durpal is one of the most commonly used Content Management System (CMS), apart from Wordpress and Joomla. CMS helps in organizing and storing files of a website.</summary>
      

      
      
    </entry>
  
  
  
    <entry>
      
      <title type="html">What is POODLE and How to Detect It</title>
      
      
      <link href="https://serializethoughts.com/2014/10/19/what-is-poodle-and-how-to-detect-it" rel="alternate" type="text/html" title="What is POODLE and How to Detect It" />
      
      <published>2014-10-19T08:17:22+00:00</published>
      <updated>2014-10-19T08:17:22+00:00</updated>
      <id>https://serializethoughts.com/2014/10/19/what-is-poodle-and-how-to-detect-it</id>
      <content type="html" xml:base="https://serializethoughts.com/2014/10/19/what-is-poodle-and-how-to-detect-it">&lt;p&gt;SSL was again center attention recently. After series of vulnerabilities, Heartbleed and OpenSSL CCS to a count a few, another vulnerability rocked one of the most important communication protocol of the internet. &lt;strong&gt;POODLE&lt;/strong&gt; - &lt;em&gt;Padding Oracle On Downgraded Legacy Encryption&lt;/em&gt;, affects SSLv3 (RFC6101) protocol and assigned &lt;a href=&quot;https://access.redhat.com/security/cve/CVE-2014-3566&quot;&gt;CVE-2014-3566&lt;/a&gt;. SSL 3.0 is an old protocol, proposed by Netscape in 1996 and now have been succeeded by new protocols, TLS 1.0, TLS 1.1 and TLS 1.2. SSL 3.0 is obsolete now and only supported because many legacy systems still use it. For example, some old embedded devices still use it and it is not very straightforward to update such devices. But after surfacing of POODLE attack, it is highly recommended to disable SSL 3.0 for any form of communication. After the demise of IE 6, all the modern browsers support TLS 1.0 and thus it is safe and logical to deprecate this old protocol.&lt;/p&gt;

&lt;p&gt;POODLE hogged the most of the limelight, but in the &lt;a href=&quot;https://www.openssl.org/news/secadv_20141015.txt&quot;&gt;OpenSSL advisory&lt;/a&gt; there were some more bugs reported, which should also be taken care by the administrators and the users. In total there are 4 bugs disclosed, other than poodle, rest 3 relates to implementation issues in OpenSSL. It is highly recommended to update your OpenSSL library version if you are using it.&lt;/p&gt;

&lt;h1 id=&quot;poodle&quot;&gt;POODLE&lt;/h1&gt;
&lt;p&gt;SSL is a very big and complex protocol. I tried to cover the basics of SSL/TLS protocol in the &lt;a href=&quot;https://serializethoughts.wordpress.com/2014/06/14/introduction-to-secure-socket-layer/&quot;&gt;previous posts&lt;/a&gt;. Most of the complexities lies in the initial &lt;em&gt;handshake phase&lt;/em&gt;, where various protocol parameters like protocol version, ciphersuite, compression etc are negotiated. POODLE attack is concerned with the next phase of the SSL protocol, the &lt;em&gt;bulk encryption phase&lt;/em&gt;, where the communication end points have already established the SSL connection and ready to exchange application’s data, e.g HTTP request and responses. POODLE is the latest in a long line of similar attacks against known weaknesses in SSL’s use of &lt;em&gt;Cipher block chaining&lt;/em&gt; (CBC) mode for block ciphers used in encryption. It is important to note that POODLE is more of a design issue than an implementation bug, unlike previous bugs like &lt;a href=&quot;http://heartbleed.com/&quot;&gt;Heartbleed&lt;/a&gt; and &lt;a href=&quot;https://serializethoughts.wordpress.com/2014/06/09/detecting-ccs-injection-vulnerability/&quot;&gt;OpenSSL CCS&lt;/a&gt; vulnerability. Some excellent explanation about the working and explanation of the attacks is available at following places:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;a href=&quot;https://www.openssl.org/~bodo/ssl-poodle.pdf&quot;&gt;security advisory&lt;/a&gt; by the authors of the attack, Bodo Moller, Thai Duong and Krzysztof Kotowicz.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://security.stackexchange.com/questions/70719/ssl3-poodle-vulnerability&quot;&gt;Thomas Pornin explaining&lt;/a&gt; very succinctly at security stackexchange.&lt;/li&gt;
  &lt;li&gt;A detailed &lt;a href=&quot;https://www.dfranke.us/posts/2014-10-14-how-poodle-happened.html&quot;&gt;explanation&lt;/a&gt; of the vulnerability and its history .&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://security.stackexchange.com/questions/70719/ssl3-poodle-vulnerability%20&quot;&gt;This&lt;/a&gt; and &lt;a href=&quot;https://security.stackexchange.com/questions/70719/ssl3-poodle-vulnerability&quot;&gt;this&lt;/a&gt; contains information about configuration changes in various servers and browsers to be taken care of in order to protect against POODLE.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;the-workaround&quot;&gt;The Workaround&lt;/h1&gt;
&lt;p&gt;There are couple of workarounds suggested by experts. One recommended by most is to outright &lt;strong&gt;totally disable SSLv3&lt;/strong&gt;. As argued, it is a very old protocol and now most modern devices support its successor, thus it makes sense to do so. But if this is not an option, then using &lt;strong&gt;TLS_FALLBACK_SCSV&lt;/strong&gt; proposal by Google’s Adam Langley is another option.&lt;/p&gt;

&lt;p&gt;SCSV stands for “signaling cipher suite value”, and its essentially a hack which allows TLS clients to indicate to servers that they support some extensions to TLS, while ensuring that servers that don’t understand the extension will simply ignore. SCSV works by appending a special, bogus value to the list of ciphersuites that the client advertises support for. The working of this proposal is a IETF draft and not standardised yet, but many implementation are supporting it
now.&lt;/p&gt;

&lt;p&gt;The working of SCSV is very simple, but tend to confuse in the first shot. In case of an attack via downgrading the SSL version, TLS_FALLBACK_SCSV indicates that the client is knowingly repeating  a SSL/TLS connection attempt over a lower protocol version than its supports, as the last one failed for some reason.  When the server sees this TLS_FALLBACK_SCSV in ciphersuite list, it compares the highest protocol version it supports to the version indicated in the Client Hello. If the client’s version is lower, then the server responds with a new Alert defined by the RFC called ‘inappropriate_fallback’ (code 86). The logic being that the server knows the client supports something better so the connection should have negotiated that. The ‘inappropriate_fallback’ Alert is a “fatal” error and the connection attempt should be aborted. In practice, this protects from all forced downgrades attack completely. Unfortunately, this is not the silver bullet to the problem. In case the client-server negotiate SSLv3 protocol then this attack can be carried out. To further read about TLS_FALLBACK_SCSV, you can visit &lt;a href=&quot;http://www.exploresecurity.com/poodle-and-the-tls_fallback_scsv-remedy/&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00&quot;&gt;RFC draft&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;how-to-detect&quot;&gt;How To Detect&lt;/h1&gt;
&lt;p&gt;The detection is also straightforward. Send the TLS_FALLBACK_SCSV {0x56,0x00} in the list of supported ciphersuites in the Client Hello, if the server responds with an alert message &lt;em&gt;inappropriate_fallback&lt;/em&gt;, then the server is not vulnerable to downgrade attack. Additionally, it is best if the server does not support SSLv3 outright.&lt;/p&gt;

&lt;p&gt;Keep hacking!! :D&lt;/p&gt;

&lt;Paste&gt;
&lt;/Paste&gt;</content>

      
      
      
      
      

      
        <author>
            <name>Vikas Gupta</name>
          
          
        </author>
      

      

      

      
        <summary type="html">SSL was again center attention recently. After series of vulnerabilities, Heartbleed and OpenSSL CCS to a count a few, another vulnerability rocked one of the most important communication protocol of the internet. POODLE - Padding Oracle On Downgraded Legacy Encryption, affects SSLv3 (RFC6101) protocol and assigned CVE-2014-3566. SSL 3.0 is an old protocol, proposed by Netscape in 1996 and now have been succeeded by new protocols, TLS 1.0, TLS 1.1 and TLS 1.2. SSL 3.0 is obsolete now and only supported because many legacy systems still use it. For example, some old embedded devices still use it and it is not very straightforward to update such devices. But after surfacing of POODLE attack, it is highly recommended to disable SSL 3.0 for any form of communication. After the demise of IE 6, all the modern browsers support TLS 1.0 and thus it is safe and logical to deprecate this old protocol.</summary>
      

      
      
    </entry>
  
  
</feed>
