r/dailyprogrammer • u/nottoobadguy • Feb 13 '12
[2/12/2012] Challenge #5 [easy]
Your challenge for today is to create a program which is password protected, and wont open unless the correct user and password is given.
For extra credit, have the user and password in a seperate .txt file.
for even more extra credit, break into your own program :)
21
Upvotes
16
u/leegao Feb 13 '12
C - login code
https://gist.github.com/1819034
To break in, we note the following disassembly of the generated binary (gcc 4.1.2 target: x86_64 redhat)
where -0xc(%rbp) dereferences to auth and -0x40 dereferences to user. This gives us an offset of 0x34 between the two elements on the stack, with user at a lower address than auth, so one way we can break in is by stack smashing our way in.
4
u/Kealper Feb 13 '12 edited Feb 13 '12
AutoIt
Program stores accounts in accounts.ini in the same directory as the program, it allows the user to change their password on successful login, supports multiple users (no way to create new accounts though) and uses SHA1 hashed passwords in the config file. This is more than just a few lines but oh well, if it's worth doing, it's worth overdoing. :P
Default username/password: root/toor
Lots of comments in the code to explain what goes on, etc.
inside the file accounts.ini:
These easy challenges are pretty fun, and are great to kill a few minutes of time, keep up the awesome work!
EDIT: Oh yeah, forgot to say how to crack it... open accounts.ini and SHA1 hash the string "ROOT-" and the new password, and then paste that in to the Password field of accounts.ini. Try logging in with the new password you set it to and it should work!
3
u/[deleted] Feb 13 '12
Python, with user and pass in separate .txt files. Constructive criticism much appreciated.
http://codepad.org/ZhutPu16
4
u/robin-gvx 0 2 Feb 13 '12
Déjà Vu: (I made it as minimalist as possible, using zero variables)
To break in, we note the following disassembly of the generated bytecode
where we can see that the strings "bill" and "admin" in the -- nevermind. It's a joke.
2
u/Koldof 0 0 Feb 13 '12 edited Feb 13 '12
C++. Just got extra credit. There is lots of bloated code, just to get that apature feel.
Example "info.txt":
Example output:
Welcome to Apature Science Labs.
Username: GLaDos
Password: beiber4life
Hello, GLaDos
Your last order was to: "commence world destruction"
World destruction imminent.
2
u/Zardoz84 Feb 13 '12 edited Feb 13 '12
D:
Where password.conf looks like :
.
2
u/m_geist Feb 13 '12
Python 2.7: http://pastebin.com/Y4Ga4Se9 Pastebin if someone prefers to look at it that way
I think later today, I'll try my hand at some encryption. I think I go a bit overboard with declaring variables, but not all paths potentially return a value for the variable, so it's the easiest way to keep it from kicking an error.
2
u/namekuseijin Feb 13 '12
; in R5RS scheme. ; read-line is not in R5RS, but all implementations do provide something like it, perhaps get-line. If not, implementing is trivial from get-char
1
u/CachooCoo Feb 13 '12
C++ something like this?
1
u/[deleted] Feb 13 '12 edited Feb 13 '12
Python 2.5 with extra credit (and strengthening against the double extra credit).
The password is stored as a sha512 hash (the line in the file is username$hashalgorithm$passwordhash), which is a start on encryption; I should have added some sort of salt to it to prevent easy hacks with rainbow tables.
Edit: updated to use getpass module; still no salt because I'm lazy.
1
u/matthewhughes Feb 13 '12
Ruby - A bit crap, to be honest.
1
u/TheOnlyBoss Feb 13 '12
My C++ answer
http://pastebin.com/RSRQJ689
The user name and password is stored into a text file that looks sort of like this:
username
password
1
u/matthewhughes Feb 13 '12
Doesn't work. Comes up with this error message: "Error CS5001: Program
dailyprogramming5easy.exe' does not contain a staticMain' method suitable for an entry point (CS5001) (dailyprogramming5easy)"Anyone got an idea why it isn't playing nice?
1
u/drb226 0 0 Feb 13 '12
37 lines of Haskell: http://hpaste.org/63638
I had a hard time getting the password input to be hidden, and then afterwards, someone pointed me to System.IO.hSetEcho, which makes it trivial...
1
u/ArriMurri Feb 14 '12
My first stab at Factor:
1
u/HazzyPls 0 0 Feb 14 '12
Spent most of my time trying to get
crypt()to work. x.x I think I could clean this up, but it works. Run it like so:./a username passwordNo idea how to try and break into this. None at all.
login.txt:
Foo 2ZeC22SSjvU6rsKCmFQcN
1
u/mymainmanbrown Feb 22 '12
python, no extra credit
1
u/savagecub Apr 10 '12
C++ using a do while to keep asking unless the correct combo is given
// password gen.cpp : main project file.
include "stdafx.h"
include <iostream>
include <string>
include <cctype>
include <fstream>
using namespace std;
int main() { string UN; string U = "promethius"; string PW; string P = "reddit";
}
1
u/Should_I_say_this Jun 17 '12
I'm way late to the party, but I'm new to programming and wanted to paste my code here. Using Python 3.2 but I didn't do any encryption or use the getpass module because I'm still learning...(PS mine is very similiar to m_geist code because I essentially used his to learn how to program mine...However I had some errors with his so mine is a bit different. I.e. an error in his would occur if someone typed part of the username and thus it would show up as True that the partial username was in the file...So I used an equals operator instead...minor tweaks all around. I like my code better cause it stops you if your username does not exist in the system :).
1
u/Jatak 0 0 Jun 20 '12
In Python 3.2.3
Two files store all usernames and passwords. "users.txt" stores every usernames like so:
"passwords.txt" stores all usernames and their respective password separated by a space, like so:
I realised after writing this that the "users.txt" file isn't really needed, but I was too lazy to change it :)
1
u/mordisko Aug 09 '12
Python 3.2, extra credit with hashing and able to create new users. http://pastebin.com/qdeX1ttB
1
u/ragtag_creature Jul 09 '22
R - found a way to match info to that stored in a .txt file!
1
u/nikoma Feb 13 '12
python 3.2 code: