Advertisement
Guest User

Untitled

a guest
May 20th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <?php
  2.  
  3. # DDoS Detection & Packet Capture Script
  4. # Written by Robert 'xnite' Whitney
  5. # Website: http://xnite.org
  6. # Email: xnite@xnite.org
  7.  
  8. # Run script as root via crontab every 5 to 10 minutes
  9. # Ensure all dependences are satisfied before running this script (ifstat, tcpdump, php)
  10. # This script will only allow a single tcpdump process to run at once
  11.  
  12. # Configuration
  13. $CONFIG = [
  14. 'device' => 'eth0', //Usually eth0, if you are unsure, you can find the device name by running ifconfig.
  15. 'report_speed' => '15', //MBps that you want to start tracking at.
  16. 'packets2capture' => '1000', //Number of packets to capture in pcap dump.
  17. 'save_to' => '/var/log/ddos' //Path to save ddos pcap logs to without the trailing /.
  18. ];
  19.  
  20. while (true){
  21. # Do not edit below this line!
  22. exec("/usr/bin/ifstat .5 1 | /bin/grep -o '[0-9]\{1,9\}\.[0-9]\{1,9\}'", $iospeed);
  23. $report_speed = $CONFIG['report_speed']*1024;
  24. $ts = date('U');
  25. $folder = $CONFIG['save_to'];
  26. $interface = $CONFIG['device'];
  27. $packnum = $CONFIG['packets2capture'];
  28. if($iospeed[0]+$iospeed[1] >= $CONFIG['report_speed']*1024) {
  29. echo $iospeed[0]+$iospeed[1]." is equal to or greater than $report_speed.\n";
  30. echo "Capturing tcpdump.\nPackets: $packnum\nInterface: $interface\n Saving to: $folder/$ts.ddos.pcap\n";
  31. exec("/usr/bin/pkill -9 tcpdump");
  32. exec("/usr/sbin/tcpdump -nn -i $interface -s 0 -c $packnum -w $folder/$ts.ddos.pcap");
  33. } else {
  34. echo $iospeed[0]+$iospeed[1]." is less than $report_speed.\n";
  35. }
  36.  
  37. sleep(1);
  38. }
  39.  
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement