{"id":136,"date":"2007-07-11T18:53:10","date_gmt":"2007-07-11T23:53:10","guid":{"rendered":"http:\/\/www.nynaeve.net\/?p=136"},"modified":"2019-12-13T17:37:42","modified_gmt":"2019-12-13T22:37:42","slug":"silly-debugger-tricks-using-kd-to-reset-a-forgotten-administrator-password","status":"publish","type":"post","link":"http:\/\/www.nynaeve.net\/?p=136","title":{"rendered":"Silly debugger tricks: Using KD to reset a forgotten administrator password"},"content":{"rendered":"<p>One particularly annoying occurance that&#8217;s happened to me on a couple of occasions is losing the password to a long-forgotten test VM that I need to thaw for some reason or another, months from the last time I used it.  (If you follow good password practices and use differing passwords for accounts, you might find yourself in this position.)<\/p>\n<p>Normally, you&#8217;re kind of sunk if you&#8217;re in this position, which is the whole idea &#8211; no administrator password is no administrative access to the box, right?<\/p>\n<p>The officially supported solution in this case, assuming you don&#8217;t have a password reset disk (does anyone actually use those?) is to reformat.  Oh, what fun that is, especially if you just need to grab something off of a test system and be done with it in a few minutes.<\/p>\n<p>Well, with physical access (or the equivalent if the box is a VM), you can do a bit better with the kernel debugger.  It&#8217;s a bit embarassing having to &#8220;hack&#8221; (and I use that term very loosely) into your own VM because you don&#8217;t remember which throwaway password you used 6 months ago, but it beats waiting around for a reformat (and in the case of a throwaway test VM, it&#8217;s probably not worth the effort anyway compared to cloning a new one, unless there was something important on the drive).<\/p>\n<p>(Note that as far as security models go, I don&#8217;t really think that this is a whole lot of a security risk.  After all, to use the kernel debugger, you need physical access to the system, and if you have that much, you could always just use a boot CD, swap out hard drives, or a thousand other different things.  This is just more convenient if you&#8217;ve got a serial cable and a second box with a serial port, say a laptop, and you just want to reset the password for an account on an existing install.)<\/p>\n<p>This is, however, perhaps an instructive reminder in how much access the kernel debugger gives you over a system &#8211; namely, the ability to do whatever you want, like bypass password authentication.<\/p>\n<p>The basic idea behind this trick is to use the debugger to disable the password cheeck used at interactive logon inside LSA.<\/p>\n<p>The first step is to locate the LSA process.  The typical way to do this is to use the <em>!process 0 0<\/em> command and look for a process name of LSASS.exe.  The next step requires that we know the EPROCESS value for LSA, hence the enumeration.  For instance:<\/p>\n<pre>\r\nkd&gt; !process 0 0\r\n**** NT ACTIVE PROCESS DUMP ****\r\nPROCESS fffffa80006540d0\r\n    SessionId: none  Cid: 0004    Peb: 00000000\r\n      ParentCid: 0000\r\n    DirBase: 00124000  ObjectTable: fffff88000000080\r\n      HandleCount: 545.\r\n    Image: System\r\n[...]\r\nPROCESS <span style=\"color:#ff0000\">fffffa8001a893a0<\/span>\r\n    SessionId: 0  Cid: 025c    Peb: 7fffffda000\r\n     ParentCid: 01ec\r\n    DirBase: 0cf3e000  ObjectTable: fffff88001b99d90\r\n     HandleCount: 822.\r\n    Image: <span style=\"color:#ff0000\">lsass.exe<\/span>\r\n<\/pre>\n<p>Now that we&#8217;ve got the LSASS EPROCESS value, the next step is to switch to it as the active process.  This is necessary as we&#8217;re going to need to set a conditional breakpoint in the context of LSA&#8217;s address space.  For this task, we&#8217;ll use the <em>.process \/p \/r eprocess-pointer<\/em> command, which changes the debugger&#8217;s process context and reloads user mode symbols.<\/p>\n<pre>\r\nkd&gt; .process \/p \/r fffffa8001a893a0\r\nImplicit process is now fffffa80`01a893a0\r\n.cache forcedecodeuser done\r\nLoading User Symbols\r\n.....\r\n<\/pre>\n<p>Next, we set up a breakpoint on a particular internal LSA function that is used to determine whether a given password is accepted for a local account logon.  The breakpoint changes the function to always return TRUE, such that all local account logons will succeed if they get to the point of a password check.  After that, execution is resumed.<\/p>\n<pre>\r\nkd&gt; ba e1 msv1_0!MsvpPasswordValidate\r\n   \"g @$ra ; r @al = 1 ; g\"\r\nkd&gt; g\r\n<\/pre>\n<p>We can dissect this breakpoint to understand better just what it is doing:<\/p>\n<ul>\n<li>Set a break on execute hardware breakpoint on <em>msv1_0!MsvpPasswordValidate<\/em>.  Why did I use a hardware breakpoint?  Well, they&#8217;re generally more reliable when doing user mode breakpoints from the kernel debugger, especially if what you&#8217;re setting a breakpoint on might be paged out.  (Normal breakpoints require overwriting an instruction with an &#8220;int 3&#8221;, whereas a hardware breakpoint simply programs an address into the processor such that it&#8217;ll trap if that address is accessed for read\/write\/execute, depending on the breakpoint type.)<\/li>\n<li>The breakpoint has a condition (or command) attached to it.  Specifically, this command runs the target until it returns from the current function (&#8220;g @$ra&#8221; continues the target until the return address is hit.  @$ra is a special platform-independent psueod-register that refers to the return address of the ccurrent function.)  Once the function has returned, the <em>al<\/em> register is set to 1 and execution is resumed.  This function returns a BOOLEAN value (in other words an 8-bit value), which is stored in <em>al<\/em> (the low 8 bits of the <em>eax<\/em> or <em>rax<\/em> register, depending on whether you&#8217;re on x86 or x64).  IA64 targets don&#8217;t store return values in this fashion and so the breakpoint is x86\/x64-specific.<\/li>\n<\/ul>\n<p>Now, log on to the console.  Make sure to use a local account and not a domain account, so the authentication is processed by the Msv1_0 package.  Also, non-console logons might not run through the Msv1_0 package, and may not be affected.  (For example, Network Level Authentication (NLA) for RDP in Vista\/Srv08 doesn&#8217;t seem to use Msv1_0, even for local accounts.  The console will still allow you to log in, however.)<\/p>\n<p>From there, you can simply reset the password for your account via the Computer Management console.  Be warned that this will wipe out EFS keys and the like, however.  To restore password checking to normal, either reboot the box without the kernel debugger, or use the <em>bc*<\/em> command to disable the breakpoint you set.<\/p>\n<p>(For the record, <a title=\"Bypassing our testbox's login password\" href=\"http:\/\/rootkit.com\/newsread_print.php?newsid=549\">I can&#8217;t really take credit<\/a> for coming up with this trick, but it&#8217;s certainly one I&#8217;ve found handy in a number of scenarios.)<\/p>\n<p>Now, one thing that you might take away from this article, from a security standpoint, is that it is important to provide physical security for critical computers.  To be honest, if someone really wants to access a box they have physical access to, this is probably not even the easist way; it would be simplere to just pop in a bootable CD or floppy and load a different operating system.  As a result, as previously mentioned, I wouldn&#8217;t exactly consider this a security hole as it already requires you to have physical access in order to be effective.  It is, however, a handy way to reset passwords for your own computers or VMs in a pinch if you happen to know a little bit about the debugger.  Conversely, it&#8217;s not really a supported &#8220;solution&#8221; (more of a giant hack at best), so use it with care (and don&#8217;t expect PSS to bail you out if you break something by poking around in the kernel debugger).  It may break without warning on future OS versions (and there are many cases that won&#8217;t be caught by this trick, such as domain accounts that use the Kerberos provider to process authentication).<\/p>\n<p>Update: I forgot to mention the very important fact that you can <a title=\"Windows Boot Menu\" href=\"http:\/\/www.nynaeve.net\/images\/bootmenu.png\">turn on the kernel debugger from the &#8220;F8&#8221; boot menu<\/a> when booting the system, even if you don&#8217;t have kernel debugging enabled in the boot configuration or boot.ini.  This will enable kernel debugging on the highest numbered COM port, at 19200bps.  (On Windows Vista, this also seems capable of auto-selecting 1394 if your machine had a 1394 port, if memory serves.  I don&#8217;t know offhand whether that translates to downlevel platforms, though.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One particularly annoying occurance that&#8217;s happened to me on a couple of occasions is losing the password to a long-forgotten test VM that I need to thaw for some reason or another, months from the last time I used it. (If you follow good password practices and use differing passwords for accounts, you might find [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,3,5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/136"}],"collection":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=136"}],"version-history":[{"count":1,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":579,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions\/579"}],"wp:attachment":[{"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nynaeve.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}