sql time


SUBMITTED BY: leakage

DATE: Nov. 29, 2015, 3:25 a.m.

FORMAT: Text only

SIZE: 3.8 kB

HITS: 47232

  1. <?php include("../includes/header.inc"); ?>
  2. <div class="col">
  3. <h2>Budget Listing</h2>
  4. <?php
  5. $search = "";
  6. if (isset($_POST["search"]))
  7. $search = $_POST["search"];
  8. ?>
  9. <form method="post">
  10. Enter your budget (no decimals - ex: 50) : <input type="text" name="search" size="40" value="<?php echo htmlentities($search); ?>" />
  11. <input type="submit" name="submit" value="Go!" />
  12. </form><br /><br />
  13. <?php
  14. // Define vars.
  15. $conn = @mysql_connect(DB_SERVER, DB_USER, DB_PWD);
  16. $query = "SELECT id, name, description, (SELECT MAX(price) FROM products WHERE price <= $search AND ".
  17. "categories.id = category) AS maxamount FROM categories HAVING maxamount IS NOT NULL";
  18. // Connection is OK.
  19. if ($conn)
  20. {
  21. // Table head.
  22. echo '<table class="listTable" cellspacing="0" cellpadding="0">';
  23. echo '<tr>';
  24. echo '<td class="listHead">Category</td>';
  25. echo '<td class="listHead">Best item price</td>';
  26. echo '</tr>';
  27. if ($search == "")
  28. {
  29. echo '<tr>';
  30. echo '<td colspan="2" class="listRow" style="text-align:center;"><i>Enter something in the search box</i></td>';
  31. echo '</tr>';
  32. $query = "<i>No query was executed because search is empty.</i>";
  33. }
  34. // Execute query.
  35. else
  36. {
  37. @mysql_select_db(DB_NAME);
  38. $result = @mysql_query($query);
  39. if (@mysql_num_rows($result)==0)
  40. {
  41. echo '<tr>';
  42. echo '<td colspan="2" class="listRow" style="text-align:center;"><i>No product match - Try with a higher budget.</i></td>';
  43. echo '</tr>';
  44. }
  45. else
  46. {
  47. // Listing data in table.
  48. while ($row = @mysql_fetch_array($result))
  49. {
  50. echo '<tr>';
  51. echo '<td class="listRow">'.$row[1].'</td>';
  52. echo '<td class="listRow">'.$row[3].'</td>';
  53. echo '</tr>';
  54. }
  55. }
  56. }
  57. echo '</table>';
  58. }
  59. // Show debug boxes (MySQL error and Query generated).
  60. include("../includes/debug.inc");
  61. ?>
  62. </div>
  63. <div class="col last">
  64. <h3>Context</h3>
  65. <div class="case">
  66. <p><font class="caseTitle">Page purpose</font><br />
  67. This page allows the customer to do a budget search. The listing on the left should be read as follows :
  68. &quot;The best item you can buy under [budget entered in textbox] costs [price]&quot;.</p>
  69. </div>
  70. <div class="case">
  71. <p><font class="caseTitle">Goal</font><br />
  72. Try to find out what is the structure of the query and then list all the products of the database.
  73. Then you could try to recover data from other tables (complete SQL injection attack).</p>
  74. </div>
  75. <div class="lastcase">
  76. <p><font class="caseTitle">Parameter</font><br />
  77. The parameter for the SQL injection is given by the search field and it is transfered to the PHP script through
  78. &quot;POST&quot; method. You can try to enter &quot;RAM&quot; in the search field. This will generate a query
  79. that returns results.
  80. </div>
  81. </div>
  82. <div class="divclear"></div>
  83. <?php include("../includes/footer.inc"); ?>

comments powered by Disqus