Kaydet (Commit) eca991df authored tarafından Guido van Rossum's avatar Guido van Rossum

Change security policy -- only accept requests from current host.

üst d1bef00f
...@@ -6,13 +6,15 @@ This is really a prototype for the same thing in C. ...@@ -6,13 +6,15 @@ This is really a prototype for the same thing in C.
Usage: pysvr.py [port] Usage: pysvr.py [port]
For security reasons, it only accepts requests from the current host.
This can still be insecure, but restricts violations from people who
can log in on your machine. Use with caution!
""" """
import sys, os, string, getopt, thread, socket, traceback import sys, os, string, getopt, thread, socket, traceback
OK_DOMAINS = [".cnri.reston.va.us", ".python.org"] PORT = 4000 # Default port
PORT = 7585892 % 0xFFFF # == 49367
def main(): def main():
try: try:
...@@ -43,6 +45,7 @@ def main_thread(port): ...@@ -43,6 +45,7 @@ def main_thread(port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("", port)) sock.bind(("", port))
sock.listen(5) sock.listen(5)
print "Listening on port", port, "..."
while 1: while 1:
(conn, addr) = sock.accept() (conn, addr) = sock.accept()
thread.start_new_thread(service_thread, (conn, addr)) thread.start_new_thread(service_thread, (conn, addr))
...@@ -50,26 +53,11 @@ def main_thread(port): ...@@ -50,26 +53,11 @@ def main_thread(port):
def service_thread(conn, addr): def service_thread(conn, addr):
(caddr, cport) = addr (caddr, cport) = addr
try: if caddr != socket.gethostbyname(socket.gethostname()):
host, aliases, ipaddrs = socket.gethostbyaddr(caddr) print "Connection from", caddr, "not accepted."
except socket.error:
print "Don't know hostname for", caddr
return
if '.' not in host:
for a in aliases:
if '.' in a:
host = a
break
else:
print "Only a local name (%s) for %s" % (host, caddr)
return
i = string.find(host, '.')
domain = string.lower(host[i:])
if domain not in OK_DOMAINS:
print "Connection from", host, "not accepted"
return return
print "Thread %s has connection from %s.\n" % (str(thread.get_ident()), print "Thread %s has connection from %s.\n" % (str(thread.get_ident()),
host), caddr),
stdin = conn.makefile("r") stdin = conn.makefile("r")
stdout = conn.makefile("w", 0) stdout = conn.makefile("w", 0)
run_interpreter(stdin, stdout) run_interpreter(stdin, stdout)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment