Advertisement
cdolphin

Dangerous

Nov 26th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import cgi
  2.  
  3. from google.appengine.api import users
  4. from google.appengine.ext import webapp
  5. from google.appengine.ext.webapp.util import run_wsgi_app
  6. import sys
  7. import StringIO
  8.  
  9. class MainPage(webapp.RequestHandler):
  10.     def get(self):
  11.         self.response.out.write("""
  12.          <html>
  13.            <body>
  14.              <form action="/execute" method="post">
  15.                <div><textarea name="code" rows="3" cols="60"></textarea></div>
  16.                <div><input type="submit" value="Write some arbitrary python!!!"></div>
  17.              </form>
  18.            </body>
  19.          </html>""")
  20.  
  21.  
  22. class Executor(webapp.RequestHandler):
  23.     def post(self):
  24.         gae_stdout = sys.stdout
  25.         output = StringIO.StringIO()
  26.         self.response.out.write('<html><body>You wrote:<pre>')
  27.         sys.stdout = output
  28.         code = compile(self.request.get('code'),'<string>','exec')
  29.         ns = {} #one should clone globals and remove dangerous items
  30.         exec code in ns
  31.         self.response.out.write(output.getvalue())
  32.         self.response.out.write('</pre></body></html>')
  33.         sys.stdout = gae_stdout
  34.  
  35. application = webapp.WSGIApplication(
  36.                                      [('/', MainPage),
  37.                                       ('/execute', Executor)],
  38.                                      debug=True)
  39. def main():
  40.     run_wsgi_app(application)
  41.  
  42. if __name__ == "__main__":
  43.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement