Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^5: Querying program port

by jcb (Vicar)
on Aug 11, 2019 at 07:28 UTC ( #11104275=note: print w/replies, xml ) Need Help??

in reply to Re^4: Querying program port
in thread Querying program port

I did not say that I am uncomfortable with this. At this point I'm asking exactly what steps are involved. The descriptions that you have given appear to be incomplete. As I understand, most game servers speak various binary protocols, so simply sending "status" to a UDP(!) port is unlikely to do anything useful. What program are you typing "status" into?

Please read carefully and ask your friend if he has tried netstat.

Replies are listed 'Best First'.
Re^6: Querying program port
by CougarXR7 (Acolyte) on Aug 11, 2019 at 15:32 UTC

    "What program are you typing "status" into?"< status is not being typed into a program
    but a Ubuntu terminal after the ip&port has been entered.
    The same terminal that would run this script.
    Sir, I owe you 2 apologies,
    1. I was told the query was UDP but they are wrong it's TCP.
    2. It's a game server status query and not player stats.
    I ran a different game on my main computer with win10.
    To my right is my Ubuntu box, accessing a terminal I typed in my ip and game's UDP port,
    it returned nothing, changed port to TCP and got server info:
    \gamename\JetFighter\gamever\0.9\location\1\hostname\Cats Lair\hostport\8181\mapname\Armed Bandits
    teamplay\0\player_0\Cougar\frags_0\0\deaths_0\0\skill_0\0\ping_0\0\team_0\Team 0\final\\queryid\3.1
    Do you have access to a terminal? , "nc 27900 -u" enter without quotes, then enter \status\ , you'll get game server info.
    I used netstat, comparing before running my friend's game server and while running the game server.
    Using the ports that showed up while running the server still returned nothing.
    Having a terminal run script named, (script name, example:)
    Script runs with printing data on terminal to show terminal is running script.
    "ip port"/ enter
    \status\ enter
    Server returns/replies, exiting script, printing info on terminal.
    NO return/reply, script must access "ctrl+c" to start a terminal new session.
    inc port by 1.
    Now with the same ip and a new port number (inc by 1) entered in a new terminal session followed by \status\
    This continues until game server replies to the query.
    I hope I cleared up anymore questions you have, if not please ask away!
    Friday I ordered the book from amazon "Learning Perl", not sure how many years it will take me but I will try!
    Sir, I cannot thank you enough for helping me! Thank you!
    Should you decide to write this script, you can use "333networks" query to test it. Starting with port 27895, watch it inc on terminal until it incs to 27900, and get a return/reply.

      Here is a Perl solution that not only indicates which port answered, but also decodes that backslash-delimited blob into a nicely formatted list.

      This script takes full advantage of UDP by sending all of the queries before attempting to read a response.

      #!/usr/bin/perl # A simple tool to find a UDP server on a known host, adapted from an # example in perlipc. The server speaks a strange protocol. # This script is free software; you can redistribute it and/or modify +it # under the same terms as Perl itself. use strict; use warnings; use Socket; # Configuration my $HOST_ADDR = ''; my @PORTS = (27895 .. 27905); my $TIMEOUT = 3.0; # seconds # Translate network addresses my $Host = inet_aton $HOST_ADDR; my $UDP_Protocol = getprotobyname 'udp'; # Open socket socket(SOCKET, PF_INET, SOCK_DGRAM, $UDP_Protocol) or die "socket: $!" +; # Go! foreach my $port (@PORTS) { defined(send(SOCKET, qq[\\status\\], 0, sockaddr_in($port, $Host))) or die "send: $!" } # Any replies within timeout period? my @Reports = (); # each element: [$sockaddr, $data] my $Start_time = time; my $rout; my $rin = ''; vec($rin, fileno(SOCKET), 1) = 1; while ((time < ($Start_time + 2*$TIMEOUT)) && (select($rout = $rin, undef, undef, $TIMEOUT))) { my $remote_sockaddr; my $report; ($remote_sockaddr = recv(SOCKET, $report, 4096, 0)) or die "recv: $! +"; push @Reports, [$remote_sockaddr, $report]; } # Parse and pretty-print unless (scalar @Reports) { print "No responses received.\n"; exit 1 } foreach my $report (@Reports) { my ($remote_port, $remote_address) = sockaddr_in $report->[0]; my @rows = (); # cannot use hash due to duplicate keys { local $_ = $report->[1]; # \---- $1: key $2: value ----\ while (m/\\([^\\]+)\\([^\\]*)(?=\\|\z)/gs) { push @rows, [$1, $2] +} } my $namewidth = 0; foreach my $row (@rows) { $namewidth = length $row->[0] if length $row->[0] > $namewidth } print "Response from port $remote_port:\n"; printf ' %*s: %s%s', $namewidth, @$_, "\n" for @rows; } exit 0 __END__

      Sample output:

      Response from port 27900: gamename: 333networks gamever: MS-perl 2.4.3 location: 0 queryid: 72.1 hostname: (The Errorist Network Master Server) hostport: 28900 gametype: MasterServer mapname: 333networks numplayers: 14 maxplayers: 2965 gamemode: openplaying queryid: 72.2 mutators: 333networks synchronization, UCC Master applet synchron +ization, Server Status Checker AdminName: Syntax-Error AdminEMail: queryid: 72.3 final:

      Your homework assignment is to learn enough of Perl to explain how this script works. I have used some odd features and deliberately written parts of the script to illustrate some features of Perl that I would not have used if this were not intended as a teaching aid. Learning Perl enough to complete this assignment may take a while, so you are not expected to present it here for grading, only to yourself. And remember, if you cheat on this assignment, you are only cheating yourself.

        Thank you! I tried sending you a PM but I need to learn how to use this forum. I will be sending you a pm once I learn how.
        Tried running script in terminal and it gave me a Permission denied.

      Well, resolves to here, but I get no responses, not even to ping, from that address. I have tried connecting with TCP to port 27900 with no response to the connection attempt. I have tried sending UDP packets with both "status\n" and "status\r\n" with no response, not even an ICMP error.

      Of course I have all the terminals I want here... but if that server refuses to talk to me, that is a bit of a problem... wait a minute...

      You keep putting backslashes around "status"... (echo -ne '\status\'; sleep 1) | socat STDIO produces

      \gamename\333networks\gamever\MS-perl 2.4.3\location\0\queryid\41.1\ho +stname\ (The Errorist Network Master Server)\hostpo +rt\28900\gametype\MasterServer\mapname\333networks\numplayers\14\maxp +layers\2965\gamemode\openplaying\queryid\41.2\mutators\333networks sy +nchronization, UCC Master applet synchronization, Server Status Check +er\AdminName\Syntax-Error\AdminEMail\\queryid\41.3\ +final\

      It is using UDP. And the first thing you need to study is "quoting".

      The server is firewalled: an incorrect packet or a packet sent to the wrong port elicits no response at all, while '\status\' sent to the correct port produces that response. I have a bone to pick with whomever designed that atrocity of a protocol, but I think I can make a simple "shotgun query" tool. As a proof of concept, here is a simple solution at the shell:

      (for port in `seq 27895 1 27905`; do (echo -ne '\status\'; sleep 1) | socat STDIO${port} & done; sleep 1; echo '')

      Paste that into a terminal and observe the results. That one does not tell you which port responded, only the response that was received, but the returned "hostport" happens to be 1000 higher than the port that produces the response. Writing this in Perl will be a fun exercise.

      Note that I am deliberately designing this in a way that will set off alarms and get you caught if you try to use it as a system cracking tool.

      2019-08-12 Athanasius fixed long line.

      2019-08-12 jcb concurs with this edit to his node and thanks Athanasius. Let us see if I remember how to fix this the next time I need it...

        Sir, I am no hacker/cracker/internet punk!

        I pasted in terminal, (for port in `seq 27895 1 27905`; do (echo -ne '\status\'; sleep 1) | socat STDIO${port} & done; sleep 1; echo '') , it returned nothing.

        In my previous post I told you it was TCP. Jetfighter game port 8181 is UDP, I tried it first, no response, tried TCP port 8182 and got a response.
        Pasting this, nc 27900 -u into a terminal, enter, followed by \status\ , enter
        should of gave you a return/reply. Since it was a UDP port, my bad I am learning this as I go.
        You have a pm.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104275]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-09-20 05:02 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (118 votes). Check out past polls.