I am writing a server base for a conceptual problem that can be posted on some CTF issues. It will be hosted on Ubuntu 12.04 LTS, nginx 1.1.19 and uWSGI 1.0.3-debian, which will handle Python 2.7.3.
The challenge is to use JavaScript loaded in competitors' browsers to initiate a function defined by PyV8 runThis() by successfully entering a function call like XSS. The Python script described below will work as CGI and check the participants' input with PyV8, evaluating whether XSS succeeded or not.
However, the problem is that this Python script is vulnerable to a DoS attack (I believe that some participants can supply this script with "while (1) {}")
I want to deal with this by setting a timeout on evalJavaScript() , so I tried to make a decision that uses SIGALRM from https://stackoverflow.com/a/97722/ ... of this link, but it does not work.
Here is the concept code (greatly simplified so as not to be distracted too much by the game and focus on the current timeout problem):
I also tested a very small script that worked.
import signal from time import sleep def main(): while 1: sleep(1) print "main" def timeout_handler(signum, frame): raise Exception signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(10) try: main() except: print "whoops"
Below are the links that I have looked so far:
Could you give me a hint about what I'm doing wrong or, better yet, suggest a better way to solve anti-DoS?
source share