[solved] Logging into HTS with python

Bad threads go here

Re: [solved] Logging into HTS with python

Post by HoleSystem on Fri Nov 20, 2009 10:14 am
([msg=30595]see Re: [solved] Logging into HTS with python[/msg])

I prefer this login better:
Code: Select all
import re
import sys
import md5
import time
import random
import urllib
import urllib2
import getpass
import cookielib

if len(sys.argv) != 3:
        print "usage", sys.argv[0], "<username> <password>"
        print
        sys.stdout.write("enter username: ")
        username = sys.stdin.readline().strip()
        if len(username) == 0:
            sys.exit(0)

        password = getpass.getpass("enter password: ")
        if len(password) == 0:
            sys.exit(0)

else:
        username = sys.argv[1]
        password = sys.argv[2]

cookieJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
opener.addheaders = [('User-agent', "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5")]

url = "http://www.google.com"

request = urllib2.Request(url)
page = opener.open(request)
contents = page.read()
HoleSystem
New User
New User
 
Posts: 7
Joined: Fri Apr 18, 2008 5:16 am
Blog: View Blog (0)


Re: [solved] Logging into HTS with python

Post by predator78 on Sat Nov 28, 2009 5:57 pm
([msg=30839]see Re: [solved] Logging into HTS with python[/msg])

Hey, I was having some trouble doing this with just urllib and urllib2.
I had to do it this way cause I couldn't download httplib2 or pycurl for version 2.6 on windows.
Anyway here is the code if anyone runs into the same problem I did.
I used cookie lib to handle the cookies to. :D
Code: Select all
import urllib, urllib2, cookielib

host = 'www.hackthissite.org'
user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0)'
referer = 'http://www.hackthissite.org/user/login'
content_type = 'application/x-www-form-urlencoded'
accept_encoding = 'gzip,deflate'

body = {'username': 'username', 'password': 'password'}


values = {'Host': 'www.hackthissite.org',
          'User-Agent':'Mozilla/4.0 (compatible; MSIE 8.0)',
          'Referer':'http://www.hackthissite.org/user/login',
          'Content-Type':'application/x-www-form-urlencoded',
          'Accept-Encoding':'gzip,deflate',
          }

#build cookie handler
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

#encode request information
data = urllib.urlencode(body)

#send login information
req = urllib2.Request(referer, data, values)
page = urllib2.urlopen(req)


#start opening pages
url = "http://www.hackthissite.org/missions/prog/1/"


page2 = urllib2.urlopen(url)

print page.info()
print "------------------"
print page2.read()
predator78
New User
New User
 
Posts: 2
Joined: Sat Sep 27, 2008 5:54 pm
Blog: View Blog (0)


Re: [solved] Logging into HTS with python

Post by moejo on Sat Feb 27, 2010 12:56 am
([msg=35846]see Re: [solved] Logging into HTS with python[/msg])

thanks predator for the help!
I had trouble installing Pycurl so I did it your way, and works. :D
moejo
New User
New User
 
Posts: 3
Joined: Sat Feb 27, 2010 12:53 am
Blog: View Blog (0)


Re: [solved] Logging into HTS with python

Post by sanddbox on Sat Feb 27, 2010 12:58 am
([msg=35847]see Re: [solved] Logging into HTS with python[/msg])

moejo wrote:thanks predator for the help!
I had trouble installing Pycurl so I did it your way, and works. :D


Whoa, there. No need to mega-necro.
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2331
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: [solved] Logging into HTS with python

Post by volaron on Tue Feb 15, 2011 10:57 pm
([msg=53619]see Re: [solved] Logging into HTS with python[/msg])

Thanks to Defience for the python code. Helped me to get the 10 words.

However, I'm having trouble with the submission part. How do I submit the form once I figure out the 10 words? I have tried many things I found through google.

The best I can get is the "Invalid referer. The requested URL /missions/prog/1/index.php will not be loaded." page.

Code: Select all
url = 'http://www.hackthissite.org/missions/prog/1/index.php'
value = {'solution':answer}    # answer being the string of 10 words
data = urllib.urlencode(value)
req = urllib2.Request(url,data,dicHeaders)
response = urllib2.urlopen(req)


There are too many unknowns for me to go any further. A little bit of info on form submission would be great!
volaron
New User
New User
 
Posts: 1
Joined: Tue Feb 15, 2011 10:41 pm
Blog: View Blog (0)


Re: [solved] Logging into HTS with python

Post by TheDallas on Wed Feb 16, 2011 1:43 am
([msg=53626]see Re: [solved] Logging into HTS with python[/msg])

Don't mean to change gears here, but does anyone know how this would be done in Perl?
TheDallas
New User
New User
 
Posts: 14
Joined: Mon Sep 27, 2010 11:05 pm
Blog: View Blog (0)


Re: [solved] Logging into HTS with python

Post by Goatboy on Wed Feb 16, 2011 3:51 am
([msg=53629]see Re: [solved] Logging into HTS with python[/msg])

Three necros in one thread? Really?
Assume that everything I say is or could be a lie.
1UHQ15HqBRZFykqx7mKHpYroxanLjJcUk
User avatar
Goatboy
Expert
Expert
 
Posts: 2799
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Previous

Return to Graveyard

Who is online

Users browsing this forum: No registered users and 0 guests