This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_conn.php
135 lines (121 loc) · 3.69 KB
/
debug_conn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* SourceBans "Error Connecting()" Debug
* Checks for the ports being forwarded correctly
*/
/**
* Config part
* Change to IP and port of the gameserver you want to test
*/
$serverip = $_GET["ip"];
$serverport = $_GET["port"];
$serverrcon = $_GET["rcon"]; // You only need to specify this, if you want to test the rcon tcp connection either! Leave blank if it's only the serverinfo erroring.
/******* Don't change below here *******/
if(empty($serverip) || empty($serverport))
die('[-] No server information set. Open up this file and specify your gameserver\'s IP and port.');
echo '[+] SourceBans "Error Connecting()" Debug starting for server ' . $serverip . ':' . $serverport . '<br /><br />';
// Check for UDP connection being available and writable
echo '[+] Trying to establish UDP connection<br />';
$sock = @fsockopen("udp://" . $serverip, $serverport, $errno, $errstr, 2);
$isBanned = false;
if(!$sock)
{
echo '[-] Error connecting #' . $errno . ': ' . $errstr . '<br />';
}
else
{
echo '[+] UDP connection successfull!<br />';
stream_set_timeout($sock, 1);
// Try to get serverinformation
echo '[+] Trying to write to the socket<br />';
$written = fwrite($sock, "\xFF\xFF\xFF\xFF\x54Source Engine Query\0");
if($written === false)
{
echo '[-] Error writing.<br />';
}
else
{
echo '[+] Successfully requested server info. (That doesn\'t mean anything on an UDP stream.) Reading...<br />';
$packet = fread($sock, 1480);
if(empty($packet))
{
echo '[-] Error getting server info. Can\'t read from UDP stream. Port is possibly blocked.<br />';
}
else
{
if(substr($packet, 5, (strpos(substr($packet, 5), "\0")-1)) == "Banned by server")
{
echo '[-] Got an response, but this webserver\'s ip is banned by the server.<br />';
$isBanned = true;
}
else
{
$packet = substr($packet, 6);
$hostname = substr($packet, 0, strpos($packet, "\0"));
echo '[+] Got an response! Server: ' . $hostname . ' <br />';
}
}
}
fclose($sock);
}
echo '<br />';
// Check for TCP connection being available and writeable
echo '[+] Trying to establish TCP connection<br />';
$sock = @fsockopen($serverip, $serverport, $errno, $errstr, 2);
if(!$sock)
{
echo '[-] Error connecting #' . $errno . ': ' . $errstr . '<br />';
}
else
{
echo '[+] TCP connection successfull!<br />';
if(empty($serverrcon))
{
echo '[o] Stopping here since no rcon password specified.';
}
else if($isBanned)
{
echo '[o] Stopping here since this ip is banned by the gameserver.';
}
else
{
stream_set_timeout($sock, 2);
$data = pack("VV", 0, 03) . $serverrcon . chr(0) . '' . chr(0);
$data = pack("V", strlen($data)) . $data;
echo '[+] Trying to write to TCP socket and authenticate via rcon<br />';
$written = fwrite($sock, $data, strlen($data));
if($written === false)
{
echo '[-] Error writing.<br />';
}
else
{
echo '[+] Successfully sent authentication request. Reading...<br />';
$size = fread($sock, 4);
if(!$size)
{
echo '[-] Error reading.<br />';
}
else
{
echo '[+] Got an response! <br />';
$size = unpack('V1Size', $size);
$packet = fread($sock, $size["Size"]);
$size = fread($sock, 4);
$size = unpack('V1Size', $size);
$packet = fread($sock, $size["Size"]);
$ret = unpack("V1ID/V1Reponse/a*S1/a*S2", $packet);
if(empty($ret) || (isset($ret['ID']) && $ret['ID'] == -1))
{
echo '[-] Bad password ;) Don\'t try this too often or your webserver will get banned by the gameserver.<br />';
}
else
{
echo '[+] Password correct!';
}
}
}
}
fclose($sock);
}
?>