Saturday 7 July 2007

SourceSafe Password Decryption Part 2

In my previous article I managed to demonstrate that the password in SourceSafe could be broken if the code for the actual password portion could be obtained.
This is easy if the length of the password is known, but of course this will not be the case most of the time.

In order to break the password, we need to ascertain the length of the password portion. I will again consider my admin password 'ADAD', which has been coded (in full) to 0x6DAF (28079).
I don't know the length of this password though, I just have the full code 28079.

If I subtract all possible filler codes from this password, I get the following list of values:

Pot LenFillerRemain
028304-255
12801267
227657422
3270741005
4259592120
5249973082
6234934586
7215396540
8198268253
91752110558
101556112518
111278315296
12977318306
13638821691
14318024899
15028079


Assuming that I don't know that 2120 is the correct code, I need a way of working out which remaining codes are valid. Obviously, 0 isn't valid (-255), so we know this is not a blank password.

The answer, as it turns out, is quite straight forward. Basically, if you consider all the characters between 0-9 and A-Z (remember all passwords are converted to upper case), and how they are coded (XOR 0x96), then the lowest possible password code is 160 (0xA0), for '6', and the highest is 223 (0xDF) for 'I'.
Now if, at each potential length, we work out the values of the equivalent lengths of '6's and 'I's, as so:

Pot LenMin (6)Max (I)
000
1160223
2480669
39601338
416002230
524003345
633604683
744806244
857608028
9720010035
10880012265
111056014718
121248017394
131456020293
141680023415
151920026760


It becomes clear that for the remaining code to be valid for a length 4 password, it has to fall between the range 1600 ('6666') and 2230 ('IIII').

If you consider our remaining codes from our coded password (28079), I have listed the codes that appear to fall within the valid ranges:

Pot LenFillerRemainValid?
028304-255No
12801267No
227657422No
3270741005Yes
4259592120Yes
5249973082Yes
6234934586Yes
7215396540No
8198268253No
91752110558No
101556112518No
111278315296No
12977318306No
13638821691No
14318024899No
15028079No


Based on the above list, we could actually have a valid password consisting of 3, 4, 5 and 6 characters for the code 28079.

From my example in my part one of this post, we know that a 4 character password could be 'KNSB'. There are many other 4 character passwords that would generate a code of 28079.

Based upon the above list though, I want to see if I can also generate 3, 5 and 6 character passwords.

Working with a 3 character password which has a target code of 1005, if I use the lowest possible password, '666', I get a value of 960, thus:

PosChar CodeCode ValueTotal
154 (0x36) '6'160 * 1160
254 (0x36) '6'160 * 2 = 320480 (160 + 320)
354 (0x36) '6'160 * 3 = 480960 (480 + 480)


This is exactly 45 less than our intended target code, 1005.
If I add a value of 1 to the character at position 1, this will increase the code by 1.
Adding a value of 1 to character position 2 will increase the code by 2, and so on.

So to make an additional 45, without causing any of the codes to pass above the maximum ('I', 223), the simplest solution is to add 15 to the coded value of position 3, so change the code value 160 to 175 (which is the coded value of '9'):

PosChar CodeCode ValueTotal
154 (0x36) '6'160 * 1160
254 (0x36) '6'160 * 2 = 320480 (160 + 320)
357 (0x39) '9'175 * 3 = 5251005 (480 + 525)


So this means a potential 3 character password could be '669'.

Taking this idea and applying it to the 5 and 6 character codes, we get the potential passwords '76PII' and '6XIIII' respectively.

I tried all of these in SourceSafe and was immensely pleased to discover that they all worked.

This article has demonstrated that it is possible to break SourceSafe passwords, and using the above method I could gain access to a SourceSafe repository using any user account... providing I know the password code.
Of course, as I am unlikely to have the code (without using a debugger), I am going to try and find a way to get the codes directly from SourceSafe in my next article...

No comments: