Systemsicherheit/Assignment 5 - Software Security - Teil 1/abgabe.tex
chronal e8edfc9f39
Some checks are pending
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Waiting to run
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Waiting to run
Assignment 5 Berarbeitung Aufgabe 1 wip
2024-06-09 19:17:16 +02:00

267 lines
11 KiB
TeX

\documentclass[11pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{xspace}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{xifthen}
\usepackage{xcolor}
\usepackage[a4paper,lmargin={2cm},rmargin={2cm},tmargin={2.5cm},bmargin = {2.5cm},headheight = {4cm}]{geometry}
\usepackage{amsmath,amssymb,amstext,amsthm}
\usepackage[shortlabels]{enumitem}
\usepackage[headsepline]{scrlayer-scrpage}
\pagestyle{scrheadings}
\usepackage{titling}
\usepackage{etoolbox}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, calc, automata, arrows.meta, positioning,decorations.pathmorphing,backgrounds,decorations.markings,decorations.pathreplacing, graphs}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains, calc}
\usetikzlibrary{arrows.meta,matrix,shapes,arrows,positioning,chains, calc}
\tikzset{%
initial text={},
state/.style={circle, draw, minimum size=.6cm},
every initial by arrow/.style={-stealth},
every loop/.append style={-stealth},
>=stealth
}
\ohead{\parbox[t]{.5\linewidth}{\raggedleft \theauthor}}
\ihead{System Security, SoSe 24, Assignment \thesheetnr}
% Sheet number
\newcounter{sheetnr}
\newcommand{\sheetnr}[1]{\setcounter{sheetnr}{#1}}
% Exercise environments
\newenvironment{exercise}[2][]{\section*{#2\expandafter\ifstrempty\expandafter{#1}{}{\ #1}}}{}
\newenvironment{subexercises}{\begin{enumerate}[a), font=\bfseries, wide, labelindent=0pt]}{\end{enumerate}}
\newenvironment{subsubexercises}{\begin{enumerate}[i), font=\bfseries, wide, labelindent=0pt]}{\end{enumerate}}
% Makros
% MACRO for whole diagram
% #1: total width of diagram
% #2: total height of diagram
% #3: nodes, paths, ...
\newcommand\protocolflow[3]{
\begin{center}
\begin{tikzpicture}[x=#1cm,y=#2cm]
#3
\end{tikzpicture}
\end{center}
}
% MACRO for path line shortening
% #1: start coordinate
% #2: target coordinate
% #3: text above arrow
\newcommand{\package}[3]{
\path[*-{latex[width=5pt, length=5pt]}] (#1) edge node [above] {#3} (#2);
}
% Anpassen --> %
\author{Benjamin Haschka\\Sascha Tommasone\\Paul Zinselmeyer}
\sheetnr{5}
% <-- Anpassen %
\begin{document}
\begin{exercise}[Analyse von Binärdaten]{1}
\begin{subexercises}
\item Der Output von \texttt{objdump} mit der \texttt{secret} Funktion extrahiert.
\begin{lstlisting}[language=bash]
user@intro:~$ objdump -d intro | awk -v RS= '/^[[:xdigit:]]+ <secret>/'
0000120d <secret>:
120d: f3 0f 1e fb endbr32
1211: 55 push %ebp
1212: 89 e5 mov %esp,%ebp
1214: 8b 45 08 mov 0x8(%ebp),%eax
1217: 8d 50 ff lea -0x1(%eax),%edx
121a: 89 d0 mov %edx,%eax
121c: 01 c0 add %eax,%eax
121e: 01 d0 add %edx,%eax
1220: 83 c0 05 add $0x5,%eax
1223: 5d pop %ebp
1224: c3 ret
\end{lstlisting}
\item Man kann durch den Command \lstinline[language=bash]{gdb -x commands} gdb mit der Datei \texttt{commands} ausgeben.
\begin{figure}[H]
\begin{lstlisting}[]
# Lines starting with a '#' symbol are comments
# Do not remove this intial line; it will disable pagination
set pagination off
file intro
break secret
# TODO: your commands go here
r 5
i r eax
stepi 6
# after 5. instruction
i r eax
stepi
# after 6. instruction
i r eax
stepi
# after 7. instruction
i r eax
stepi
# after 8. instruction
i r eax
# continue program to end
continue
# END of your commands
# Do not remove the final quit; it will exit GDB automatically
quit
\end{lstlisting}
\caption[short]{Inhalt der command Datei}
\end{figure}
Dabei wird zuerst die Datei \texttt{intro} in gdb eingelesen.
Anschließend wird ein Breakpoint bei der Funktion secret gesetzt.
Dann wird das Programm mit dem Parameter gestartet und, wie in der Aufgabe gewollt, wird das Register eax an verschiedenen Stellen ausgelesen.
Der Ausgabewert der Funktion ist dann 17.
\begin{lstlisting}[language=bash]
user@intro:~$ gdb -x commands
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Breakpoint 1 at 0x120d: file intro.c, line 5.
Breakpoint 1, secret (num=5) at intro.c:5
5 intro.c: No such file or directory.
eax 0x5 5
0x5655621c 6 in intro.c
eax 0x4 4
0x5655621e 6 in intro.c
eax 0x8 8
6 in intro.c
eax 0xc 12
7 in intro.c
eax 0x11 17
[Inferior 1 (process 630) exited normally]
\end{lstlisting}
\item Für die Herleitung der Funktion werden zuerst ein paar Probewerte genommen.
\begin{align*}
f(0) &= 2\\
f(3) &= 11\\
f(4) &= 14\\
f(5) &= 17\\
f(7) &= 23\\
\end{align*}
Die Funktion $f(n)$ muss eine konstante 2 haben, da $f(0) = 2$.
Anschließend gehe man davon aus, dass $f(n)$ linear sei. Dann müsste $f(n) = an + 2$ sein.
Das gilt genau dann, wenn der ggT aller Paare $(n, f(n) - 2)$ für jeden Wert gleich ist. Das gilt mit $\forall n \in \mathbb{N} : ggT(n, f(n) - 2) = 3$.
Also:
\begin{align*}
f(n) = 3n + 2
\end{align*}
\item Das Programm liefert den Output
\begin{lstlisting}[language=bash]
user@intro:~$ readelf -S intro
There are 36 section headers, starting at offset 0x413c:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 000001b4 0001b4 000013 00 A 0 0 1
[ 2] .note.gnu.build-i NOTE 000001c8 0001c8 000024 00 A 0 0 4
[ 3] .note.gnu.propert NOTE 000001ec 0001ec 00001c 00 A 0 0 4
[ 4] .note.ABI-tag NOTE 00000208 000208 000020 00 A 0 0 4
[ 5] .gnu.hash GNU_HASH 00000228 000228 000020 04 A 6 0 4
[ 6] .dynsym DYNSYM 00000248 000248 0000a0 10 A 7 1 4
[ 7] .dynstr STRTAB 000002e8 0002e8 0000a7 00 A 0 0 1
[ 8] .gnu.version VERSYM 00000390 000390 000014 02 A 6 0 2
[ 9] .gnu.version_r VERNEED 000003a4 0003a4 000030 00 A 7 1 4
[10] .rel.dyn REL 000003d4 0003d4 000060 08 A 6 0 4
[11] .rel.plt REL 00000434 000434 000020 08 AI 6 24 4
[12] .init PROGBITS 00001000 001000 000024 00 AX 0 0 4
[13] .plt PROGBITS 00001030 001030 000050 04 AX 0 0 16
[14] .plt.got PROGBITS 00001080 001080 000010 10 AX 0 0 16
[15] .plt.sec PROGBITS 00001090 001090 000040 10 AX 0 0 16
[16] .text PROGBITS 000010d0 0010d0 000249 00 AX 0 0 16
[17] .fini PROGBITS 0000131c 00131c 000018 00 AX 0 0 4
[18] .rodata PROGBITS 00002000 002000 00001c 00 A 0 0 4
[19] .eh_frame_hdr PROGBITS 0000201c 00201c 000054 00 A 0 0 4
[20] .eh_frame PROGBITS 00002070 002070 00013c 00 A 0 0 4
[21] .init_array INIT_ARRAY 00003ec8 002ec8 000004 04 WA 0 0 4
[22] .fini_array FINI_ARRAY 00003ecc 002ecc 000004 04 WA 0 0 4
[23] .dynamic DYNAMIC 00003ed0 002ed0 000100 08 WA 7 0 4
[24] .got PROGBITS 00003fd0 002fd0 000030 04 WA 0 0 4
[25] .data PROGBITS 00004000 003000 000008 00 WA 0 0 4
[26] .bss NOBITS 00004008 003008 000004 00 WA 0 0 1
[27] .comment PROGBITS 00000000 003008 00002b 01 MS 0 0 1
[28] .debug_aranges PROGBITS 00000000 003033 000020 00 0 0 1
[29] .debug_info PROGBITS 00000000 003053 000369 00 0 0 1
[30] .debug_abbrev PROGBITS 00000000 0033bc 00011f 00 0 0 1
[31] .debug_line PROGBITS 00000000 0034db 00010a 00 0 0 1
[32] .debug_str PROGBITS 00000000 0035e5 0002b9 01 MS 0 0 1
[33] .symtab SYMTAB 00000000 0038a0 0004d0 10 34 51 4
[34] .strtab STRTAB 00000000 003d70 000271 00 0 0 1
[35] .shstrtab STRTAB 00000000 003fe1 000158 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
p (processor specific)
\end{lstlisting}
\item Die in dem Code angegebenen labels können wie folgt eingeteilt werden:
\begin{enumerate}[<A>:]
\item .bss
\item .data
\item Stack
\item Stack
\item Stack
\end{enumerate}
\end{subexercises}
\end{exercise}
\begin{exercise}[Crackme]{2}
Die Funkion \lstinline{verify_key} leitet das Passwort aus einem geheimen Schlüssel ab, indem der ASCII-Wert jedes Zeichens, abhängig von dessen Position, verändert wird.
Dem ASCII-Wert jedes Zeichens wird der doppelte Positionswert, bei 0 startend, abgezogen.
Die Funktion gibt den Wert \lstinline{1} zurück, falls das abgeleitete Passwort mit der konstanten Zeichenkette \lstinline{MMNNQ} übereinstimmt.
Andernfalls wird der Wert \lstinline{0} zurückgegeben.
\end{exercise}
\begin{exercise}[System Calls und Shellcode]{3}
\begin{subexercises}
\item Ein Linux-Syscall auf der x86-Architektur ist als i386-Architektur in \lstinline{syscall(2)} der Linux Manpages spezifiziert.
oohhh
Dabei wird die Zahlenkennung des Syscalls in Register eax übergeben.
Bis zu 6 Argumente können in den Registern \lstinline{ebx}, \lstinline{ecx}, \lstinline{edx}, \lstinline{esi}, \lstinline{edi} und \lstinline{ebp} übergeben werden.
Mit dem Aufruf der Instruktion \lstinline{int $0x80} wird der Syscall ausgelöst und der Syscall-Handler im Kernel durch Auslösen eines Interrupts ausgeführt.
Ausgaben des Syscalls werden in den Registern eax und edx zurückgegeben.
\end{subexercises}
\end{exercise}
\end{document}