{"id":263,"date":"2015-05-21T09:12:48","date_gmt":"2015-05-21T06:12:48","guid":{"rendered":"http:\/\/ustinych.net\/wordpress\/?p=263"},"modified":"2015-05-21T09:14:05","modified_gmt":"2015-05-21T06:14:05","slug":"synologys-secret-telnet-password","status":"publish","type":"post","link":"https:\/\/ustinych.net\/wordpress\/?p=263","title":{"rendered":"Synology&#8217;s &#171;secret&#187; telnet password"},"content":{"rendered":"<p>If you have a Synology NAS and had some sort of disk crash in the past, you&#8217;ve probably encountered the famous\u00a0<em>&#171;Cannot format system partition&#187;<\/em>\u00a0and\u00a0<em>&#171;Please configure your router to forward port 23 to DiskStation and contact Synology online support&#187;<\/em>.<\/p>\n<p>Yeah, it sucks.<\/p>\n<p>It sucks even more when you know the disk is perfectly fine, and you still have hope to recover your data. Or you simply don&#8217;t like the idea of having your port 23 open to the world for god-knows-how-long until Synology tech support can look into your case.<\/p>\n<p>You&#8217;ve probably tried telneting to your NAS. Maybe you&#8217;ve even tried\u00a0<a href=\"http:\/\/wrgms.com\/recovering-a-failed-synology-diskstation-ds2xx-serial\/\">opening the case and hacking the serial port<\/a>, only to discover that you don&#8217;t have the root password. The DS Assistant password doesn&#8217;t work, and you exhausted all obvious guesses &#8212;\u00a0<em>blank<\/em>,\u00a0<em>synopass<\/em>,\u00a0<em>synology<\/em>,\u00a0<em>password<\/em>,\u00a0<em>admin<\/em>,\u00a0<em>root<\/em>, etc.<\/p>\n<p>Well, what about\u00a0<code>c12-0804<\/code>? This is today&#8217;s password.<\/p>\n<p>But if you&#8217;re reading this a few days (or years) from now, too bad; it won&#8217;t work. Unless, of course, you wait until December 8th. Because the password repeats every year.<\/p>\n<p>Basically Synology hardcoded the login binary within the firmware, in order to accept an obfuscated password for root, which depends on the current date.<\/p>\n<p>Based on the original\u00a0<a href=\"https:\/\/gist.github.com\/4242127\">correct_password.c<\/a>\u00a0source, I hacked a short snippet to generate the daily password.<\/p>\n<p>Here&#8217;s the Synology Telnet password generator:<\/p>\n<pre><code class=\"1c hljs cpp\"><span class=\"hljs-preprocessor\">#include &lt;stdlib.h&gt; <\/span>\r\n<span class=\"hljs-preprocessor\">#include &lt;time.h&gt; <\/span>\r\n<span class=\"hljs-preprocessor\">#include &lt;stdio.h&gt; <\/span>\r\n\r\n<span class=\"hljs-keyword\">void<\/span> main()\r\n{\r\n    <span class=\"hljs-keyword\">struct<\/span> timeval tvTime;\r\n    <span class=\"hljs-keyword\">struct<\/span> tm tmOutput;\r\n\r\n    gettimeofday(&amp;tvTime, <span class=\"hljs-number\">0<\/span>);\r\n    localtime_r(&amp;(tvTime.tv_sec), &amp;tmOutput);\r\n\r\n    tmOutput.tm_mon += <span class=\"hljs-number\">1<\/span>;\r\n    <span class=\"hljs-built_in\">printf<\/span>(<span class=\"hljs-string\">\"password for today is: %x%02d-%02x%02d\\n\\n\"<\/span>,\r\n        tmOutput.tm_mon, tmOutput.tm_mon, tmOutput.tm_mday,\r\n        gcd(tmOutput.tm_mon, tmOutput.tm_mday));\r\n}\r\n\r\n<span class=\"hljs-keyword\">int<\/span> gcd(<span class=\"hljs-keyword\">int<\/span> a, <span class=\"hljs-keyword\">int<\/span> b)\r\n{\r\n    <span class=\"hljs-keyword\">return<\/span> (b?gcd(b,a%b):a);\r\n}\r\n<\/code><\/pre>\n<p>Compile and run the code above with\u00a0<code>gcc<\/code>, and you&#8217;ll get the password for today. You can also use the excellent\u00a0<a href=\"http:\/\/codepad.org\/4TrgWs9X\">Codepad<\/a>.<\/p>\n<p>Bonus tip: if you&#8217;re curious how exactly the password is generated, here&#8217;s the gist:<\/p>\n<ul>\n<li>1st character = month in hexadecimal, lower case (1=Jan, &#8230; , a=Oct, b=Nov, c=Dec)<\/li>\n<li>2-3 = month in decimal, zero padded and starting in 1 (01, 02, 03, &#8230;, 11, 12)<\/li>\n<li>4 = dash<\/li>\n<li>5-6 = day of the month in hex (01, 02 .., 0A, .., 1F)<\/li>\n<li>7-8 =\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Greatest_common_divisor\">greatest common divisor<\/a>\u00a0between month and day, zero padded. This is always a number between 01 and 12.<\/li>\n<\/ul>\n<p>So, let&#8217;s say today is October 15, the password would be:\u00a0<strong>a10-0f05<\/strong>\u00a0(<strong>a<\/strong>\u00a0= month in hex,\u00a0<strong>10<\/strong>\u00a0= month in dec,\u00a0<strong>0f<\/strong>\u00a0= day in hex,\u00a0<strong>05<\/strong>\u00a0= greatest divisor between 10 and 15).<\/p>\n<p>If you have trouble calculating the greatest common divisor (elementary math, anyone?),\u00a0<a href=\"http:\/\/www.wolframalpha.com\/input\/?i=gcd%2815%2C+5%29\">Wolfram Alpha is your friend<\/a>.<\/p>\n<p>This was tested on a Synology DS212+, with Marvell Kirkwood mv6282 chipset. It&#8217;s unlikely but still possible that different models use a different algorithm. YMMV, so always check the\u00a0<a href=\"http:\/\/sourceforge.net\/projects\/dsgpl\/\">source code<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a Synology NAS and had some sort of disk crash in the past, you&#8217;ve probably encountered the famous\u00a0&#171;Cannot format system partition&#187;\u00a0and\u00a0&#171;Please configure your router to forward port 23 to DiskStation and contact Synology online support&#187;. Yeah, it sucks. It sucks even more when you know the disk is perfectly fine, and you\u2026 <span class=\"read-more\"><a href=\"https:\/\/ustinych.net\/wordpress\/?p=263\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":266,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-synology"],"_links":{"self":[{"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263"}],"version-history":[{"count":1,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions\/265"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/266"}],"wp:attachment":[{"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ustinych.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}