From 96f38ce6b44e096a9ae84859d3815e52e1ed9c22 Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter@cassini.intern>
Date: Mon, 27 Jun 2016 19:19:48 +0200
Subject: [PATCH] Notizen und Beispiel-Programme: Sicherheit

---
 20160627/bs-20160627.txt | 63 ++++++++++++++++++++++++++++++++++++++++
 20160627/hello-1.c       |  9 ++++++
 20160627/hello-10.c      | 10 +++++++
 20160627/hello-11.c      | 10 +++++++
 20160627/hello-12.c      | 10 +++++++
 20160627/hello-13.c      | 12 ++++++++
 20160627/hello-2.c       | 10 +++++++
 20160627/hello-3.c       |  2 ++
 20160627/hello-4.c       | 13 +++++++++
 20160627/hello-5.c       | 15 ++++++++++
 20160627/hello-6.c       | 15 ++++++++++
 20160627/hello-7.c       | 12 ++++++++
 20160627/hello-8.c       | 10 +++++++
 20160627/hello-9.c       | 12 ++++++++
 14 files changed, 203 insertions(+)
 create mode 100644 20160627/bs-20160627.txt
 create mode 100644 20160627/hello-1.c
 create mode 100644 20160627/hello-10.c
 create mode 100644 20160627/hello-11.c
 create mode 100644 20160627/hello-12.c
 create mode 100644 20160627/hello-13.c
 create mode 100644 20160627/hello-2.c
 create mode 100644 20160627/hello-3.c
 create mode 100644 20160627/hello-4.c
 create mode 100755 20160627/hello-5.c
 create mode 100755 20160627/hello-6.c
 create mode 100644 20160627/hello-7.c
 create mode 100644 20160627/hello-8.c
 create mode 100644 20160627/hello-9.c

