예제 #1
0
    def createCookie(self, name, value, **kwargs):
        """Make a cookie from underspecified parameters.
        By default, the pair of `name` and `value` will be set for the domain ''
        and sent on every request (this is sometimes called a "supercookie").
        """
        result = dict(
            version=0,
            name=name,
            value=value,
            port=None,
            domain='',
            path='/',
            secure=False,
            expires=None,
            discard=True,
            comment=None,
            comment_url=None,
            rest={'HttpOnly': None},
            rfc2109=False,
        )

        badargs = set(kwargs) - set(result)
        if badargs:
            err = 'create_cookie() got unexpected keyword arguments: %s'
            raise TypeError(err % list(badargs))

        result.update(kwargs)
        result['port_specified'] = bool(result['port'])
        result['domain_specified'] = bool(result['domain'])
        result['domain_initial_dot'] = result['domain'].startswith('.')
        result['path_specified'] = bool(result['path'])

        return mechanize.Cookie(**result)
예제 #2
0
파일: curl.py 프로젝트: blropb/qt-test
def add_cookie(name,
               value,
               domain,
               version=0,
               expires=365,
               port=None,
               port_specified=False,
               domain_specified=True,
               domain_initial_dot=False,
               path='/',
               path_specified=True,
               secure=True,
               discard=False,
               comment=None,
               comment_url=None,
               rest={'HttpOnly': False},
               rfc2109=False):
    return mechanize.Cookie(version=version,
                            name=name,
                            value=value,
                            expires=expires,
                            port=port,
                            port_specified=port_specified,
                            domain=domain,
                            domain_specified=domain_specified,
                            domain_initial_dot=domain_initial_dot,
                            path=path,
                            path_specified=path_specified,
                            secure=secure,
                            discard=discard,
                            comment=comment,
                            comment_url=comment_url,
                            rest=rest,
                            rfc2109=rfc2109)
예제 #3
0
def csrfCookie(csrftoken):
    return mechanize.Cookie(version=0,
            name='csrftoken',
            value=csrftoken,
            port=None, port_specified=False,
            domain=config.DOMAIN,
            domain_specified=False,
            domain_initial_dot=False,
            path='/', path_specified=True,
            secure=False, expires=None,
            discard=True,
            comment=None, comment_url=None,
            rest={'HttpOnly': None}, rfc2109=False)
예제 #4
0
    def asignarCookie(self, archivoCookie):
        archivo = open(archivoCookie, 'r')
        datas = dict()
        datas = json.loads(archivo.read())

        cookie01 = mechanize.Cookie(0, str(datas[0]['name']),
                                    str(datas[0]['value']), None, False,
                                    str(datas[0]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie02 = mechanize.Cookie(0, str(datas[1]['name']),
                                    str(datas[1]['value']), None, False,
                                    str(datas[1]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie03 = mechanize.Cookie(0, str(datas[2]['name']),
                                    str(datas[2]['value']), None, False,
                                    str(datas[2]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie04 = mechanize.Cookie(0, str(datas[3]['name']),
                                    str(datas[3]['value']), None, False,
                                    str(datas[3]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie05 = mechanize.Cookie(0, str(datas[4]['name']),
                                    str(datas[4]['value']), None, False,
                                    str(datas[4]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie06 = mechanize.Cookie(0, str(datas[5]['name']),
                                    str(datas[5]['value']), None, False,
                                    str(datas[5]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie07 = mechanize.Cookie(0, str(datas[6]['name']),
                                    str(datas[6]['value']), None, False,
                                    str(datas[6]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie08 = mechanize.Cookie(0, str(datas[7]['name']),
                                    str(datas[7]['value']), None, False,
                                    str(datas[7]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie09 = mechanize.Cookie(0, str(datas[8]['name']),
                                    str(datas[8]['value']), None, False,
                                    str(datas[8]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie10 = mechanize.Cookie(0, str(datas[9]['name']),
                                    str(datas[9]['value']), None, False,
                                    str(datas[9]['domain']), False, False, '/',
                                    True, False, None, True, None, None, {},
                                    False)
        cookie11 = mechanize.Cookie(0, str(datas[10]['name']),
                                    str(datas[10]['value']), None, False,
                                    str(datas[10]['domain']), False, False,
                                    '/', True, False, None, True, None, None,
                                    {}, False)
        cookie12 = mechanize.Cookie(0, str(datas[11]['name']),
                                    str(datas[11]['value']), None, False,
                                    str(datas[11]['domain']), False, False,
                                    '/', True, False, None, True, None, None,
                                    {}, False)

        self.cookie = mechanize.CookieJar()
        self.cookie.set_cookie(cookie01)
        self.cookie.set_cookie(cookie02)
        self.cookie.set_cookie(cookie03)
        self.cookie.set_cookie(cookie04)
        self.cookie.set_cookie(cookie05)
        self.cookie.set_cookie(cookie06)
        self.cookie.set_cookie(cookie07)
        self.cookie.set_cookie(cookie08)
        self.cookie.set_cookie(cookie09)
        self.cookie.set_cookie(cookie10)
        self.cookie.set_cookie(cookie11)
        self.cookie.set_cookie(cookie12)

        self.br = mechanize.Browser()
        self.br.set_cookiejar(self.cookie)
        self.br.set_handle_equiv(True)
        self.br.set_handle_gzip(True)
        self.br.set_handle_redirect(True)
        self.br.set_handle_referer(True)
        self.br.set_handle_robots(False)

        self.br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(),
                                   max_time=1)

        self.br.addheaders = [(
            'User-agent',
            'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'
        )]
예제 #5
0
print_title(browser)
print "\n\n"
print "Cookie Injection"

answer = "y"
name = []
value = []
domain = []
cookie = []

while answer == "y":
    name.append(raw_input("Please insert Cookiename > "))
    value.append(raw_input("Please insert Cookievalue > "))
    domain.append(raw_input("Please insert Domain > "))
    answer = raw_input("More Cookies?[y/n] ")
    while (answer != "n") and (answer != "y"):
        answer = raw_input("More Cookies?[y/n] ")
        answer = answer.lower()

for i in range(len(name)):
    cookie.append(
        mechanize.Cookie(0, name[i], value[i], None, False, domain[i], False,
                         False, "/", True, False, None, True, None, None, {},
                         False))
    cj.set_cookie(cookie[i])

browser.set_cookiejar(cj)
browser.reload()

check_result(browser)
예제 #6
0
start_page = "https://online.cnbank.com/CNB_Online/Authentication/Login.aspx"

if not USERNAME \
 or not PASSWORD \
 or not COOKIE['name'] \
 or not COOKIE['value'] \
 or not USERAGENT:
    print 'Please edit this file and follow the directions in the comments.'
    sys.exit(1)

br = mechanize.Browser()

cj = mechanize.CookieJar()
cj.set_cookie(
    mechanize.Cookie(None, COOKIE['name'], COOKIE['value'], None, False,
                     'online.cnbank.com', True, True, '/', True, True,
                     int(time.time()) + 86400, False, None, None, None))

br.addheaders = [('User-agent', USERAGENT)]

if proxy['http'] and proxy['https']:
    if DEBUG:
        print 'Setting Proxy.'
    br.set_proxies(proxy)

br.set_cookiejar(cj)
br.set_handle_robots(False)
br.set_handle_refresh(True, 10, True)
br.set_handle_redirect(True)

#
예제 #7
0
 def dashboard(self):
     """Get dashboard tasks list"""
     br = self.get_browser()
     if self.get_dashboard_url():
         response = self.request(self.get_dashboard_url())
         page = BeautifulSoup(response.read())
         if not page.find('input', attrs={'id': 'c*k'}):
             self.login()
             response = self.request(self.get_dashboard_url())
             page = BeautifulSoup(response.read())
     else:
         self.login()
         response = self.request(self.get_dashboard_url())
         page = BeautifulSoup(response.read())
     c*k = page.find('input', attrs={'id': 'c*k'}).get('value')
     cok_cookie = mechanize.Cookie(version=0,
                                   name='gdriveid',
                                   value=c*k,
                                   port=None,
                                   port_specified=False,
                                   domain='.vip.xunlei.com',
                                   domain_specified=False,
                                   domain_initial_dot=True,
                                   path='/',
                                   path_specified=True,
                                   secure=False,
                                   expires=int(time.time() + 3600 * 24 * 7),
                                   discard=True,
                                   comment=None,
                                   comment_url=None,
                                   rest={},
                                   rfc2109=False)
     br._ua_handlers['_cookies'].cookiejar.set_cookie(cok_cookie)
     br._ua_handlers['_cookies'].cookiejar.save(self.cookie_file,
                                                ignore_discard=True,
                                                ignore_expires=True)
     raw_items = page.findAll('div', attrs={'class': 'rw_list'})
     items = []
     for raw_item in raw_items:
         item = {}
         item['id'] = raw_item.get('taskid')
         item['type'] = raw_item.find('input',
                                      attrs={
                                          'id': 'd_tasktype%s' % item['id']
                                      }).get('value')
         item['status'] = raw_item.find('input',
                                        attrs={
                                            'id': 'd_status%s' % item['id']
                                        }).get('value')
         item['size'] = int(
             raw_item.find('input',
                           attrs={
                               'id': 'ysfilesize%s' % item['id']
                           }).get('value'))
         item['name'] = raw_item.find('input',
                                      attrs={
                                          'id': 'taskname%s' % item['id']
                                      }).get('value')
         item['download_url'] = raw_item.find('input',
                                              attrs={
                                                  'id':
                                                  'dl_url%s' % item['id']
                                              }).get('value')
         item['bt_download_url'] = raw_item.find('input',
                                                 attrs={
                                                     'id':
                                                     'bt_down_url%s' %
                                                     item['id']
                                                 }).get('value')
         items.append(item)
     return items