Пример #1
0
    def HTTPHandler(self, conn, request, response, requesttime, responsetime):
        host = ''
        loc = ''
        lastmodified = ''

        #request_time, request, response = self.httpDict[conn.addr]

        # extract method,uri,host from response
        host = util.getHeader(request, 'host')
        if host == '':
            host = conn.serverip

        try:
            status = response.status
        except:
            status = ''
        try:
            reason = response.reason
        except:
            reason = ''

        loc = ''
        if status[:2] == '30':
            loc = util.getHeader(response, 'location')
            if len(loc):
                loc = '-> ' + loc

        lastmodified = util.HTTPlastmodified(response)
        referer = util.getHeader(request, 'referer')
        useragent = util.getHeader(request, 'user-agent')
        via = util.getHeader(request, 'via')

        try:
            responsesize = len(response.body.rstrip('\0'))
        except:
            responsesize = 0

        if self.md5:
            md5 = self._bodyMD5(response)
        else:
            md5 = ''

        # File objects
        try:
            if len(response.body) > 0:
                responsefile = dfile.dfile(
                    name=request.uri, data=response.body)
            else:
                responsefile = ''
        except:
            responsefile = ''
        if request.method == 'POST' and len(request.body):
            ulcontenttype, ulfilename, uldata = self.POSTHandler(request.body)
            uploadfile = dfile.dfile(name=ulfilename, data=uldata)
        else:
            uploadfile = None

        requestInfo = '%s %s%s HTTP/%s' % (request.method,
                                           host,
                                           request.uri[:self.maxurilen] + '[truncated]' if self.maxurilen > 0 and len(
                                               request.uri) > self.maxurilen else request.uri,
                                           request.version)
        if response:
            responseInfo = '%s %s %s %s' % (status, reason, loc, lastmodified)
        else:
            responseInfo = ''

        self.alert("%-80s // %s" % (requestInfo, responseInfo), referer=referer, useragent=useragent, request=requestInfo, response=responseInfo, request_time=requesttime, response_time=responsetime, request_method=request.method, host=host,
                   uri=request.uri, status=status, reason=reason, lastmodified=lastmodified, md5=md5, responsesize=responsesize, contenttype=util.getHeader(response, 'content-type'), responsefile=responsefile, uploadfile=uploadfile, via=via, **conn.info())
        if self.out.sessionwriter:
            self.write(request.data, direction='cs')
            if response:
                self.write(response.body, direction='sc')
Пример #2
0
    def HTTPHandler(self, conn, request, response, requesttime, responsetime):

        #
        # Establish kw_items dictionary for extracted details from tcp/ip layer and request/response
        #
        kw_items = conn.info()

        #
        # Extract useful information from HTTP *request*
        #
        for h in request.headers.keys():
            kw_items[h] = util.getHeader(request, h)
        # Rename user-agent for backward compatability
        if 'user-agent' in kw_items:
            kw_items['useragent'] = kw_items.pop('user-agent')

        # Override non-existent host header with server IP address
        if kw_items['host'] == '':
            kw_items['host'] = conn.serverip

        # request info string for standard output
        requestInfo = '%s %s%s HTTP/%s' % (
            request.method,
            kw_items['host'] if kw_items['host'] != request.uri else
            '',  # With CONNECT method, the URI is or contains the host, making this redudant
            request.uri[:self.maxurilen] + '[truncated]' if self.maxurilen > 0
            and len(request.uri) > self.maxurilen else request.uri,
            request.version)

        #
        # Extract useful information from HTTP *response* (if available)
        #
        status = ''
        reason = ''
        responsesize = 0
        loc = ''
        lastmodified = ''
        md5 = ''
        if response != None:

            try:
                responsesize = len(response.body.rstrip('\0'))
            except:
                responsesize = 0

            if self.md5:
                md5 = self._bodyMD5(response)
            else:
                md5 = ''

            try:
                status = response.status
            except:
                status = ''
            try:
                reason = response.reason
            except:
                reason = ''

            for h in response.headers.keys():
                if not h in kw_items:
                    kw_items[h] = util.getHeader(response, h)
                else:
                    kw_items['server_' + h] = util.getHeader(response, h)
            if 'content-type' in kw_items:
                kw_items['contenttype'] = kw_items.pop('content-type')

            loc = ''
            if status[:2] == '30':
                loc = util.getHeader(response, 'location')
                if len(loc):
                    loc = '-> ' + loc

            lastmodified = util.HTTPlastmodified(response)

            # response info string for standard output
            responseInfo = '%s %s %s %s' % (status, reason, loc, lastmodified)

        else:
            responseInfo = ''

        #
        # File objects
        #
        try:
            if len(response.body) > 0:
                responsefile = dfile.dfile(name=request.uri,
                                           data=response.body)
            else:
                responsefile = ''
        except:
            responsefile = ''
        if request.method == 'POST' and len(request.body):
            ulcontenttype, ulfilename, uldata = self.POSTHandler(request.body)
            uploadfile = dfile.dfile(name=ulfilename, data=uldata)
        else:
            uploadfile = None

