Die Legende von den Reiskörnern auf dem Schachbrett mit PHP berechnen

Datei rice.php mit folgendem Inhalt anlegen:

<?php

// Reiskörner auf dem Schachbrett
// Rice grains on the chessboard

function rice($rounds){ 

 $grains1 = 1; 

 $field = 1; 
 while ($field < $rounds){
  echo (str_pad($field, 2, '0', STR_PAD_LEFT) . ": " . $grains1 . "<br>");
  $grains2 = $grains1 * 2; 
  $grains1 = $grains2;
  $field = $field + 1; 
  } 
} 

$rounds = 65; 
rice($rounds); 
?>

Beispiel: rice.php

MD5-Hashwert aus Passwort erzeugen

Message-Digest Algorithm 5

Datei md5hash.php mit folgendem Inhalt erzeugen:

<?php
$password = 'MyPassword';
$salt = mt_rand( 10000, 99999 );
$encrypted = 'salt:' . $salt . ' md5:' . md5( $salt . $password );
echo $encrypted;
?>

Hostname und User-Agent prüfen, Bild von Webcam laden und mit Timestamp in Dateinamen in Unterordner speichern

<?php

$useragent = $_SERVER["HTTP_USER_AGENT"];
$ipaddress = $_SERVER["HTTP_X_REAL_IP"];
$hostname = gethostbyaddr($ipaddress);

if ((strpos($hostname, 'cable-xdsl.tld') !== false) and (strpos($useragent, 'Wget') !== false))
{
	$timestamp = date("Y-m-d_H-i-s");
	$url = "https://webcam.tld/full.jpg";
	$img = "./webcam/img_".$timestamp.".jpg";
	file_put_contents($img, file_get_contents($url));
	print "OK...action performed :-)";
}

else {
	echo 'Error...you are not permitted to perform this action :-(';
}

?>

Hostname prüfen und IP in .htaccess in Unterverzeichnis schreiben

<?php
$ipaddress = $_SERVER["HTTP_X_REAL_IP"];
$hostname = gethostbyaddr($ipaddress);
if (strpos($hostname, 'cable-xdsl.tld') !== false) {
$data2write1 = "order deny,allow\n";
$data2write2 = "deny from all\n";
$data2write3 = "allow from ".$ipaddress;
$subdir1 = fopen("./subdir1/.htaccess","w");
$subdir2 = fopen("./subdir2/.htaccess","w");
fwrite($subdir1, $data2write1);
fwrite($subdir1, $data2write2);
fwrite($subdir1, $data2write3);
fwrite($subdir2, $data2write1);
fwrite($subdir2, $data2write2);
fwrite($subdir2, $data2write3);
print "OK...data written :-)";
}
else {
echo 'Error...you are not permitted to perform this action :-(';
}
?>

Honeypot

honeypot.php

<?php
$timestamp = date("d.m.Y H:i:s");
$ip = $_SERVER["REMOTE_ADDR"];
$host = gethostbyaddr($_SERVER['HTTP_X_REAL_IP']);
$reqtype = $_SERVER['REQUEST_METHOD'];
$file = $_SERVER['REQUEST_URI'];
$browser = $_SERVER["HTTP_USER_AGENT"];

$filename="logging/logfile.txt";

$header = array("Timestamp", "IP", "Hostname", "RequestType", "File", "Browser");
$infos = array($timestamp, $ip, $host, $reqtype, $file, $browser);

$entry = implode("\t", $infos);

$write_header = !file_exists($filename);

$file=fopen($filename,"a");

if($write_header) {
$heading = implode("\t", $header);
fwrite($file, $heading."\n");
}

fwrite($file,$entry."\n");
fclose($file);
?>

xmlrpc.php / wp-login.php #1:

<?php include 'honeypot.php'; ?>