const synFloodTracker = {};
const MAX_SYN_REQUESTS = 10; // Max allowed per minute
const SYN_BLOCK_TIME_MS = 60000; // Block time if SYN flood detected
// Rate Limiting Configurations
const rateLimit = {};
const MAX_REQUESTS_PER_MINUTE = 100; // Set your limit here (100)
const BLOCK_TIME_MS = 60000; // Time to block the IP (1 minute) (60000)
// DNS attack prevention configurations
const dnsWhitelist = ['8.8.8.8', '1.1.1.1']; // Trusted DNS resolvers (Google DNS and Cloudflare DNS)
const MAX_DNS_REQUESTS_PER_MINUTE = 50; // Limit DNS-related requests
const dnsRateLimit = {};
// Function to normalize IP addresses
const normalizeIp = (ip) => {
if (ip.startsWith("::ffff:")) {
return ip.substring(7);
}
if (ip === "::1") {
return "127.0.0.1";
}
return ip;
};
// Function to check if IP is from cloud/server ranges
const isCloudOrServerIp = (ip) => {
return cloudServerIpRanges.some((range) => ip.startsWith(range));
};
// Helper function to check GeoIP blocking
const isBlockedGeoIp = (ip) => {
const geo = geoip.lookup(ip);
if (geo && !allowedCountries.includes(geo.country)) {
return true;
}
return false;
};
const isSynFlood = (ip) => {
const now = Date.now();
if (!synFloodTracker[ip]) {
synFloodTracker[ip] = { count: 1, timestamp: now };
return false;
}
const timePassed = now - synFloodTracker[ip].timestamp;
if (timePassed > SYN_BLOCK_TIME_MS) {
synFloodTracker[ip] = { count: 1, timestamp: now };
return false;
} else {
synFloodTracker[ip].count++;
if (synFloodTracker[ip].count > MAX_SYN_REQUESTS) {
console.log(chalk.red(SYN flood detected from IP: ${ip}));
logBlockedIP(ip, 'SYN Flood');
return true;
}
}
return false;
};
// Start UI Server
configApp.listen(CONFIG_PORT, () => {
console.log(chalk.blue(Admin dashboard is running on http://localhost:${CONFIG_PORT}/config));
});
// Start Server Function
const startServer = async () => {
const proxy = httpProxy.createProxyServer({});
const pk = fs.readFileSync(path.join(__dirname, 'server.key'));
const pc = fs.readFileSync(path.join(__dirname, 'server.crt'));
const optss = { key: pk, cert: pc };
const trustedIPs = ['127.0.0.1'];
const port = process.argv[2] || 443;
EventEmitter.defaultMaxListeners = 100;
const packet = server|${config.ip}\nport|${config.port}\ntype|1\n#maint|Server is currently initializing or re-syncing with sub servers. Please try again in a minute.\n\n\nloginurl|${config.loginurl}\nbeta_server|127.0.0.1\nbeta_port|17091\nbeta_type|1\nbeta2_server|127.0.0.1\nbeta2_port|17099\nbeta2_type|1\nmeta|${Math.floor(Date.now() / 1000)}\nRTENDMARKERBS1001;
const server = https.createServer(optss, function (req, res) {
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const normalizedIp = normalizeIp(ip);
const hostHeader = req.headers.host;
// Set keepAliveTimeout, which sets how long a connection should remain open in milliseconds.
server.keepAliveTimeout = 60 * 1000; // Keep alive for 60 seconds
// Set the headers timeout slightly longer than keepAliveTimeout to accommodate requests that arrive just before the keep alive timeout
server.headersTimeout = 65 * 1000; // 65 seconds
code
console.log(chalk.green(`[DEVELOPER MODE]`, req.headers['user-agent']));
console.log(chalk.green(`Request received from IP: ${normalizedIp}`));
if (isSynFlood(ip)) {
console.log(chalk.red(`SYN flood detected from IP: ${normalizedIp}`));
logBlockedIP(normalizedIp, 'SYN Flood');
// Use the underlying socket to destroy the connection
req.socket.end(); // Gracefully end the connection
req.socket.destroy(); // Forcefully close the connection, ignoring any pending data or errors
return;
}
// Rate Limiting Logic
if (!rateLimit[normalizedIp]) {
rateLimit[normalizedIp] = { count: 1, timestamp: Date.now() };
} else {
const currentTime = Date.now();
const timePassed = currentTime - rateLimit[normalizedIp].timestamp;
// Reset count if more than 1 minute has passed
if (timePassed > BLOCK_TIME_MS) {
rateLimit[normalizedIp] = { count: 1, timestamp: currentTime };
} else {
rateLimit[normalizedIp].count++;
}
// Check if the limit is reached
if (rateLimit[normalizedIp].count > MAX_REQUESTS_PER_MINUTE) {
console.log(chalk.red(`Rate limit exceeded for IP: ${normalizedIp}`));
logBlockedIP(normalizedIp, 'TCP');
res.statusCode = 429; // Too Many Requests
res.end('Too many requests. Your connection is being throttled.');
return;
}
}
// DNS attack protection
if (isSuspiciousDNSRequest(normalizedIp, req.url)) {
console.log(chalk.red(`DNS DDoS detected from IP: ${normalizedIp}`));
logBlockedIP(normalizedIp, 'TCP-DNS');
res.statusCode = 403; // Forbidden
res.end('Forbidden: DNS DDoS attack detected.');
return;
}
// Network Usage Limiting for TCP
const requestBytes = Buffer.byteLength(req.url); // Approximate
if (isNetworkUsageLimited(normalizedIp, requestBytes)) {
console.log(chalk.red(`Network usage limit exceeded for IP: ${normalizedIp} (TCP)`));
logBlockedIP(normalizedIp, 'TCP-NETWORK');
res.statusCode = 429; // Too Many Requests
res.end('Too many requests. Your connection is being throttled.');
return;
}
// Check for cloud or server IP range
if (!trustedIPs.includes(normalizedIp) && isCloudOrServerIp(normalizedIp)) {
console.log(chalk.red(`Blocking cloud/server IP: ${normalizedIp}`));
logBlockedIP(normalizedIp, 'TCP-Cloud');
res.statusCode = 403;
res.end('Forbidden: Access from cloud/server IP is blocked.');
return;
}
// Check for GeoIP block
if (isBlockedGeoIp(normalizedIp)) {
console.log(chalk.red(`Blocking access from IP: ${normalizedIp} (GeoIP Block)`));
logBlockedIP(normalizedIp, 'TCP-GeoIP');
res.statusCode = 403;
res.end('Forbidden: Access from your location is blocked.');
return;
}
const parsedUrl = url.parse(req.url);
const pathname = `.${parsedUrl.pathname}`;
const ext = path.parse(pathname).ext;
console.log(chalk.blue(`Connection Request from: ${normalizedIp} URL: ${req.url} Method: ${req.method}`));
const map = {
'.ico': 'image/x-icon',
'.html': 'text/html',
'.js': 'text/javascript',
'.json': 'application/json',
'.css': 'text/css',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.wav': 'audio/wav',
'.mp3': 'audio/mpeg',
'.svg': 'image/svg+xml',
'.pdf': 'application/pdf',
'.doc': 'application/msword'
};
const allowedUserAgents = [
'UbiServices_SDK_2022.Release.9_PC64_ansi_static',
'UbiServices_SDK_2022.Release.9_PC32_ansi_static',
'UbiServices_SDK_2022.Release.9_ANDROID64_static',
'UbiServices_SDK_2022.Release.9_ANDROID32_static',
'UbiServices_SDK_2022.Release.9_IOS64',
'UbiServices_SDK_2022.Release.9_IOS32',
'UbiServices_SDK_2022.Release.9_MAC64',
'UbiServices_SDK_2022.Release.9_MAC32',
];
const userAgent = req.headers['user-agent'];
// Handle /growtopia/server_data.php - Only POST and allowed User-Agents
// Handle /growtopia/server_data.php - Only POST and allowed User-Agents
if (req.url === "/growtopia/server_data.php") {
if (req.method !== 'POST' || hostHeader !== 'www.growtopia2.com') {
console.log(chalk.red(Mata mata : ${req.url}));
res.statusCode = 403;
res.end(`
server|normalizedIpport∣{Math.floor(Date.now() / 69)}
type|1
#maint|Server is currently initializing or re-syncing with sub servers. Please try again in a minute.
server.listen(port, () => {
console.log(chalk.green(Server is running on port ${port}));
});
// -------------------- UDP Server Setup --------------------
const udpServer = dgram.createSocket('udp4');
const UDP_PORT = 53; // DNS typically uses port 53
udpServer.on('error', (err) => {
console.error(UDP server error:\n${err.stack});
udpServer.close();
});
udpServer.on('message', (msg, rinfo) => {
const ip = rinfo.address;
const normalizedIp = normalizeIp(ip);
console.log(chalk.yellow(UDP request from IP: ${normalizedIp}, Port: ${rinfo.port}));
code
// Rate Limiting
if (isUdpRateLimited(normalizedIp)) {
console.log(chalk.red(`UDP Rate limit exceeded for IP: ${normalizedIp}`));
logBlockedIP(normalizedIp, 'UDP');
return; // Drop the packet silently or send a response indicating rate limiting
}
// GeoIP Blocking
if (isBlockedGeoIp(normalizedIp)) {
console.log(chalk.red(`Blocking UDP access from IP: ${normalizedIp} (GeoIP Block)`));
logBlockedIP(normalizedIp, 'UDP-GeoIP');
return; // Drop the packet silently or send a forbidden response
}
// Network Usage Limiting for UDP
const messageBytes = msg.length;
if (isNetworkUsageLimited(normalizedIp, messageBytes)) {
console.log(chalk.red(`Network usage limit exceeded for IP: ${normalizedIp} (UDP)`));
logBlockedIP(normalizedIp, 'UDP-NETWORK');
return; // Drop the packet
}
// Implement your DNS handling logic here
// For example, respond with a simple DNS response or forward the request to a legitimate DNS server
// Example: Forward the DNS request to an external DNS server (e.g., Google DNS)
const externalDns = '8.8.8.8';
const externalDnsPort = 53;
const externalClient = dgram.createSocket('udp4');
externalClient.send(msg, 0, msg.length, externalDnsPort, externalDns, (error) => {
if (error) {
console.error(`Error forwarding UDP request: ${error}`);
externalClient.close();
}
});
externalClient.on('message', (response) => {
udpServer.send(response, 0, response.length, rinfo.port, rinfo.address, (err) => {
if (err) {
console.error(`Error sending UDP response: ${err}`);
}
externalClient.close();
});
});
// Optional: Implement timeouts to prevent hanging
externalClient.on('error', (err) => {
console.error(`External DNS client error: ${err}`);
externalClient.close();
});
// Set a timeout for the external DNS response
externalClient.setTimeout(5000, () => { // 5 seconds timeout
console.error(`External DNS request timed out for IP: ${normalizedIp}`);
externalClient.close();
});
});
udpServer.on('listening', () => {
const address = udpServer.address();
console.log(chalk.green(UDP Server listening on ${address.address}:${address.port}));
});
udpServer.bind(UDP_PORT);
const shutdown = () => {
console.log('Shutting down the server...');
code
// Stop the server from accepting new connections
server.close(() => {
console.log('HTTP server closed.');
// Close the UDP server
udpServer.close(() => {
console.log('UDP server closed.');
// Exit the process
process.exit(0);
});
});
// Ensure shutdown if connections remain
setTimeout(() => {
console.error('Forced shutdown due to open connections.');
process.exit(1); // exit with error code if connections remain
}, 5000).unref();
untuk post /growtopia/server_data.php adalah jalur menuju login ke game private server nya, www.growtopia2.com adalah hostnya jika saya menggunakan www.growtopia2.com tanpa http debugger pro saya tidak bisa login, namun sambil membuka http debugger pro saya bisa login. untuk host lain nya adalah www.growtopia1.com tapi saya tidak mau menggunakan nya, bisakah kamu bantu saya
If you're experiencing issues where a specific HTTP host is only working when HTTP traffic is being monitored (like through HTTP Debugger Pro), it often indicates that there may be some headers or traffic characteristics that are being added or modified by the debugger. These modifications might be critical for your request to be processed correctly by the game server.
Debugging Steps
Inspect Traffic: Use HTTP Debugger Pro to inspect the outgoing requests when trying to log in to understand what's different. Pay close attention to any additional headers or any changes in the request body.
Replicate Behavior:
Headers: Ensure that all necessary headers required by the server are present. Compare them with those captured via HTTP Debugger Pro.
Keep-Alive: HTTP debuggers might handle connection keep-alives differently. Make sure your server is configured to handle persistent connections similar to how HTTP Debugger Pro handles them.
Request Timing: Analyze the timing of requests in HTTP Debugger Pro, as it may alter the sequence/timing which might help discover timing dependencies.
SSL/TLS Handling: Sometimes debugging tools alter SSL/TLS settings. Ensure SSL/TLS settings on your application match those captured by your HTTP Debugger Pro.
Replace Host Header: On your server implementation, ensure you properly replace the host header of incoming requests when forwarding to the backend server. This is sometimes automatically handled, but explicit coverage might be needed based on backend expectations.
Network Conditions: Check if there are any network-specific conditions (like MTU size, packet fragmentation, etc.) that might affect normal operation outside of the debugging environment.
Request Handling: Double-check that your server implementation handles all aspects of the incoming request. Especially details like:
Method: Your code should ensure it's expecting the correct HTTP method.
Path: Make sure path handling logic aligns with server requirements.
Body/Params: Assure that any posted data/parameters align with the server's expectations.
Security/Anti-Virus/Sandboxing: Some security products can interfere subtly with network traffic, which they may sometimes leave untouched in debugging mode. Consider temporarily disabling them for purely diagnostic purposes.
Example Server Code Adjustment
Make sure you've checked configurations or logic adjustments to ensure compatibility with the expected backend API:
javascript
if (req.url === "/growtopia/server_data.php") {
if (req.method !== 'POST' || hostHeader !== 'www.growtopia2.com') {
// Handling configuration matching
res.statusCode = 403;
res.end('Request forbidden.');
return;
}
// Handle normal processing here, ensuring headers and body content are expected.
res.write(packet, function (err) {
if (err) console.log(chalk.red(err));
});
res.end();
}
Final Note:
If the debugging tool allows login while running, test suggestions above incrementally when disabling HTTP Debugger Pro, noting any differences. You may also want to involve network debugging or packet capturing tools (like Wireshark) to diagnose what's changing on a packet level.
If your problem persists beyond these tests, reevaluating server-side restrictions, potentially involving server logs, or debugging the backend server might be necessary for comprehensive troubleshooting.
To resolve the issue where you can only login to your private server when using HTTP Debugger Pro with the host www.growtopia2.com, follow these steps systematically:
Compare HTTP Requests:
Use HTTP Debugger Pro to capture all HTTP requests and responses when the login attempt is successful.
Note down headers, request methods, URL paths, and body contents in detail.
Check Connections:
Make sure that your server allows connections from the necessary IPs and that any firewall settings aren't blocking traffic to www.growtopia2.com.
Replicate Headers:
Ensure that the headers observed during the successful login are being sent when trying without HTTP Debugger Pro. This might include specific user-agent strings, cookies, or custom headers.
Adjust Server Code:
Modify your node.js server code to reflect details captured from HTTP Debugger Pro. For example, copy whatever headers or changes HTTP Debugger might implement and add them into your server logic.
Here’s a minimal example on how to set specific headers:
javascript
// Add necessary headers
res.setHeader('User-Agent', 'YourSpecificUserAgentHere');
// Add any other headers that were used during the successful login
SSL/TLS Handling:
Check SSL certificates and ensure that your server certificate (if used for HTTPS connections) is properly configured.
Network Configuration:
Ensure that there are no restrictions at the network level (such as firewalls or NAT settings) that might prevent direct requests from reaching the private server.
Check Timing Issues:
HTTP Debuggers sometimes change the timing of requests. Make sure your server can handle rapid successive requests if that's what's different between the working and non-working scenarios.
Diagnose with Additional Tools:
Use additional tools like Wireshark to capture and analyze network traffic. This can help pinpoint differences in how requests are sent with and without the debugger.
Logs and Debugging:
Enable detailed logging on your server side to understand how incoming requests are being handled. This may reveal discrepancies when trying operations without HTTP Debugger.
Backend Verification:
Ensure that there's no backend validation logic that distinguishes between requests that come via HTTP Debugger Pro versus direct requests.
By carefully following these steps, you should be able to identify the discrepancy between the scenarios and adjust your system to work without the need for an HTTP Debugger to log in successfully. If changes to your node.js server setup are required, make sure these changes reflect exactly the encoding, headers, and protocol usages expected by the backend server.