-2

im currently trying to make it where my minecraft server has a reverse proxy that mostly shields it against ddos attacks and recently i have found a proxy i can host on my computer called proxy.py im getting help from chat gpt to make the proxy as ive never done this kind of stuff before chat gpt helped me to make a plugin that detects traffic coming from a minecraft client and redirect them to my minecraft server ive finnaly managed to make the code work so then i start the proxy server seems to star without error i have it where the port of the proxy is port forwarded and not the port of my minecraft server i have the proxy started on 0.0.0.0 to listen for all possible connection but when i try to have my friend connect it disconnects and says cant connect to server disconneted

the github for the proxy.py is: https://github.com/abhinavsingh/proxy.py

the code for the plugin is

import re
from typing import List, Tuple, Union

from ..http import Url
from ..http.parser import HttpParser
from ..http.server import ReverseProxyBasePlugin
from ..common.types import RePattern
from ..http.exception.base import HttpProtocolException

class DDoSProtectedReverseProxyPlugin(ReverseProxyBasePlugin):
    def __init__(self):
        self.ddos_threshold = 1000  # Adjust this threshold as needed
        self.ip_request_counts = {}

    def should_redirect_to_minecraft(self, client_ip: str) -> Tuple[bool, str]:
        if client_ip in self.ip_request_counts:
            self.ip_request_counts[client_ip] += 1
            if self.ip_request_counts[client_ip] <= self.ddos_threshold:
                return True, "internal-ip:port"  # Your internal Minecraft server IP and port
            else:
                return False, "loopback-ip:port"  # Redirect to local server to absorb the attack
        else:
            self.ip_request_counts[client_ip] = 1
            return True, "public-ip:port"  # Your external Minecraft server IP and port

    def routes(self) -> List[Union[str, Tuple[str, List[bytes]]]]:
        return [
            (
                r'/get$',
                [b'http://httpbin.org/get', b'https://httpbin.org/get'],
            ),
            r'/get/(\d+)$',
        ]

    def handle_route(self, request: HttpParser, pattern: RePattern) -> Url:
        client_ip = request.client
        should_redirect, target_server = self.should_redirect_to_minecraft(client_ip)
        choice: Url = Url.from_bytes(f'http://{target_server}'.encode())
        choice.remainder = request.path
        return choice

i replace the ip's and ports with letters for security reasons

also the command i use to start the proxy is proxy --hostname 0.0.0.0 --port (port is here) --plugin proxy.plugin.reverse_proxy.ReverseProxyPlugin

im replacing ports and ips cuz im trying to protect myself sorry

poop face
  • 1
  • 3

0 Answers0