Skip to content

Instantly share code, notes, and snippets.

@paceaux
Created September 1, 2024 18:25
Show Gist options
  • Save paceaux/ce65ba3ef3567c4a5411f994d4f0a0d6 to your computer and use it in GitHub Desktop.
Save paceaux/ce65ba3ef3567c4a5411f994d4f0a0d6 to your computer and use it in GitHub Desktop.
Basic Hacker management for folks looking for PHP vulnerabilities
<?php
function getUserIP() {
if( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')>0) {
$addr = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($addr[0]);
} else {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
else {
return $_SERVER['REMOTE_ADDR'];
}
}
function getRequestInfo() {
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
return $host . $uri;
}
function getTime() {
return date('F jS Y h:i:s A');
}
function get_post() {
$body = "";
if (isset($_POST)) {
$body = ", ";
$body .= json_encode($_POST);
}
return $body;
}
function getRecord() {
$user_ip = getUserIP();
$time = getTime();
$requestInfo = getRequestInfo();
$post = get_post();
$record = $user_ip . ", " . $time . ", " . $requestInfo . $post . "\r\n";
return $record;
}
function recordEvent($file) {
$record = getRecord();
$current_records = file_get_contents($file);
$current_records .= $record;
file_put_contents($file, $current_records);
}
function beAnAsshole($file) {
$lines = count(file($file));
sleep($lines * 20);
}
$log_file = 'evil_visitors.txt';
recordEvent($log_file);
beAnAsshole($log_file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment