{"id":353,"date":"2012-10-17T16:33:41","date_gmt":"2012-10-17T14:33:41","guid":{"rendered":"http:\/\/clark.tipistrani.it\/?p=353"},"modified":"2012-11-09T09:27:23","modified_gmt":"2012-11-09T08:27:23","slug":"apache2-per-sugarcrm","status":"publish","type":"post","link":"http:\/\/clark.tipistrani.it\/?p=353","title":{"rendered":"Apache2 per SugarCrm"},"content":{"rendered":"<p>Il web server a cui si appoggia SugarCrm \u00e8 Apache2,\u00a0 di seguito le note di configurazione e hardening.<br \/>\napt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 libapache2-mod-php5 php5-common php5-gd php5-idn php-pear php5-imap php5-mcrypt php5-mhash php5-mysql php5-sqlite php5-xmlrpc php5-xsl php5-curl libapache-mod-security,<br \/>\nche si tirano dietro tutte le necessarie dipendenze,\u00a0 poich\u00e9 questo sito lavorer\u00e0 solo in https genero le chiavi necessarie come spiegato qui.<br \/>\nabilito il modulo ssl con a2enmod ssl.<br \/>\nRiprendo dopo qualche giorno questa configurazione per renderla un pochino piu&#8217; flessibile visto che mi son trovato davvero male a fare degli aggiornamenti.<\/p>\n<p>Sotto \/etc\/apache2 creo la directory myconf e li sotto metteo tutte le personalizzazioni possibili, in modo che siano facilmente escludibili aggiungendo al file apache2.con la direttiva\u00a0 &#8220;Include&#8221; myconf\/ che all&#8217;occorenza pu\u00f2 essere commentata.<\/p>\n<p>In \/etc\/apache2\/myconf creo il file mod_security che contiene:<br \/>\n&lt;IfModule mod_security.c&gt;<br \/>\n# mod_security configuration directives<br \/>\n# &#8230;<br \/>\n# Turn the filtering engine On or Off<br \/>\nSecFilterEngine On<br \/>\n# The audit engine works independently and<br \/>\n# can be turned On of Off on the per-server or<br \/>\n# on the per-directory basis<br \/>\nSecAuditEngine RelevantOnly<br \/>\n# Some sane defaults<br \/>\n#Check if URL characters where encoded<br \/>\nSecFilterCheckURLEncoding On<br \/>\n#Check UTF-8 encoding<br \/>\nSecFilterCheckUnicodeEncoding Off<br \/>\n#Allow 1 byte characters<br \/>\n# Accept almost all byte values<br \/>\nSecFilterForceByteRange 0 255<br \/>\n# Should mod_security inspect POST payloads<br \/>\nSecFilterScanPOST On<br \/>\n# Server masking is optional<br \/>\n# SecServerSignature &#8220;Microsoft-IIS\/0.0&#8221;<br \/>\nSecAuditEngine RelevantOnly<br \/>\n# The name of the audit log file<br \/>\nSecAuditLog \/var\/log\/apache2\/audit_log<br \/>\n# Require HTTP_USER_AGENT and HTTP_HOST headers<br \/>\nSecFilterSelective &#8220;HTTP_USER_AGENT|HTTP_HOST&#8221; &#8220;^$&#8221;<br \/>\n# You normally won&#8217;t need debug logging<br \/>\n# Debug level set to a minimum<br \/>\nSecFilterDebugLog \/var\/log\/apache2\/modsec_debug_log<br \/>\nSecFilterDebugLevel 0<br \/>\n# Should mod_security inspect POST payloads<br \/>\nSecFilterScanPOST On<br \/>\n# By default log and deny suspicious requests<br \/>\n# with HTTP status 500<br \/>\nSecFilterDefaultAction &#8220;deny,log,status:500&#8221;<br \/>\n# Only accept request encodings we know how to handle<br \/>\n# we exclude GET requests from this because some (automated)<br \/>\n# clients supply &#8220;text\/html&#8221; as Content-Type<br \/>\nSecFilterSelective REQUEST_METHOD &#8220;!^GET$&#8221; chain<br \/>\nSecFilterSelective HTTP_Content-Type &#8220;!(^$|^application\/x-www-form-urlencoded$|^multipart\/form-data)&#8221;<br \/>\n# Require Content-Length to be provided with<br \/>\n# every POST request<br \/>\nSecFilterSelective REQUEST_METHOD &#8220;^POST$&#8221; chain<br \/>\nSecFilterSelective HTTP_Content-Length &#8220;^$&#8221;<br \/>\n# Don&#8217;t accept transfer encodings we know we don&#8217;t handle<br \/>\n# (and you don&#8217;t need it anyway)SecFilterSelective HTTP_Transfer-Encoding &#8220;!^$&#8221;<br \/>\n# Some common application-related rules from<br \/>\n# http:\/\/modsecrules.monkeydev.org\/rules.php?safety=safe<br \/>\n#Nuke Bookmarks XSS<br \/>\nSecFilterSelective THE_REQUEST &#8220;\/modules\\.php\\?name=Bookmarks\\&amp;file=(del_cat\\&amp;catname|del_mark\\&amp;markname|edit_cat\\&amp;catname|edit_cat\\&amp;catcomment|marks\\&amp;catname|uploadbookmarks\\&amp;category)=(&lt;[[:space:]]*script|(http|https|ftp)\\:\/)&#8221;<br \/>\n#Nuke Bookmarks Marks.php SQL Injection Vulnerability<br \/>\nSecFilterSelective THE_REQUEST &#8220;modules\\.php\\?name=Bookmarks\\&amp;file=marks\\&amp;catname=.*\\&amp;category=.*\/\\*\\*\/(union|select|delete|insert)&#8221;<br \/>\n#PHPNuke general XSS attempt<br \/>\n#\/modules.php?name=News&amp;file=article&amp;sid=1&amp;optionbox=<br \/>\nSecFilterSelective THE_REQUEST &#8220;\/modules\\.php\\?*name=&lt;[[:space:]]*script&#8221;<br \/>\n# PHPNuke SQL injection attempt<br \/>\nSecFilterSelective THE_REQUEST &#8220;\/modules\\.php\\?*name=Search*instory=&#8221;<br \/>\n#phpnuke sql insertion<br \/>\nSecFilterSelective THE_REQUEST &#8220;\/modules\\.php*name=Forums.*file=viewtopic*\/forum=.*\\&#8217;\/&#8221;<br \/>\n# WEB-PHP phpbb quick-reply.php arbitrary command attempt<br \/>\nSecFilterSelective THE_REQUEST &#8220;\/quick-reply\\.php&#8221; chain<br \/>\nSecFilter &#8220;phpbb_root_path=&#8221;<br \/>\n#Topic Calendar Mod for phpBB Cross-Site Scripting Attack<br \/>\nSecFilterSelective THE_REQUEST &#8220;\/calendar_scheduler\\.php\\?start=(&lt;[[:space:]]*script|(http|https|ftp)\\:\/)&#8221;<br \/>\n# phpMyAdmin: Safe<br \/>\n#phpMyAdmin Export.PHP File Disclosure Vulnerability<br \/>\nSecFilterSelective SCRIPT_FILENAME &#8220;export\\.php$&#8221; chain<br \/>\nSecFilterSelective ARG_what &#8220;\\.\\.&#8221;<br \/>\n#phpMyAdmin path vln<br \/>\nSecFilterSelective REQUEST_URI &#8220;\/css\/phpmyadmin\\.css\\.php\\?GLOBALS\\[cfg\\]\\[ThemePath\\]=\/etc&#8221;<\/p>\n<p>#SQL injection<br \/>\nSecFilter &#8220;delete[[:space:]]+from&#8221;<br \/>\nSecFilter &#8220;insert[[:space:]]+into&#8221;<br \/>\nSecFilter &#8220;select.+from&#8221;<br \/>\nSecFilter &#8220;drop[[:space:]]table&#8221;<br \/>\nSecFilter &#8220;&lt;script&#8221;<br \/>\nSecFilter &#8220;&lt;.+&gt;&#8221;<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>creo\u00a0 il file \/etc\/apache2\/myconf\/myapache2.conf\u00a0 che contiene:<\/p>\n<p>&lt;IfModule mod_security.c&gt;<br \/>\n# Turn the filtering engine On or Off<br \/>\nSecFilterEngine On<\/p>\n<p># Make sure that URL encoding is valid<br \/>\nSecFilterCheckURLEncoding On<\/p>\n<p># Unicode encoding check<br \/>\nSecFilterCheckUnicodeEncoding Off<\/p>\n<p># Only allow bytes from this range<br \/>\nSecFilterForceByteRange 0 255<\/p>\n<p># Only log suspicious requests<br \/>\nSecAuditEngine RelevantOnly<\/p>\n<p># The name of the audit log file<br \/>\nSecAuditLog \/var\/log\/apache2\/audit_log<br \/>\n# Debug level set to a minimum<br \/>\nSecFilterDebugLog \/var\/log\/apache2\/modsec_debug_log<br \/>\nSecFilterDebugLevel 0<\/p>\n<p># Should mod_security inspect POST payloads<br \/>\nSecFilterScanPOST On<\/p>\n<p># By default log and deny suspicious requests<br \/>\n# with HTTP status 500<br \/>\nSecFilterDefaultAction &#8220;deny,log,status:500&#8221;<\/p>\n<p>&lt;\/IfModule&gt;<br \/>\nOra posso modificare il file \/etc\/apache2\/conf.d\/security modificando le due voci<br \/>\n[orig] ServerTokens OS<br \/>\n[mod] ServerTokens Prod<br \/>\ne<br \/>\n[orig] ServerSignature On<br \/>\n[mod] ServerSignature Off<br \/>\nche rispettivamente indicano negli header che il server trasmette al client che sistema operativo hosta il sito e la versione di apache2, informazioni utili a un possibile attacker per sfruttare vulnerabilit\u00e0 note o meno note di quegli elementi specifici.<\/p>\n<p>Creo in \/etc\/apache2\/sites-avaible il virtual-host crm.myfirm.com che contiene:<br \/>\n&lt;VirtualHost *:443&gt;<br \/>\nServerAdmin webmaster@myfirml.com<br \/>\nServerName crm.myfirm.com<br \/>\nDocumentRoot \/var\/www\/crm.myfirm.com\/<br \/>\nphp_admin_value open_basedir \/var\/www\/crm.myfirm.com<br \/>\nOptions +FollowSymLinks<br \/>\nSSLEngine on<br \/>\nSSLOptions +FakeBasicAuth +ExportCertData +StrictRequire<br \/>\nSSLCertificateFile \/etc\/ssl\/myfirm\/crm.myfirm.com.crt<br \/>\nSSLCertificateKeyFile \/etc\/ssl\/myfirm\/crm.myfirm.com.key<br \/>\nSSLCACertificateFile \/etc\/ssl\/myfirm\/myfirm-CA.crt<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>Con a2ensite\u00a0 lo rendo disponibile e il sito e&#8217; pronto.<\/p>\n<p>Per pura paranoia (qualcuno disse: &#8220;non \u00e8 in dubbio se tu sia paranoico o meno, piuttosto quanto tu lo sia), mi sono posto il quesito e\u00a0 se per puro sbaglio qualcuno ci capita sopra?<br \/>\nCio\u00e8 se Mr Murphy. quel giorno \u00e8 particolarmente in vena e il gatto della Signora Giusy (che non idea di chi sia) camminando sulla tastiera digita https:\/\/crm.myfirm.com?<br \/>\nla Signora in questione potrebbe accorgersi che c&#8217;\u00e8\u00a0 un sito che richiede nome e password&#8230;<br \/>\nCi\u00f2 \u00e8 MALE!<br \/>\nNecessita un filtro di prima istanza per poterti loggare al crm devi sapere che c&#8217;\u00e8 e non solo devi anche dire chi sei prima di poterti loggare e operare.<br \/>\nLa soluzione la troviamo in htpasswd, possiamo ipotizzare una unica login e password per avere accesso alla login vera e propria che poi sar\u00e0 a seconda dei casi con permessi di varia natura ma questo a livello di applicativo, Io voglio che per arrivare all&#8217;applicativo il sistema riconosca che si e&#8217; autorizzati e quindi htpasswd -cbs \/etc\/apache2\/.htpasswd\u00a0 agent passwordcomune<br \/>\nCosi&#8217; facendo creiamo sotto \/etc\/apache2 il file .htpasswd che conterr\u00e0 la login agent e la password passwordcomune criptata in SHA<\/p>\n<p>Configurazione finita e hardenizzata per quanto possibile.<\/p>\n<p>files di configurazione:<br \/>\n<a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=577\" rel=\"attachment wp-att-577\">apache2.conf.tar<\/a><br \/>\n<a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=578\" rel=\"attachment wp-att-578\">myapache2.conf.tar<\/a><a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=365\" rel=\"attachment wp-att-365\"><br \/>\n<\/a><a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=369\" rel=\"attachment wp-att-369\">mod_security.tar<\/a><a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=365\" rel=\"attachment wp-att-365\"><br \/>\n<\/a><a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=370\" rel=\"attachment wp-att-370\">security.tar<br \/>\n<\/a><a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=372\" rel=\"attachment wp-att-372\">crm.myfirm.com.tar<\/a><a href=\"http:\/\/clark.tipistrani.it\/?attachment_id=370\" rel=\"attachment wp-att-370\"><br \/>\n<\/a><\/p>\n<p>Per comodit\u00e0 allego qui i files di configurazione di apache2<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Il web server a cui si appoggia SugarCrm \u00e8 Apache2,\u00a0 di seguito le note di configurazione e hardening. apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 libapache2-mod-php5 php5-common php5-gd php5-idn php-pear php5-imap php5-mcrypt php5-mhash php5-mysql php5-sqlite php5-xmlrpc php5-xsl php5-curl libapache-mod-security, che si tirano dietro tutte le necessarie dipendenze,\u00a0 poich\u00e9 questo sito lavorer\u00e0 solo in https genero [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,7,6],"tags":[],"class_list":["post-353","post","type-post","status-publish","format-standard","hentry","category-linux","category-sistemi-operativi","category-work"],"_links":{"self":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=353"}],"version-history":[{"count":20,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":581,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=\/wp\/v2\/posts\/353\/revisions\/581"}],"wp:attachment":[{"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/clark.tipistrani.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}