OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Minecraft TCP Socket Connection

  • Thread starter Thread starter Gabriel Jungles
  • Start date Start date
G

Gabriel Jungles

Guest
I'm trying to make a MITM to check the packages passed by the Minecraft client and the server, but I'm having a bit of a problem.

There don't seem to be any connection problems, I'm passing a proxy locally on the client and trying to connect by forcing the traffic to pass through it, the client responds normally but there's no response from the server and the client ends up discounting due to the lack of response from the server

Code:
import socket
from threading import Thread


class Proxy2Server(Thread):
    def __init__(self, host, port):
        super(Proxy2Server, self).__init__()
        self.game = None
        self.port = port
        self.host = host
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.connect((host, port))

    def run(self):
        while True:
            data = self.server.recv(4096 * 8 * 8 * 8)

            if len(data) == 0:
                print("Server Close the Connection")
                break

            self.game.send(data)
            print(f"Server Data: {data}")

class Game2Proxy(Thread):
    def __init__(self):
        super(Game2Proxy, self).__init__()
        self.server = None

    def run(self):
        while True:
            data = self.game.recv(4096 * 8 * 8 * 8)

            if len(data) == 0:
                print("Game Close the Connection")
                break

            self.server.send(data)
            print(f"Game Data: {data}")

class Proxy(Thread):
    def __init__(self, from_host, to_host, target_port, listen_port):
        super(Proxy, self).__init__()
        self.from_host = from_host
        self.to_host = to_host
        self.target_port = target_port
        self.listen_port = listen_port

    def run(self):

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind((self.from_host, self.listen_port))
        sock.listen(5)

        print(f"Proxy Listening in {self.listen_port}")

        while True:
            self.g2p = Game2Proxy()
            self.p2s = Proxy2Server(self.to_host, self.target_port)

            self.g2p.server = self.p2s.server

            connection, addr = sock.accept()
            self.p2s.game = connection
            self.g2p.game = connection

            print(f'Accepted connection from {addr[0]}:{addr[1]}')

            self.g2p.start() 
            self.p2s.start()

master_server = Proxy('0.0.0.0', '0.0.0.0', 25565, 5555)
master_server.start()

Output
<p>I'm trying to make a MITM to check the packages passed by the Minecraft client and the server, but I'm having a bit of a problem.</p>
<p>There don't seem to be any connection problems, I'm passing a proxy locally on the client and trying to connect by forcing the traffic to pass through it, the client responds normally but there's no response from the server and the client ends up discounting due to the lack of response from the server</p>
<pre><code>import socket
from threading import Thread


class Proxy2Server(Thread):
def __init__(self, host, port):
super(Proxy2Server, self).__init__()
self.game = None
self.port = port
self.host = host
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server.connect((host, port))

def run(self):
while True:
data = self.server.recv(4096 * 8 * 8 * 8)

if len(data) == 0:
print("Server Close the Connection")
break

self.game.send(data)
print(f"Server Data: {data}")

class Game2Proxy(Thread):
def __init__(self):
super(Game2Proxy, self).__init__()
self.server = None

def run(self):
while True:
data = self.game.recv(4096 * 8 * 8 * 8)

if len(data) == 0:
print("Game Close the Connection")
break

self.server.send(data)
print(f"Game Data: {data}")

class Proxy(Thread):
def __init__(self, from_host, to_host, target_port, listen_port):
super(Proxy, self).__init__()
self.from_host = from_host
self.to_host = to_host
self.target_port = target_port
self.listen_port = listen_port

def run(self):

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((self.from_host, self.listen_port))
sock.listen(5)

print(f"Proxy Listening in {self.listen_port}")

while True:
self.g2p = Game2Proxy()
self.p2s = Proxy2Server(self.to_host, self.target_port)

self.g2p.server = self.p2s.server

connection, addr = sock.accept()
self.p2s.game = connection
self.g2p.game = connection

print(f'Accepted connection from {addr[0]}:{addr[1]}')

self.g2p.start()
self.p2s.start()

master_server = Proxy('0.0.0.0', '0.0.0.0', 25565, 5555)
master_server.start()
</code></pre>
<p><a href="https://i.sstatic.net/kT73HTb8.png" rel="nofollow noreferrer">Output</a></p>
 

Latest posts

A
Replies
0
Views
1
AgencyAnalytics
A
S
Replies
0
Views
1
Stacker Media
S
C
Replies
0
Views
1
CC.Talent
C
Top