diff --git a/20160627/bs-20160627.txt b/20160627/bs-20160627.txt
new file mode 100644
index 0000000..8c615f6
--- /dev/null
+++ b/20160627/bs-20160627.txt
@@ -0,0 +1,63 @@
+Treiber-Entwicklung, Echtzeit- und Betriebssysteme, 27.06.2016
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+:) Der Bootvorgang
+:) Die Unix-Shell
+:) Treiber
+:) Signale
+:) Massenspeicher
+:) Speicherverwaltung
+:) Netzwerk
+:) Echtzeit
+:) User-Space-Treiber
+:) Grafik
+ ? Netzwerk: Programmierung
+ ! Sicherheit
+
+Sicherheit
+==========
+
+Angriff auf einen Rechner:
+
+ 1. Benutzer dazu bringen, ein selbstgeschriebenes Programm auszuführen (MalWare)
+    Beispiel: tolles_bild.jpg.exe
+
+ 2. Benutzer dazu bringen, ein vorhandenes Programm mit Sicherheitslücke
+    mit selbstgeschriebenen Daten auszuführen (MalWare)
+    Beispiele: Macro-, JavaScript-, Flash- und PDF-Würmer
+
+ 3. Aus dem Netz: ein laufendes Programm mit Sicherheitslücke
+    mit selbstgeschriebenen Daten füttern
+    Beispiel: http://xkcd.com/327/
+
+    "Robert'); DROP TABLE Students; --"
+
+    INSERT INTO Students (Name='Robert', Klasse='3b', Telefon='12345');
+
+    INSERT INTO Students (Name='Robert'); DROP TABLE Students; -- ', Klasse='3b', Telefon='12345');
+
+Gegenmaßnahme:
+ gegen 1: Medienkompetenz
+ gegen 2. und 3.: keine Sicherheitlücken programmieren
+
+Sicherheitslücken in Programmen
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Buffer-Overflow: siehe Rechnertechnik
+Gegenmaßnahmen:
+
+ * ordentlich programmieren
+    - ordentlich einrücken
+    - Compiler-Warnungen aktivieren und beachten
+
+ * automatische Code-Analyse
+    - Compiler: gcc oder llvm mit Warnungen
+    - statisch: [sp]lint, sparse (cgcc)
+      automatische Suche nach typischen Fehlern
+    - dynamisch: valgrind
+      ausführbares Programm wird auf Speicherfehler analysiert
+   --> finden viele, aber nicht alle Fehler
+
+ * Speicherschutzmechanismen des Compilers und des Betriebssystems
+    - Hardware-Unterstützung: DEP/NX (siehe: Speicherverwaltung)
+    - Canary: http://www.drdobbs.com/240001832
+    - ASLR: http://heise.de/-2718449
+    - Austricksen: http://security.stackexchange.com/questions/20497
diff --git a/20160627/hello-1.c b/20160627/hello-1.c
new file mode 100644
index 0000000..1eeb73a
--- /dev/null
+++ b/20160627/hello-1.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main (void)
+{
+printf ("Hauptprogramm, vor printf\n");
+  printf ("Hello, world!\n");
+printf ("Hauptprogramm, nach printf\n");
+  return 0;
+}
diff --git a/20160627/hello-10.c b/20160627/hello-10.c
new file mode 100644
index 0000000..fc7a4a0
--- /dev/null
+++ b/20160627/hello-10.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *str1 = "Hello, world!";
+  char *str2 = "";
+  scanf ("%s", str2);
+  printf ("%s\n%s\n", str1, str2);
+  return 0;
+}
diff --git a/20160627/hello-11.c b/20160627/hello-11.c
new file mode 100644
index 0000000..76610d2
--- /dev/null
+++ b/20160627/hello-11.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *str1 = "Hello, world!";
+  char *str2 = "Hier ist viel Platz.";
+  scanf ("%s", str2);
+  printf ("%s\n%s\n", str1, str2);
+  return 0;
+}
diff --git a/20160627/hello-12.c b/20160627/hello-12.c
new file mode 100644
index 0000000..a5618d0
--- /dev/null
+++ b/20160627/hello-12.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char str1[] = "Hello, world!";
+  char str2[] = "Hier ist viel Platz.";
+  scanf ("%s", str2);
+  printf ("%s\n%s\n", str1, str2);
+  return 0;
+}
diff --git a/20160627/hello-13.c b/20160627/hello-13.c
new file mode 100644
index 0000000..32c61f3
--- /dev/null
+++ b/20160627/hello-13.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <sys/mman.h>
+
+int main (void)
+{
+  char *str1 = "Hello, world!";
+  char *str2 ="Hier ist viel Platz.";
+  mprotect (str1, 65536, PROT_WRITE | PROT_READ);
+  scanf ("%s", str2);
+  printf ("%s\n%s\n", str1, str2);
+  return 0;
+}
diff --git a/20160627/hello-2.c b/20160627/hello-2.c
new file mode 100644
index 0000000..b76f1dd
--- /dev/null
+++ b/20160627/hello-2.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+/* printf ("Hauptprogramm, vor printf\n"); */
+  printf ("Hello, world!\n");
+/* printf ("Hauptprogramm, nach printf\n");
+ */
+  return 0;
+}
diff --git a/20160627/hello-3.c b/20160627/hello-3.c
new file mode 100644
index 0000000..d55cd5b
--- /dev/null
+++ b/20160627/hello-3.c
@@ -0,0 +1,2 @@
+#include <stdio.h>
+int main (void) { printf ("Hello, world!\n"); return 0; }
diff --git a/20160627/hello-4.c b/20160627/hello-4.c
new file mode 100644
index 0000000..fab7a48
--- /dev/null
+++ b/20160627/hello-4.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int main (void)
+{
+  int a = 3;
+  int b = 2;
+  if (b != 0)
+    printf ("a / b = %d\n", a / b);
+  else
+    printf ("Kann nicht durch 0 dividieren.\n");
+    printf ("Ciao!\n");
+  return 0;
+}
diff --git a/20160627/hello-5.c b/20160627/hello-5.c
new file mode 100755
index 0000000..18036f9
--- /dev/null
+++ b/20160627/hello-5.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main (void)
+{
+  int a = 6;
+  int b = 2;
+  if (b = 0)
+    {
+      printf ("Kann nicht durch 0 dividieren.\n");
+      printf ("Ciao!\n");
+    }
+  else
+    printf ("a / b = %d\n", a / b);
+  return 0;
+}
diff --git a/20160627/hello-6.c b/20160627/hello-6.c
new file mode 100755
index 0000000..73b4894
--- /dev/null
+++ b/20160627/hello-6.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main (void)
+{
+  int a = 6;
+  int b = 2;
+  if ((b = 0))
+    {
+      printf ("Kann nicht durch 0 dividieren.\n");
+      printf ("Ciao!\n");
+    }
+  else
+    printf ("a / b = %d\n", a / b);
+  return 0;
+}
diff --git a/20160627/hello-7.c b/20160627/hello-7.c
new file mode 100644
index 0000000..cddd61e
--- /dev/null
+++ b/20160627/hello-7.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (void)
+{
+  int *a = malloc (5 * sizeof (int));
+  for (int i = 1; i <= 5; i++)
+    a[i] = i;
+  for (int i = 1; i <= 5; i++)
+    printf ("%d\n", a[i]);
+  return 0;
+}
diff --git a/20160627/hello-8.c b/20160627/hello-8.c
new file mode 100644
index 0000000..6bc7342
--- /dev/null
+++ b/20160627/hello-8.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *str1 = "Hello, world!";
+  char *str2 = "";
+  scanf ("%s", &str2);
+  printf ("%s\n%s\n", str1, str2);
+  return 0;
+}
diff --git a/20160627/hello-9.c b/20160627/hello-9.c
new file mode 100644
index 0000000..2e204f3
--- /dev/null
+++ b/20160627/hello-9.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int main (void)
+{
+  char *str1 = "Hello, world!";
+  char *str2 = "";
+  printf ("str2 = %x --> %x\n", str2, *str2);
+  scanf ("%s", &str2);
+  printf ("str2 = %x --> %x\n", str2, *str2);
+  printf ("%s\n%s\n", str1, str2);
+  return 0;
+}
-- 
GitLab