require 'sinatra' require 'sinatra/contrib' REGEXP = { php: 'echo\s([0-9]+)\s?\+\s?([0-9]+);', perl: 'print\s([0-9]+)\s?\+\s?([0-9]+);', python: 'print\s([0-9]+)\s?\+\s?([0-9]+)$', asp: 'Response.Write\(\s?([0-9]+)\s?\+\s?([0-9]+)\s?\)' } def exec( lang, str, prefix = nil, postfix = nil ) return if !str r = '' r << Regexp.escape( prefix ) if prefix r << '^' if !(prefix || postfix) r << REGEXP[lang] r << Regexp.escape( postfix ) if postfix x, y = str.scan( Regexp.new( r ) ).flatten (x && y) ? Integer( x ) + Integer( y ) : nil end def variations @@v ||= [ '', ';%s', "\";%s#", "';%s#" ] end def get_variations( lang, str ) variations.map do |v| pre, post = v.split( '%s' ) exec( lang, str, pre, post ) end.compact.to_s end REGEXP.keys.each do |language| language_str = language.to_s get '/' + language_str do <<-EOHTML Link Form Cookie Header EOHTML end get "/#{language_str}/link" do <<-EOHTML Link Link EOHTML end get "/#{language_str}/link/straight" do default = 'default' return if params['input'].start_with?( default ) get_variations( language, params['input'] ) end get "/#{language_str}/link/append" do default = 'default' return if !params['input'].start_with?( default ) get_variations( language, params['input'].split( default ).last ) end get "/#{language_str}/form" do <<-EOHTML
EOHTML end post "/#{language_str}/form/straight" do default = 'default' return if !params['input'] || params['input'].start_with?( default ) get_variations( language, params['input'] ) end get "/#{language_str}/form/append" do default = 'default' return if !params['input'] || !params['input'].start_with?( default ) get_variations( language, params['input'].split( default ).last ) end get "/#{language_str}/cookie" do <<-EOHTML Cookie Cookie EOHTML end get "/#{language_str}/cookie/straight" do default = 'cookie value' cookies['cookie'] ||= default return if cookies['cookie'].start_with?( default ) get_variations( language, cookies['cookie'] ) end get "/#{language_str}/cookie/append" do default = 'cookie value' cookies['cookie2'] ||= default return if !cookies['cookie2'].start_with?( default ) get_variations( language, cookies['cookie2'].split( default ).last ) end get "/#{language_str}/header" do <<-EOHTML Cookie Cookie EOHTML end get "/#{language_str}/header/straight" do default = 'arachni_user' return if env['HTTP_USER_AGENT'].start_with?( default ) get_variations( language, env['HTTP_USER_AGENT'] ) end get "/#{language_str}/header/append" do default = 'arachni_user' return if !env['HTTP_USER_AGENT'].start_with?( default ) get_variations( language, env['HTTP_USER_AGENT'].split( default ).last ) end end