Schwachstellenseite unter Debian einrichten: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(16 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 71: Zeile 71:
 
==Zentrale==
 
==Zentrale==
 
* index.html erstellen:
 
* index.html erstellen:
  nano index.html
+
  vi index.html
  
 
* Inhalt einfügen:
 
* Inhalt einfügen:
Zeile 77: 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>Schwachstellen Demos</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>
  
  <h2>Gib einen FQDN ein - ich zeige dir die IP-Adresse</h2>
 
  <form action="cmd.php" method="GET">
 
    <input name="cmd" placeholder="z.B. google.de"><input type="submit">
 
  </form>
 
 
</body>
 
</body>
 
</html>
 
</html>
 +
 
</pre>
 
</pre>
  
 
==PHP Dateien==
 
==PHP Dateien==
;cmd.php
+
===cmd.php===
 
<pre>
 
<pre>
 
&lt;?php
 
&lt;?php
Zeile 99: Zeile 108:
 
   echo "&lt;/pre&gt;";
 
   echo "&lt;/pre&gt;";
 
}
 
}
 +
</pre>
 +
===sql-classic.php===
 +
<pre>
 +
&lt;?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']}&lt;br&gt;";
 +
                    echo "Passwort: {$row['password']}&lt;br&gt;";
 +
                    echo "E-Mail: {$row['email']}&lt;br&gt;";
 +
                    echo "Hinweis: {$row['notes']}&lt;br&gt;&lt;hr&gt;";
 +
                }
 +
                mysqli_free_result($res);
 +
            }
 +
        } while (mysqli_next_result($link));
 +
    } else {
 +
        echo "Fehler oder keine Ausgabe.";
 +
    }
 +
}
 +
 +
mysqli_close($link);
 
?&gt;
 
?&gt;
 +
 +
&lt;form method="post"&gt;
 +
  &lt;input type="text" name="username" placeholder="Benutzername oder Injection"&gt;
 +
  &lt;input type="submit" value="Suchen"&gt;
 +
  &lt;!-- eingabe "' or '1' = '1' -- " Leerzeichen nach -- ist wichtig --&gt;
 +
  &lt;!-- eingabe "' OR 1=1; DELETE FROM mitarbeiter WHERE username='ruedi'; -- " Leerzeichen nach -- ist wichtig --&gt;
 +
  &lt;!-- eingabe "' ; INSERT INTO mitarbeiter (username, password, fullname, email, notes)
 +
      VALUES ('evil', 'pwned', 'Evil Hacker', 'evil@hax.local', 'per injection hinzugefügt'); -- " --&gt;
 +
&lt;/form&gt;
 
</pre>
 
</pre>
;email.php
+
===sql-blind.php===
 +
<pre>
 +
&lt;?php
 +
error_reporting(E_ALL);
 +
ini_set(&#x27;display_errors&#x27;, 1);
 +
 
 +
// Datenbankverbindung (unsicher für Demo!)
 +
$link = mysqli_connect(&#x27;127.0.0.1&#x27;, &#x27;webuser&#x27;, &#x27;secret&#x27;, &#x27;tuxmen&#x27;);
 +
if (!$link) {
 +
    die(&quot;Verbindungsfehler: &quot; . mysqli_connect_error());
 +
}
 +
 
 +
// Benutzereingabe (ohne Escaping/Sanitizing!)
 +
$username = $_POST[&#x27;username&#x27;] ?? &#x27;&#x27;;
 +
$message = &#x27;&#x27;;
 +
 
 +
if (!empty($username)) {
 +
    // Kritische SQL-Abfrage (vulnerabel für Injection)
 +
    $query = &quot;SELECT * FROM mitarbeiter WHERE username = &#x27;$username&#x27;&quot;;
 +
  // echo $query;
 +
    $result = mysqli_query($link, $query);
 +
 
 +
    if (mysqli_num_rows($result) &gt; 0) {
 +
        $message = &quot;&lt;div class=&#x27;valid&#x27;&gt;VALID: Benutzer &#x27;$username&#x27; existiert!&lt;/div&gt;&quot;;
 +
    } else {
 +
        $message = &quot;&lt;div class=&#x27;invalid&#x27;&gt;INVALID: Benutzer &#x27;$username&#x27; existiert NICHT.&lt;/div&gt;&quot;;
 +
    }
 +
}
 +
?&gt;
 +
 
 +
&lt;!DOCTYPE html&gt;
 +
&lt;html&gt;
 +
&lt;head&gt;
 +
    &lt;title&gt;Blind-SQL-Injection Demo&lt;/title&gt;
 +
    &lt;style&gt;
 +
        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; }
 +
    &lt;/style&gt;
 +
&lt;/head&gt;
 +
&lt;body&gt;
 +
    &lt;h1&gt;Benutzer-Check (Demo für Blind-Injection)&lt;/h1&gt;
 +
   
 +
    &lt;form method=&quot;POST&quot;&gt;
 +
        &lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;Benutzername&quot; required&gt;
 +
        &lt;button type=&quot;submit&quot;&gt;Prüfen&lt;/button&gt;
 +
    &lt;/form&gt;
 +
 
 +
    &lt;?php echo $message; ?&gt;
 +
 
 +
    &lt;h3&gt;Demo-Angriffe (für Blind-Injection):&lt;/h3&gt;
 +
    &lt;ul&gt;
 +
        &lt;li&gt;Normale Abfrage: &lt;code&gt;maria&lt;/code&gt; → VALID&lt;/li&gt;
 +
        &lt;li&gt;Blind-Injection: &lt;code&gt;hans&#x27; AND password LIKE &#x27;1%&#x27; -- &lt;/code&gt; → VALID, wenn Passwort mit &quot;1&quot; beginnt.&lt;/li&gt;
 +
        &lt;li&gt;Erfolgreicher Guess: &lt;code&gt;hans&#x27; AND password = &#x27;1234&#x27; -- &lt;/code&gt; → VALID (Passwort erraten!)&lt;/li&gt;
 +
    &lt;/ul&gt;
 +
&lt;/body&gt;
 +
&lt;/html&gt;
 +
&lt;!--
 +
Hacks im Eingabefeld
 +
 
 +
maria&#x27; AND length(password) &lt; 5  -- &#x27;
 +
maria&#x27; AND length(password) &gt; 5  -- &#x27;
 +
maria&#x27; AND password = &#x27;1234&#x27; -- &#x27;
 +
 
 +
--&gt;
 +
 
 +
&lt;?php mysqli_close($link); ?&gt;
 +
 
 +
</pre>
 +
===upload.php===
 +
;Vorabeiten
 +
mkdir /var/www/html/uploads
 +
chown www-data:www-data /var/www/html/uploads
 +
<pre>
 +
<?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>
 +
</pre>
 +
 
 +
===info.php===
 
  <?php
 
  <?php
  error_reporting(E_ALL);
+
  phpinfo();
ini_set('display_errors', 1);
 
 
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
 
  $username = $_POST['username'] ?? '';
 
 
  $link = mysqli_connect('127.0.0.1', 'webuser', 'secret', 'tuxmen');
 
  mysqli_set_charset($link, "utf8");
 
 
  if (!$link) {
 
    die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
 
  }
 
 
  $query = "SELECT email FROM mitarbeiter WHERE username='$username'";
 
  $result = mysqli_query($link, $query);
 
 
  $email = null;
 
  if ($result && mysqli_num_rows($result) > 0) {
 
    $email = mysqli_fetch_assoc($result)['email'];
 
  }
 
 
  mysqli_close($link);
 
}
 
 
  ?>
 
  ?>
 
<!DOCTYPE html>
 
<html>
 
<head><meta charset="utf-8"><title>E-Mail Abfrage</title></head>
 
<body>
 
  <h2>E-Mail-Adresse suchen</h2>
 
  <form method="post">
 
    <input type="text" name="username" placeholder="z.B. alice">
 
    <input type="submit" value="Suchen">
 
  </form>
 
 
<?php if (isset($email)): ?>
 
  <p><strong>E-Mail:</strong> <?= htmlspecialchars($email) ?></p>
 
<?php elseif ($_SERVER['REQUEST_METHOD'] === 'POST'): ?>
 
  <p style="color:red;">Kein Benutzer gefunden.</p>
 
<?php endif; ?>
 
</body>
 
</html>
 

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();
?>