1. Miki Tebeka
  2. ingress

Commits

Miki Tebeka  committed 1708798

Initial commit

  • Participants
  • Branches default

Comments (0)

Files changed (4)

File .hgignore

View file
  • Ignore whitespace
+syntax: glob
+
+dist
+ingress.egg-info

File LICENSE.txt

View file
  • Ignore whitespace
+Copyright (c) 2011 Miki Tebeka <miki.tebeka@gmail.com>.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+

File ingress.py

View file
  • Ignore whitespace
+#!/usr/bin/env python
+'''A "backdoor" shell for running servers (very much like Twisted manhole).
+
+This one uses only modules found in the standard library.
+'''
+
+__author__ = "Miki Tebeka <miki.tebeka@gmail.com>"
+__version__ = "0.1.0"
+
+from SocketServer import StreamRequestHandler, TCPServer, ThreadingMixIn
+from threading import Thread
+from traceback import print_exc
+
+EOF = chr(4)
+
+class PyHandler(StreamRequestHandler):
+
+    def handle(self):
+        env = self.env.copy()
+        self.wfile.write("Welcome to ingress (type 'exit()' to exit)")
+        while True:
+            try:
+                self.wfile.write(">>> ")
+                expr = self.rfile.readline().rstrip()
+                if expr == EOF:
+                    return
+                try:
+                    value = eval(expr, globals(), env)
+                    self.wfile.write(format(value) + "\n")
+                except:
+                    exec expr in env
+            except (EOFError, SystemExit):
+                return
+            except Exception as e:
+                print_exc(file=self.wfile)
+
+class ThreadedServer(ThreadingMixIn, TCPServer):
+    daemon_threads = True
+
+def server_thread(env, port):
+    # Create a new handler class for this with it's own env
+    class Handler(PyHandler):
+        pass
+    Handler.env = env
+
+    server = ThreadedServer(("localhost", port), Handler)
+    server.serve_forever()
+
+DEFAULT_PORT = 9998
+def serve(env=None, port=DEFAULT_PORT):
+    env = env.copy() if env else {}
+    t = Thread(target=server_thread, args=(env, port))
+    t.daemon = True
+    t.start()
+
+    return t
+
+if __name__ == "__main__":
+    t = serve()
+    print("Serving on port {0}".format(DEFAULT_PORT))
+    t.join()

File setup.py

View file
  • Ignore whitespace
+#!/usr/bin/env python
+
+from setuptools import setup
+import ingress
+
+setup(
+    name='ingress',
+    version=ingress.__version__,
+    description='A back door to servers.',
+    long_description=ingress.__doc__,
+    author='Miki Tebeka',
+    author_email='miki.tebeka@gmail.com',
+    url='https://bitbucket.org/tebeka/ingress/src',
+    license='MIT License',
+    platforms=['any'],
+    zip_safe=True,
+    py_modules=['ingress']
+)
+