#
# Call alert with text info and kw values
#
        self.alert("%-80s // %s" % (requestInfo, responseInfo),
                   request=requestInfo,
                   response=responseInfo,
                   request_time=requesttime,
                   response_time=responsetime,
                   request_method=request.method,
                   uri=request.uri,
                   status=status,
                   reason=reason,
                   lastmodified=lastmodified,
                   md5=md5,
                   responsesize=responsesize,
                   responsefile=responsefile,
                   uploadfile=uploadfile,
                   **kw_items)

        if self.out.sessionwriter:
            self.write(request.data, direction='cs')
            if response:
                self.write(response.body, direction='sc')
Пример #3
0
    def HTTPHandler(self, conn, request, response, requesttime, responsetime):
        host = ''
        loc = ''
        lastmodified = ''

        #request_time, request, response = self.httpDict[conn.addr]

        # extract method,uri,host from response
        host = util.getHeader(request, 'host')
        if host == '':
            host = conn.serverip

        try:
            status = response.status
        except:
            status = ''
        try:
            reason = response.reason
        except:
            reason = ''

        loc = ''
        if status[:2] == '30':
            loc = util.getHeader(response, 'location')
            if len(loc):
                loc = '-> ' + loc

        lastmodified = util.HTTPlastmodified(response)
        referer = util.getHeader(request, 'referer')
        useragent = util.getHeader(request, 'user-agent')
        via = util.getHeader(request, 'via')

        try:
            responsesize = len(response.body.rstrip('\0'))
        except:
            responsesize = 0

        if self.md5:
            md5 = self._bodyMD5(response)
        else:
            md5 = ''

        # File objects
        try:
            if len(response.body) > 0:
                responsefile = dfile.dfile(
                    name=request.uri, data=response.body)
            else:
                responsefile = ''
        except:
            responsefile = ''
        if request.method == 'POST' and len(request.body):
            ulcontenttype, ulfilename, uldata = self.POSTHandler(request.body)
            uploadfile = dfile.dfile(name=ulfilename, data=uldata)
        else:
            uploadfile = None

        requestInfo = '%s %s%s HTTP/%s' % (request.method,
                                           host if host != request.uri else '',  # With CONNECT method, the URI is or contains the host, making this redudant
                                           request.uri[:self.maxurilen] + '[truncated]' if self.maxurilen > 0 and len(
                                               request.uri) > self.maxurilen else request.uri,
                                           request.version)
        if response:
            responseInfo = '%s %s %s %s' % (status, reason, loc, lastmodified)
        else:
            responseInfo = ''

        self.alert("%-80s // %s" % (requestInfo, responseInfo), referer=referer, useragent=useragent, request=requestInfo, response=responseInfo, request_time=requesttime, response_time=responsetime, request_method=request.method, host=host,
                   uri=request.uri, status=status, reason=reason, lastmodified=lastmodified, md5=md5, responsesize=responsesize, contenttype=util.getHeader(response, 'content-type'), responsefile=responsefile, uploadfile=uploadfile, via=via, **conn.info())
        if self.out.sessionwriter:
            self.write(request.data, direction='cs')
            if response:
                self.write(response.body, direction='sc')
Пример #4
0
    def HTTPHandler(self, conn, request, response, requesttime, responsetime):
        host = ''
        loc = ''
        lastmodified = ''

        # extract method,uri,host from response
        host = util.getHeader(request, 'host')
        if host == '':
            host = conn.serverip
        try:
            status = response.status
        except:
            status = ''
        try:
            reason = response.reason
        except:
            reason = ''

        loc = ''
        if status[:2] == '30':
            loc = util.getHeader(response, 'location')
            if len(loc):
                loc = '-> ' + loc

        lastmodified = util.HTTPlastmodified(response)
        referer = util.getHeader(request, 'referer')
        useragent = util.getHeader(request, 'user-agent')
        via = util.getHeader(request, 'via')
        content_type = util.getHeader(response, 'content-type')

        if self.color:
            color_code = self.set_color(content_type)
        else:
            color_code = '\x1b[37m'
        print color_code,

        try:
            responsesize = len(response.body.rstrip('\0'))
        except:
            responsesize = 0

        if self.md5:
            md5 = self._bodyMD5(response)
        else:
            md5 = ''

        # File objects
        try:
            if len(response.body) > 0:
                responsefile = dfile.dfile(name=request.uri,
                                           data=response.body)
            else:
                responsefile = ''
        except:
            responsefile = ''
        if request.method == 'POST' and len(request.body):
            ulcontenttype, ulfilename, uldata = self.POSTHandler(request.body)
            uploadfile = dfile.dfile(name=ulfilename, data=uldata)
        else:
            uploadfile = None

        requestInfo = '%s %s%s HTTP/%s' % (
            request.method, host, request.uri[:self.maxurilen] + '[truncated]'
            if self.maxurilen > 0 and len(request.uri) > self.maxurilen else
            request.uri, request.version)
        if response:
            responseInfo = '%s %s %s %s' % (status, reason, loc, lastmodified)
        else:
            responseInfo = ''

        self.generate_alert(conn,
                            color_code,
                            requestInfo,
                            responseInfo,
                            referer=referer,
                            useragent=useragent,
                            request=requestInfo,
                            response=responseInfo,
                            request_time=requesttime,
                            response_time=responsetime,
                            request_method=request.method,
                            host=host,
                            uri=request.uri,
                            status=status,
                            reason=reason,
                            lastmodified=lastmodified,
                            md5=md5,
                            responsesize=responsesize,
                            contenttype=util.getHeader(response,
                                                       'content-type'),
                            responsefile=responsefile,
                            uploadfile=uploadfile,
                            via=via)

        if self.out.sessionwriter:
            self.write(request.data, direction='cs')
            if response:
                self.write(response.body, direction='sc')
Пример #5
0
    def HTTPHandler(self, conn, request, response, requesttime, responsetime):
        host = ''
        loc = ''
        lastmodified = ''

        # extract method,uri,host from response
        host = util.getHeader(request, 'host')
        if host == '':
            host = conn.serverip

        try:
            status = response.status
        except:
            status = ''
        try:
            reason = response.reason
        except:
            reason = ''

        loc = ''
        if status[:2] == '30':
            loc = util.getHeader(response, 'location')
            if len(loc):
                loc = '-> {0}'.format(loc)

        lastmodified = util.HTTPlastmodified(response)
        referer = util.getHeader(request, 'referer')
        useragent = util.getHeader(request, 'user-agent')
        via = util.getHeader(request, 'via')
        contenttype = util.getHeader(response, 'content-type')

        if self.color:
            self.color_code = self.set_color(contenttype, response)

        try:
            responsesize = len(response.body.rstrip('\0'))
        except:
            responsesize = 0

        if self.md5:
            md5 = self._bodyMD5(response)
        else:
            md5 = ''

        # File objects
        try:
            if len(response.body) > 0:
                responsefile = dfile.dfile(
                    name=request.uri, data=response.body)
            else:
                responsefile = ''
        except:
            responsefile = ''
        if request.method == 'POST' and len(request.body):
            ulcontenttype, ulfilename, uldata = self.POSTHandler(request.body)
            uploadfile = dfile.dfile(name=ulfilename, data=uldata)
        else:
            uploadfile = None

        requestInfo = '{0} {1}{2} HTTP/{3}'.format(
                       request.method, host,
                       request.uri[:self.maxurilen] + '[truncated]' if self.maxurilen > 0 and len(
                                               request.uri) > self.maxurilen else request.uri,
                                           request.version)
        if response:
            responseInfo = '{0} {1} {2} {3}'.format(status, reason, loc, lastmodified)
        else:
            responseInfo = ''

        print "{0}".format(self.color_code)
        self.alert("{0:<80} // {1}".format(requestInfo, responseInfo) , referer=referer, 
                   useragent=useragent, request=requestInfo, response=responseInfo, 
                   request_time=requesttime, response_time=responsetime, 
                   request_method=request.method, host=host, uri=request.uri, 
                   status=status, reason=reason, lastmodified=lastmodified, 
                   md5=md5, responsesize=responsesize, 
                   contenttype=contenttype,
                   responsefile=responsefile, uploadfile=uploadfile, via=via, **conn.info())
        #Reset terminal colors to the users default
        print "{0}".format(ansi_colors.DEFAULT)

        if self.out.sessionwriter:
            self.write(request.data, direction='cs')
            if response:
                self.write(response.body, direction='sc')