<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>johker&#039;s blog &#187; port</title>
	<atom:link href="http://johker.ibutho.de/tag/port/feed/" rel="self" type="application/rss+xml" />
	<link>http://johker.ibutho.de</link>
	<description>stories about me, my life and my trips</description>
	<lastBuildDate>Sun, 18 Dec 2011 11:53:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Der neue Server: Teil 2 System härten</title>
		<link>http://johker.ibutho.de/2009/03/18/der-neue-server-teil-2-system-harten/</link>
		<comments>http://johker.ibutho.de/2009/03/18/der-neue-server-teil-2-system-harten/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 19:04:38 +0000</pubDate>
		<dc:creator>johker</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[absichern]]></category>
		<category><![CDATA[aide]]></category>
		<category><![CDATA[bastille]]></category>
		<category><![CDATA[benachrichtigung]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[chkrootkit]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[dienst]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[fcheck]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[forkbomb]]></category>
		<category><![CDATA[freiheit]]></category>
		<category><![CDATA[gestapo]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacker]]></category>
		<category><![CDATA[hardening]]></category>
		<category><![CDATA[härten]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[IDS]]></category>
		<category><![CDATA[innenminister]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[jail]]></category>
		<category><![CDATA[kompromiss]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[limits.conf]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[nessus]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[nodev]]></category>
		<category><![CDATA[noexec]]></category>
		<category><![CDATA[nosuid]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[passwd]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[rkhunter]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[rootkit]]></category>
		<category><![CDATA[schäuble]]></category>
		<category><![CDATA[security by obscurity]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sicherheit]]></category>
		<category><![CDATA[sshd]]></category>
		<category><![CDATA[sshd_config]]></category>
		<category><![CDATA[stasi]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[tmp]]></category>
		<category><![CDATA[tripwire]]></category>
		<category><![CDATA[whitelist]]></category>

		<guid isPermaLink="false">http://johker.ibutho.de/?p=114</guid>
		<description><![CDATA[Wenn man einen Server betreibt, dann legt man normalerweise auch Wert auf Sicherheit (wenn nicht, dann diesen Abschnitt einfach überspringen). Hier zeige ich einige Mittel und Wege auf einen Server sicherer zu machen. Die Liste ist sicherlich nicht komplett und &#8230; <a href="http://johker.ibutho.de/2009/03/18/der-neue-server-teil-2-system-harten/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Wenn man einen Server betreibt, dann legt man normalerweise auch Wert auf Sicherheit (wenn nicht, dann diesen Abschnitt einfach überspringen). Hier zeige ich einige Mittel und Wege auf einen Server sicherer zu machen. Die Liste ist sicherlich nicht komplett und wird es wohl auch nie werden und selbst wenn ihr alles unternehmt, was ich hier aufführe, kann euer System immer noch gehackt werden &#8211; totale Sicherheit gibt es nicht &#8211; also schiebt die Schuld nicht auf mich, wenn euer System gehackt wurde. Und vor allem: <strong>installiert</strong> euer System komplett <strong>neu</strong>, wenn ihr <strong>gehackt</strong> wurdet!</p>
<h1>Verzeichnisse härten</h1>
<p>Das <em>/tmp</em>-Verzeichnis ist oft ein Einfalltor für Angreifer, deshalb werden wir dieses nun absichern. Zusätzlich wollen wir auch die Verzeichnisse <em>/var</em> und <em>/home</em> besser schützen, &#8230; sowie <em>/</em> bei Fehlern read-only mounten:</p>
<p><em>/etc/fstab</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">proc <span style="color: #000000; font-weight: bold;">/</span>proc proc defaults <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
none <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>pts devpts <span style="color: #007800;">gid</span>=<span style="color: #000000;">5</span>,<span style="color: #007800;">mode</span>=<span style="color: #000000;">620</span> <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md0 <span style="color: #000000; font-weight: bold;">/</span>boot ext2 defaults <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
<span style="color: #666666; font-style: italic;"># /dev/md1 belongs to LVM volume group 'vg0'</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg0<span style="color: #000000; font-weight: bold;">/</span>root  <span style="color: #000000; font-weight: bold;">/</span>  ext3  defaults,<span style="color: #007800;">errors</span>=remount-ro <span style="color: #000000;">0</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg0<span style="color: #000000; font-weight: bold;">/</span>swap  swap  swap  defaults <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg0<span style="color: #000000; font-weight: bold;">/</span>tmp  <span style="color: #000000; font-weight: bold;">/</span>tmp  ext3  rw,noexec,nosuid,nodev <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg0<span style="color: #000000; font-weight: bold;">/</span>home  <span style="color: #000000; font-weight: bold;">/</span>home  ext3  rw,nosuid,nodev <span style="color: #000000;">0</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg0<span style="color: #000000; font-weight: bold;">/</span>var  <span style="color: #000000; font-weight: bold;">/</span>var  ext3  rw,nosuid,nodev <span style="color: #000000;">0</span> <span style="color: #000000;">2</span></pre></div></div>

<p>Quelle: <a href="http://www.cromwell-intl.com/security/linux-hardening.html" target="_blank">http://www.cromwell-intl.com/security/linux-hardening.html</a></p>
<h1>sshd absichern</h1>
<p>Voraussetzung dafür diesen Abschnitt zu implementieren ist, dass es neben root noch mindestens einen anderen Benutzer gibt, denn im folgenden wird root das direkte Anmelden über ssh verboten. Dies erschwert es einem Angreifer root-Rechte zu erlangen, da er erst das Passwort eines Benutzers knacken muss und dann zusätzlich noch das root-Passwort (oder aber er macht es sich einfach und benutzt einfach einen Exploit um sich root-Rechte zu verschaffen). Zudem kann man so immer über &#8220;<em>/var/log/auth.log</em>&#8221; herausfinden, wer sich als root angemeldet hat.</p>
<p>Als erstes erstellen wir eine Gruppe &#8220;sshusers&#8221;. Nur Benutzer, die dieser Gruppe angehören, dürfen sich auch am ssh-Server anmelden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">addgroup <span style="color: #660033;">--system</span> sshusers</pre></div></div>

<p>Danach fügen wir unseren nicht-root Benutzer dieser Gruppe hinzu:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #000000; font-weight: bold;">&lt;</span>Benutzername<span style="color: #000000; font-weight: bold;">&gt;</span> sshusers</pre></div></div>

<p>Nun meine <em>sshd_config</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Package generated configuration file</span>
<span style="color: #666666; font-style: italic;"># See the sshd(8) manpage for details</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># What ports, IPs and protocols we listen for</span>
Port <span style="color: #000000;">22</span>
<span style="color: #666666; font-style: italic;"># Use these options to restrict which interfaces/protocols sshd will bind to</span>
<span style="color: #666666; font-style: italic;">#ListenAddress ::</span>
<span style="color: #666666; font-style: italic;">#ListenAddress 0.0.0.0</span>
ListenAddress 78.46.92.6
Protocol <span style="color: #000000;">2</span>
<span style="color: #666666; font-style: italic;"># HostKeys for protocol version 2</span>
HostKey <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>ssh_host_rsa_key
HostKey <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>ssh_host_dsa_key
<span style="color: #666666; font-style: italic;">#Privilege Separation is turned on for security</span>
UsePrivilegeSeparation <span style="color: #c20cb9; font-weight: bold;">yes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Lifetime and size of ephemeral version 1 server key</span>
KeyRegenerationInterval <span style="color: #000000;">3600</span>
ServerKeyBits <span style="color: #000000;">768</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Logging</span>
SyslogFacility AUTH
LogLevel VERBOSE
&nbsp;
<span style="color: #666666; font-style: italic;"># Authentication:</span>
LoginGraceTime <span style="color: #000000;">30</span>
AllowGroups sshusers
PermitRootLogin no
StrictModes <span style="color: #c20cb9; font-weight: bold;">yes</span>
&nbsp;
RSAAuthentication <span style="color: #c20cb9; font-weight: bold;">yes</span>
PubkeyAuthentication <span style="color: #c20cb9; font-weight: bold;">yes</span>
AuthorizedKeysFile      <span style="color: #000000; font-weight: bold;">%</span>h<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys
&nbsp;
<span style="color: #666666; font-style: italic;"># Don't read the user's ~/.rhosts and ~/.shosts files</span>
IgnoreRhosts <span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #666666; font-style: italic;"># For this to work you will also need host keys in /etc/ssh_known_hosts</span>
RhostsRSAAuthentication no
<span style="color: #666666; font-style: italic;"># similar for protocol version 2</span>
HostbasedAuthentication no
<span style="color: #666666; font-style: italic;"># Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication</span>
<span style="color: #666666; font-style: italic;">#IgnoreUserKnownHosts yes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># To enable empty passwords, change to yes (NOT RECOMMENDED)</span>
PermitEmptyPasswords no
&nbsp;
<span style="color: #666666; font-style: italic;"># Change to yes to enable challenge-response passwords (beware issues with</span>
<span style="color: #666666; font-style: italic;"># some PAM modules and threads)</span>
ChallengeResponseAuthentication no
&nbsp;
<span style="color: #666666; font-style: italic;"># Change to no to disable tunnelled clear text passwords</span>
<span style="color: #666666; font-style: italic;">#PasswordAuthentication yes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Kerberos options</span>
<span style="color: #666666; font-style: italic;">#KerberosAuthentication no</span>
<span style="color: #666666; font-style: italic;">#KerberosGetAFSToken no</span>
<span style="color: #666666; font-style: italic;">#KerberosOrLocalPasswd yes</span>
<span style="color: #666666; font-style: italic;">#KerberosTicketCleanup yes</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># GSSAPI options</span>
<span style="color: #666666; font-style: italic;">#GSSAPIAuthentication no</span>
<span style="color: #666666; font-style: italic;">#GSSAPICleanupCredentials yes</span>
&nbsp;
X11Forwarding no
X11DisplayOffset <span style="color: #000000;">10</span>
PrintMotd no
PrintLastLog <span style="color: #c20cb9; font-weight: bold;">yes</span>
TCPKeepAlive <span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #666666; font-style: italic;">#UseLogin no</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#MaxStartups 10:30:60</span>
Banner <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>issue.net
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow client to pass locale environment variables</span>
AcceptEnv LANG LC_<span style="color: #000000; font-weight: bold;">*</span>
&nbsp;
Subsystem sftp <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>openssh<span style="color: #000000; font-weight: bold;">/</span>sftp-server
&nbsp;
UsePAM <span style="color: #c20cb9; font-weight: bold;">yes</span></pre></div></div>

<p>Wer auf &#8220;security by obscurity&#8221; steht, kann auch noch den ssh-Port auf einen nicht Standardport verlegen. Im Grunde genommen bringt es nichts &#8211; außer vielleicht Verstimmungen bei den Benutzern, da die Benutzerfreundlichkeit stark leidet und die Tipparbeit steigt &#8211; da jeder Portscan, z.b. mit nmap, den ssh-Port preisgibt. Natürlich kann man auf der anderen Seite auch argumentieren, dass primitive DoS-Skripts nur den Standardport ausprobieren und das Umlegen des ssh-Ports doch einen gewissen Schutz bietet.<br />
Zusätzlich kann man noch <em>fail2ban</em> installieren, um sich vor DoS-Attacken über ssh (und auch über viele andere Dienste) zu schützen. Dies wird in einem späteren Abschnitt behandelt und stellt meiner Meinung nach die bessere Alternative zu einem nicht-Standardport dar.</p>
<p>Quellen:</p>
<p><a href="http://root-support.com/blog/?p=183" target="_blank">http://root-support.com/blog/?p=183</a><br />
<a href="http://aymanh.com/tips-to-secure-linux-workstation" target="_blank">http://aymanh.com/tips-to-secure-linux-workstation</a><br />
<a href="http://www.pro-linux.de/work/rootserver/teil2.html" target="_blank">http://www.pro-linux.de/work/rootserver/teil2.html</a></p>
<h1>forkbombs</h1>
<p>Eine <a href="http://de.wikipedia.org/wiki/Forkbomb" target="_blank">forkbomb</a> ist ein DoS-Angriff, bei dem sehr viele Prozesse gestartet werden. So viele, dass der komplette Arbeitsspeicher vollgeschrieben wird und das System somit unbenutzbar wird. Ein Beispiel für eine forkbomb wäre (<strong>ACHTUNG:</strong> Nicht auf einem Produktivsystem ausführen!):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> :<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span> :<span style="color: #000000; font-weight: bold;">|</span>:<span style="color: #000000; font-weight: bold;">&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>;:</pre></div></div>

<p>Um diese Art eines Angriffs (zumindest teilweise) zu verhindern, ändern wir die Datei &#8220;<em>/etc/security/limits.conf</em>&#8221; dahingehend ab, dass jeder Nutzer der Gruppe &#8220;users&#8221; (in denen all unsere Konsolennutzer Mitglied sind) maximal 150 Prozesse starten darf:</p>
<p><em>/etc/security/limits.conf</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span><span style="color: #c20cb9; font-weight: bold;">users</span>          soft    nproc  <span style="color: #000000;">100</span>
<span style="color: #000000; font-weight: bold;">@</span><span style="color: #c20cb9; font-weight: bold;">users</span>          hard    nproc  <span style="color: #000000;">150</span></pre></div></div>

<p>Quelle:<br />
<a href="http://wiki.craz1.homelinux.com/index.php/Linux:Security:Forkbomb" target="_blank"> http://wiki.craz1.homelinux.com/index.php/Linux:Security:Forkbomb</a><br />
<a href="http://aymanh.com/tips-to-secure-linux-workstation" target="_blank"> http://aymanh.com/tips-to-secure-linux-workstation</a></p>
<h1>rkhunter</h1>
<p>Dieses Tool dient dem Aufspüren von <a href="http://de.wikipedia.org/wiki/Rootkit" target="_blank">rootkits</a>. Es hat eine Datenbank mit Signaturen, welche wöchentlich aktualisiert wird und überprüfen täglich über einen cronjob, ob das System potentiell infiziert ist. Wird eine Infizierung/Gefahr festgestellt, verschickt <em>rkhunter</em> eine E-Mail.<br />
Neben <em>rkhunter</em> gibts es auch noch <em>chkrootkit</em>, falls jemand will kann er zusätzlich auch noch dieses Tool installieren.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> rkhunter chkrootkit</pre></div></div>

<p>Editieren der Datei &#8220;<em>/etc/rkhunter.conf</em>&#8221; (hier werden nur die Zeilen angezeigt, die geändert wurden):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">DISABLE_TESTS</span>=<span style="color: #ff0000;">&quot;suspscan deleted_files packet_cap_apps&quot;</span>
<span style="color: #007800;">ALLOWHIDDENDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>.java</pre></div></div>

<p><em>/etc/default/rkhunter</em>: (auch nur geänderte Zeilen):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">DB_UPDATE_EMAIL</span>=<span style="color: #ff0000;">&quot;yes&quot;</span></pre></div></div>

<p>Diese Einstellungen nehmen einen erweiterten Test für versteckte Prozesse zu den Standardtests auf und nehmen das Verzeichnis &#8220;<em>/etc/.java</em>&#8221; auf die Whitelist mit auf, damit <em>rkhunter</em> sich nicht bei jedem Scan beschwert, dass er eine verdächtige Datei gefunden hat, nur weil Java installiert ist. Darüber hinaus bekommt man wöchentlich eine E-Mail über die Ergebnisse des Datenbank-Updates.</p>
<h1>bastille</h1>
<p><em>Bastille</em> ist ein Tool, welches das Härten eines Systems drastisch vereinfacht. <em>Bastille</em> führt den Nutzer über eine Textberfläche durch verschiedene Fragen und anhand der Antworten des Benutzers wird das System am Schluss verändert. Das Besondere dabei ist, dass <em>bastille</em> alle Aktionen genau und ausführlich erklärt und man die Aktionen auch selbst ausführen kann, anstatt <em>bastille</em> die Ausführung zu überlassen. <em>Bastille</em> wird aktiv von vielen großen Firmen entwickelt und sollte eigentlich zu den Standardwerkzeugen eines jeden verantwortungsbewussten Linux-Administrators gehören, da es viel Arbeit abnimmt und auf Dinge aufmerksam macht, die man sonst evtl. übersieht.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> bastille</pre></div></div>

<p>Da das <em>bastille</em> Paket in lenny von Haus aus nicht kompatibel mit lenny ist, muss die Konfigurationsdateien von <em>bastille</em> ändern werden, um <em>bastille</em> vorzugaukeln, dass es kompatibel mit lenny wäre (siehe <a href="http://www.debianforum.de/forum/viewtopic.php?f=29&amp;t=108266" target="_blank">hier</a> und <a href="http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg610868.html" target="_blank">hier</a>):</p>
<p><em>/usr/lib/Bastille/API.pm</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">sub</span> get_supported_OS_list <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@list</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;DB2.2&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;DB3.0&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;DB3.1&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;DB4.0&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;DB5.0&quot;</span><span style="color: #339933;">,</span></pre></div></div>

<p><em>/usr/lib/Bastille/IOLoader.pm</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$supported_versions</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'DB2.2 DB3.0 DB3.1      DB4.0 DB5.0'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Die Fragen von <em>bastille</em> nach bestem Wissen und Gewissen beantworten und das System so seinen Wünschen nach anpassen.<br />
<em>Bastille</em> legt ein ausführliches Log über die Änderungen an und bietet die Möglichkeit die vorgenommenen Änderungen später wieder rückgängig zu machen.</p>
<p>Quelle:<br />
<a href="http://linux.com/feature/118353" target="_blank"> http://linux.com/feature/118353</a></p>
<h1>/etc/passwd</h1>
<p>In diesem Abschnitt geht es darum, die Shells von Systembenutzern auf &#8220;<em>/bin/false</em>&#8221; bzw. &#8220;<em>/bin/nologin</em>&#8221; umzustellen, denn die meisten Serverdienste brauchen keinen Konsolenzugriff und stellen in der Standardeinstellung eine gewisse Sicherheitsgefahr dar. Welche Diensten ohne Konsole zurechtkommen, muss man recherchieren oder ausprobieren. Nachdem man einen neuen Serverdienst installiert hat, bietet es sich an diese Datei erneut zu überprüfen und die Konsole der Benutzer ggf. zu ändern.</p>
<p>Beispielhaft zwei Zeilen, wie soetwas aussehen könnte:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">man</span>:x:<span style="color: #000000;">6</span>:<span style="color: #000000;">12</span>:<span style="color: #c20cb9; font-weight: bold;">man</span>:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">man</span>:<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span>
mail:x:<span style="color: #000000;">8</span>:<span style="color: #000000;">8</span>:mail:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail:<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span></pre></div></div>

<h1>fail2ban</h1>
<p>Fail2ban ist eine effektive Waffe gegen DoS-Angriffe jedweder Art &#8211; und nicht nur das: man kann auch gescheiterte Authentifizierungsversuche über PAM oder Overflow-Angriffe auf Apache eindämmen. Es bringt schon viele vordefinierte Filter (jails), z.B. für ssh und apache, mit und lässt sich zusätzlich über selbstgeschriebene jails erweitern. Es ist über die Datei &#8220;<em>/etc/fail2ban/jail.local</em>&#8221; anpassbar. Man sollte die Datei &#8220;<em>/etc/fail2ban/jail.conf</em>&#8221; nicht selbst verändern. Das stellt sicher, dass bei einem Update auch immer die neuesten Regeln und Anpassungen verwendet werden. Über <em>jail.local</em> lässt sich jede Einstellung in <em>jail.conf</em> überschreiben. Bitte genau abwägen, welche jails man aktiviert und welche nicht (falls postfix nicht auf dem Server nicht installiert ist, ist es unsinnig den jail dafür zu aktivieren).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fail2ban<span style="color: #000000; font-weight: bold;">/</span>jail.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fail2ban<span style="color: #000000; font-weight: bold;">/</span>jail.local</pre></div></div>

<p><em>/etc/fail2ban/jail.local</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Fail2Ban jail.local file</span>
<span style="color: black;">&#91;</span>DEFAULT<span style="color: black;">&#93;</span>
&nbsp;
ignoreip = 127.0.0.1
bantime  = <span style="color: #ff4500;">600</span>
maxretry = <span style="color: #ff4500;">3</span>
&nbsp;
backend = polling
destemail = root
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># ACTIONS</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
banaction = iptables-multiport
mta = sendmail
protocol = tcp
action = <span style="color: #66cc66;">%</span><span style="color: black;">&#40;</span>action_mwl<span style="color: black;">&#41;</span>s
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># JAILS</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: black;">&#91;</span>ssh<span style="color: black;">&#93;</span>
enabled = true
port    = ssh
<span style="color: #008000;">filter</span>  = sshd
logpath  = /var/log/auth.<span style="color: black;">log</span>
&nbsp;
<span style="color: black;">&#91;</span>ssh-ddos<span style="color: black;">&#93;</span>
enabled = true
port    = ssh
<span style="color: #008000;">filter</span>  = sshd-ddos
logpath  = /var/log/auth.<span style="color: black;">log</span>
&nbsp;
<span style="color: black;">&#91;</span>pam-generic<span style="color: black;">&#93;</span>
enabled = true
<span style="color: #008000;">filter</span>  = pam-generic
port = <span style="color: #008000;">all</span>
banaction = iptables-allports
port     = anyport
logpath  = /var/log/auth.<span style="color: black;">log</span>
&nbsp;
<span style="color: black;">&#91;</span>xinetd-fail<span style="color: black;">&#93;</span>
enabled   = false
<span style="color: #008000;">filter</span>    = xinetd-fail
port      = <span style="color: #008000;">all</span>
banaction = iptables-multiport-log
logpath   = /var/log/daemon.<span style="color: black;">log</span>
maxretry  = <span style="color: #ff4500;">2</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># HTTP servers</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: black;">&#91;</span>apache<span style="color: black;">&#93;</span>
enabled = true
port    = http,https
<span style="color: #008000;">filter</span>  = apache-auth
logpath = /var/log/apache<span style="color: #66cc66;">*</span>/<span style="color: #66cc66;">*</span>error.<span style="color: black;">log</span>
&nbsp;
<span style="color: black;">&#91;</span>apache-noscript<span style="color: black;">&#93;</span>
enabled = true
port    = http,https
<span style="color: #008000;">filter</span>  = apache-noscript
logpath = /var/log/apache<span style="color: #66cc66;">*</span>/<span style="color: #66cc66;">*</span>error.<span style="color: black;">log</span>
&nbsp;
<span style="color: black;">&#91;</span>apache-overflows<span style="color: black;">&#93;</span>
enabled = true
port    = http,https
<span style="color: #008000;">filter</span>  = apache-overflows
logpath = /var/log/apache<span style="color: #66cc66;">*</span>/<span style="color: #66cc66;">*</span>error.<span style="color: black;">log</span>
maxretry = <span style="color: #ff4500;">2</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Mail servers</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: black;">&#91;</span>postfix<span style="color: black;">&#93;</span>
enabled  = true
port     = smtp,ssmtp
<span style="color: #008000;">filter</span>   = postfix
logpath  = /var/log/mail.<span style="color: black;">log</span>
&nbsp;
<span style="color: black;">&#91;</span>sasl<span style="color: black;">&#93;</span>
enabled  = true
port     = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
<span style="color: #008000;">filter</span>   = sasl
logpath  = /var/log/mail.<span style="color: black;">log</span></pre></div></div>

<p>Quellen:<br />
<a href="http://debianclusters.cs.uni.edu/index.php/Fail2Ban:_Preventing_Brute_Force_SSH" target="_blank"> http://debianclusters.cs.uni.edu/index.php/Fail2Ban:_Preventing_Brute_Force_SSH</a><br />
<a href="http://debaday.debian.net/2007/04/29/fail2ban-an-enemy-of-script-kiddies/" target="_blank"> http://debaday.debian.net/2007/04/29/fail2ban-an-enemy-of-script-kiddies/</a></p>
<h1>Intrusion Detection System</h1>
<p>IDS-Systeme wie <em>tripwire</em>, <em>aide</em> oder <em>fcheck</em> helfen Manipulationen an Dateien festzustellen. Um das bewerkstelligen zu können, wird anfänglich eine Datenbank erstellt mit Hash-Werten der zu überwachenden Ordner und dann werden die Werte regelmäßig überprüft. Stimmen die Hash-Werte nicht mehr überein, wird man per E-Mail benachrichtigt. Der große Nachteil ist natürlich, dass man die Datenbank immer aktuell halten muss und z.B. nach jeden &#8220;<em>aptitude update/install/purge/&#8230;</em>&#8221; ist dies der Fall. Die große Frage ist: Zu welchem Zeitpunkt es interessant ist ein IDS aufzusetzen. Wenn man einen Server ganz neu hat, ändern sich fast täglich Konfigurationsdateien oder es werden neue Pakete installiert, zu einem späteren Zeitpunkt läuft man Gefahr, dass ein Angreifer schon Programme/Konfigurationsdateien ausgetauscht hat und dann ist das IDS bereits nutzlos.<br />
Dieser Abschnitt wird zu einem späteren Zeitpunkt mit Inhalt gefüllt.</p>
<h1>iptables</h1>
<p>Früher oder später sollte man sich darüber Gedanken machen, ob man eine Firewall/Paketfilter einsetzen will oder nicht, bzw. ob es überhaupt Sinn macht.<br />
Diese Sektion wird zu einem späteren Zeitpunk um Vorschläge für eine kleine Firewall-Konfiguration, bzw. über den Aufbau von <em>iptables</em>-Regeln erweitert.</p>
<h1>Netzwerkscanner</h1>
<p>Um von außen zu überprüfen, ob der Server sicher ist, kann man Tools wie <em>nmap</em> oder <em>nessus</em> einsetzen. <em>nmap</em> dient dabei dazu offene Ports aufzuspüren, damit man diese ggf. schließen kann. <em>nessus</em> hingegen überprüft, ob der Server anfällig für bestimmte Exploits ist, z.B. anhand der Versionsnummer eines Dienstes. Um es allgemeiner auszudrücken: <em>nessus</em> ist ein Vulnerability (Schwachstellen)-Scanner.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nmap</span> <span style="color: #660033;">-A</span> <span style="color: #660033;">-T4</span> <span style="color: #000000; font-weight: bold;">&lt;</span>Serveradresse<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Die Bedienung von nessus ist etwas umfangreicher und an dieser Stelle sei deshalb auf <a href="http://www.google.com/" target="_blank">google</a> verwiesen und es wird zum Ausprobieren ermuntert.<br />
Des Weiteren sollte man einen Blick auf <em>netstat</em> werfen. Mit diesem Tool kann man lokal auf dem Server herausfinden, welche Ports geöffnet sind und welcher Dienst sich hinter welchem Port versteckt.<br />
Beispielhafter Aufruf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-tulpen</span></pre></div></div>

<h1>Weitere Möglichkeiten sich zu schützen</h1>
<p>Dies sind nur einige grundlegende Schritte, die man unternehmen kann, um einen Server abzusichern. Die Liste ist keineswegs vollständig und erhebt auch nicht den Anspruch darauf. Falls jemand weitere Wege kennt, einen Server abzusichern, dann bitte ich um einen Kommentar, bzw. um eine E-Mail und ich werde dieses Howto erweitern.<br />
Empfehlenswert ist natürlich auch das Eintragen in Mailinglisten zum Thema Sicherheit und sich allgemein über sicherheitsrelevante Themen auf dem Laufenden zu halten. Ein weiterer Schritt, um Schwachstellen zu vermeiden ist es, das System immer aktuell zu halten. Das Paketmanagement macht es einem unter Linux sehr einfach und deshalb empfehle ich es aktiv zu nutzen, anstatt Programme selbst zu kompilieren. Normalerweise ist jedes Programm, das man auf einem Server brauchen könnte in den <em>Debian</em>-Repositories enthalten (dass man auf einem Server nur mit den <em>stable</em>-Repositories arbeiten sollte und von <em>testing</em> tunlichst die Finger lassen sollte, brauche ich hier wohl kaum zu erwähnen).<br />
Abschließend bleibt nur noch einmal zu wiederholen, dass es keine absolute Sicherheit gibt und dass man einen guten Kompromiss zwischen Sicherheit und Freiheit (der Nutzer) finden sollte (Hallo, Herr Innenminister).</p>
]]></content:encoded>
			<wfw:commentRss>http://johker.ibutho.de/2009/03/18/der-neue-server-teil-2-system-harten/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

