Advertisement
rfmonk

SQL_injection_notes.sql

Jan 15th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.91 KB | None | 0 0
  1. -- SQLi is #1 of OWASP Top 10 Web vulns
  2. -- Sample code of vuln php script
  3.  
  4. $sql_cmd ="SELECT * FROM user WHERE id = " . $_POST['id'];
  5.  
  6. -- Form-Input: 42; UPDATE user SET type="admin" WHERE id=23;
  7. -- Resulting Query:
  8.  
  9. SELECT * FROM USER WHERE id =42; UPDATE USER
  10. SET TYPE="admin" WHERE id=23;
  11.  
  12. SELECT author, subject FROM article
  13. WHERE ID=42 UNION SELECT login,
  14. password FROM USER;
  15.  
  16. -- Very fast, can sometimes retrieve multiple strings in one request
  17.  
  18. --------------------------------------------------
  19.  
  20. -- Boolean SQLi
  21. -- No output of the quer can be seen
  22. -- There's an indication, if the result of a query is true or false
  23. -- because a certain string appears in the webpage, e.g. an error message
  24.  
  25. -- Fastest retreiving method is binary search:
  26. -- Is the ASCII-Code of the 1st character of the password of the user
  27. -- 'admin' lower than 64?
  28. -- If 'true': Is the ASCII-Code of the 1st character of the password
  29. -- of user 'admin' lower than 32?
  30. -- ...
  31.  
  32. -- Slow: Needs 7 requests per ASCII character (but can be multithreaded)
  33.  
  34. ----------------------------------------------------
  35.  
  36. -- Time based SQLi
  37. -- Neither output of the query can be seen nor any indication of its result
  38. -- Only possible way to determine the result, is to let the database SLEEP()
  39. -- some seconds, if the query turns out false and continue immediately if true.
  40. -- In other databases time intensive instructions have to be executed
  41. -- (effectively doing a short DoS)
  42. -- Very slow and prone to errors because of hard distinction between SLEEP()
  43. -- and a network lag
  44. -- Multithreading difficult to impossible
  45.  
  46. -- Time based SQLi binary search
  47. -- String to get:"1234", only 4 possibilities
  48. -- Is number <= 2?
  49. -- If true:
  50.     -- Is it 1?
  51.     --  If true: found 1
  52.     --  If false:found 2
  53. -- If false:
  54.     -- Is it 3?...
  55. -- To get 1234 it takes 8 requests
  56.  
  57. -- linear search takes 9 requests
  58. -- Is this not a 1  -- 6 slow and 3 fast requests
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement