1

I'm asked to create 'worm' as for my homework assignment. I got everything working by using SID but when I try to copy SID by using Regex I get NULL result and can't figure out why. This code does copy itself to new thread but can't find the SID for some reason.

In first screenshot we can see the code I have that create a new post and additional code that copies entire code. The selected (orange part is what I'm having problem with) is what I don't understand why it wouldn't work. As I am using HTML encoding I cannot use plus signs this is why I am trying to use concat function. Also, the Regex expression I'm using have worked correctly as far I did some testing.

enter image description here

In this screen shot we can see that the result where I perform Regex returns NULL.

enter image description here

Any ideas?

Small note, this is my homework assignment and we are exploiting specially modified phpBB forums which allows code injection (JavaScript).

Not sure if this is the right SO section to post, please say so if I should move.

1 Answer 1

1

match returns an array of matches. xx[0] will have the full match, but if you want just the SID then you should do

/sid=([^;]+)/

and .concat(xx[1]).

3
  • Ok, while trying your solution I notices it should be .concat(xx[0]). Perfect! The only problem I'm having now is that code isn't copying plus sign within the Regex expression. Thank you very much!
    – HelpNeeder
    Oct 24, 2013 at 6:37
  • No problem. Hm, that's indeed vexing. What I'd do is, first of all, use the alternative regex construction method: var re = new RegExp(regexStr);, because that way you can supply a regex in the form of a string. Why is this useful? Because you can do this: var regexStr = 'sid=[^;]'.concat(String.fromCharCode(43));. (43 is the ASCII code for the plus sign.) Once you have your RegExp object, re, you call it like this: var xx = re.exec(document.cookie);. I haven't tested any of this, but it's just to give you an idea :-) Oct 24, 2013 at 6:51
  • Worked as a charm! Thank you again!
    – HelpNeeder
    Oct 24, 2013 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.