Schwachstellenseite unter Debian einrichten: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „= Schwachstellenseite unter Debian einrichten = * Apache und PHP installieren: apt update apt install -y apache2 php libapache2-mod-php * PHP aktivieren un…“) |
|||
| (35 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| − | = | + | = Apache vorbereiten = |
* Apache und PHP installieren: | * Apache und PHP installieren: | ||
| Zeile 9: | Zeile 9: | ||
systemctl start apache2 | systemctl start apache2 | ||
| − | + | = MariaDB vorbereiten = | |
| − | |||
| − | |||
| + | * MariaDB und PHP-MySQL-Modul installieren: | ||
| + | apt install -y mariadb-server php-mysql | ||
| + | |||
| + | * MariaDB starten und beim Boot aktivieren: | ||
| + | systemctl enable mariadb | ||
| + | systemctl start mariadb | ||
| + | |||
| + | = Datenbank „tuxmen“ vorbereiten = | ||
| + | |||
| + | * Als root anmelden: | ||
| + | mysql -u root | ||
| + | |||
| + | * Datenbank anlegen: | ||
| + | CREATE DATABASE tuxmen; | ||
| + | USE tuxmen; | ||
| + | |||
| + | = Tabelle „mitarbeiter“ erstellen = | ||
| + | |||
| + | * Tabelle erzeugen: | ||
| + | CREATE TABLE mitarbeiter ( | ||
| + | id INT PRIMARY KEY AUTO_INCREMENT, | ||
| + | username VARCHAR(50), | ||
| + | password VARCHAR(50), | ||
| + | fullname VARCHAR(100), | ||
| + | email VARCHAR(100), | ||
| + | notes TEXT | ||
| + | ); | ||
| + | =User erstellen= | ||
| + | mysql -u root -p <<EOF | ||
| + | CREATE USER 'webuser'@'localhost' IDENTIFIED BY 'secret'; | ||
| + | GRANT ALL PRIVILEGES ON tuxmen.* TO 'webuser'@'localhost'; | ||
| + | FLUSH PRIVILEGES; | ||
| + | EOF | ||
| + | |||
| + | = Beispieldaten einfügen = | ||
| + | |||
| + | * Testdaten hinzufügen: | ||
| + | INSERT INTO mitarbeiter (username, password, fullname, email, notes) VALUES | ||
| + | ('admin', 'admin123', 'Karl Rootmann', 'admin@tuxmen.local', 'Zugang zu allen Systemen'), | ||
| + | ('alice', 'alicepw', 'Alice Liddell', 'alice@tuxmen.local', 'Team Marketing, Urlaub bis 22. Mai'), | ||
| + | ('bob', 'bobpw', 'Bob Baumeister', 'bob@tuxmen.local', 'Serverraum: Türcode 1234'), | ||
| + | ('charlie', 'charliepw','Charlie Foxtrot', 'charlie@tuxmen.local','Entwicklungstools: VSCode, Docker'), | ||
| + | ('dora', 'dorapw', 'Dora Explorer', 'dora@tuxmen.local', 'VPN-Probleme gemeldet'), | ||
| + | ('eve', 'evepw', 'Evelyn Mallory', 'eve@tuxmen.local', 'Audit-Team, Zugang GVM'), | ||
| + | ('frank', 'frankpw', 'Frank Underroot', 'frank@tuxmen.local', 'Sudo-Zugang beantragt'), | ||
| + | ('grace', 'gracepw', 'Grace Hopper', 'grace@tuxmen.local', 'Legacy-Projekt „COBOL Revival“'), | ||
| + | ('hans', '1234', 'Hans Hacker', 'hans@tuxmen.local', 'Kali-Linux Testumgebung'), | ||
| + | ('irene', '5678', 'Irene Adler', 'irene@tuxmen.local', 'Zuständig für LDAP und Mailserver'); | ||
| + | |||
| + | * Sitzung beenden: | ||
| + | EXIT | ||
| + | |||
| + | =Umsetzung= | ||
| + | ==Zentrale== | ||
* index.html erstellen: | * index.html erstellen: | ||
nano index.html | nano index.html | ||
| + | =Umsetzung= | ||
| + | |||
| + | ==Zentrale== | ||
| + | * index.html erstellen: | ||
| + | vi index.html | ||
* Inhalt einfügen: | * Inhalt einfügen: | ||
| Zeile 20: | Zeile 77: | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html> | <html> | ||
| + | <meta charset="UTF-8"> | ||
<head><title>VulnSite</title></head> | <head><title>VulnSite</title></head> | ||
<body> | <body> | ||
| − | <h1> | + | <h1>VulnSite – Systemmodule</h1> |
| − | < | + | <ul> |
| − | + | <li><a href="host.html">Hostauflösung</a></li> | |
| − | < | + | <li><a href="sql-classic.php">Benutzerdaten anzeigen</a></li> |
| − | </ | + | <li><a href="sql-blind.php">Meine Daten bearbeiten</a></li> |
| + | <li><a href="upload.php">Datei senden</a></li> | ||
| + | <li><a href="info.php">Info</a></li> | ||
| + | <!-- <li><a href="sqli_blind.php">Verbindung prüfen</a></li> | ||
| + | <li><a href="xss.html">Mitteilung eingeben</a></li> | ||
| + | --> | ||
| + | </ul> | ||
| − | + | </body> | |
| − | + | </html> | |
| − | |||
| − | |||
| − | + | </pre> | |
| − | |||
| − | |||
| − | |||
| − | + | ==PHP Dateien== | |
| − | + | ===cmd.php=== | |
| − | + | <pre> | |
| − | + | <?php | |
| + | if (isset($_GET['cmd'])) { | ||
| + | $input = $_GET['cmd']; | ||
| + | echo "<pre>"; | ||
| + | system("host " . $input); | ||
| + | echo "</pre>"; | ||
| + | } | ||
| + | </pre> | ||
| + | ===sql-classic.php=== | ||
| + | <pre> | ||
| + | <?php | ||
| + | error_reporting(E_ALL); | ||
| + | ini_set('display_errors', 1); | ||
| + | |||
| + | $link = mysqli_connect('127.0.0.1', 'webuser', 'secret', 'tuxmen'); | ||
| + | mysqli_set_charset($link, "utf8"); | ||
| − | + | if (!$link) { | |
| − | + | die("Verbindung fehlgeschlagen: " . mysqli_connect_error()); | |
| − | + | } | |
| − | |||
| − | + | $search = $_POST['username'] ?? ''; | |
| − | + | $result = null; | |
| − | |||
| − | |||
| − | + | if (!empty($search)) { | |
| − | + | $query = "SELECT * FROM mitarbeiter WHERE username = '$search'"; | |
| − | + | if (mysqli_multi_query($link, $query)) { | |
| − | + | do { | |
| − | + | if ($res = mysqli_store_result($link)) { | |
| − | + | while ($row = mysqli_fetch_assoc($res)) { | |
| + | echo "Benutzer: {$row['username']}<br>"; | ||
| + | echo "Passwort: {$row['password']}<br>"; | ||
| + | echo "E-Mail: {$row['email']}<br>"; | ||
| + | echo "Hinweis: {$row['notes']}<br><hr>"; | ||
| + | } | ||
| + | mysqli_free_result($res); | ||
| + | } | ||
| + | } while (mysqli_next_result($link)); | ||
| + | } else { | ||
| + | echo "Fehler oder keine Ausgabe."; | ||
| + | } | ||
| + | } | ||
| − | + | mysqli_close($link); | |
| − | + | ?> | |
| − | |||
| − | |||
| − | |||
| − | + | <form method="post"> | |
| + | <input type="text" name="username" placeholder="Benutzername oder Injection"> | ||
| + | <input type="submit" value="Suchen"> | ||
| + | <!-- eingabe "' or '1' = '1' -- " Leerzeichen nach -- ist wichtig --> | ||
| + | <!-- eingabe "' OR 1=1; DELETE FROM mitarbeiter WHERE username='ruedi'; -- " Leerzeichen nach -- ist wichtig --> | ||
| + | <!-- eingabe "' ; INSERT INTO mitarbeiter (username, password, fullname, email, notes) | ||
| + | VALUES ('evil', 'pwned', 'Evil Hacker', 'evil@hax.local', 'per injection hinzugefügt'); -- " --> | ||
| + | </form> | ||
| + | </pre> | ||
| + | ===sql-blind.php=== | ||
<pre> | <pre> | ||
| − | + | <?php | |
| − | + | error_reporting(E_ALL); | |
| − | + | ini_set('display_errors', 1); | |
| + | |||
| + | // Datenbankverbindung (unsicher für Demo!) | ||
| + | $link = mysqli_connect('127.0.0.1', 'webuser', 'secret', 'tuxmen'); | ||
| + | if (!$link) { | ||
| + | die("Verbindungsfehler: " . mysqli_connect_error()); | ||
} | } | ||
| − | |||
| − | |||
| − | + | // Benutzereingabe (ohne Escaping/Sanitizing!) | |
| − | + | $username = $_POST['username'] ?? ''; | |
| − | + | $message = ''; | |
| − | $ | ||
| − | |||
| − | |||
| − | |||
| − | + | if (!empty($username)) { | |
| − | + | // Kritische SQL-Abfrage (vulnerabel für Injection) | |
| − | + | $query = "SELECT * FROM mitarbeiter WHERE username = '$username'"; | |
| − | $ | + | // echo $query; |
| − | echo | + | $result = mysqli_query($link, $query); |
| − | |||
| − | |||
| − | + | if (mysqli_num_rows($result) > 0) { | |
| − | + | $message = "<div class='valid'>VALID: Benutzer '$username' existiert!</div>"; | |
| − | + | } else { | |
| − | $ | + | $message = "<div class='invalid'>INVALID: Benutzer '$username' existiert NICHT.</div>"; |
| − | + | } | |
| − | |||
} | } | ||
| − | ? | + | ?> |
| + | |||
| + | <!DOCTYPE html> | ||
| + | <html> | ||
| + | <head> | ||
| + | <title>Blind-SQL-Injection Demo</title> | ||
| + | <style> | ||
| + | body { font-family: Arial, sans-serif; padding: 20px; } | ||
| + | .valid { color: green; font-weight: bold; } | ||
| + | .invalid { color: red; font-weight: bold; } | ||
| + | input, button { padding: 8px; margin: 5px 0; } | ||
| + | </style> | ||
| + | </head> | ||
| + | <body> | ||
| + | <h1>Benutzer-Check (Demo für Blind-Injection)</h1> | ||
| + | |||
| + | <form method="POST"> | ||
| + | <input type="text" name="username" placeholder="Benutzername" required> | ||
| + | <button type="submit">Prüfen</button> | ||
| + | </form> | ||
| + | |||
| + | <?php echo $message; ?> | ||
| + | |||
| + | <h3>Demo-Angriffe (für Blind-Injection):</h3> | ||
| + | <ul> | ||
| + | <li>Normale Abfrage: <code>maria</code> → VALID</li> | ||
| + | <li>Blind-Injection: <code>hans' AND password LIKE '1%' -- </code> → VALID, wenn Passwort mit "1" beginnt.</li> | ||
| + | <li>Erfolgreicher Guess: <code>hans' AND password = '1234' -- </code> → VALID (Passwort erraten!)</li> | ||
| + | </ul> | ||
| + | </body> | ||
| + | </html> | ||
| + | <!-- | ||
| + | Hacks im Eingabefeld | ||
| + | |||
| + | maria' AND length(password) < 5 -- ' | ||
| + | maria' AND length(password) > 5 -- ' | ||
| + | maria' AND password = '1234' -- ' | ||
| + | |||
| + | --> | ||
| + | |||
| + | <?php mysqli_close($link); ?> | ||
| + | |||
</pre> | </pre> | ||
| − | + | ===upload.php=== | |
| − | + | ;Vorabeiten | |
| + | mkdir /var/www/html/uploads | ||
| + | chown www-data:www-data /var/www/html/uploads | ||
<pre> | <pre> | ||
<?php | <?php | ||
| + | error_reporting(E_ALL); | ||
| + | ini_set('display_errors', 1); | ||
| + | |||
if (!empty($_FILES['upload'])) { | if (!empty($_FILES['upload'])) { | ||
| − | + | $filename = basename($_FILES['upload']['name']); | |
| − | + | $target = "uploads/" . $filename; | |
| + | |||
| + | if (move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { | ||
| + | echo "Datei erfolgreich hochgeladen: <a href='$target'>$filename</a>"; | ||
| + | } else { | ||
| + | echo "Fehler beim Hochladen."; | ||
| + | } | ||
} | } | ||
?> | ?> | ||
| − | |||
| − | + | <form method="post" enctype="multipart/form-data"> | |
| − | < | + | <input type="file" name="upload"> |
| − | < | + | <input type="submit" value="Hochladen"> |
| − | + | </form> | |
| − | |||
| − | |||
</pre> | </pre> | ||
| − | + | ===info.php=== | |
| − | + | <?php | |
| − | <?php | + | phpinfo(); |
| − | phpinfo(); | + | ?> |
| − | ? | ||
| − | |||
Aktuelle Version vom 15. Mai 2025, 18:52 Uhr
Apache vorbereiten
- Apache und PHP installieren:
apt update apt install -y apache2 php libapache2-mod-php
- PHP aktivieren und Apache starten:
systemctl enable apache2 systemctl start apache2
MariaDB vorbereiten
- MariaDB und PHP-MySQL-Modul installieren:
apt install -y mariadb-server php-mysql
- MariaDB starten und beim Boot aktivieren:
systemctl enable mariadb systemctl start mariadb
Datenbank „tuxmen“ vorbereiten
- Als root anmelden:
mysql -u root
- Datenbank anlegen:
CREATE DATABASE tuxmen; USE tuxmen;
Tabelle „mitarbeiter“ erstellen
- Tabelle erzeugen:
CREATE TABLE mitarbeiter ( id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50), password VARCHAR(50), fullname VARCHAR(100), email VARCHAR(100), notes TEXT );
User erstellen
mysql -u root -p <<EOF CREATE USER 'webuser'@'localhost' IDENTIFIED BY 'secret'; GRANT ALL PRIVILEGES ON tuxmen.* TO 'webuser'@'localhost'; FLUSH PRIVILEGES; EOF
Beispieldaten einfügen
- Testdaten hinzufügen:
INSERT INTO mitarbeiter (username, password, fullname, email, notes) VALUES
('admin', 'admin123', 'Karl Rootmann', 'admin@tuxmen.local', 'Zugang zu allen Systemen'),
('alice', 'alicepw', 'Alice Liddell', 'alice@tuxmen.local', 'Team Marketing, Urlaub bis 22. Mai'),
('bob', 'bobpw', 'Bob Baumeister', 'bob@tuxmen.local', 'Serverraum: Türcode 1234'),
('charlie', 'charliepw','Charlie Foxtrot', 'charlie@tuxmen.local','Entwicklungstools: VSCode, Docker'),
('dora', 'dorapw', 'Dora Explorer', 'dora@tuxmen.local', 'VPN-Probleme gemeldet'),
('eve', 'evepw', 'Evelyn Mallory', 'eve@tuxmen.local', 'Audit-Team, Zugang GVM'),
('frank', 'frankpw', 'Frank Underroot', 'frank@tuxmen.local', 'Sudo-Zugang beantragt'),
('grace', 'gracepw', 'Grace Hopper', 'grace@tuxmen.local', 'Legacy-Projekt „COBOL Revival“'),
('hans', '1234', 'Hans Hacker', 'hans@tuxmen.local', 'Kali-Linux Testumgebung'),
('irene', '5678', 'Irene Adler', 'irene@tuxmen.local', 'Zuständig für LDAP und Mailserver');
- Sitzung beenden:
EXIT
Umsetzung
Zentrale
- index.html erstellen:
nano index.html
Umsetzung
Zentrale
- index.html erstellen:
vi index.html
- Inhalt einfügen:
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head><title>VulnSite</title></head>
<body>
<h1>VulnSite – Systemmodule</h1>
<ul>
<li><a href="host.html">Hostauflösung</a></li>
<li><a href="sql-classic.php">Benutzerdaten anzeigen</a></li>
<li><a href="sql-blind.php">Meine Daten bearbeiten</a></li>
<li><a href="upload.php">Datei senden</a></li>
<li><a href="info.php">Info</a></li>
<!-- <li><a href="sqli_blind.php">Verbindung prüfen</a></li>
<li><a href="xss.html">Mitteilung eingeben</a></li>
-->
</ul>
</body>
</html>
PHP Dateien
cmd.php
<?php
if (isset($_GET['cmd'])) {
$input = $_GET['cmd'];
echo "<pre>";
system("host " . $input);
echo "</pre>";
}
sql-classic.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$link = mysqli_connect('127.0.0.1', 'webuser', 'secret', 'tuxmen');
mysqli_set_charset($link, "utf8");
if (!$link) {
die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
}
$search = $_POST['username'] ?? '';
$result = null;
if (!empty($search)) {
$query = "SELECT * FROM mitarbeiter WHERE username = '$search'";
if (mysqli_multi_query($link, $query)) {
do {
if ($res = mysqli_store_result($link)) {
while ($row = mysqli_fetch_assoc($res)) {
echo "Benutzer: {$row['username']}<br>";
echo "Passwort: {$row['password']}<br>";
echo "E-Mail: {$row['email']}<br>";
echo "Hinweis: {$row['notes']}<br><hr>";
}
mysqli_free_result($res);
}
} while (mysqli_next_result($link));
} else {
echo "Fehler oder keine Ausgabe.";
}
}
mysqli_close($link);
?>
<form method="post">
<input type="text" name="username" placeholder="Benutzername oder Injection">
<input type="submit" value="Suchen">
<!-- eingabe "' or '1' = '1' -- " Leerzeichen nach -- ist wichtig -->
<!-- eingabe "' OR 1=1; DELETE FROM mitarbeiter WHERE username='ruedi'; -- " Leerzeichen nach -- ist wichtig -->
<!-- eingabe "' ; INSERT INTO mitarbeiter (username, password, fullname, email, notes)
VALUES ('evil', 'pwned', 'Evil Hacker', 'evil@hax.local', 'per injection hinzugefügt'); -- " -->
</form>
sql-blind.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Datenbankverbindung (unsicher für Demo!)
$link = mysqli_connect('127.0.0.1', 'webuser', 'secret', 'tuxmen');
if (!$link) {
die("Verbindungsfehler: " . mysqli_connect_error());
}
// Benutzereingabe (ohne Escaping/Sanitizing!)
$username = $_POST['username'] ?? '';
$message = '';
if (!empty($username)) {
// Kritische SQL-Abfrage (vulnerabel für Injection)
$query = "SELECT * FROM mitarbeiter WHERE username = '$username'";
// echo $query;
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) > 0) {
$message = "<div class='valid'>VALID: Benutzer '$username' existiert!</div>";
} else {
$message = "<div class='invalid'>INVALID: Benutzer '$username' existiert NICHT.</div>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Blind-SQL-Injection Demo</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.valid { color: green; font-weight: bold; }
.invalid { color: red; font-weight: bold; }
input, button { padding: 8px; margin: 5px 0; }
</style>
</head>
<body>
<h1>Benutzer-Check (Demo für Blind-Injection)</h1>
<form method="POST">
<input type="text" name="username" placeholder="Benutzername" required>
<button type="submit">Prüfen</button>
</form>
<?php echo $message; ?>
<h3>Demo-Angriffe (für Blind-Injection):</h3>
<ul>
<li>Normale Abfrage: <code>maria</code> → VALID</li>
<li>Blind-Injection: <code>hans' AND password LIKE '1%' -- </code> → VALID, wenn Passwort mit "1" beginnt.</li>
<li>Erfolgreicher Guess: <code>hans' AND password = '1234' -- </code> → VALID (Passwort erraten!)</li>
</ul>
</body>
</html>
<!--
Hacks im Eingabefeld
maria' AND length(password) < 5 -- '
maria' AND length(password) > 5 -- '
maria' AND password = '1234' -- '
-->
<?php mysqli_close($link); ?>
upload.php
- Vorabeiten
mkdir /var/www/html/uploads chown www-data:www-data /var/www/html/uploads
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (!empty($_FILES['upload'])) {
$filename = basename($_FILES['upload']['name']);
$target = "uploads/" . $filename;
if (move_uploaded_file($_FILES['upload']['tmp_name'], $target)) {
echo "Datei erfolgreich hochgeladen: <a href='$target'>$filename</a>";
} else {
echo "Fehler beim Hochladen.";
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="upload">
<input type="submit" value="Hochladen">
</form>
info.php
<?php phpinfo(); ?>