Author Topic: Lat Trick Bot  (Read 46568 times)

Offline Delete mine too

  • Death Knight
  • *********
  • Posts: 2652
  • http://meatspin.com
    • View Profile
    • http://meatspin.com
Re: Lat Trick Bot
« Reply #60 on: May 23, 2018, 10:19:31 PM »
Nice work tupac
I actually found it on a StarCraft site and said i bet it works here and it did yay!

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: Lat Trick Bot
« Reply #61 on: May 24, 2018, 01:41:13 PM »
BAHAHAHAHA

The little noob has put parts of my email address in his post LOLOLOL That's what all the weird capitol letters are in his last post.

ooooo scary, what are you going to do phishing scam me?

Everybody already knows you pulled the SQL db from the server years ago. Then you got locked out because you bragged about it like the little wannabe script kiddie that you are and now you're trying to scam your way back in.

Are you actually trying to threaten me with my email address? ;D ROTF


the nat stats arent even a necessary component of the program so take it or leave it.

DUH. My point EXACTLY. So leave it.

you should know we know much more than just your nat type lmao jeez quit trippin. no need for the nasty Gram

Who is "we"?  .... you and your mom?

Point proven - this guy is a complete dick.
its gooder to hax hard and NEVER get caught!

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: Lat Trick Bot
« Reply #62 on: May 24, 2018, 05:13:50 PM »
Ok here is the whole entire thing:
tried that, looks like not working as is.

nat_type, external_ip, external_port = stun.get_ip_info("0.0.0.0", war2_port)
Not working after you join bnet (returns "blocked").
You should check that before join bnet, then it's fine.
Not a big deal now.

And the big problem:
      # create a socket object
      client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      client.bind(('0.0.0.0', war2_port))

      # send some data
      client.sendto("For the Alliance", (target_host, war2_port))
      print "Sent data to " + str(player_ip) + " on port " + str(war2_port)
causes disconnect after i join the game, build TH and then building the farm or barracks (checked twice).
I still didn't try to host the game as i didn't get real list of ips.

My player_ips.php is: {"player_ips": ["45.33.94.234", "2.2.2.2", "3.3.3.3"]}

I think my router becomes confused about too many outgoing UDP from the same port to different addresses or w/e.

Also, i changed Game Data Port to 6113 to not reconfigure nat redirections on my router. Here's my code then:
Code: [Select]
war2_client_port = 6113
war2_remote_port = 6112
...
      client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      client.bind(('0.0.0.0', war2_client_port))
      client.sendto("For the Alliance", (target_host, war2_remote_port))
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: Lat Trick Bot
« Reply #63 on: May 24, 2018, 07:10:06 PM »
Ok here is the whole entire thing:
tried that, looks like not working as is.

nat_type, external_ip, external_port = stun.get_ip_info("0.0.0.0", war2_port)
Not working after you join bnet (returns "blocked").
You should check that before join bnet, then it's fine.
Not a big deal now.

And the big problem:
      # create a socket object
      client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      client.bind(('0.0.0.0', war2_port))

      # send some data
      client.sendto("For the Alliance", (target_host, war2_port))
      print "Sent data to " + str(player_ip) + " on port " + str(war2_port)
causes disconnect after i join the game, build TH and then building the farm or barracks (checked twice).
I still didn't try to host the game as i didn't get real list of ips.

My player_ips.php is: {"player_ips": ["45.33.94.234", "2.2.2.2", "3.3.3.3"]}

I think my router becomes confused about too many outgoing UDP from the same port to different addresses or w/e.

Also, i changed Game Data Port to 6113 to not reconfigure nat redirections on my router. Here's my code then:
Code: [Select]
war2_client_port = 6113
war2_remote_port = 6112
...
      client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      client.bind(('0.0.0.0', war2_client_port))
      client.sendto("For the Alliance", (target_host, war2_remote_port))

It is very simple.

WC2 worked before NAT. WC2 works over NAT. There is no problem there.
You don't need STUN. This is just the noob getting excited about stuff he read online that he doesn't actually understand.

You don't need to reverse the NAT address translation, just allow NAT to function the way it is designed.

You only need to send packets from host before game starts.

You only need to send packets to people in the channel.

That is all.
its gooder to hax hard and NEVER get caught!

Offline AHB

  • Grunt
  • ***
  • Posts: 50
    • View Profile
Re: Lat Trick Bot
« Reply #64 on: May 24, 2018, 07:29:56 PM »
@iL

Thanks for checking it out! I know we are close. Just ignore @Lambchops hes a dumbass

I think I see your problem ! I think it is because you are sending traffic to the REMOTE port. The "remote port" variable should actually be your LOCAL port, not remote port.

I know its confusing but there is a reason -- you need to send traffic to the remote host:local port, that way the connection is opened for the remote host to reply on your LOCAL port. They dont need to reply on their own port. Also, the traffic we are sending them we dont care that they dont ever receive it, we are just tricking out own firewall (not theirs) make sense? Try again with that and let me know if it works

Like this

war2_client_port = 6113
# war2_remote_port = 6112 -- this is not needed at all
...
      client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      client.bind(('0.0.0.0', war2_client_port))
      client.sendto("For the Alliance", (target_host, war2_client_port))

« Last Edit: May 24, 2018, 09:14:16 PM by AHB »

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: Lat Trick Bot
« Reply #65 on: May 25, 2018, 04:29:14 AM »
You don't need STUN. This is just the noob getting excited about stuff he read online that he doesn't actually understand.
Of course STUN is not something necessary, it's just an option to check the NAT type. Not a big deal as i said.

You don't need to reverse the NAT address translation, just allow NAT to function the way it is designed.

You only need to send packets from host before game starts.

You only need to send packets to people in the channel.
That will be a plan for future, as a 1-st step it's easier to send packets all the time.

And it causes disconnect, no idea why, but that's unacceptable behavior even if i sent them in wrong time and to wrong ips.

I think I see your problem ! I think it is because you are sending traffic to the REMOTE port. The "remote port" variable should actually be your LOCAL port, not remote port.

I know its confusing but there is a reason -- you need to send traffic to the remote host:local port, that way the connection is opened for the remote host to reply on your LOCAL port. They dont need to reply on their own port. Also, the traffic we are sending them we dont care that they dont ever receive it, we are just tricking out own firewall (not theirs) make sense? Try again with that and let me know if it works
I didn't understan your logic, well:
my Game Data Port is 6113, your Game Data Port is 6112, my external ip is 1.1.1.1, your external ip is 2.2.2.2
I host the game behind NAT on my local computer internal ip 192.168.1.1:6113, i need to make you connect from your 2.2.2.2:6112 to my 1.1.1.1:6113.
How to do that? I apply lat trick: send UDP packet to the opposite side: from my 192.168.1.1:6113 to 2.2.2.2:6112, right?
Then my (full cone) NAT translates it: you receive packet from my 1.1.1.1:6113 to 2.2.2.2:6112. Also my router keeps temporary rule: to wait answers to that packet.
When you try to connect from your 2.2.2.2:6112 to my 1.1.1.1:6113, my router thinks it's the answer to that packet and NAT's it to my internal host: 192.168.1.1:6113, right?

So, you offer to send packet from my 192.168.1.1:6113 to your 2.2.2.2:6113? Though your client listens on 2.2.2.2:6112? Looks senseless for me.

Another idea:
We open the socket:  client.bind(('0.0.0.0', war2_client_port))
Also, war2 client opens the same socket.

Who will receive packets incoming to war2_client_port? Our script or war2? Who will be more lucky?
Maybe we should close our socket right after we sent our packets?
What do you think about that?

Not a guarantee (as we can get packets while sending packets), but should become much better as for me.
Code: [Select]
...
      client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      client.bind(('0.0.0.0', war2_client_port))
      client.sendto("For the Alliance", (target_host, war2_remote_port))
      client.close() # or how to write that on python, i don't know it's syntax

UPDATE:
just got that:
Socket close is not closing the socket immediately or something like that, it goes into the TIME_WAIT instead: https://stackoverflow.com/questions/22549044/why-is-port-not-immediately-released-after-the-socket-closes
They say about SO_REUSEADDR, but that is not we need. Our task is not to catch even sinlge packet destined to war2.
How to do that? I'm not so good in network technologies. I'd say the proper way is to inject into war2 network functions. Or probably to listen our Game Data Port and copy all these traffic to war2 process (also, how to do that?)
UPDATE2:
additional info:
socket abort should guarantee to free the socket immediately. Depends on OS/language. Sometimes you have to set "linger off" or w/e and then repeat close.
Not sure if it's actual for UDP, maybe for TCP only.

Anyways, we have to control every socket function succeeded. In our situation you can never be sure your client.bind or sendto succeeded.
@AHB, can you add checking all the possible return errors in your code?
Something like:
Code: [Select]
      try:
        client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      except Exception as e:
        print e
      try:
        client.bind(('0.0.0.0', war2_client_port))
      except Exception as e:
        print e
Fix the code plz, i'm not good in programming and don't know python at all.
« Last Edit: May 25, 2018, 06:04:01 AM by iL »
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: Lat Trick Bot
« Reply #66 on: May 25, 2018, 05:03:57 AM »
One more: i didn't try to host the game from internal ip behind NAT. What i just tried is to join and play the game from NAT'ed network.
Usually i can't host with closed ports, but i can join and play.
When i tried to join and play after running udp_hole_punch.exe, i got disconnected after about 1-2 min after game start.
Tried twice.
Then i stopped udp_hole_punch.exe, tried next time, and played successfully.
So, the problem is not related to wrong ports or w/e, it means udp_hole_punch.exe crashes existing connections.
« Last Edit: May 25, 2018, 06:07:33 AM by iL »
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline AHB

  • Grunt
  • ***
  • Posts: 50
    • View Profile
Re: Lat Trick Bot
« Reply #67 on: May 25, 2018, 08:57:32 AM »
@iL

Your definition of how remote port and local port is correct actually, you are right that is how it works.

So we are able to port forward now, but possibly the problem is that Python is intercepting packets destined for War2 causing the game to disconnect. I will have to think about this...

My first idea is to try changing the "binding" IP address. 0.0.0.0 means to listen on all interfaces, but we don't actually want to listen on any interfaces.. not sure what to do. I will keep testing


I can add error checking so that if a socket fails it keeps trying instead of crashing

Offline AHB

  • Grunt
  • ***
  • Posts: 50
    • View Profile
Re: Lat Trick Bot
« Reply #68 on: May 25, 2018, 09:08:36 AM »
@iL

I updated the code below to shutdown and close the socket each time. From what I read, shutdown will fix that TIME_WAIT issue, releasing it immediately.

I also implemented a basic error check, and will skip to the next player in the list if an error occurs instead of crashing out

Let me know if this works for you. I will test also

import _winreg
import stun
import requests
import socket
import time
import json

def get_war2_port():
    # Open the key and return the handle object
    hKey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\Battle.net\Configuration")
    # Read the value
    try:
      result = _winreg.QueryValueEx(hKey, "Game Data Port")
    # If not found, set to default
    except Exception as e:
      print e
      result = [6112]
    # Return port
    return result[0]

war2_port = get_war2_port()
nat_type, external_ip, external_port = stun.get_ip_info("0.0.0.0", war2_port)
req = requests.get('https://war2.info/nat_stats.php?nat_type=' + str(nat_type))

if nat_type != "Sytmmetric NAT":
  while True:
    time.sleep(10)
    req = requests.get('https://war2.info/player_ips.php')
    json_obj = json.loads(req.content)
    player_ip_list = json_obj["player_ips"]
    print player_ip_list
    for player_ip in player_ip_list:
      try:
        # Target host is IP of player you want to be able to join your game
        target_host = player_ip

        # create a socket object
        client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        client.bind(('0.0.0.0', war2_port))

        # send some data
        client.sendto("For the Alliance", (target_host, war2_port))
        client.shutdown()
        client.close()
        print "Sent data to " + str(player_ip) + " on port " + str(war2_port)
      except Exception as e:
        print e


Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: Lat Trick Bot
« Reply #69 on: May 25, 2018, 10:27:44 AM »
My code (with local and remote ports and debug prints):

Code: [Select]
...
    for player_ip in player_ip_list:
      try:
        # Target host is IP of player you want to be able to join your game
        target_host = player_ip

        # create a socket object
        client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        client.bind(('0.0.0.0', war2_client_port))

        # send some data
        client.sendto("For the Alliance", (target_host, war2_remote_port))
        print "Shutting down socket"
        client.shutdown()
        print "Closing socket"
        client.close()
        print "Sent data to " + str(player_ip) + " from port" + str(war2_client_port) + " on port " + str(war2_remote_port)
      except Exception as e:
        print e

Stdout:
Code: [Select]
getting ips
[u'45.33.94.234', u'2.2.2.2', u'3.3.3.3']
Shutting down socket
shutdown() takes exactly one argument (0 given)
[Errno 10048] Обычно разрешается только одно использование адреса сокета (протокол/сетевой адрес/порт)
Shutting down socket
shutdown() takes exactly one argument (0 given)
getting ips
[u'45.33.94.234', u'2.2.2.2', u'3.3.3.3']
[Errno 10048] Обычно разрешается только одно использование адреса сокета (протокол/сетевой адрес/порт)
Shutting down socket
shutdown() takes exactly one argument (0 given)
[Errno 10048] Обычно разрешается только одно использование адреса сокета (протокол/сетевой адрес/порт)
getting ips
[u'45.33.94.234', u'2.2.2.2', u'3.3.3.3']
...
Sorry for russian windows, that means soemting like:
"Usually only 1 usage of socket address allowed (protocol/network address/port)".

No idea what command it related to.
« Last Edit: May 25, 2018, 10:35:10 AM by iL »
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline AHB

  • Grunt
  • ***
  • Posts: 50
    • View Profile
Re: Lat Trick Bot
« Reply #70 on: May 25, 2018, 10:32:09 AM »
client.shutdown(socket.SHUT_RDWR)

shuts down read and write on the socket

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: Lat Trick Bot
« Reply #71 on: May 25, 2018, 10:39:01 AM »
client.shutdown(socket.SHUT_RDWR)
Well, no errors now.
I'll check how it will work on the server
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: Lat Trick Bot
« Reply #72 on: May 25, 2018, 11:20:36 AM »
Adding real list of ips:
1. @AHB, can you update your script to add port to each ip into that json?
like that:
{"player_ips": [{"ip":"1.2.3.4","port":"6112"},{"ip":"5.6.7.8","port":"6112"}]}

2. my stuff becomes to know UDP port only when player hosts the game. Looks like there's no way to know Game Data port from the server side until he hosts the game.
Now let's suppose some fixed value (like 6112 or w/e) for every client.

So, for future, our logic should be more complicated. Looks like we have to read game data port for each client or check the port from hosted game.
Sad, but looks like there's no way to know UDP port for original client with no lat bots even if his ports are fine.

I mean, lets consider:
- i'm good old player with all ports forwarded/configured, i have no problems with hosting games at all. And my port is modified, not 6112. Everything works for me. I don't want to run any additional software on my side.
- you have problems with ports forwarding, you want to use UDP hole punch to host the game.
You have no way to know my Game Data Port if i didn't host the game. You have to enforce me to run some kind of software to send my port to you.
« Last Edit: May 25, 2018, 11:31:48 AM by iL »
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.

Offline AHB

  • Grunt
  • ***
  • Posts: 50
    • View Profile
Re: Lat Trick Bot
« Reply #73 on: May 25, 2018, 12:01:21 PM »
@iL

I dont think we need to know the remote player's port at all, just send from your own port, then your router will hold open the connection from your local port to the external IP and allow a response back from external IP to  your game port

Say remote host has port 6113, but person hosting the game has port 6112:

Host sends a packet to remote-host:6112 (it doesnt know that remote player port is actually 6113)
Hosts router opens a connection and listens for player to respond on port 6112
Player's router receives the packet, sees that it is for port 6112 and not 6113, so it drops it and ignores it
Player's War2 client knows to join the host's game on his port, 6112, because pvpgn told him that
So Player sends traffic to Host on port 6112
Host's router has a connection open to Player already on port 6112, so it allows the response traffic to come through

Do you see that we dont need to know the remote port? Only use the local game port as both the source and destination

Offline AHB

  • Grunt
  • ***
  • Posts: 50
    • View Profile
Re: Lat Trick Bot
« Reply #74 on: May 25, 2018, 12:06:08 PM »
The program is already working the way that I described (not knowing the remote port):


This is the code that is sending data to the wrong port for the player, but it should still trick his router to allow that player to join the game :)
 client.sendto("For the Alliance", (target_host, war2_port))