views:

204

answers:

3

I have been looking for the syntax to redirect a special url to a remote server to do some XSS testing. Any ideas?

import SimpleHTTPServer
import SocketServer

class myHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        print self.path 
        if self.path == '/analog':
-------------------->return "http://12b.dk/analog"???
        return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

theport = 1234
Handler = myHandler
pywebserver = SocketServer.TCPServer(("", theport), Handler)

print "Python based web server. Serving at port", theport
pywebserver.serve_forever()
A: 

I have been looking for the syntax to redirect a special url to a remote server to do some XSS testing. Any ideas?

import SimpleHTTPServer
import SocketServer

class myHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        print self.path 
        if self.path == '/analog':
-------------------->return "http://12b.dk/analog"???
        return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

theport = 1234
Handler = myHandler
pywebserver = SocketServer.TCPServer(("", theport), Handler)

print "Python based web server. Serving at port", theport
pywebserver.serve_forever()
tax
Do you have any problem with editing the question? Because you may see there is 1 Answer, but this isn't answer at all?
S.Mark
I edited the question to put the info there. Also edited the format of the marked line as to not break python syntax. This "answer" can now be deleted.
mizipzor
I would like to let the server request the URL and pass it on to the client.
tax
+3  A: 

For a redirect, you have to return a code 301, plus a Location header. Probably you can try something like:

class myHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
   def do_GET(self):
       self.send_response(301)
       self.send_header('Location','http://www.example.com')
       self.end_headers()
Dan Andreatta
A: 

This seems to work, now I only have the problem that firefox 3.6 downloads my file instead of displaying it.

Any idea why?

import SimpleHTTPServer
import SocketServer
import urllib

class myHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        print self.path 
        if self.path == '/analog':
            self.copyfile(urllib.urlopen('http://www.someserver.com/analog'), self.wfile)
            return self
        return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

theport = 1234
Handler = myHandler
pywebserver = SocketServer.TCPServer(("", theport), Handler)

print "Python based web server. Serving at port", theport
pywebserver.serve_forever()

The file im trying to serve is a SVG document with javascript to display the /analog data

tax