예제 #1
0
    def application(self, environ, start_response):
        req_webob = Request(environ)
        res_webob = Response()

        #addr tuple as glastopf expects it
        remote_addr = (req_webob.remote_addr, int(environ["REMOTE_PORT"]))
        if "SERVER_NAME" in environ and "SERVER_PORT" in environ:
            # we could use socket.gethostbyname to get the ip...
            sensor_addr = (environ['wsgi.input'].rfile._sock.getsockname()[0],
                           environ['wsgi.input'].rfile._sock.getsockname()[1])
        else:
            sensor_addr = ("", "")

        header, body = self.honeypot.handle_request(req_webob.as_text(),
                                                    remote_addr, sensor_addr)
        proto, code, msg = ['HTTP/1.0', '200', 'OK']

        for h in header.splitlines():
            if ":" in h:
                h, v = h.split(":", 1)
                res_webob.headers[str(h.strip())] = str(v.strip())
            elif "HTTP/" in h:
                proto, code, msg = h.split(" ", 2)

        # this will adjust content-length header
        res_webob.status = code
        res_webob.charset = "utf8"
        res_webob.text = body.decode("utf-8", "ignore")

        #WSGI applications are not allowed to create or modify hop-by-hop headers
        self.remove_hop_by_hop_headers(res_webob.headers)
        return res_webob(environ, start_response)
예제 #2
0
    def application(self, environ, start_response):
        req_webob = Request(environ)
        res_webob = Response()

        #addr tuple as glastopf expects it
        remote_addr = (req_webob.remote_addr, int(environ["REMOTE_PORT"]))
        if "SERVER_NAME" in environ and "SERVER_PORT" in environ:
            # we could use socket.gethostbyname to get the ip...
            sensor_addr = (environ["SERVER_NAME"], environ["SERVER_PORT"])
        else:
            sensor_addr = ("", "")

        header, body = self.honeypot.handle_request(req_webob.as_text(),
                                                         remote_addr, sensor_addr)
        for h in header.splitlines():
            if ":" in h:
                h, v = h.split(":", 1)
                res_webob.headers[str(h.strip())] = str(v.strip())
        # this will adjust content-length header
        res_webob.charset = "utf8"
        res_webob.text = body.decode("utf-8", "ignore")

        #WSGI applications are not allowed to create or modify hop-by-hop headers
        self.remove_hop_by_hop_headers(res_webob.headers)
        return res_webob(environ, start_response)
예제 #3
0
    def application(self, environ, start_response):
        req_webob = Request(environ)
        res_webob = Response()

        #addr tuple as glastopf expects it
        remote_addr = (req_webob.remote_addr, int(environ["REMOTE_PORT"]))
        if "SERVER_NAME" in environ and "SERVER_PORT" in environ:
            # we could use socket.gethostbyname to get the ip...
            sensor_addr = (environ["SERVER_NAME"], environ["SERVER_PORT"])
        else:
            sensor_addr = ("", "")

        header, body = self.honeypot.handle_request(req_webob.as_text(),
                                                         remote_addr, sensor_addr)

        header_list = header.splitlines()
        try:
            # format: http_version status_code description
            res_webob.status_code = int(header_list[0].split()[1])
        except ValueError:
            # ['User-agent: *', 'Disallow:']
            # default 200 OK
            pass
        for h in header_list:
            if ":" in h:
                h, v = h.split(":", 1)
                res_webob.headers[str(h.strip())] = str(v.strip())
        # this will adjust content-length header
        res_webob.charset = "utf8"
        res_webob.text = body.decode("utf-8", "ignore")

        #WSGI applications are not allowed to create or modify hop-by-hop headers
        self.remove_hop_by_hop_headers(res_webob.headers)
        return res_webob(environ, start_response)
예제 #4
0
    def application(self, environ, start_response):
        req_webob = Request(environ)
        res_webob = Response()

        # addr tuple as glastopf expects it
        remote_addr = (req_webob.remote_addr, int(environ["REMOTE_PORT"]))
        headers, response = self.honeypot.handle_request(req_webob.as_text(), remote_addr, None).split("\r\n\r\n", 1)
        # glastopf header to webob headers
        for h in headers.splitlines():
            if ":" in h:
                h, v = h.split(":")
                res_webob.headers[str(h.strip())] = str(v.strip())
        # this will adjust content-length header
        res_webob.text = unicode(response)
        # WSGI applications are not allowed to create or modify hop-by-hop headers
        self.remove_hop_by_hop_headers(res_webob.headers)
        return res_webob(environ, start_response)
예제 #5
0
    def application(self, environ, start_response):
        req_webob = Request(environ)
        res_webob = Response()

        #addr tuple as glastopf expects it
        remote_addr = (req_webob.remote_addr, int(environ['REMOTE_PORT']))
        headers, response = self.honeypot.handle_request(req_webob.as_text(),
                                                         remote_addr, None).split("\r\n\r\n", 1)
        #glastopf header to webob headers
        for h in headers.splitlines():
            if ':' in h:
                h, v = h.split(':')
                res_webob.headers[str(h.strip())] = str(v.strip())
        #this will adjust content-length header
        res_webob.text = unicode(response)
        #WSGI applications are not allowed to create or modify hop-by-hop headers
        self.remove_hop_by_hop_headers(res_webob.headers)
        return res_webob(environ, start_response)
예제 #6
0
    def application(self, environ, start_response):
        req_webob = Request(environ)
        res_webob = Response()

        #addr tuple as glastopf expects it
        remote_addr = (req_webob.remote_addr, int(environ['REMOTE_PORT']))
        header, body = self.honeypot.handle_request(req_webob.as_text(),
                                                         remote_addr, None)
        for h in header.splitlines():
            if ':' in h:
                h, v = h.split(':', 1)
                res_webob.headers[str(h.strip())] = str(v.strip())
        #this will adjust content-length header
        res_webob.charset = 'utf8'
        res_webob.text = unicode(body)

        #WSGI applications are not allowed to create or modify hop-by-hop headers
        self.remove_hop_by_hop_headers(res_webob.headers)
        return res_webob(environ, start_response)