• Welcome to Valhalla Legends Archive.
 

anti flood

Started by Tazo, March 25, 2005, 09:05 AM

Previous topic - Next topic

iago

Ah, cool.  I am kind of doing it the same way, except with no "600 point limit", just with being charged for each byte/packet.  I'll have to look into your way :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Tazo

how bout that anti-flood -.-

iago

Quote from: laurion on March 25, 2005, 11:48 PM
how bout that anti-flood -.-

Seems to me that there has been given more than enough information (from Adron and myself) to implement it yourself.  I'm actually probably going to implement Adron's tomorrow.  If I get it working well, I'll post it here :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Quote from: iago on March 26, 2005, 12:29 AM
Seems to me that there has been given more than enough information (from Adron and myself) to implement it yourself.  I'm actually probably going to implement Adron's tomorrow.  If I get it working well, I'll post it here :)

Remember that they added a new level of flood protection though. Mine is valid for a low number of messages, up to say .. 30? If you keep sending messages you'll run into the next level flood protection.

Soul Taker

Quote from: Adron on March 26, 2005, 07:02 AM
Quote from: iago on March 26, 2005, 12:29 AM
Seems to me that there has been given more than enough information (from Adron and myself) to implement it yourself.  I'm actually probably going to implement Adron's tomorrow.  If I get it working well, I'll post it here :)

Remember that they added a new level of flood protection though. Mine is valid for a low number of messages, up to say .. 30? If you keep sending messages you'll run into the next level flood protection.
I think your messages have to be over 67 bytes for that though?  Unsure, but I have stuff in place just in case, since it's never come up for me.

iago

I took a stab at implementing Adron's algorithm.  This is a fairly stripped down version of the class:


    private long lastSent = System.currentTimeMillis();
   
    private int credits;

.....

    public void activate()
    {
        credits = Integer.parseInt(out.getLocalSettingDefault(getName(), "starting credits", "200"));
    }
......
    public Properties getSettingsDescription()
    {
        Properties p = new Properties();
        p.put("debug", "This will show the current delay and the current number of credits each message, in case you want to find-tune it.");
        p.put("prevent flooding", "It's a very bad idea to turn this off -- if you do, it won't try to stop you from flooding.");
        p.put("cost - packet", "This is the amount of credits 'paid' for each sent packet.");
        p.put("cost - byte", "WARNING: I don't recommend changing ANY of the settings for anti-flood.  But if you want to tweak, you can.  This is the number of credits 'paid' for each byte.");
        p.put("cost - byte over threshold", "This is the amount of credits 'paid' for each byte after the threshold is reached.");
        p.put("starting credits", "This is the number of credits you start with.");
        p.put("threshold bytes", "This is the length of a message that triggers the treshold (extra delay).");
        p.put("max credits", "This is the maximum number of credits that the bot can have.");
        p.put("credit rate", "This is the amount of time (in milliseconds) it takes to earn one credit.");
       
        return p;
    }
   
    public Properties getDefaultSettingValues()
    {
        Properties p = new Properties();
        p.put("debug", "false");
        p.put("prevent flooding", "true");
        p.put("cost - packet", "200");
        p.put("cost - byte", "12");
        p.put("cost - byte over threshold", "20");
        p.put("starting credits", "200");
        p.put("threshold bytes", "65");
        p.put("max credits", "600");
        p.put("credit rate", "10");
       
        return p;
    }
