Advertisement
Rei_Ayanami

anti ddos

Mar 24th, 2022
1,584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Anti DDoS Attack Filterscript by Jankingston. Feel free to modify ;)
  2.  
  3. #include <a_samp>
  4. #include <FileFunctions>
  5.  
  6. #define ATTACK_TYPE_PLAYERID 1
  7. #define ATTACK_TYPE_IP 2
  8.  
  9. new File:ServerLogFile;
  10. new addostimer;
  11.  
  12. main()
  13. {
  14.     print("|----------------------------------|");
  15.     print("| Anti DDOS filterscript v0.1      |");
  16.     print("|----------------------------------|");
  17. }
  18.  
  19. public OnFilterScriptInit()
  20. {
  21.     ServerLogFile = fileOpen("server_log.txt", io_Read);
  22.     addostimer = SetTimer("Anti-DDoS", 100, true);
  23.     return 1;
  24. }
  25.  
  26. public OnFilterScriptExit()
  27. {
  28.     KillTimer(addostimer);
  29.     return 1;
  30. }
  31.  
  32. forward AntiDDoS();
  33. public AntiDDoS()
  34. {
  35.     if(!ServerLogFile)
  36.     {
  37.         print("Error opening server_log.txt!");
  38.         KillTimer(addostimer);
  39.     }
  40.     else
  41.     {
  42.         new string[128];
  43.         new strarr[2][20];
  44.         fileSeek(ServerLogFile, -128, seek_End);
  45.         while(fileRead(ServerLogFile, string)){}
  46.  
  47.         new pos = strfind(string, "Invalid client connecting from ", true, 10);
  48.         if(pos == 11)
  49.         {
  50.             OnDDosAttackAttempt(ATTACK_TYPE_IP, INVALID_PLAYER_ID, string[pos+31]);
  51.         }
  52.  
  53.         pos = strfind(string, "Warning: /rcon command exploit from: ", true, 10);
  54.         if(pos == 11){
  55.             split(string[pos+37], strarr, ':');
  56.             OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strarr[0]), strarr[1]);
  57.         }
  58.  
  59.         pos = strfind(string, "Warning: PlayerDialogResponse PlayerId: ", true, 10);
  60.         if(pos == 11){
  61.  
  62.             new idx = 0;
  63.             new plid = strval(strtok(string[pos+39], idx));
  64.             SetPVarInt(plid, "dialogDDosAtt", GetPVarInt(plid, "dialogDDosAtt")+1);
  65.             print("");
  66.             if(GetPVarInt(plid, "dialogDDosAtt") > 2)OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, plid, " ");
  67.         }
  68.  
  69.         pos = strfind(string, "Warning: PlayerDialogResponse crash exploit from PlayerId: ", true, 10);
  70.         if(pos == 11){
  71.             new idx = 0;
  72.             OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strtok(string[pos+59], idx)), " ");
  73.         }
  74.  
  75.         pos = strfind(string, "Packet was modified, sent by id: ", true, 10);
  76.         if(pos == 11){
  77.             split(string[pos+33], strarr, ',');
  78.             OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strarr[0]), " ");
  79.         }
  80.  
  81.         pos = strfind(string, "Remote Port Refused for Player: ", true, 10);
  82.         if(pos == 11){
  83.             new idx = 0;
  84.             OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strtok(string[pos+32], idx)), " ");
  85.         }
  86.  
  87.         if(strfind(string, " due to a 'server full' attack") != -1)
  88.         {
  89.             pos = strfind(string, "Blocking ", true, 10);
  90.             if(pos == 12)
  91.             {
  92.                 new idx = 0;
  93.                 OnDDosAttackAttempt(ATTACK_TYPE_IP, INVALID_PLAYER_ID, strtok(string[pos+9], idx));
  94.             }
  95.         }
  96.     }
  97. }
  98.  
  99. forward OnDDosAttackAttempt(type, playerid, ip[]);
  100. public OnDDosAttackAttempt(type, playerid, ip[])
  101. {
  102.     new string[128];
  103.     if(type == ATTACK_TYPE_PLAYERID)
  104.     {//block a playerid
  105.         BanEx(playerid, "DDOS protect");
  106.         printf("Blocked attack from playerid %d", playerid);
  107.  
  108.     }else if(type == ATTACK_TYPE_IP)
  109.     {//block an ip address
  110.         format(string, sizeof(string), "banip %s", ip);
  111.         SendRconCommand(string);
  112.         printf("Blocked attack from ip: %s", ip);
  113.     }
  114.  
  115. }
  116.  
  117. stock strtok(const string[], &index)
  118. {
  119.     new length = strlen(string);
  120.     while ((index < length) && (string[index] <= ' '))
  121.     {
  122.         index++;
  123.     }
  124.  
  125.     new offset = index;
  126.     new result[20];
  127.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  128.     {
  129.         result[index - offset] = string[index];
  130.         index++;
  131.     }
  132.     result[index - offset] = EOS;
  133.     return result;
  134. }
  135.  
  136. stock split(const strsrc[], strdest[][], delimiter)
  137. {
  138.     new i, li;
  139.     new aNum;
  140.     new len;
  141.     while(i <= strlen(strsrc)){
  142.         if(strsrc[i]==delimiter || i==strlen(strsrc)){
  143.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  144.             strdest[aNum][len] = 0;
  145.             li = i+1;
  146.             aNum++;
  147.         }
  148.         i++;
  149.     }
  150.     return 1;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement