This file is indexed.

/usr/bin/wapiti-getcookie is in wapiti 2.3.0+dfsg-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /usr/bin/python
# -*- coding: utf-8 -*-
# This file is part of the Wapiti project (http://wapiti.sourceforge.net)
# Copyright (C) 2006-2013 Nicolas Surribas
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
import urlparse
import sys
import HTMLParser
import BeautifulSoup
import getopt
import requests
import os

if "_" not in dir():
    def _(s):
        return s

if len(sys.argv) < 3:
    sys.stderr.write("Usage: getcookie.py <cookie_file.json> <url_with_form> [options]\n\n" +
                     "Supported options are:\n" +
                     "-p <url_proxy>\n" +
                     "--proxy <url_proxy>\n" +
                     "	To specify a proxy\n" +
                     "    Example: -p http://proxy:port/\n\n")
    sys.exit(1)

TIMEOUT = 6
COOKIEFILE = sys.argv[1]
url = sys.argv[2]
proxies = {}
server = urlparse.urlparse(url).netloc

if not hasattr(sys, "frozen"):
    parent_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))
    if os.path.exists(os.path.join(parent_dir, "wapitiCore")):
        sys.path.append(parent_dir)

from wapitiCore.net import jsoncookie
from wapitiCore.net import lswww

try:
    opts, args = getopt.getopt(sys.argv[3:], "p:", ["proxy="])
except getopt.GetoptError, e:
    print(e)
    sys.exit(2)
for o, a in opts:
    if o in ("-p", "--proxy"):
        parsed = urlparse.urlparse(a)
        proxies[parsed.scheme] = a

# Some websites/webapps like Webmin send a first cookie to see if the browser support them
# so we must collect these test-cookies during authentication.
jc = jsoncookie.jsoncookie()
jc.open(COOKIEFILE)
jc.delete(server)

current_full_url = url.split("#")[0]
current = current_full_url.split("?")[0]
currentdir = "/".join(current.split("/")[:-1]) + "/"
proto = url.split("://")[0]

txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}

session = requests.Session()
session.proxies = proxies
r = session.get(url, headers=txheaders)
resp_encoding = r.encoding

htmlSource = r.text
bs = BeautifulSoup.BeautifulSoup(htmlSource)
page_encoding = bs.originalEncoding

if page_encoding is None:
    page_encoding = resp_encoding

p = lswww.linkParser(url)
try:
    p.feed(htmlSource)
except HTMLParser.HTMLParseError, err:
    htmlSource = bs.prettify()
    try:
        p.reset()
        p.feed(htmlSource)
    except HTMLParser.HTMLParseError, err:
        p = lswww.linkParser2(url)
        p.feed(htmlSource)

jc.addcookies(session.cookies)

if len(p.forms) == 0:
    print(_("No forms found in this page !"))
    sys.exit(1)

myls = lswww.lswww(url)
i = 0
nchoice = 0
if len(p.forms) > 1:
    print(_("Choose the form you want to use :"))
    for form in p.forms:
        print('')
        print(u"{0}) {1}".format(i,
                                 myls.correctlink(form[0],
                                                  current,
                                                  current_full_url,
                                                  currentdir,
                                                  proto,
                                                  page_encoding)))
        for field, value in form[1]:
            print(u"\t{0} ({1})".format(field, value))
        i += 1
    ok = False
    while not ok:
        choice = raw_input(_("Enter a number : "))
        if choice.isdigit():
            nchoice = int(choice)
            if nchoice < i and nchoice >= 0:
                ok = True

form = p.forms[nchoice]
print(_("Please enter values for the following form: "))
print(_("url = {0}").format(myls.correctlink(form[0], current, current_full_url, currentdir, proto, page_encoding)))

for i in range(len(form[1])):
    field, value = form[1][i]
    new_value = raw_input(field + " (" + value + ") : ")
    form[1][i] = [field, new_value]

url = myls.correctlink(form[0], current, current_full_url, currentdir, proto, page_encoding)

txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
             'Content-type': 'application/x-www-form-urlencoded'}

r = session.post(url, data=form[1], headers=txheaders, allow_redirects=True)

jc.addcookies(session.cookies)
jc.dump()
jc.close()