views:

233

answers:

3

I use DropBox and I've had some trouble reaching to my files from other computers: I not always want to login to anything when I'm in a public computer, but I like being able to reach my stuff from wherever I am.

So I've made a simple application that when put in the public folder, ran and given the right UID, creates (still in your public folder) an HTML of all the content in the folder (including subfolders) as a tree of links.

But I didn't risk loading it anywhere, since there are slightly private things in there (yes, I know that the folder's name is "PUBLIC").

So I've came up with the idea to make it a simple login page, given the right password, the rest of the page should load. brilliant!, but how?

If I did this by redirecting to other HTML on the same folder, I'd still put the html link in the web history and the "url's accessed" history of the administrator. So I should generate itin the same page.

I've done it:
alt text
And currently the page is a textbox and a button, and only if you type in the right password (defined in the generator) the rest of the page (with the link-tree) loads. The fault is that everything (password, URL's) is easily reachable through the sourcecode.

Now, assuming I only want to avoid silly people to get it all too easily, not make a bulletproof all-content-holding NSA certified website, I though about some ways to make these informations a bit harder to get.

As you may have already figured, I use a streamwritter to write a .HTM file (head, loop through links, bottom), then it's extremely configurable, and I can come up with a pretty messy-but-working c# code, though my javascript knowledge is not that good.

Public links in DropBox look like this:
http://dl.dropbox.com/u/3045472/img.png

Summarizing: How do I hide the URL's ande the password to show them (MAINLY the password, of course) in my source-code so that no that it should require some effort on reading ?

PS.: It's not that personal, if someone REALLY wants it, it could never be 100% protected, and if it was that important, I wouldnt put it in the public folder, also, if the dude really wants to get it that hard, he should deserve it.
PS2.: "Use the ultra-3000'tron obfuscator!!11" is not a real answer, since my javascript is GENERATED by my c# program.
PS3.: I don't want other solutions as "use a serverside application and host it somewhere to redirect and bla bla" or "compress the links in a .RAR file and put a password in it" since I'm doing this ALSO to learn, and I want the thrill of it =)

--[EDIT 1]--
The one answer so far gives a perfect way (according to this question) to hide my password.
Now I want a good way to hide the URL's, maby a code snippet of the example URL I gave being composed, and if it's too tricky, maby how to generate it in C#, or anything ?

--[EDIT 2]--
I thought about maybe making three "obfuscating methods" and choosing them randomly in the runtime. So anyone who figures out how to read one XML, could only read about one third of them, and maybe having a hard time finding the other rest of this third..

--[EDIT 3]--
Just thought about REGEX, the URL could be neatly crowded by dummy not-url-allowed characters added randomly that would be removed by something like:

regex.replace(url, ^[^\w\d/:-\.%]+$,"")

So the nosy dude should have to be pretty advanced into programming somehow, eh? could anyone tell me if it would work or not ?

+4  A: 

Well, as it seems you already know, this is a rather poor choice of security mechanism, but if you insist...

Don't store the actual string in the source. Store, for example, its MD5 hash. Then, when the user types in a password, compute its MD5 hash and compare it with the expected one.

Check out:

miorel
WHOA! that's what I'm talking about! thank you so much.. still waiting for just-as-good answers! I may apply more than one solution =)
MarceloRamires
I think I'm covered about hiding the password. Now what about hiding the URL's ?
MarceloRamires
No problem :) It's not my idea though, lots of systems store password hashes rather than passwords themselves.For the URLs you'll have to use a reversible encryption mechanism. Look at http://en.wikipedia.org/wiki/ROT13, maybe it will inspire you to make something better.
miorel
Also, note that a "smart" attacker won't try to guess the password from the hash. That would take too long. You're much more likely to have people trying to extract the URL using your own code.
miorel
Yes, but I didn't think about using hashes before, and if the password was reversible somehow, putting 100% effort on extracting it would result in a beautiful fully funtional colored and organised link-tree with all my stuff.. haha. Read [edit 2], it has a new idea..
MarceloRamires
+1  A: 

Granted, this is akin to asking how you can strip in public without people seeing you, but given that, I'm assuming that the password you are trying to store is the one to DropBox. I suppose you could obfuscate the password and store it in a cookie. That would at least prevent someone from simply viewing the source to see the password, but obviously wouldn't stop someone running something like Fiddler and seeing it.

[snipped server side suggestion]

EDIT: To munge the Urls, why don't you simply build the urls on the fly and have the links call a javascript function to get the url? Your server-side code would populate an array in this function with obfuscated urls and the calling code would simply pass an index into the array. Thus, on viewing the source, there would be no instances of "http" anywhere other than static unsecure links.

ADDITION Ok. now that I have a better bead on the problem, it is easier to devise solution. There are libraries for doing encryption on the net in javascript (e.g. http://point-at-infinity.org/jsaes/) but the problem comes down to key management. Since its javascript, it is going to be public but there are hoops you can devise to make it harder to determine the key. In general, those tricks involve indirection. For example, store a lengthy stream of random characters (e.g. 40-50 or more) that is generated by your C# code and stored in the HTM file. In addition, the C# code would would store into your javascript function an array numeric values that represent pointers into the long stream of text that were used by the C# code to encrypt the passwords (or just the whole url).

Thomas
You got it wrong.. it's the password to seeing the other links of the HTML itself! read the 6th paragraph again! and about using server-side stuff, read PS3, I want to learn obfuscation, and also not rely on hosts and having to change the links in there everytime.. thank you!
MarceloRamires
But you are already using a server-side solution in C#. It seems silly to stop half way especially when the tool you want to use wasn't designed for this. With respect the Urls, another solution for obfuscating them is to make the links call a javascript function which queries an array of obfuscated links. TBH, I'm not sure I understand what you are trying to say in paragraph 6. Could you amend your post to show a munged sample of what the links look like?
Thomas
It's an EXE that I run sometimes in the public folder to refresh the .HTM that is also in the public folder. there is no server-side application, there is no ASPX, there is no host. It's a winforms applicaton that generates an HTML with links. Thanks for the array of obfuscated links! that is neat! I'll edit the 6th paragraph NOW
MarceloRamires
+1  A: 

To elaborate on miorel's idea, you can also encrypt the whole page, using password as a key. Basically, encode all content into one big string, ask for the password and decrypt that string. If the password is wrong, it will show loads of rubbish, that is it. Like

 content = "encrypted string"

 function decrypt(str, key) { your algorithm of choice here }

 document.write(decrypt(content, prompt('Password?')))

The only thing you need is a decrypt implementation in javascript - but that's easy to google out, for example here or here.

This also renders the separate 'login' page useless.

stereofrog
It's not a separate page (read 5th paragraph), The textbox + button appear at first, and if the password is right, both vanish and the page ends rendering, pretty neat =)
MarceloRamires
By the way.. encrypting the content.. that's extremely evil! I'll CERTAINLY do that! but the function is there.. and someone who had 3 months webdesign study at school could forget the password, get the function (obfuscated or not.. doesn't matter) and run it in a new HTML.. but we're on the right track!
MarceloRamires
First point: what happens if an attacker disables javascript and just loads the whole page? Second: the decrypting function itself is useless for the attacker if he doesn't know the password.
stereofrog
@stereofrog the html inputs appear, and the button doesn't do a thing, since the tree is printed by the javascript ;)
MarceloRamires
The attacker doesn't need the "tree". He wants your links and they are just lying around in the code, right?
stereofrog
That's why I said that I want to hide the URL's too, rather than just the password.. Password = hash, content = encrypted obfuscated code ? still deciding..
MarceloRamires