hi everybody, i used to lurk here but this contest caused me to sign up. used to be a 4096 byte democoder, but quit the scene and moved on to tinkering with javascript.
size-optimizing is still in my blood, and this contest combines the best of both worlds ;-)
here's my first entry. it's 195 bytes (i added the linebreak for legibility, it will of course not appear in the actual payload).
<i><img src="/" onerror=alert('xss');(f=(this.nextSibling)).firstChild.value='<i>'+this.parentNode.innerHTML+'</i>';f.submit()">
<form method=post action=post.php><input name=content></form></i>
tricks used:
- fit the code in an event handler so you can refer to the element as
this, giving you a sort of "anchor" inside a largely-unknown DOM-tree.
- grab the code via innerHTML of the parentNode
- a few tricks with parentheses and functional programming style javascript in order to shave off a few more bytes
not entirely sure if it's a legal entry because:
- i only tested it in opera and firefox so i hope it works in IE7 :)
- rsnake said "no knowledge of the DOM except for classes and ids", so
technically me using nextSibling and firstChild are illegal, but i believe it to be still within the spirit of the rules, because i put the elements there myself via the injection and work relative from there (if not, my apologies)
since entries are open and there are no prizes, somebody is probably gonna beat me before the end of the week, so i give you some ideas how to shave off a few more bytes:
- a shorter way to have an event handler executed immediately than the
IMG/onerror technique i used here
- at first i had an entry of 176 bytes using outerHTML, which is supported in Opera and IE, but not in Firefox.
- can one leave out the space between the src and onerror attribute of the
IMG tag?
- you could leave out the double quotes around the
/ in the
IMG src attribute, but in FF, the quotes are added again in the innerHTML. so this would shave off 2 bytes, but only once. i guess that would be illegal for the contest.
- possibly some more clever javascript/functional tricks to make the code itself even shorter
Edited 1 time(s). Last edit at 01/04/2008 02:40PM by ritz.