Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Can't do Timed 2 (Python)


Serosin's Avatar
Member
0 0

I finished Timed 8 no problem, and as far as I can tell, the only difference between 8 and 2 is that in Timed 2 you have to submit two pieces of information, technically, and to index.php?check instead of just index.php.

Otherwise I see no difference in how to submit the answer between these two challenges. I'm confident my Python script up to the submission is correct. Can I PM someone? Or would posting parts of the Python script here not be too much of a spoiler?


_spartax_'s Avatar
Member
0 0

you may try using mechanize library


Huitzilopochtli's Avatar
....
10 9

You can just post the code if you want, rather than being a spoiler it's more likely it'll help anyone else who has the same issue in the future.


Serosin's Avatar
Member
0 0

Mechanize looks cool, but I'll need to learn it. Hopefully it won't take me as long to finish this challenge as I'd need to learn a module :D

Mmmm yeah could help other people.

[php]

import urllib import urllib2 import re

user_agent = 'Mozilla/5.0' cookie = "fusion_visited=TRUE; fusion_user=fusion user number; PHPSESSID=php session id number;"

starturl = "http://www.hellboundhackers.org/challenges/timed/timed2/index.php" endurl = "http://www.hellboundhackers.org/challenges/timed/timed2/index.php?check" headers={'User-Agent' : user_agent , 'Cookie' : cookie}

req = urllib2.Request(starturl,headers={'User-Agent' : user_agent , 'Cookie' : cookie}) response = urllib2.urlopen(req) results = response.read()

startpoint = re.finditer('your string is: ', results)

for i in startpoint: end = i.end()

## RECORD RANDOM STRING
randomstring = None
number = None
for index in results[end:]:
    if re.match("[a-zA-Z0-9]", index):
        if randomstring == None:
            randomstring = index
        else:
            randomstring = randomstring + index
        if re.match("[0-9]", index):
            if number == None:
                number = index
                int(number)
            else:
                number = int(number) + int(index)
        else:
            continue
    else:
        totalsum = number
        break

print print "randomstring is:" print randomstring print print "totalsum is:" print totalsum print

values={'submit':'Check', 'ans':str(totalsum)} data = urllib.urlencode(values)

print "data is:" print data print

req = urllib2.Request(endurl, data, headers)

req = urllib2.Request(endurl, data, headers={'User-Agent' : user_agent , 'Cookie' : cookie}) print req.get_method()

urllib2.urlopen(req) [/php]

It's longer than it needs to be in some places because I kept using print statements and trying different things to figure out what's wrong. Dunno where to go from here. Any help would be great!


rex_mundi's Avatar
☆ Lucifer ☆
3,050 6

I changed those code tags to php ones, they're not ideal but it'll display it better that the code tags do. thumbs up


Serosin's Avatar
Member
0 0

Great! yeah the code was kinda… small in the preview, but I wasn't aware of the php option. Thanks!


rex_mundi's Avatar
☆ Lucifer ☆
3,050 6

I'm at work so I can only run it on my android, but everything looks ok right up to the part where it posts.

I can't tell on here, but check your data, is it posting the submit and ans= along with the totalsum ?


Serosin's Avatar
Member
0 0

Yes. In the code it sets ans to the value of totalsum, converted to a string. I've gotten rid of most of the print statements and kept one that reported data, and data is being sent with ans set to totalsum when the script runs, too. (Ex. data = "ans=83&submit=Check" ) Still isn't accepted, though. Status of the response is 200, also.


Huitzilopochtli's Avatar
....
10 9

You should use "requests" for Python as it's awesome for working with sessions, and it's probably an issue with cookies on the final POST that's causing the problem.


Serosin's Avatar
Member
0 0

Ok I got it. It worked.

I copied the lines concerning values, encoding, and POST submission from the script I used for Timed 3. I also changed the endurl to use https instead of http. Whatever.

Anyway, thanks for the help everyone.

:Dthumbs up