Skip to content

Instantly share code, notes, and snippets.

@direvius
Created October 13, 2012 20:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save direvius/3886110 to your computer and use it in GitHub Desktop.
Save direvius/3886110 to your computer and use it in GitHub Desktop.
Generate ammo for Yandex.tank
#!/usr/bin/env ruby
# simple GET ammo generation, pass hostname as a first parameter and uris to STDIN
STDIN.each{|line|
request = <<-EOS
GET #{line.chomp} HTTP/1.0\r
Host: #{ARGV[0]}\r
Accept: */*\r
User-Agent: tank\r
Connection: close\r
\r
EOS
puts request.length
puts request
}
#!/usr/bin/env ruby
require 'URI'
host = ARGV[0] # read hostname from first parameter
handle = ARGV[1] # read uri from second parameter
STDIN.each{|line|
################
# We have url-encoded values in our source file, so we gonna
# make some manipulations with them (this is why we used ruby)
#
body = line.split('&').map{|param| # take each parameter
par_name, par_value = param.split('=') # parse it into key-value pair
# and if the parameter name is 'words', take each word from value (unescaped),
# then split it into multiple values by ',' and make multiple 'words' parameters
# from them, encoding each value:
par_name == 'words' ? result = URI.unescape(par_value).split(',').map{|word| "words=#{URI.escape(word)}"}.join('&') : param
}.join('&') # and join them finally to a whole post-data
request = <<-EOS
POST #{handle} HTTP/1.0\r
Host: #{host}\r
Accept: */*\r
User-Agent: tank\r
Connection: close\r
Content-Length: #{body.length}\r
\r
#{body}
EOS
puts request.length
puts request
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment