![]() |
|
[C#] How to secure a login request from program? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] How to secure a login request from program? (/showthread.php?tid=4703729) |
How to secure a login request from program? - Natsumi - Feb 25, 2015 Hi all! This question somewhat ties in with PHP, but I still will need to know what I can do in the C# side of things. If anyone could provide suggestions as to what I can implement to increase the security of my program (or at least, the login / register side of it), that would be really kind of you! Thank you, all! I help build a program. This program requires a user to register and be approved by an administrator to be able to use it. The program shows a screen where a user has to enter a username and password. This is the Login / Register screen, as a user can either login or register from here. This is where my problem stems. When the "Submit" button is clicked, the username and password, as well as the user's computer name and HWID are sent to a PHP file, then it would return a string saying whether the user was approved or not. If the string said "APPROVED" the program would allow the user in. Otherwise, anything else would result in an error and would either prompt the user to try logging in again (incorrect password) or close the program (network errors, etc). Before, this was highly insecure because the PHP file I was using was designed to receive a GET request. Someone sniffed the packets being sent, and was able to see that the the URL was simply: Code http://mydomain.com/login.php?u=username&p=MD5(password)&h=hwid&c=computernameImage here, column names from left to right are: uid, username, password, computername, HWID, isAllowed. Obviously, I have revamped the security so it is not as easily compromised. My new system uses POST requests instead of GET (which makes it unable to send a request using a url and the ?value= appended), as well as a few other improvements: Once a user fills out a field and clicks Submit, a NameValueCollection is created and keys and values are assigned. The keys are named in a way so that it is not easy to identify what they represent (example: instead of having a key for the username being "u", it is "gun" which stands for "given user name"). The values assigned are all encrypted using Rijndael each with a different key and IV every time (which are also sent with the request, encoded in Base 64, so that the PHP file can decrypt all the other values). Besides the encrypted username, password, HWID, computer name, IV and key being sent, it sends another value in the request: the encrypted SHA512 hash of the current date and hour (formatted with symbols like { } and ||; example: { 2 | 25 | 15 } || { 12 }) of my server's timezone. The PHP file will generate this string and hash it as well, and check it against the sent value (when it has been decrypted). If the PHP file finds that they are not the same, it will immediately echo an error stating something along the lines of "INVALID REQUEST RECEIVED" and exit, ceasing any further execution of the script. If the date and time hashes match, the PHP file will decrypt the four values (username, password, computer name, and HWID) using the key and IV sent along with it, and do some basic login / register checks: PHP Code I think this is sufficient protection, but do you guys think I am missing anything or I should implement something else? Thank you all for reading! I appreciate it! c: * - Only3 - Feb 25, 2015 this belong to the php section anyway its look k the only thing u should change is using pdo * - dex73r - Feb 25, 2015 Nicely written, i will rewrite my authentification system just because of that. Thanks for wasting your time for us. * - hellomen - Feb 25, 2015 (Feb 25, 2015 10:27 AM)Only3 Wrote: this belong to the php section anyway its look k the only thing u should change is using pdo He's using mysqli which is fine. PDO is in my opinion easier to understand and use prepared statements with... Share the generateSalt method I think it's a bad salting we got here. As for hashing use bcrypt. * - Natsumi - Feb 25, 2015 The generate salt is just a random 10 chars. PHP Code * - Hiiro - Feb 25, 2015 (Feb 25, 2015 10:20 AM)Natsumi Wrote: Obviously, I have revamped the security so it is not as easily compromised.POST requests are just as easily sent as a GET request is easy. * - 0xDEAD10CC - Feb 25, 2015 This is still not secure. One can easily emulate the request and see what is sent and retrieved with a tool like wireshark. And because you've hardcoded that URL string into the program, it would be even easier to modify that with a hex editor. It's not like the expected value for when the user is authenticated is hidden either as you'll have to compare the received value with something defined by the program too lol... So unless you've got strong obfuscation on this, the user would probably even more easily be able to open that up in a .NET decompiler program to see what is going on. For those who know how to use a program like WinDbg, and the SOS extension, this process is even easier. It's funny what people think is "secure" on this forum lol. * - hellomen - Feb 26, 2015 (Feb 25, 2015 04:33 PM)Natsumi Wrote: The generate salt is just a random 10 chars. try to use this instead for salting: mcrypt_create_iv() PHP Documentation Would save you time and you're sure that it's randomized :-) as for your hashing. Use bcrypt. would help a lot more then using sha512 :-) Watch this: Password Storage (and hacking) in PHP [Anthony Ferrara] - the salting used here is currently changed with /dev/urandom aka mcrypt_urandom And this: Password Hashing in PHP [Anthony Ferrara] enjoy the videos * - Zettabit - Feb 26, 2015 You could always create a session ID type authentication. If the login credentials are correct, hash them in some format and return that value as a session ID. Have your application verify the session ID to make sure that the hash is the same with the values the application provides, and keep doing this in the background every so often. |