scriptz-team

[PHP-CLi] SERVER LOG SEARCHER WiTH iPs EXTRACTOR

Jun 4th, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <?php
  2. if(PHP_SAPI != 'cli') {
  3. die("Run this script ONLY iN CLI MODE!");
  4. }
  5. //header('Content-Type: text/plain');
  6. /* _____ _____ _ _____ _____ _____ _____ _____ _____
  7. ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
  8. |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
  9. |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
  10. |s C R i P T z - T E A M . i N F O|----------------------------
  11.  
  12. [PHP] SERVER LOG SEARCHER WiTH iPs EXTRACTOR
  13.  
  14. USAGE:
  15. php /path_to_php_file/index.php /path_to_logs/logs/file-custom_log what_to_search
  16.  
  17. $file -> in what file to search for $searchfor
  18. $searchfor -> what to search in $file
  19. */
  20. $file = $argv[1];
  21. $searchfor = $argv[2]; //Example can be %00 => NULLBYTE ATTACK or ../
  22.  
  23. $do_not_show_ip = array(
  24. ""
  25. ); //Define if you want to remove IPs from Extracted IPs
  26.  
  27.  
  28.  
  29. $contents = file_get_contents($file);
  30. $pattern = preg_quote($searchfor, '/');
  31. $pattern = "/^.*$pattern.*\$/m";
  32.  
  33. function pretty($arr)
  34. {
  35. $retStr = '';
  36. if (is_array($arr)) {
  37. foreach ($arr as $key => $val) {
  38. if (is_array($val)) {
  39. $retStr .= '
  40. ' . pretty($val) . '
  41. ';
  42. } else {
  43. $retStr .= '' . $val . '
  44. ';
  45. /*$retStr .= '
  46. ' . $key . ' => ' . pretty($val) . '
  47. ';
  48. }else{
  49. $retStr .= '
  50. ' . $key . ' => ' . $val . '
  51. ';
  52. */
  53. }
  54. }
  55. }
  56. $retStr .= '';
  57. return $retStr;
  58. }
  59.  
  60.  
  61. if (preg_match_all($pattern, $contents, $matches)) {
  62. echo " _____ _____ _ _____ _____ _____ _____ _____ _____
  63. ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
  64. |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
  65. |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
  66. |s C R i P T z - T E A M . i N F O|
  67.  
  68. [PHP] SERVER LOG SEARCHER WiTH iPs EXTRACTOR
  69.  
  70. Search results => Results for \$searchfor
  71. Extracted IPs => Extracted IPs from Search results
  72. _______________________________________________________________
  73.  
  74. /**************
  75. Search results:
  76. ***************/
  77.  
  78. ";
  79. echo implode("\n", $matches[0]);
  80. echo "\n\n";
  81. if (preg_match_all("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", implode("\n", $matches[0]), $matches)) {
  82. echo "
  83. /**************
  84. Extracted IPs:
  85. ***************/
  86.  
  87. ";
  88. echo str_replace($do_not_show_ip, "", pretty(array_unique($matches[0])));
  89. }
  90. } else {
  91. echo "No matches found";
  92. }
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment