Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1085)

Unified Diff: net/tools/testserver/testserver.py

Issue 7246021: Prevent DOS attack on UDP echo servers by distinguishing between an echo request (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/testserver/echo_message.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/testserver/testserver.py
===================================================================
--- net/tools/testserver/testserver.py (revision 96850)
+++ net/tools/testserver/testserver.py (working copy)
@@ -3,8 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""This is a simple HTTP/FTP/SYNC/TCP ECHO/UDP ECHO/ server used for testing
-Chrome.
+"""This is a simple HTTP/FTP/SYNC/TCP/UDP/ server used for testing Chrome.
It supports several test URLs, as specified by the handlers in TestPageHandler.
By default, it listens on an ephemeral port and sends the port number back to
@@ -21,6 +20,7 @@
import errno
import optparse
import os
+import random
import re
import select
import simplejson
@@ -36,6 +36,7 @@
# Ignore deprecation warnings, they make our output more cluttered.
warnings.filterwarnings("ignore", category=DeprecationWarning)
+import echo_message
import pyftpdlib.ftpserver
import tlslite
import tlslite.api
@@ -1521,12 +1522,21 @@
"""
def handle(self):
- data = self.request.recv(65536)
- if not data:
+ """Handles the request from the client and constructs a response."""
+
+ data = self.request.recv(65536).strip()
+ # Verify the "echo request" message received from the client. Send back
+ # "echo response" message if "echo request" message is valid.
+ try:
+ return_data = echo_message.GetEchoResponseData(data)
+ if not return_data:
return
- self.request.send(data)
+ except ValueError:
+ return
+ self.request.send(return_data)
+
class UDPEchoHandler(SocketServer.BaseRequestHandler):
"""The RequestHandler class for UDP echo server.
@@ -1535,9 +1545,19 @@
"""
def handle(self):
+ """Handles the request from the client and constructs a response."""
+
data = self.request[0].strip()
socket = self.request[1]
- socket.sendto(data, self.client_address)
+ # Verify the "echo request" message received from the client. Send back
+ # "echo response" message if "echo request" message is valid.
+ try:
+ return_data = echo_message.GetEchoResponseData(data)
+ if not return_data:
+ return
+ except ValueError:
+ return
+ socket.sendto(return_data, self.client_address)
class FileMultiplexer:
@@ -1604,10 +1624,16 @@
server_data['port'] = server.server_port
server_data['xmpp_port'] = server.xmpp_port
elif options.server_type == SERVER_TCP_ECHO:
+ # Used for generating the key (randomly) that encodes the "echo request"
+ # message.
+ random.seed()
server = TCPEchoServer(('127.0.0.1', port), TCPEchoHandler)
print 'Echo TCP server started on port %d...' % server.server_port
server_data['port'] = server.server_port
elif options.server_type == SERVER_UDP_ECHO:
+ # Used for generating the key (randomly) that encodes the "echo request"
+ # message.
+ random.seed()
server = UDPEchoServer(('127.0.0.1', port), UDPEchoHandler)
print 'Echo UDP server started on port %d...' % server.server_port
server_data['port'] = server.server_port
« no previous file with comments | « net/tools/testserver/echo_message.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698