As a sysadmin I come into contact with a lot of email systems. Being a curious person I tend to want to know how the systems work under the hood. Some times the password limitations of the system give a way clues about the password system. Other times looking at the actual password store reveals much. In two of the email systems I have managed there were glaring issues with the password management. I’m not going to name these email systems outright, but you may be able to figure out what they are from the clues provided.
The first mail system I will refer to as Mail1. One of the things that made me raise an eyebrow was the password policy for the system. When updating a password on Mail1 I was presented with the following error message.
This is a dead giveaway that the system isn’t hashing passwords. We can probably tell that the passwords will be encrypted, encoded, or stored in plain text on disk. I took a look at the password store and found passwords were stored in a format like this.
This tells me that the passwords are encoded in Base64 format. I decided that the next thing to do would be to set try setting the passwords to something I knew so that I could try some analysis on the stored values. I set the passwords for the users to these plaintext values.
Here are those values from the account store.
The fact that the stored versions of the passwords for user1 and user2 were so similar confirmed to me that the passwords were not being encrypted. If these were encrypted I would have expected a huge difference in the values of user1 and user2. Since they are almost identical except for the last character I went with the assumption that these passwords were put through a static process before being stored on disk. My next step was to remove the base64 encoding on the passwords and see if they would decode directly to ASCII values. Unfortunately they did not and the output was unreadable, so I converted the base64 values to hex values using the following command.
This gave the following outputs.
I then converted my plain text passwords to hex values so that I could compare the two.
And the outputs.
While comparing the hex strings to each other I noticed that some constant was probably being applied to each password before being stored. I started with the assumption that the encoded password was being stored in 8-bit ASCII and the constant was the same format. My next step would be to see if I could find what the constant is, so subtracting the first byte of the plain text password from the encoded password should give me the first byte of the constant. I should be able to get the second byte of the constant by subtracting the second byte of the plain text password from the encoded password, and so on.
Here is the math from the first password.
This was looking very promising, so I applied the same process for the longest password that was allowed by the system in order to get the entire constant.
And just like that we have our constant “The setup proce”. From there I wrote a python function to automate the process. This function is Python 3 compliant. If you are having issues with it in Python 2, try stripping off the .decode('ascii')
functions.
Part two of this post will be coming out soon which will describe the password decoding process for the second mail system.