{"id":1142,"date":"2014-01-10T16:54:47","date_gmt":"2014-01-10T16:54:47","guid":{"rendered":"http:\/\/www.phillips321.co.uk\/?p=1142"},"modified":"2014-04-28T14:41:46","modified_gmt":"2014-04-28T13:41:46","slug":"cracking-a-juniper-netscreen-screenos-password-hash","status":"publish","type":"post","link":"https:\/\/www.phillips321.co.uk\/2014\/01\/10\/cracking-a-juniper-netscreen-screenos-password-hash\/","title":{"rendered":"Cracking a Juniper Netscreen ScreenOS Password Hash"},"content":{"rendered":"<p>So the Juniper Netscreen\/SSG ScreenOS password hash is a bit of a hidden mystery. I had in my hand the config of a Netscreen device and I wanted to perform a reverse of the password hashes to see if they were weak.<\/p>\n<p>In this case here&#8217;s the line from the config:<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">set admin user &quot;admin&quot; password &quot;nAePB0rfAm+Nc4YO3s0JwPHtRXIHdn&quot; privilege &quot;all&quot;<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>John The ripper has supported Netscreen passwords since back in 2008 when Samuel Mo\u00f1ux released <a href=\"http:\/\/www.openwall.com\/lists\/john-users\/2008\/06\/20\/1\" target=\"_blank\">this patch<\/a>. Unfortunately John was too slow for my needs as I was up against a deadline, thus I looked at the faster approach of using the GPU to perform the cracking. <a href=\"https:\/\/hashcat.net\/oclhashcat\/\" target=\"_blank\">Hashcat<\/a> is the best tool for the job but unfortunately Hashcat didn&#8217;t support this hashing algorithm. \ud83d\ude41<\/p>\n<p>After a looking through jar source code I found <a href=\"https:\/\/github.com\/magnumripper\/JohnTheRipper\/blob\/7dceaf7f6ea015b219de72948aaa774ac3ecf7e7\/run\/netscreen.py\" target=\"_blank\">this python script<\/a> which can generate a Netscreen hash, getting warmer. Here&#8217;s a shortened version of the code to show just the function we&#8217;re interested in:<\/p>\n<div class=\"codecolorer-container python vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/><\/div><\/td><td><div class=\"python codecolorer\"><span class=\"kw1\">def<\/span> makepass<span class=\"br0\">&#40;<\/span><span class=\"kw3\">user<\/span><span class=\"sy0\">,<\/span> password<span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; middle <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;Administration Tools&quot;<\/span><br \/>\n&nbsp; &nbsp; s <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;%s:%s:%s&quot;<\/span> % <span class=\"br0\">&#40;<\/span><span class=\"kw3\">user<\/span><span class=\"sy0\">,<\/span> middle<span class=\"sy0\">,<\/span> password<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">print<\/span> s<br \/>\n&nbsp; &nbsp; m <span class=\"sy0\">=<\/span> hashlib.<span class=\"kw3\">md5<\/span><span class=\"br0\">&#40;<\/span>s<span class=\"br0\">&#41;<\/span>.<span class=\"me1\">digest<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; narray <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> i <span class=\"kw1\">in<\/span> <span class=\"kw2\">range<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">8<\/span><span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; n1 <span class=\"sy0\">=<\/span> <span class=\"kw2\">ord<\/span><span class=\"br0\">&#40;<\/span>m<span class=\"br0\">&#91;<\/span><span class=\"nu0\">2<\/span>*i<span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; n2 <span class=\"sy0\">=<\/span> <span class=\"kw2\">ord<\/span><span class=\"br0\">&#40;<\/span>m<span class=\"br0\">&#91;<\/span><span class=\"nu0\">2<\/span>*i+<span class=\"nu0\">1<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; narray.<span class=\"me1\">append<\/span><span class=\"br0\">&#40;<\/span> <span class=\"br0\">&#40;<\/span>n1<span class=\"sy0\">&lt;&lt;<\/span><span class=\"nu0\">8<\/span> &amp; <span class=\"nu0\">0xff00<\/span><span class=\"br0\">&#41;<\/span> | <span class=\"br0\">&#40;<\/span>n2 &amp; <span class=\"nu0\">0xff<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#41;<\/span> <br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; res <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;&quot;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> i <span class=\"kw1\">in<\/span> narray:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; p1 <span class=\"sy0\">=<\/span> i <span class=\"sy0\">&gt;&gt;<\/span> <span class=\"nu0\">12<\/span> &amp; <span class=\"nu0\">0xf<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; p2 <span class=\"sy0\">=<\/span> i <span class=\"sy0\">&gt;&gt;<\/span> <span class=\"nu0\">6<\/span> &nbsp;&amp; <span class=\"nu0\">0x3f<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; p3 <span class=\"sy0\">=<\/span> i &nbsp; &nbsp; &nbsp; &amp; <span class=\"nu0\">0x3f<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; res +<span class=\"sy0\">=<\/span> b64<span class=\"br0\">&#91;<\/span>p1<span class=\"br0\">&#93;<\/span> + b64<span class=\"br0\">&#91;<\/span>p2<span class=\"br0\">&#93;<\/span> + b64<span class=\"br0\">&#91;<\/span>p3<span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> c<span class=\"sy0\">,<\/span> n <span class=\"kw1\">in<\/span> &nbsp;<span class=\"kw2\">zip<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;nrcstn&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"br0\">&#91;<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">,<\/span> <span class=\"nu0\">6<\/span><span class=\"sy0\">,<\/span> <span class=\"nu0\">12<\/span><span class=\"sy0\">,<\/span> <span class=\"nu0\">17<\/span><span class=\"sy0\">,<\/span> <span class=\"nu0\">23<\/span><span class=\"sy0\">,<\/span> <span class=\"nu0\">29<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; res <span class=\"sy0\">=<\/span> res<span class=\"br0\">&#91;<\/span>:n<span class=\"br0\">&#93;<\/span> + c + res<span class=\"br0\">&#91;<\/span>n:<span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> res<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>After looking through the code it is clear that there is a fixed salt of <em>Administration Tools<\/em> and a salt of the username(lines 2 and 3).<br \/>\nThe code then takes each 2 chars and adds the binaries together(lines 8-11)<br \/>\nFrom this it creates 3 characters from the 16bits(lines 14-18)<br \/>\nAnd finally is scatters the letters n,r,c,s,t &#038; n onto the hash in specific places (lines 20 and 21)<br \/>\nIt&#8217;s worth noting that the letters nrcstn is actually <strong>N<\/strong>e<strong>TSCR<\/strong>ee<strong>N<\/strong> in reverse without the e&#8217;s \ud83d\ude42<\/p>\n<p>Using this code it was possible to write some new code to reverse backwards through the steps in order to go from a Netscreen hash back to the raw MD5 hash. Here&#8217;s the function for this:<\/p>\n<div class=\"codecolorer-container python vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/><\/div><\/td><td><div class=\"python codecolorer\"><span class=\"kw1\">def<\/span> reversetomd5<span class=\"br0\">&#40;<\/span>knownhash<span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; <span class=\"co1\"># strip out nrcstn fixed characters<\/span><br \/>\n&nbsp; &nbsp; clean<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;&quot;<\/span> <br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> i <span class=\"kw1\">in<\/span> <span class=\"br0\">&#91;<\/span><span class=\"nu0\">1<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">3<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">4<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">5<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">7<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">8<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">9<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">10<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">11<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">13<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">14<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">15<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">16<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">18<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">19<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">20<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">21<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">22<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">24<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">25<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">26<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">27<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">28<\/span><span class=\"br0\">&#93;<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; clean+<span class=\"sy0\">=<\/span>knownhash<span class=\"br0\">&#91;<\/span>i<span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"co1\"># create blocks<\/span><br \/>\n&nbsp; &nbsp; block<span class=\"sy0\">=<\/span><span class=\"br0\">&#91;<\/span><span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> i <span class=\"kw1\">in<\/span> <span class=\"kw2\">xrange<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">24<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">3<\/span><span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; p1 <span class=\"sy0\">=<\/span> b64.<span class=\"me1\">index<\/span><span class=\"br0\">&#40;<\/span>clean<span class=\"br0\">&#91;<\/span>i-<span class=\"nu0\">2<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; p2 <span class=\"sy0\">=<\/span> b64.<span class=\"me1\">index<\/span><span class=\"br0\">&#40;<\/span>clean<span class=\"br0\">&#91;<\/span>i-<span class=\"nu0\">1<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; p3 <span class=\"sy0\">=<\/span> b64.<span class=\"me1\">index<\/span><span class=\"br0\">&#40;<\/span>clean<span class=\"br0\">&#91;<\/span>i<span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; block.<span class=\"me1\">append<\/span><span class=\"br0\">&#40;<\/span>p1 <span class=\"sy0\">&lt;&lt;<\/span> <span class=\"nu0\">12<\/span> | p2 <span class=\"sy0\">&lt;&lt;<\/span> <span class=\"nu0\">6<\/span> | p3<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"co1\"># split block into half and find out character for each decimal<\/span><br \/>\n&nbsp; &nbsp; md5hash<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;&quot;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> i <span class=\"kw1\">in<\/span> block:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; n1 <span class=\"sy0\">=<\/span> i <span class=\"sy0\">&gt;&gt;<\/span> <span class=\"nu0\">8<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; n2 <span class=\"sy0\">=<\/span> i &amp; <span class=\"nu0\">0xff<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; md5hash+<span class=\"sy0\">=<\/span><span class=\"kw2\">chr<\/span><span class=\"br0\">&#40;<\/span>n1<span class=\"br0\">&#41;<\/span>+<span class=\"kw2\">chr<\/span><span class=\"br0\">&#40;<\/span>n2<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw3\">binascii<\/span>.<span class=\"me1\">hexlify<\/span><span class=\"br0\">&#40;<\/span>md5hash<span class=\"br0\">&#41;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Using this function you are able to give it a Netscreen hash and you&#8217;ll get back the raw MD5.<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">Knownhash of:nAePB0rfAm+Nc4YO3s0JwPHtRXIHdn has MD5Hash of: 078f1d1f09bede18edf49c0f745781dd<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Now using the power of GPU cracking and my favourite tool Hashcat it is possible to crack the hash. We need to put the hash in a format that hashcat can understand so we create a file called netscreen.txt and put the hash in the following format(note the training colon after the fixed salt):<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">[hash]:[user]:Administration Tools:<br \/>\n078f1d1f09bede18edf49c0f745781dd:admin:Administration Tools:<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>We then use hashcat&#8217;s mode 20 which is md5($salt.$pass) to crack the hash:<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/><\/div><\/td><td><div class=\"text codecolorer\">C:\\cudaHashcat64.exe -m 20 netscreen.txt rockyou.txt<br \/>\ncudaHashcat v1.01 starting...<br \/>\nHashes: 1 total, 1 unique salts, 1 unique digests<br \/>\nBitmaps: 8 bits, 256 entries, 0x000000ff mask, 1024 bytes<br \/>\nWatchdog: Temperature abort trigger set to 90c<br \/>\nWatchdog: Temperature retain trigger set to 80c<br \/>\nDevice #1: GeForce GTX 660M, 2048MB, 950Mhz, 2MCU<br \/>\nDevice #1: Kernel .\/kernels\/4318\/m0020_a0.sm_30.64.ptx<br \/>\nDevice #1: Kernel .\/kernels\/4318\/bzero.64.ptx<br \/>\n<br \/>\nGenerated dictionary stats for rockyou.txt: 139921541 bytes, 14344395 words, 14343300 keyspace<br \/>\n<br \/>\n078f1d1f09bede18edf49c0f745781dd:admin:Administration Tools::MySecretPassword<br \/>\n<br \/>\nSession.Name...: cudaHashcat<br \/>\nStatus.........: Cracked<br \/>\nInput.Mode.....: File (rockyou.txt)<br \/>\nHash.Target....: 078f1d1f09bede18edf49c0f745781dd:admin:Administration Tools:<br \/>\nHash.Type......: md5($salt.$pass)<br \/>\nTime.Started...: Fri Jan 10 15:03:24 2014 (5 secs)<br \/>\nSpeed.GPU.#1...: &nbsp;4886.1 kH\/s<br \/>\nRecovered......: 1\/1 (100.00%) Digests, 1\/1 (100.00%) Salts<br \/>\nProgress.......: 11109723\/14343300 (77.46%)<br \/>\nRejected.......: 1371\/11109723 (0.01%)<br \/>\nHWMon.GPU.#1...: &nbsp;0% Util, 41c Temp, N\/A Fan<br \/>\n<br \/>\nStarted: Fri Jan 10 15:03:24 2014<br \/>\nStopped: Fri Jan 10 15:03:32 2014<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Bingo it&#8217;s cracked the hash with the password MySecretPassword<\/p>\n<p>As this algorithm uses more than just a fixed salt to create the hash I&#8217;ll speak to <a href=\"https:\/\/twitter.com\/hashcat\" target=\"_blank\">Atom (the creator of hashcat)<\/a> to see if he want&#8217;s to implement it into a future release, but until then this code should help you in cracking netscreen passwords.<\/p>\n<p><strong>Update:<\/strong> Atom has added this hash type to oclHashcat as of version 1.20 <a href=\"https:\/\/hashcat.net\/hashcat\/\" target=\"_blank\">https:\/\/hashcat.net\/hashcat\/<\/a> (Feature request here: <a href=\"https:\/\/hashcat.net\/trac\/ticket\/235\" target=\"_blank\">https:\/\/hashcat.net\/trac\/ticket\/235<\/a>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So the Juniper Netscreen\/SSG ScreenOS password hash is a bit of a hidden mystery. I had in my hand the config of a Netscreen device and I wanted to perform a reverse of the password hashes to see if they were weak. In this case here&#8217;s the line from the config: 1set admin user &quot;admin&quot; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[186,159,408,161,406,205,405,111,407],"_links":{"self":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/1142"}],"collection":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/comments?post=1142"}],"version-history":[{"count":11,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/1142\/revisions"}],"predecessor-version":[{"id":1190,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/1142\/revisions\/1190"}],"wp:attachment":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media?parent=1142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/categories?post=1142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/tags?post=1142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}