........

    public long getDelay(String text, Object data)
    {
        if(out.getLocalSettingDefault(getName(), "prevent flooding", "true").equals("false"))
            return 0;
       
        boolean debug               = Boolean.parseBoolean(out.getLocalSettingDefault(getName(), "debug", "false"));
        int packetCost              = Integer.parseInt(out.getLocalSettingDefault(getName(), "cost - packet", "200"));
        int byteCost                = Integer.parseInt(out.getLocalSettingDefault(getName(), "cost - byte", "12"));
        int byteOverThresholdCost   = Integer.parseInt(out.getLocalSettingDefault(getName(), "cost - byte over threshold", "20"));
        int thresholdBytes          = Integer.parseInt(out.getLocalSettingDefault(getName(), "threshold bytes", "65"));
        int maxCredits              = Integer.parseInt(out.getLocalSettingDefault(getName(), "max credits", "600"));
        int creditRate              = Integer.parseInt(out.getLocalSettingDefault(getName(), "credit rate", "10"));
       
        // Add the credits for the elapsed time
        if(credits < maxCredits)
        {
            credits += (System.currentTimeMillis() - lastSent) / creditRate;
           
            if(credits > maxCredits)
            {
                if(debug)
                    out.systemMessage(DEBUG, "Maximum anti-flood credits reached (" + maxCredits + ")");
                credits = maxCredits;
            }
        }
       
        lastSent = System.currentTimeMillis();

        // Get the packet's "cost"
        int thisByteDelay = byteCost;
       
        if(text.length() > thresholdBytes)
            byteCost = byteOverThresholdCost;

        int thisPacketCost = packetCost + (thisByteDelay * text.length());

        if(debug)
            out.systemMessage(DEBUG, "Cost for this packet = " + thisPacketCost);

        // Check how long this packet will have to wait
        int requiredDelay = 0;
        // If we can't "afford" the packet, figure out how much time we'll have to wait
        if(thisPacketCost > credits)
            requiredDelay = (thisPacketCost - credits) * thisByteDelay;
       
        // Deduct this packet from the credits
        credits -= thisPacketCost;
       
        if(debug)
            out.systemMessage(DEBUG, "Remaining credits: " + credits + "; Delay: " + requiredDelay);
       
        System.out.println(requiredDelay);

        return requiredDelay;
    }


So far, it seems to be working pretty good.  I sent 250 packets of each of a variety of lengths, and it seemed to hold up (after tweaking the perByte time to 12 instead of 10).  And it's much faster than my old implementation :)

This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Networks


Option Explicit

'Original class created by iago
'Ported to VB6 by Networks
'
'http://www.zeroforce.net
'http://www.x86labs.org

Private Declare Function GetTickCount Lib "kernel32.dll" () As Long

Private lastSent                    As Long
Private Credits                     As Long
Private byteCost                    As Integer

Private Const packetCost            As Integer = 200
Private Const byteOverThresholdCost As Integer = 20
Private Const thresholdBytes        As Integer = 65
Private Const maxCredits            As Integer = 600
Private Const creditRate            As Integer = 10

Private Sub Class_Initialize()
    Credits = 200
    byteCost = 12
    lastSent = GetTickCount()
End Sub

Public Function getDelay(ByVal strText As String) As Long
   
    'Add credits for elasped time
    If (Credits < maxCredits) Then
        Credits = Credits + ((GetTickCount() - lastSent) / creditRate)
       
        If (Credits > maxCredits) Then
            'Maximum anti-flood credits reached
            Credits = maxCredits
        End If
    End If
   
    lastSent = GetTickCount()
   
    'Get the packet's "cost"
    Dim thisByteDelay As Integer
    thisByteDelay = byteCost
   
    If (Len(strText) > thresholdBytes) Then
        byteCost = byteOverThresholdCost
    End If
   
    Dim thisPacketCost As Integer
    thisPacketCost = packetCost + (thisByteDelay * Len(strText))
   
    'Check how long this packet will have to wait
    Dim requiredDelay As Long
    requiredDelay = 0
   
    'If we can't "afford" the packet, figure out how much time we'll have to wait
    If (thisPacketCost > Credits) Then
        requiredDelay = (thisPacketCost - Credits) * thisByteDelay
    End If

    'Deduct this packet from the credits
    Credits = Credits - thisPacketCost
   
    getDelay = requiredDelay
End Function


Ported to Visual Basic 6.0. Have fun kids.

Blaze

I was porting it for my bot then I fell asleep. :P
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Tazo

Blaze, where is the perByte//BytesPerMS or w/e u wanna call it in that/? Using the one that you ported blaze, it does not work very well with repeated short messages.