<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shimon Gb Gibraltar on Medium]]></title>
        <description><![CDATA[Stories by Shimon Gb Gibraltar on Medium]]></description>
        <link>https://medium.com/@data_man?source=rss-af218336f134------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*s_G9J82XJSprfO4m.</url>
            <title>Stories by Shimon Gb Gibraltar on Medium</title>
            <link>https://medium.com/@data_man?source=rss-af218336f134------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 09:45:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@data_man/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The weak link: how to reveal database passwords in SQL Server]]></title>
            <link>https://medium.com/@data_man/the-weak-link-how-to-reveal-database-passwords-in-sql-server-da8ba79dcb76?source=rss-af218336f134------2</link>
            <guid isPermaLink="false">https://medium.com/p/da8ba79dcb76</guid>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Shimon Gb Gibraltar]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 11:02:43 GMT</pubDate>
            <atom:updated>2019-01-07T19:13:21.214Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve stumbled upon an interesting post on <a href="http://www.sqlservercentral.com/scripts/108092/"><strong>sqlservercentral.com</strong></a></p><p>The title “<strong>Script Out Passwords”</strong> was very appealing and the post included a query that will script out any password.</p><p>seems powerful but is it real?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*0-dyvRrSLgRPOQzY0oplHQ.png" /><figcaption>This is the result of running the query</figcaption></figure><p>As suspected, it was just another April fools<strong> </strong>joke</p><p>In the above code the string “We cannot really recover passwords…” was converted to binary and wrapped with a cast function, so when the query is executed the binary code is decoded using a conversion to text function</p><p>Clearly, That’s not really good encryption since anyone can simply decode the binary string using a <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-2017">cast / convert</a> function and therefore it shouldn’t be used to hide any sensitive data.</p><p>However, In SQL Server credentials are stored in a hashed form using a cryptographic algorithm called <strong>SHA</strong></p><ul><li><strong>S</strong>ecure <strong>H</strong>ash <strong>A</strong>lgorithms (SHA) are a family of cryptographic hash functions and you can read more about it <a href="http://en.wikipedia.org/wiki/Secure_Hash_Algorithm"><strong>here</strong></a></li></ul><p>SQL Server passwords are hashed with an addition of a binary string called <strong>Header</strong> and another random string that is called <strong>Salt </strong>and<strong> </strong>it is used just like salt in order to cover the password and hide it.</p><p>The hashing is performed using a function called <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/hashbytes-transact-sql?view=sql-server-2017"><strong>HASHBYTES</strong></a> which accepts two parameters, the first one is the desired hashing algorithm and the second is the text to hash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*HFzTlPZIi2dEgkF1pLQvyQ.png" /><figcaption>HASHBYTES Function description from MSDN site</figcaption></figure><p>I did a test by hashing the string 123456 and received the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*122dB41Ro06MTkEEN8WeSw.png" /></figure><p>But what if I will create a login with the same value as the password, will the server generate a hash that matches one of the values from my test?</p><p>Let’s find out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mxrHkR8VUD2RJ0Mi-z2HFg.png" /></figure><p>I created a login and pulled the generated password hash from the logins table, and I’ve failed.</p><p>the encrypted string didn’t even match the results I had from encrypting the same password in any existing algorithm.</p><p>but why?</p><p>Well, the answer is written above, the hashed string stored in the system table contains the <strong>Header </strong>and the <strong>Salt</strong> in addition to the original password</p><p>When they’re hashed together it looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8D1myVUed9A9aGNstrL6uQ.jpeg" /><figcaption>The SQL Server Password Hashing function</figcaption></figure><p>In order to emphasize the common denominator and the way to decipher the <strong>Header</strong> and the <strong>Salt</strong>, I will create a few more logins and retrieve the passwords</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*XI6TObZi6crkBsv9EP7WUw.png" /></figure><p>So it turns out that there is a common denominator, that’s the <strong>Header</strong> I‘ve found before and his value indicates the SQL Server<strong> </strong>version.</p><p>Now let’s try to hash the same value with the <strong>Header </strong>appended to the start</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*m9a3whSGgQTJSOqGNIC-YA.png" /></figure><p>With the <strong>Header,</strong> the hashed values begin to resemble the values generated by the server after saving the password</p><p>But they are still different because the <strong>Salt</strong> is missing</p><p>I’ve since improved my test by generating a file with 2 million passwords and is available for download <a href="http://dazzlepod.com/site_media/txt/passwords.txt"><strong>here</strong></a></p><p>The next step was to write a script that encrypts those passwords accordingly, separate the passwords from the <strong>Salt</strong>, and then compares them with the hashed values from the server logins table.</p><p>and guess what — <strong>it worked!</strong></p><p>I’ve discovered that passwords like <strong>LetMeIn, 123456, trustno1, 1qaz2wsx and pa$$word</strong> was common in our secured servers. the next step was to send a lot of emails and make sure that all those passwords will be updated to something a bit more secure ASAP.</p><p>do you think your server’s security is better?</p><p>now you can actually find out.</p><p>The script can be found here:<strong> </strong><a href="https://github.com/Shimongb/Find-weak-passwords-script/blob/master/script.sql"><strong>Find weak passwords script</strong></a></p><p><strong>Pro tip:</strong> importing the password list into a predefined table will<strong> </strong>make the process<strong> </strong>run<strong> much faster</strong></p><h4>What exactly does the script do?</h4><ul><li>Collect all passwords from the system table</li><li>Hashes all the passwords from the password table according to all the existing algorithms (or those defined in the “alg” table variable) and the <strong>Salt</strong> that is decoded from the string</li><li>Execute a small <a href="http://en.wikipedia.org/wiki/Dictionary_attack"><strong>dictionary attack</strong></a> and output the results</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXNBccTcctLjvXFtRA3fug.jpeg" /><figcaption>The results :)</figcaption></figure><p><strong>Stuff you should know</strong></p><p>Executing the script took me less than a minute with simple hardware and was tested on all the <strong>Microsoft SQL Server versions from 2008 and above</strong></p><p>It should be noted that running time is dependent on the number of algorithms tested,</p><p>therefore <strong>more algorithms = more running time!</strong></p><p>I have tested the <strong>SHA-2 256 &amp; 512</strong> algorithms only since they are the only ones that are considered safe to use today (MD2 was created in 1989 and considered deprecated)</p><h4>Summary</h4><p>Although there is an enforcement policy on passwords, there are millions of common passwords collected every year from sites and leaked databases. and of course, the human factor that makes <strong>people choose LetMeIn or 123456 as a legitimate password.</strong></p><p>But luckily we can monitor this by maintaining an updated list of bad passwords and comparing it against the logins table every once in a while.</p><p>The script can be used to deploy a <a href="https://www.owasp.org/index.php/Brute_force_attack"><strong>Brute Force</strong></a> attacks on the server and reveal passwords</p><blockquote><em>The idea is to have a random string that is easy to remember.</em></blockquote><blockquote><em>Unfortunately if it’s easy to remember, it’s something nonrandom like ‘Susan’.</em></blockquote><blockquote><em>And if it’s random, like ‘r7U2*Qnp’, then it’s not easy to remember.</em></blockquote><blockquote><em>— </em><strong>Bruce Schneier</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da8ba79dcb76" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>