Schwachstellenseite unter Debian einrichten: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(32 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 8: Zeile 8:
 
  systemctl enable apache2
 
  systemctl enable apache2
 
  systemctl start apache2
 
  systemctl start apache2
 
* Verzeichnis für Testseite anlegen:
 
mkdir -p /var/www/html/
 
cd /var/www/html/
 
  
 
= MariaDB vorbereiten =
 
= MariaDB vorbereiten =
Zeile 22: Zeile 18:
 
  systemctl start mariadb
 
  systemctl start mariadb
  
* Zugriff als root:
 
mysql -u root
 
 
= Datenbank „tuxmen“ vorbereiten =
 
= Datenbank „tuxmen“ vorbereiten =
  
Zeile 44: Zeile 38:
 
   notes TEXT
 
   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 =
 
= Beispieldaten einfügen =
Zeile 57: Zeile 57:
 
  ('frank',  'frankpw',  'Frank Underroot',  'frank@tuxmen.local',  'Sudo-Zugang beantragt'),
 
  ('frank',  'frankpw',  'Frank Underroot',  'frank@tuxmen.local',  'Sudo-Zugang beantragt'),
 
  ('grace',  'gracepw',  'Grace Hopper',      'grace@tuxmen.local',  'Legacy-Projekt „COBOL Revival“'),
 
  ('grace',  'gracepw',  'Grace Hopper',      'grace@tuxmen.local',  'Legacy-Projekt „COBOL Revival“'),
  ('hans',    'hanspw',  'Hans Hacker',      'hans@tuxmen.local',  'Kali-Linux Testumgebung'),
+
  ('hans',    '1234',  'Hans Hacker',      'hans@tuxmen.local',  'Kali-Linux Testumgebung'),
  ('irene',  'irenepw',  'Irene Adler',      'irene@tuxmen.local',  'Zuständig für LDAP und Mailserver');
+
  ('irene',  '5678',  'Irene Adler',      'irene@tuxmen.local',  'Zuständig für LDAP und Mailserver');
  
 
* Sitzung beenden:
 
* Sitzung beenden:
 
  EXIT
 
  EXIT
  
=Umesetzung==
+
=Umsetzung=
 +
==Zentrale==
 +
* index.html erstellen:
 +
nano index.html
 +
=Umsetzung=
  
 +
==Zentrale==
 
* index.html erstellen:
 
* index.html erstellen:
  nano index.html
+
  vi index.html
  
 
* Inhalt einfügen:
 
* Inhalt einfügen:
Zeile 72: 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>Schwachstellendemo</h1>
+
   <h1>VulnSite – Systemmodule</h1>
  
   <h2>Command Injection</h2>
+
   <ul>
  <form action="cmd.php" method="GET">
+
    <li><a href="host.html">Hostauflösung</a></li>
     <input name="cmd" placeholder="whoami"><input type="submit">
+
    <li><a href="sql-classic.php">Benutzerdaten anzeigen</a></li>
   </form>
+
    <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>SQL Injection</h2>
+
</body>
  <form action="sqli.php" method="GET">
+
</html>
    <input name="id" placeholder="1 OR 1=1"><input type="submit">
 
  </form>
 
  
  <h2>XSS</h2>
+
</pre>
  <form action="xss.php" method="GET">
 
    <input name="q" placeholder="Suchbegriff"><input type="submit">
 
  </form>
 
  
  <h2>LFI</h2>
+
==PHP Dateien==
  <form action="lfi.php" method="GET">
+
===cmd.php===
    <input name="file" placeholder="/etc/passwd"><input type="submit">
+
<pre>
  </form>
+
&lt;?php
 +
if (isset($_GET['cmd'])) {
 +
  $input = $_GET['cmd'];
 +
  echo "&lt;pre&gt;";
 +
  system("host " . $input);
 +
  echo "&lt;/pre&gt;";
 +
}
 +
</pre>
 +
===sql-classic.php===
 +
<pre>
 +
&lt;?php
 +
error_reporting(E_ALL);
 +
ini_set('display_errors', 1);
  
  <h2>Upload</h2>
+
$link = mysqli_connect('127.0.0.1', 'webuser', 'secret', 'tuxmen');
  <form action="upload.php" method="POST" enctype="multipart/form-data">
+
mysqli_set_charset($link, "utf8");
    <input type="file" name="upload"><input type="submit">
 
  </form>
 
  
  <h2>Redirect</h2>
+
if (!$link) {
  <form action="header.php" method="GET">
+
     die("Verbindung fehlgeschlagen: " . mysqli_connect_error());
     <input name="redirect" placeholder="http://example.com"><input type="submit">
+
}
  </form>
 
  
  <p><a href="info.php">PHP Info</a></p>
+
$search = $_POST['username'] ?? '';
  <p><a href="config.txt">Offene Konfigdatei</a></p>
+
$result = null;
  <p><a href="uploads/">Upload-Verzeichnis</a></p>
+
 
</body>
+
if (!empty($search)) {
</html>
+
    $query = "SELECT * FROM mitarbeiter WHERE username = '$search'";
</pre>
+
    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.";
 +
    }
 +
}
  
* PHP-Dateien erstellen:
+
mysqli_close($link);
touch cmd.php sqli.php xss.php lfi.php upload.php header.php info.php
+
?&gt;
mkdir uploads
 
echo "dbpass = admin" > config.txt
 
chmod 777 uploads
 
  
* Inhalt für cmd.php:
+
&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>
 +
===sql-blind.php===
 
<pre>
 
<pre>
<?php
+
&lt;?php
if (isset($_GET['cmd'])) {
+
error_reporting(E_ALL);
  system($_GET['cmd']);
+
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());
 
}
 
}
?>
 
</pre>
 
  
* Inhalt für sqli.php:
+
// Benutzereingabe (ohne Escaping/Sanitizing!)
<pre>
+
$username = $_POST[&#x27;username&#x27;] ?? &#x27;&#x27;;
<?php
+
$message = &#x27;&#x27;;
$id = $_GET['id'] ?? '';
 
echo "Sie haben Benutzer-ID: $id eingegeben.";
 
?>
 
</pre>
 
  
* Inhalt für xss.php:
+
if (!empty($username)) {
<pre>
+
    // Kritische SQL-Abfrage (vulnerabel für Injection)
<?php
+
    $query = &quot;SELECT * FROM mitarbeiter WHERE username = &#x27;$username&#x27;&quot;;
$q = $_GET['q'] ?? '';
+
  // echo $query;
echo "<p>Ergebnis für: $q</p>";
+
    $result = mysqli_query($link, $query);
?>
 
</pre>
 
  
* Inhalt für lfi.php:
+
    if (mysqli_num_rows($result) &gt; 0) {
<pre>
+
        $message = &quot;&lt;div class=&#x27;valid&#x27;&gt;VALID: Benutzer &#x27;$username&#x27; existiert!&lt;/div&gt;&quot;;
<?php
+
    } else {
$file = $_GET['file'] ?? '';
+
        $message = &quot;&lt;div class=&#x27;invalid&#x27;&gt;INVALID: Benutzer &#x27;$username&#x27; existiert NICHT.&lt;/div&gt;&quot;;
if ($file) {
+
    }
  include($file);
 
 
}
 
}
?>
+
?&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>
 
</pre>
 
+
===upload.php===
* Inhalt für 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'])) {
  move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/" . basename($_FILES['upload']['name']));
+
    $filename = basename($_FILES['upload']['name']);
  echo "Datei hochgeladen.";
+
    $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.";
 +
    }
 
}
 
}
 
?>
 
?>
</pre>
 
  
* Inhalt für header.php:
+
<form method="post" enctype="multipart/form-data">
<pre>
+
  <input type="file" name="upload">
<?php
+
  <input type="submit" value="Hochladen">
$redirect = $_GET['redirect'] ?? '';
+
</form>
header("Location: $redirect");
 
?>
 
 
</pre>
 
</pre>
  
* Inhalt für info.php:
+
===info.php===
<pre>
+
<?php
<?php
+
phpinfo();
phpinfo();
+
?>
?>
 
</pre>
 

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