Differenze tra le versioni di "Migrazione su wikivirtuale"
(→Mobile FrontEnd) |
|||
(64 versioni intermedie di 2 utenti non mostrate) | |||
Riga 2: | Riga 2: | ||
Ottenere una macchina wiki (fisica o virtuale) con le seguenti specifiche: | Ottenere una macchina wiki (fisica o virtuale) con le seguenti specifiche: | ||
− | * os ubuntu server | + | * os ubuntu server 18.04 aggiornato |
* IP 192.168.1.6 corrispondente a wiki.tes.mi.it | * IP 192.168.1.6 corrispondente a wiki.tes.mi.it | ||
* compatibile con configurazione dns su 192.168.1.9 | * compatibile con configurazione dns su 192.168.1.9 | ||
Riga 21: | Riga 21: | ||
--------------------- | --------------------- | ||
Configurazione HD | Configurazione HD | ||
− | Disk /dev/sda: 250.1 GB, 250059350016 bytes | + | Disk /dev/sda: 250.1 GB, 250059350016 bytes - Identificativo disco: 0x000de591 |
− | + | ||
− | + | Dispositivo Boot Start End Blocks Id System<br /> | |
− | + | ||
− | + | /dev/sda1 * 2048 471644159 235821056 83 Linux<br /> | |
− | + | ||
+ | /dev/sda2 471646206 488396799 8375297 5 Esteso<br /> | ||
− | |||
− | |||
− | |||
/dev/sda5 471646208 488396799 8375296 82 Linux swap / Solaris | /dev/sda5 471646208 488396799 8375296 82 Linux swap / Solaris | ||
Riga 167: | Riga 165: | ||
* mancano ancora diverse estensioni di wiki | * mancano ancora diverse estensioni di wiki | ||
− | = | + | =Azioni svolte sinora= |
+ | |||
* backup wikivirtuale (salvato) | * backup wikivirtuale (salvato) | ||
− | * | + | * assegnato a wikivirtuale l'IP di wiki.tes.mi.it |
− | ** | + | * Scambiato il valore della variabile $wgServer nel file LocalSettings.php di wikivirtuale con il valore della stessa variabile dello stesso file in wiki.tes.mi.it |
− | + | * Corretto il redirect nel file /var/www/html/index.html in modo da raggiungere la macchina giusta. | |
+ | |||
+ | * verificato che il sistema non presente nuovi bot | ||
+ | * Effettuato il backup del sito con lo script wikibackup | ||
+ | |||
==preparazione MvWiki== | ==preparazione MvWiki== | ||
* aggiungere un disco da 20gb montato nella cartella /dati. | * aggiungere un disco da 20gb montato nella cartella /dati. | ||
* portare in /dati archivio tar.gz di wiki grosso | * portare in /dati archivio tar.gz di wiki grosso | ||
− | * | + | * creata cartella /dati/wiki25 e riversarci /var/www/html del wiki con dati e utenti |
− | * | + | * creata cartella /dati/wiki28 e riversarci /var/www/html diciamo che stimo facendo un backup del running, usando linguaggio cisco |
− | * | + | * verificata che la mv wiki risponda accedendo con il browser, e fare un backup TOTALE della macchina virtuale |
==adattamento di wiki 1.25 alla nuova versione wiki 1.28== | ==adattamento di wiki 1.25 alla nuova versione wiki 1.28== | ||
− | * | + | * aggiustato LocalSettings.php in modo che FUNZIONI con wiki 1.28 ma con le estensione di wiki.tes.mi.it (tutte quelle ancora supportate) |
− | |||
− | |||
− | |||
=== UserMerge=== | === UserMerge=== | ||
Riga 250: | Riga 250: | ||
Esito: sui dispositivi mobili ora appare la versione apposita (è possibile passare alla versione tradizionale usando il link desktop in fondo alla pagina) | Esito: sui dispositivi mobili ora appare la versione apposita (è possibile passare alla versione tradizionale usando il link desktop in fondo alla pagina) | ||
− | == | + | * verificato che FUNZIONI sui contenuti wikivirtuale |
− | * | + | Ora abbiamo una mvWiki ver 28 con tutte le funzionalità del vecchio wiki |
− | * | + | * backup integrale della macchina virtuale |
− | * | + | |
+ | ==Confronto fra la cartella di wiki25 e quella di wiki28== | ||
+ | Da un sommario confronto, ecco le principali differenze nelle estensioni.<br /> | ||
+ | Nota: non ho indagato se qualche estensione è modificata dalla 1.25 alla 1.28 | ||
+ | {| class="wikitable sortable" style= "text-align: center; color:green; background-color:#ffffcc;" cellpadding="10" | ||
+ | |- | ||
+ | ! Esensione !! wiki25!! wiki28 || Note | ||
+ | |- | ||
+ | | Antispam || No || Si || Indagare come si usa, magari è utile | ||
+ | |- | ||
+ | | CiteThisPage || Si || No || Forse già incluso in Cite? | ||
+ | |- | ||
+ | | PdfHandler || Si || No || Aggiungere | ||
+ | |- | ||
+ | | WikiForum || Si || No || Indagare perchè no, come fa a funzionare forum? | ||
+ | |- | ||
+ | | wiki_filebrowser || No || Si || Indagare come si usa, magari è utile | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | ------ | ||
+ | La cartella includes contiene numerosi file .php necessari al sistema. i contenuti delle 2 cartelle NON sono uguali, ci sono piccole differenze, su cui ora non stiamo a indagare. | ||
+ | ------- | ||
+ | |||
+ | =Migrazione contenuti da wiki25 a wiki28= | ||
+ | == lavori preparatori al passaggio dei dati== | ||
+ | * partire da backup integrale di wiki, salvato come file .tar.gz dal programma wikibackup | ||
+ | * estrarre dal file tar.gz il dump del data base e il contenuto di /var/www/html CHE VA MESSO IN /Data/wiki25 | ||
+ | * Copiare nel running le immagini e gli altri file che servono al contenuto di wiki | ||
+ | ===Analisi funzionamento cartella images=== | ||
+ | Prima di cominciare, osserviamo che la cartella /images di wiki28 è vuota in quanto il sistema non ha ancora alcuna immagine salvata<br /> | ||
+ | (il logo non conta in quanto è inserito nella cartella assets)<br /> | ||
+ | |||
+ | [[File:Immagini28Inizio.png]] | ||
+ | Nota: il file immagini in effetti NON fa parte di mediawiki, è semplicemente stato copiato manualmente durante prove e lavori per replicare la cartella. Non tenerne conto.<br /> | ||
+ | <br /> | ||
+ | |||
+ | Dopo aver caricato UNA immagine la situazione è:<br /> | ||
+ | |||
+ | [[File:Immagine28DopoCaricamento.png]] | ||
+ | Notiamo che: | ||
+ | * è stata creata la cartella f, che contiene il file f9 (corrispondente all'immagine caricata) | ||
+ | * è stata creata la dir /archive, che contiene al suo interno ancora la cartella f | ||
+ | * è stata creta la dir lockdir (non indaghiamo per ora il suo funzionamento) | ||
+ | * è stata creata la cartella /thum | ||
+ | |||
+ | Possiamo quindi ritenere che se spostiamo dentro /var/www/html l'intero contenuto di images del vecchio wiki, rinominando preventivamente images in images28, dovremmo avere una base da cui poter partire. | ||
+ | |||
+ | fatto un check e assicurato che wikivirtuale funziona | ||
− | + | fatto backup integrale della macchina | |
− | |||
− | == | + | * rinominata cartella images di wiki28, sostituirta con images da wiki25 |
+ | |||
+ | =Ripristino di wiki 25= | ||
+ | ==Lavori preliminari== | ||
+ | * predisposto cartella /var/www/html/images25 concopia di tutte leimmagini di wiki | ||
+ | * predisposto una copia del file LocalSettings.php (OriginLocalSetting.php) | ||
+ | |||
+ | ==Molto importante premessa== | ||
+ | Il Dump del DB richiede la presenza in mysql di un database vuoto ma contenente l'intera struttura tabellare.<br /> | ||
+ | Non disponendo di script, abbiamo fatto generare su wiki28 un nuovo DB vuoto, che abbiamo chiamato wiki-itsos.<br /> | ||
+ | Per fare questo è sufficiente togliere o rinominare il file LocalSettings.php.<br /> | ||
+ | Ovviamente la configurazione data durante la procedura è la medesima di quella usata per wikivirtuale,con l'unica eccezione il nome del database.<br /> | ||
+ | Fatto. Verificato che il sistema vuoto funziona, quindi procediamo all'import del DB | ||
+ | |||
+ | ==restore del database== | ||
+ | * esecuzione dump del DB (importarlo in mysql) | ||
+ | |||
+ | In wiki25 originale,esportato il DB con | ||
+ | mysqldump -u root -psuppipds wiki-itsos> /backupwiki/backupwiki.sql | ||
+ | Quindi copiato con | ||
+ | scp backupwiki.sql root@wiki.tes.mi.it://dati | ||
+ | |||
+ | ===Molto importante per il DUMP=== | ||
+ | Per importare, il comando corretto da dare non è mysqldump ma il seguente | ||
+ | mysql --silent --password=suppmysql wiki-itsos< backupwiki.sql | ||
+ | Fatto.<br /> | ||
+ | |||
+ | A un controllo su Mysql,le tabelle risultano piene. | ||
+ | |||
+ | * Ripristinare il LocalSettings.originale | ||
+ | * cambiare i parametri del DB e del sito in LocalSettings | ||
+ | Riportiamo solo le righe significative | ||
+ | |||
+ | #$wgSitename = "wikivirtuale"; | ||
+ | $wgSitename = "Wiki-itsos"; | ||
+ | |||
+ | ## 2017-06-12 Modificato per girare su Mv di migrazione, avente IP 192.168.1.6 | ||
+ | #$wgServer = "http://wikivirtuale.tes.mi.it"; | ||
+ | $wgServer = "http://wiki.tes.mi.it"; | ||
+ | |||
+ | ## Database settings | ||
+ | $wgDBtype = "mysql"; | ||
+ | $wgDBserver = "localhost"; | ||
+ | #$wgDBname = "my_wikivirtuale"; | ||
+ | $wgDBname = "wiki-itsos"; | ||
+ | $wgDBuser = "root"; | ||
+ | $wgDBpassword = "*******"; | ||
+ | |||
+ | * impostare come artella di immagini quella con le immagini25 | ||
+ | |||
+ | * dare comando di manutenzione php | ||
+ | |||
+ | * verificare che il sistema funzioni. | ||
+ | |||
+ | Se ok, ora abbiamo un sistema wiki 1.28 che gira su mv e ospita sia i contenuti del vecchio wiki, sia quelli del nuovo, con possibilità di swappare tra i 2 sistemi | ||
+ | |||
+ | * backup integrale del sistema | ||
+ | |||
+ | ==aumentare la dimensione il disco di sistema== | ||
+ | Ho portato la cartella della macchina virtuale su pc windows e ho dato il seguente comando: | ||
+ | C:\Program Files\Oracle\VirtualBox>VboxManage.exe modifyhd "E:\Scuola\macchine virtuali\WikiVirtuale-con-LocalSettings\Ubuntu16.04.vdi" --resize 36000 | ||
+ | |||
+ | =Pulizia degli utenti fake= | ||
Questa operazione richiede solamente tempo, si tratta di usare la funzione unione e cancellazione degli utenti | Questa operazione richiede solamente tempo, si tratta di usare la funzione unione e cancellazione degli utenti | ||
+ | |||
* collaudo e sistemazione | * collaudo e sistemazione | ||
Ora si dispone di un sistema wiki pulito, aggiornato, funzionante e con tutti i contenuti disponibili | Ora si dispone di un sistema wiki pulito, aggiornato, funzionante e con tutti i contenuti disponibili | ||
Riga 265: | Riga 375: | ||
* valutare se ripristinare wiki su macchina fisica | * valutare se ripristinare wiki su macchina fisica | ||
− | = | + | =Proteggere il server da attacchi hacker= |
− | Fatto | + | avendo notato il server cadere ripetutamente ho fatto un controllo nel file di log |
+ | less /var/log/auth.log | ||
+ | e ho notato quanto segue | ||
+ | Oct 16 06:30:51 WikiVirtuale sshd[27376]: Connection closed by 186.46.25.210 port 58812 [preauth] | ||
+ | Oct 16 06:30:51 WikiVirtuale sshd[27376]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=186.46.25.210 | ||
+ | Oct 16 06:31:02 WikiVirtuale sshd[27378]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.172.62 | ||
+ | user=root | ||
+ | Oct 16 06:31:05 WikiVirtuale sshd[27378]: Failed password for root from 61.177.172.62 port 35181 ssh2 | ||
+ | Oct 16 06:31:10 WikiVirtuale sshd[27378]: message repeated 2 times: [ Failed password for root from 61.177.172.62 port 35181 ssh2] | ||
+ | Oct 16 06:31:11 WikiVirtuale sshd[27378]: Received disconnect from 61.177.172.62 port 35181:11: [preauth] | ||
+ | |||
+ | quindi ho bannato gli ip 186.46.25.210 e 61.177.172.62 modificando il file | ||
+ | nano /etc/hosts.deny | ||
+ | nel seguente modo | ||
+ | |||
+ | sshd: 186.46.25.210 | ||
+ | sshd: 61.177.172.62<br /> | ||
+ | |||
+ | Tale soluzione non è definitiva. Infatti gli attacchi proseguono con altri ip mittenti. Decido di seguire la seguente guida di protezione al server:<br /> | ||
+ | https://www.thefanclub.co.za/how-to/how-secure-ubuntu-1604-lts-server-part-1-basics <br /> | ||
+ | ==install firewall ufw== | ||
+ | root@WikiVirtuale:~# sudo apt-get install ufw | ||
+ | Lettura elenco dei pacchetti... Fatto | ||
+ | Generazione albero delle dipendenze | ||
+ | Lettura informazioni sullo stato... Fatto | ||
+ | ufw is already the newest version (0.35-0ubuntu2). | ||
+ | I seguenti pacchetti sono stati installati automaticamente e non sono più richie sti: | ||
+ | linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic | ||
+ | linux-image-4.4.0-93-generic linux-image-extra-4.4.0-93-generic | ||
+ | Usare "sudo apt autoremove" per rimuoverli. | ||
+ | 0 aggiornati, 0 installati, 0 da rimuovere e 0 non aggiornati. | ||
+ | root@WikiVirtuale:~# ufw allow ssh | ||
+ | Regole aggiornate | ||
+ | Regole aggiornate (v6) | ||
+ | root@WikiVirtuale:~# ufw allow http | ||
+ | Regole aggiornate | ||
+ | Regole aggiornate (v6) | ||
+ | root@WikiVirtuale:~# ufw enable | ||
+ | Il comando potrebbe interrompere le connessioni SSH esistenti. Procedere con l'o | ||
+ | perazione (s|n)? s | ||
+ | Firewall attivo e abilitato all'avvio del sistema | ||
+ | root@WikiVirtuale:~# | ||
+ | <br /> | ||
+ | ==Proteggere la memoria condivisa== | ||
+ | Inseriamo nel file /etc/fstab le seguente riga:<br /> | ||
+ | |||
+ | tmpfs /run/shm tmpfs defaults,noexec,nosuid 0 0<br /> | ||
+ | ==cambiare la porta ove risponde ssh== | ||
+ | Nel file /etc/ssh/sshd_config modificare come segue:<br /> | ||
+ | Port xxxx<br /><br /> | ||
+ | forbid root login via ssh - è chiaro che cio' implica avere un utente del gruppo admin che puo' fare ssh | ||
+ | PermitRootLogin no<br /> | ||
+ | nascosto OpenSSH server version | ||
+ | DebianBanner no<br /> | ||
+ | <br /> | ||
+ | successivamente allineo firewall a ssh daemon- ho abilitato il firewall sulla porta prescelta<br /> | ||
+ | root@WikiVirtuale:~#ufw allow xxxx/tcp<br /> | ||
+ | e disabiltitato la porta 22 sul firewall ufw<br /> | ||
+ | root@WikiVirtuale:~#ufw deny 22/tcp<br /> | ||
+ | |||
+ | ==impedire a Apache di usare protocolli insicuri== | ||
+ | modificare il file <br /> | ||
+ | /etc/apache2/mods-available/ssl.conf<br /> | ||
+ | cambiando la riga<br /> | ||
+ | SSLProtocol all -SSLv3 | ||
+ | To the following and save. | ||
+ | SSLProtocol all -SSLv2 -SSLv3 | ||
+ | <br /> | ||
+ | ==Protect su by limiting access only to admin group.== | ||
+ | Non sono state svolte azioni in tale direzione<br /> | ||
+ | Abbiamo un solo utente, oltre a root, e tale utente fa parte del gruppo sudo e adm | ||
− | + | ==Harden network with sysctl settings== | |
+ | <br /> | ||
− | + | The /etc/sysctl.conf file contain all the sysctl settings. | |
+ | Prevent source routing of incoming packets and log malformed IP's enter the following in a terminal window: | ||
− | + | sudo vi /etc/sysctl.conf | |
− | + | Edit the /etc/sysctl.conf file and un-comment or add the following lines : | |
− | |||
− | + | # IP Spoofing protection | |
+ | net.ipv4.conf.all.rp_filter = 1 | ||
+ | net.ipv4.conf.default.rp_filter = 1 | ||
− | + | # Ignore ICMP broadcast requests | |
+ | net.ipv4.icmp_echo_ignore_broadcasts = 1 | ||
− | + | # Disable source packet routing | |
+ | net.ipv4.conf.all.accept_source_route = 0 | ||
+ | net.ipv6.conf.all.accept_source_route = 0 | ||
+ | net.ipv4.conf.default.accept_source_route = 0 | ||
+ | net.ipv6.conf.default.accept_source_route = 0 | ||
+ | |||
+ | # Ignore send redirects | ||
+ | net.ipv4.conf.all.send_redirects = 0 | ||
+ | net.ipv4.conf.default.send_redirects = 0 | ||
+ | |||
+ | # Block SYN attacks | ||
+ | net.ipv4.tcp_syncookies = 1 | ||
+ | net.ipv4.tcp_max_syn_backlog = 2048 | ||
+ | net.ipv4.tcp_synack_retries = 2 | ||
+ | net.ipv4.tcp_syn_retries = 5 | ||
+ | |||
+ | # Log Martians | ||
+ | net.ipv4.conf.all.log_martians = 1 | ||
+ | net.ipv4.icmp_ignore_bogus_error_responses = 1 | ||
+ | |||
+ | # Ignore ICMP redirects | ||
+ | net.ipv4.conf.all.accept_redirects = 0 | ||
+ | net.ipv6.conf.all.accept_redirects = 0 | ||
+ | net.ipv4.conf.default.accept_redirects = 0 | ||
+ | net.ipv6.conf.default.accept_redirects = 0 | ||
+ | |||
+ | # Ignore Directed pings | ||
+ | net.ipv4.icmp_echo_ignore_all = 1 | ||
+ | |||
+ | To reload sysctl with the latest changes, enter: | ||
+ | |||
+ | sudo sysctl -p<br /><br /> | ||
+ | ==Disable Open DNS Recursion and Remove Version Info - Bind9 DNS == | ||
+ | Sul server DNS sono state applicate le seguenti modifiche<br /> | ||
+ | |||
+ | Open a Terminal and enter the following : | ||
+ | |||
+ | sudo nano /etc/bind/named.conf.options | ||
+ | |||
+ | Add the following to the Options section : | ||
+ | |||
+ | recursion no; | ||
+ | version "Not Disclosed"; | ||
+ | |||
+ | Restart BIND DNS server. Open a Terminal and enter the following : | ||
+ | |||
+ | sudo service bind9 restart | ||
+ | a seguito di tale modifica wiki non svolgeva aggiornamenti<br /> | ||
+ | quindi ho commentato le righe inserite nel file /etc/bind/named.conf.options | ||
+ | <br /> | ||
+ | ==Prevent IP Spoofing.== | ||
+ | |||
+ | Open a Terminal and enter the following : | ||
+ | |||
+ | sudo vi /etc/host.conf | ||
+ | |||
+ | Add or edit the following lines : | ||
− | + | order bind,hosts | |
+ | nospoof on | ||
− | + | ==Harden PHP for security== | |
− | + | Edit the php.ini file : | |
− | + | sudo vi /etc/php5/apache2/php.ini | |
− | + | Add or edit the following lines an save : | |
− | + | disable_functions = exec,system,shell_exec,passthru<br /> | |
+ | ==Restrict Apache Information Leakage.== | ||
− | + | Edit the Apache2 configuration security file : | |
− | + | sudo vi /etc/apache2/conf-available/security.conf | |
− | + | Add or edit the following lines and save : | |
+ | |||
+ | ServerTokens Prod | ||
+ | ServerSignature Off | ||
+ | TraceEnable Off | ||
+ | Header unset ETag | ||
+ | Header always unset X-Powered-By | ||
+ | FileETag None | ||
+ | |||
+ | Restart Apache server. Open a Terminal and enter the following : | ||
+ | |||
+ | sudo service apache2 restart | ||
+ | Dopo aver effettuato le modifiche anzidette ho notato che Apache non riparte. Quindi ho annullato le modifiche | ||
+ | ==Web Application Firewall - ModSecurity.== | ||
+ | dal sito: https://komunity.komand.com/learn/article/server-administration/how-to-configure-modsecurity-with-apache-on-ubuntu-linux/ | ||
+ | apt-get install libapache2-modsecurity | ||
+ | apachectl -M | grep security | ||
+ | mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf | ||
+ | nano /etc/modsecurity/modsecurity.conf | ||
+ | Change the following line: | ||
+ | SecRuleEngine on | ||
+ | systemctl restart apache2 | ||
+ | rm -rf /usr/share/modsecurity-crs | ||
+ | cd /usr/share/modsecurity-crs | ||
+ | mv crs-setup.conf.example crs-setup.conf | ||
+ | nano /etc/apache2/mods-enabled/security2.conf | ||
+ | Change the file as shown below: | ||
+ | <IfModule security2_module> | ||
+ | SecDataDir /var/cache/modsecurity | ||
+ | IncludeOptional /etc/modsecurity/*.conf | ||
+ | IncludeOptional "/usr/share/modsecurity-crs/*.conf" | ||
+ | IncludeOptional "/usr/share/modsecurity-crs/rules/*.conf | ||
+ | </IfModule> | ||
+ | systemctl restart apache2 | ||
+ | Visto che wiki.tes.mi.it dava problemi a pubblicare un documento ho spento il motore | ||
+ | nano /etc/modsecurity/modsecurity.conf | ||
+ | Change the following line: | ||
+ | SecRuleEngine off | ||
+ | |||
+ | ==Protect from DDOS (Denial of Service) attacks - ModEvasive.== | ||
+ | dal sito:https://www.server-world.info/en/note?os=Ubuntu_16.04&p=httpd2&f=8 | ||
+ | root@www:~# apt-get -y install libapache2-mod-evasive | ||
+ | root@www:~# a2enmod evasive | ||
+ | |||
+ | root@www:~# nano /etc/apache2/mods-enabled/evasive.conf | ||
+ | # line 3: threshhold for the number of requests for the same page per page interval | ||
+ | |||
+ | DOSPageCount 5 | ||
+ | # line 4: threshhold for the total number of requests for any object by the same client on the same listener per site interval | ||
+ | |||
+ | DOSSiteCount 50 | ||
+ | # line 5: The interval for the page count threshhold | ||
+ | |||
+ | DOSPageInterval 1 | ||
+ | # line 6: The interval for the site count threshhold | ||
+ | |||
+ | DOSSiteInterval 1 | ||
+ | # line 7: amount of time (in seconds) that a client will be blocked for if they are added to the blocking list | ||
+ | |||
+ | DOSBlockingPeriod 300 | ||
+ | # line 9: notification address if IP address becomes blacklisted | ||
+ | |||
+ | DOSEmailNotify root@localhost | ||
+ | # line 11: specify log directory | ||
+ | |||
+ | DOSLogDir "/var/log/mod_evasive" | ||
+ | root@www:~# mkdir /var/log/mod_evasive | ||
+ | |||
+ | root@www:~# chown www-data /var/log/mod_evasive | ||
+ | |||
+ | root@www:~# systemctl restart apache2 | ||
+ | |||
+ | ==Scan logs and ban suspicious hosts - DenyHosts and Fail2Ban.== | ||
+ | DenyHosts is a python program that automatically blocks SSH attacks by adding entries to /etc/hosts.deny. | ||
+ | root@apt-get install denyhosts | ||
+ | root@nano /etc/denyhosts.conf | ||
+ | |||
+ | Change the following values as required on your server : | ||
+ | |||
+ | ADMIN_EMAIL = apache@wiki.tes.mi.it | ||
+ | SMTP_HOST = localhost | ||
+ | SMTP_PORT = 25 | ||
+ | #SMTP_USERNAME=foo | ||
+ | #SMTP_PASSWORD=bar | ||
+ | SMTP_FROM = DenyHosts nobody@localhost | ||
+ | #SYSLOG_REPORT=YES<br /> | ||
+ | |||
+ | Fail2ban is more advanced than DenyHosts as it extends the log monitoring to other services including SSH, Apache, Courier, FTP, and more. | ||
+ | Fail2ban scans log files and bans IPs that show the malicious signs -- too many password failures, seeking for exploits, etc. | ||
+ | Generally Fail2Ban then used to update firewall rules to reject the IP addresses for a specified amount of time, although any arbitrary other action could also be configured. | ||
+ | Out of the box Fail2Ban comes with filters for various services (apache, courier, ftp, ssh, etc).<br /> | ||
+ | root@apt-get install fail2ban | ||
+ | root@nano /etc/fail2ban/jail.conf | ||
+ | [sshd] | ||
+ | |||
+ | enabled = true | ||
+ | port = 1023 | ||
+ | filter = sshd | ||
+ | logpath = /var/log/auth.log | ||
+ | maxretry = 3 | ||
− | + | destemail = root@localhost<br /> | |
+ | |||
+ | root#service fail2ban restart | ||
+ | |||
+ | ==Intrusion Detection - PSAD.== | ||
+ | ==Check for rootkits - RKHunter and CHKRootKit.== | ||
+ | Both RKHunter and CHKRootkit basically do the same thing - check your system for rootkits. No harm in using both. | ||
+ | Open a Terminal and enter the following : | ||
+ | sudo apt-get install rkhunter chkrootkit | ||
+ | To run chkrootkit open a terminal window and enter : | ||
+ | sudo chkrootkit | ||
+ | To update and run RKHunter. Open a Terminal and enter the following : | ||
+ | sudo rkhunter --update | ||
+ | sudo rkhunter --propupd | ||
+ | sudo rkhunter --check | ||
+ | |||
+ | ==Scan open ports - Nmap.== | ||
+ | Nmap ("Network Mapper") is a free and open source utility for network discovery and security auditing. | ||
+ | Open a Terminal and enter the following : | ||
+ | sudo apt-get install nmap | ||
+ | Scan your system for open ports with : | ||
+ | nmap -v -sT localhost | ||
+ | SYN scanning with the following : | ||
+ | sudo nmap -v -sS localhost | ||
+ | |||
+ | ==Analyse system LOG files - LogWatch.== | ||
− | - | + | Logwatch is a customizable log analysis system. Logwatch parses through your system's logs and creates a report analyzing areas that you specify. Logwatch is easy to use and will work right out of the package on most systems. |
+ | Open a Terminal and enter the following : | ||
+ | sudo apt-get install logwatch libdate-manip-perl | ||
+ | To view logwatch output use less : | ||
+ | sudo logwatch | less | ||
+ | ==Apparmor - Application Armor.== | ||
+ | More information can be found here. Ubuntu Server Guide - Apparmor | ||
+ | It is installed by default since Ubuntu 7.04. | ||
+ | Open a Terminal and enter the following : | ||
+ | sudo apt-get install apparmor apparmor-profiles | ||
+ | Check to see if things are running : | ||
+ | sudo apparmor_status | ||
− | - | + | ==Audit your system security - Tiger and Tripwire== |
+ | Tiger is a security tool that can be use both as a security audit and intrusion detection system. | ||
+ | Tripwire is a host-based intrusion detection system (HIDS) that checks file and folder integrity. | ||
+ | Open a Terminal and enter the following : | ||
+ | sudo apt-get install tiger tripwire | ||
+ | To setup Tripwire good installation guides can be found on Digital Ocean here and on Unixmen here | ||
+ | To run tiger enter : | ||
+ | sudo tiger | ||
+ | All Tiger output can be found in the /var/log/tiger | ||
+ | To view the tiger security reports, open a Terminal and enter the following : | ||
+ | sudo less /var/log/tiger/security.report.* | ||
− | - | + | =Errore nel caricamento delle immagini= |
+ | L'impossibilità di caricare immagini ha comportato le seguenti modifiche | ||
+ | <br /> | ||
+ | cambiare i diritti di lettura-scrittura-esecuzione della cartella images | ||
+ | root@WikiVirtuale:/home/tech# chmod -R 755 images | ||
+ | assegnare ad apache la proprietà della cartella images | ||
+ | chown -R www-data:www-data images/ |
Versione attuale delle 09:25, 25 dic 2018
Indice
- 1 Obiettivi
- 2 Situazione iniziale
- 3 Azioni svolte sinora
- 4 Migrazione contenuti da wiki25 a wiki28
- 5 Ripristino di wiki 25
- 6 Pulizia degli utenti fake
- 7 Proteggere il server da attacchi hacker
- 7.1 install firewall ufw
- 7.2 Proteggere la memoria condivisa
- 7.3 cambiare la porta ove risponde ssh
- 7.4 impedire a Apache di usare protocolli insicuri
- 7.5 Protect su by limiting access only to admin group.
- 7.6 Harden network with sysctl settings
- 7.7 Disable Open DNS Recursion and Remove Version Info - Bind9 DNS
- 7.8 Prevent IP Spoofing.
- 7.9 Harden PHP for security
- 7.10 Restrict Apache Information Leakage.
- 7.11 Web Application Firewall - ModSecurity.
- 7.12 Protect from DDOS (Denial of Service) attacks - ModEvasive.
- 7.13 Scan logs and ban suspicious hosts - DenyHosts and Fail2Ban.
- 7.14 Intrusion Detection - PSAD.
- 7.15 Check for rootkits - RKHunter and CHKRootKit.
- 7.16 Scan open ports - Nmap.
- 7.17 Analyse system LOG files - LogWatch.
- 7.18 Apparmor - Application Armor.
- 7.19 Audit your system security - Tiger and Tripwire
- 8 Errore nel caricamento delle immagini
Obiettivi
Ottenere una macchina wiki (fisica o virtuale) con le seguenti specifiche:
- os ubuntu server 18.04 aggiornato
- IP 192.168.1.6 corrispondente a wiki.tes.mi.it
- compatibile con configurazione dns su 192.168.1.9
- funzionante su mediawiki 1.28 o superiore
- deve consentire la autoregistrazione ma deve bloccare i bot
- deve contenere tutte le estensioni di wiki presenti su wiki.tes.mi.it (o almeno tutte quelle compatibili con 1.28)
- deve contenere tutti i contenuti e tutti gli utenti di wiki.tes.mi.it
- deve essere pulito dai bot
- mantenere funzionante la macchina wikivirtuale attuale, con ip 192.168.1.14 e la documentazione presente
Situazione iniziale
Macchina fisica wiki.tes.mi.it
- 5-2-2015 Carlo Bocchetti - Nuovo server ifs e wiki
Configurazione HD Disk /dev/sda: 250.1 GB, 250059350016 bytes - Identificativo disco: 0x000de591
Dispositivo Boot Start End Blocks Id System
/dev/sda1 * 2048 471644159 235821056 83 Linux
/dev/sda2 471646206 488396799 8375297 5 Esteso
/dev/sda5 471646208 488396799 8375296 82 Linux swap / Solaris
avente la seguente configurazione di rete
- The loopback network interface
auto lo iface lo inet loopback
- The primary network interface
auto em1 iface em1 inet static
address 192.168.1.6 netmask 255.255.248.0 network 192.168.0.0 broadcast 192.168.7.255 gateway 192.168.0.70
- dns-nameservers 192.168.0.70
- 22-11-2016 cambiato momentaneamente il ns
dns-nameservers 192.168.1.6 dns-search tes.mi.it
auto em1:0 iface em1:0 inet static
address 192.168.1.9 netmask 255.255.248.0 network 192.168.0.0 broadcast 192.168.7.255
dns-nameservers 192.168.0.70 dns-search tes.mi.it
Su wiki è configurato bind9 con queste configurazioni salienti
include "/etc/bind/named.conf.options"; include "/etc/bind/named.conf.local"; include "/etc/bind/named.conf.default-zones";
zone "tes.mi.it" IN {
type master; file "/etc/bind/zones/interno.tes.mi.it"; allow-transfer { any; }; allow-query { any; };
};
zone "1.168.192.in-addr.arpa" { type master; file "/etc/bind/zones/1.168.192.in-addr.arpa"; };
options {
directory "/var/cache/bind"; forwarders { 192.168.0.70; };
$ttl 24h
tes.mi.it. IN SOA ns.tes.mi.it. admin.tes.mi.it. (
//il seriale è nel formato aaaammddhh 2017053109 28800 3600 604800 38400 )
tes.mi.it. IN NS ns.tes.mi.it. IN A 192.168.1.9 mail.tes.mi.it. IN MX 10 mail.tes.mi.it. tes.mi.it. IN MX 10 mail.tes.mi.it.
ns IN A 192.168.1.9 www IN A 192.168.1.242 mail IN A 192.168.1.9 wiki IN A 192.168.1.6 cis IN A 192.168.1.47 WikiVirtuale IN A 192.168.1.14 wikiprova IN A 192.168.1.19
$ttl 24h @ IN SOA ns.tes.mi.it. admin.tes.mi.it. ( //il seriale è in formato aaaammddhh
2017053109; 28800; 604800; 604800; 86400
)
@ IN NS ns.
9 IN PTR ns.tes.mi.it.
9 IN PTR mail.tes.mi.it.
242 IN PTR www.tes.mi.it.
6 IN PTR wiki.tes.mi.it.
47 IN PTR cis.tes.mi.it.
14 IN PTR WikiVirtuale.tes.mi.it.
19 IN PTR WikiVirtuale2.tes.mi.it.
Macchina virtuale wikivirtuale.tes.mi.it
Configurazione MV
- 1 processore 64bit
- 2Gb Ram
- hd 8G
- 1 sk rete
# 5-6-2017 Bocchetti Ramon configurazione wikivirtuale base
source /etc/network/interfaces.d/*
- The loopback network interface
auto lo iface lo inet loopback
- configurazione in lab 121
auto enp0s3 iface enp0s3 inet static address 192.168.1.14 netmask 255.255.248.0 network 192.168.0.0 broadcast 192.168.7.255 gateway 192.168.0.70 dns-nameservers 192.168.1.9 dns-search tes.mi.it
Installato e funzionante
- mediawiki 1.28
- autoregistrazione con invio mail
- iniziale produzione di contenuti
- mancano ancora diverse estensioni di wiki
Azioni svolte sinora
- backup wikivirtuale (salvato)
- assegnato a wikivirtuale l'IP di wiki.tes.mi.it
- Scambiato il valore della variabile $wgServer nel file LocalSettings.php di wikivirtuale con il valore della stessa variabile dello stesso file in wiki.tes.mi.it
- Corretto il redirect nel file /var/www/html/index.html in modo da raggiungere la macchina giusta.
- verificato che il sistema non presente nuovi bot
- Effettuato il backup del sito con lo script wikibackup
preparazione MvWiki
- aggiungere un disco da 20gb montato nella cartella /dati.
- portare in /dati archivio tar.gz di wiki grosso
- creata cartella /dati/wiki25 e riversarci /var/www/html del wiki con dati e utenti
- creata cartella /dati/wiki28 e riversarci /var/www/html diciamo che stimo facendo un backup del running, usando linguaggio cisco
- verificata che la mv wiki risponda accedendo con il browser, e fare un backup TOTALE della macchina virtuale
adattamento di wiki 1.25 alla nuova versione wiki 1.28
- aggiustato LocalSettings.php in modo che FUNZIONI con wiki 1.28 ma con le estensione di wiki.tes.mi.it (tutte quelle ancora supportate)
UserMerge
#2016-06-14 - per UserMerge require_once "$IP/extensions/UserMerge/UserMerge.php"; // By default nobody can use this function, enable for bureaucrat? $wgGroupPermissions['bureaucrat']['usermerge'] = true; // optional: default is array( 'sysop' ) $wgUserMergeProtectedGroups = array( 'groupname' );
WikiEditor
#2016-06-14 aggiunto WikiEditor wfLoadExtension( 'WikiEditor' ); # Con questo codice, WikiEditor è abilitato ma l'utente può disabilitarlo nelle$ $wgDefaultUserOptions['usebetatoolbar'] = 1; $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1; # Mostra l'anteprima e la sezione Modifica $wgDefaultUserOptions['wikieditor-preview'] = 1; # Mostra i pulsanti Pubblica e Annulla in alto a destra $wgDefaultUserOptions['wikieditor-publish'] = 1;
QuestyCaptcha
Da un controllo fatto sul sito, sembra che mancasse qualche elemento.
Ho aggiunto il tutto, tolto i commenti e inserito una nuova domanda.
Ora il codice presente è
#-----------Confirm Edit e QuestyCaptcha------------- wfLoadExtensions([ 'ConfirmEdit', 'ConfirmEdit/QuestyCaptcha' ]); $wgCaptchaClass = 'QuestyCaptcha'; $wgCaptchaQuestions = [ 'Quale è la capitale della Francia?' => 'Parigi', 'Quale è la capitale della Spagna?' => 'MADRID', 'Quale è il nome di questo wiki?' => $wgSitename, 'Quante dita ha una mano?' => [ 5, 'cinque' ], 'Come si chiama il pollice del piede?' => 'alluce', 'Come si chiama la donna amata da Romeo?' => 'Giulietta', 'Quale è il contrario di pari?' => 'dispari' 'Quale è il contrario di pari?' => 'dispari' ]; foreach ( $arr as $key => $value ) { $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value ); } #Configurazionei suggerite nella pagina di QuestyCaptcha $wgMainCacheType = CACHE_ANYTHING; $wgCaptchaTriggers['edit'] = true; $wgCaptchaTriggers['create'] = true; $wgCaptchaTriggers['createtalk'] = true; $wgCaptchaTriggers['addurl'] = true; $wgCaptchaTriggers['createaccount'] = true; $wgCaptchaTriggers['badlogin'] = true; #-----------Fine sezione QuestyCaptcha----------------
Esito: dopo 24 ore circa, sembra che non ci sono nuovi bot, la procedura di registrazione comunque funziona.
Mobile FrontEnd
A differenza del precedente, non è necessario usare mantle.
Procedura seguita, riferimento MobileFrontEnd su Mediawiki
- scaricare l'archivio e decomprimerlo, creando la cartella in extensions con
wget http://extdist.wmflabs.org/dist/extensions/MobileFrontend-REL1_28-a0c8024.tar.gz tar -xzf MobileFrontend-REL1_28-a0c8024.tar.gz -C /var/www/html/extensions/
- aggiunto le seguenti righe a LocalSettings.php
#----2016-06-17-Mobile FrontEnd------- wfLoadExtension( 'MobileFrontend' ); $wgMFAutodetectMobileView = true;
Esito: sui dispositivi mobili ora appare la versione apposita (è possibile passare alla versione tradizionale usando il link desktop in fondo alla pagina)
- verificato che FUNZIONI sui contenuti wikivirtuale
Ora abbiamo una mvWiki ver 28 con tutte le funzionalità del vecchio wiki
- backup integrale della macchina virtuale
Confronto fra la cartella di wiki25 e quella di wiki28
Da un sommario confronto, ecco le principali differenze nelle estensioni.
Nota: non ho indagato se qualche estensione è modificata dalla 1.25 alla 1.28
Esensione | wiki25 | wiki28 | Note |
---|---|---|---|
Antispam | No | Si | Indagare come si usa, magari è utile |
CiteThisPage | Si | No | Forse già incluso in Cite? |
PdfHandler | Si | No | Aggiungere |
WikiForum | Si | No | Indagare perchè no, come fa a funzionare forum? |
wiki_filebrowser | No | Si | Indagare come si usa, magari è utile |
La cartella includes contiene numerosi file .php necessari al sistema. i contenuti delle 2 cartelle NON sono uguali, ci sono piccole differenze, su cui ora non stiamo a indagare.
Migrazione contenuti da wiki25 a wiki28
lavori preparatori al passaggio dei dati
- partire da backup integrale di wiki, salvato come file .tar.gz dal programma wikibackup
- estrarre dal file tar.gz il dump del data base e il contenuto di /var/www/html CHE VA MESSO IN /Data/wiki25
- Copiare nel running le immagini e gli altri file che servono al contenuto di wiki
Analisi funzionamento cartella images
Prima di cominciare, osserviamo che la cartella /images di wiki28 è vuota in quanto il sistema non ha ancora alcuna immagine salvata
(il logo non conta in quanto è inserito nella cartella assets)
Nota: il file immagini in effetti NON fa parte di mediawiki, è semplicemente stato copiato manualmente durante prove e lavori per replicare la cartella. Non tenerne conto.
Dopo aver caricato UNA immagine la situazione è:
- è stata creata la cartella f, che contiene il file f9 (corrispondente all'immagine caricata)
- è stata creata la dir /archive, che contiene al suo interno ancora la cartella f
- è stata creta la dir lockdir (non indaghiamo per ora il suo funzionamento)
- è stata creata la cartella /thum
Possiamo quindi ritenere che se spostiamo dentro /var/www/html l'intero contenuto di images del vecchio wiki, rinominando preventivamente images in images28, dovremmo avere una base da cui poter partire.
fatto un check e assicurato che wikivirtuale funziona
fatto backup integrale della macchina
- rinominata cartella images di wiki28, sostituirta con images da wiki25
Ripristino di wiki 25
Lavori preliminari
- predisposto cartella /var/www/html/images25 concopia di tutte leimmagini di wiki
- predisposto una copia del file LocalSettings.php (OriginLocalSetting.php)
Molto importante premessa
Il Dump del DB richiede la presenza in mysql di un database vuoto ma contenente l'intera struttura tabellare.
Non disponendo di script, abbiamo fatto generare su wiki28 un nuovo DB vuoto, che abbiamo chiamato wiki-itsos.
Per fare questo è sufficiente togliere o rinominare il file LocalSettings.php.
Ovviamente la configurazione data durante la procedura è la medesima di quella usata per wikivirtuale,con l'unica eccezione il nome del database.
Fatto. Verificato che il sistema vuoto funziona, quindi procediamo all'import del DB
restore del database
- esecuzione dump del DB (importarlo in mysql)
In wiki25 originale,esportato il DB con
mysqldump -u root -psuppipds wiki-itsos> /backupwiki/backupwiki.sql
Quindi copiato con
scp backupwiki.sql root@wiki.tes.mi.it://dati
Molto importante per il DUMP
Per importare, il comando corretto da dare non è mysqldump ma il seguente
mysql --silent --password=suppmysql wiki-itsos< backupwiki.sql
Fatto.
A un controllo su Mysql,le tabelle risultano piene.
- Ripristinare il LocalSettings.originale
- cambiare i parametri del DB e del sito in LocalSettings
Riportiamo solo le righe significative
#$wgSitename = "wikivirtuale"; $wgSitename = "Wiki-itsos";
## 2017-06-12 Modificato per girare su Mv di migrazione, avente IP 192.168.1.6 #$wgServer = "http://wikivirtuale.tes.mi.it"; $wgServer = "http://wiki.tes.mi.it";
## Database settings $wgDBtype = "mysql"; $wgDBserver = "localhost"; #$wgDBname = "my_wikivirtuale"; $wgDBname = "wiki-itsos"; $wgDBuser = "root"; $wgDBpassword = "*******";
- impostare come artella di immagini quella con le immagini25
- dare comando di manutenzione php
- verificare che il sistema funzioni.
Se ok, ora abbiamo un sistema wiki 1.28 che gira su mv e ospita sia i contenuti del vecchio wiki, sia quelli del nuovo, con possibilità di swappare tra i 2 sistemi
- backup integrale del sistema
aumentare la dimensione il disco di sistema
Ho portato la cartella della macchina virtuale su pc windows e ho dato il seguente comando:
C:\Program Files\Oracle\VirtualBox>VboxManage.exe modifyhd "E:\Scuola\macchine virtuali\WikiVirtuale-con-LocalSettings\Ubuntu16.04.vdi" --resize 36000
Pulizia degli utenti fake
Questa operazione richiede solamente tempo, si tratta di usare la funzione unione e cancellazione degli utenti
- collaudo e sistemazione
Ora si dispone di un sistema wiki pulito, aggiornato, funzionante e con tutti i contenuti disponibili
- backup integrale della Mv
- valutare se ripristinare wiki su macchina fisica
Proteggere il server da attacchi hacker
avendo notato il server cadere ripetutamente ho fatto un controllo nel file di log
less /var/log/auth.log
e ho notato quanto segue
Oct 16 06:30:51 WikiVirtuale sshd[27376]: Connection closed by 186.46.25.210 port 58812 [preauth] Oct 16 06:30:51 WikiVirtuale sshd[27376]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=186.46.25.210 Oct 16 06:31:02 WikiVirtuale sshd[27378]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=61.177.172.62 user=root Oct 16 06:31:05 WikiVirtuale sshd[27378]: Failed password for root from 61.177.172.62 port 35181 ssh2 Oct 16 06:31:10 WikiVirtuale sshd[27378]: message repeated 2 times: [ Failed password for root from 61.177.172.62 port 35181 ssh2] Oct 16 06:31:11 WikiVirtuale sshd[27378]: Received disconnect from 61.177.172.62 port 35181:11: [preauth]
quindi ho bannato gli ip 186.46.25.210 e 61.177.172.62 modificando il file
nano /etc/hosts.deny
nel seguente modo
sshd: 186.46.25.210 sshd: 61.177.172.62
Tale soluzione non è definitiva. Infatti gli attacchi proseguono con altri ip mittenti. Decido di seguire la seguente guida di protezione al server:
https://www.thefanclub.co.za/how-to/how-secure-ubuntu-1604-lts-server-part-1-basics
install firewall ufw
root@WikiVirtuale:~# sudo apt-get install ufw Lettura elenco dei pacchetti... Fatto Generazione albero delle dipendenze Lettura informazioni sullo stato... Fatto ufw is already the newest version (0.35-0ubuntu2). I seguenti pacchetti sono stati installati automaticamente e non sono più richie sti: linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic linux-image-4.4.0-93-generic linux-image-extra-4.4.0-93-generic Usare "sudo apt autoremove" per rimuoverli. 0 aggiornati, 0 installati, 0 da rimuovere e 0 non aggiornati. root@WikiVirtuale:~# ufw allow ssh Regole aggiornate Regole aggiornate (v6) root@WikiVirtuale:~# ufw allow http Regole aggiornate Regole aggiornate (v6) root@WikiVirtuale:~# ufw enable Il comando potrebbe interrompere le connessioni SSH esistenti. Procedere con l'o perazione (s|n)? s Firewall attivo e abilitato all'avvio del sistema root@WikiVirtuale:~#
Proteggere la memoria condivisa
Inseriamo nel file /etc/fstab le seguente riga:
tmpfs /run/shm tmpfs defaults,noexec,nosuid 0 0
cambiare la porta ove risponde ssh
Nel file /etc/ssh/sshd_config modificare come segue:
Port xxxx
forbid root login via ssh - è chiaro che cio' implica avere un utente del gruppo admin che puo' fare ssh
PermitRootLogin no
nascosto OpenSSH server version
DebianBanner no
successivamente allineo firewall a ssh daemon- ho abilitato il firewall sulla porta prescelta
root@WikiVirtuale:~#ufw allow xxxx/tcp
e disabiltitato la porta 22 sul firewall ufw
root@WikiVirtuale:~#ufw deny 22/tcp
impedire a Apache di usare protocolli insicuri
modificare il file
/etc/apache2/mods-available/ssl.conf
cambiando la riga
SSLProtocol all -SSLv3
To the following and save.
SSLProtocol all -SSLv2 -SSLv3
Protect su by limiting access only to admin group.
Non sono state svolte azioni in tale direzione
Abbiamo un solo utente, oltre a root, e tale utente fa parte del gruppo sudo e adm
Harden network with sysctl settings
The /etc/sysctl.conf file contain all the sysctl settings. Prevent source routing of incoming packets and log malformed IP's enter the following in a terminal window:
sudo vi /etc/sysctl.conf
Edit the /etc/sysctl.conf file and un-comment or add the following lines :
# IP Spoofing protection net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.default.rp_filter = 1
# Ignore ICMP broadcast requests net.ipv4.icmp_echo_ignore_broadcasts = 1 # Disable source packet routing net.ipv4.conf.all.accept_source_route = 0 net.ipv6.conf.all.accept_source_route = 0 net.ipv4.conf.default.accept_source_route = 0 net.ipv6.conf.default.accept_source_route = 0
# Ignore send redirects net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0
# Block SYN attacks net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 5
# Log Martians net.ipv4.conf.all.log_martians = 1 net.ipv4.icmp_ignore_bogus_error_responses = 1
# Ignore ICMP redirects net.ipv4.conf.all.accept_redirects = 0 net.ipv6.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv6.conf.default.accept_redirects = 0
# Ignore Directed pings net.ipv4.icmp_echo_ignore_all = 1
To reload sysctl with the latest changes, enter:
sudo sysctl -p
Disable Open DNS Recursion and Remove Version Info - Bind9 DNS
Sul server DNS sono state applicate le seguenti modifiche
Open a Terminal and enter the following :
sudo nano /etc/bind/named.conf.options
Add the following to the Options section :
recursion no; version "Not Disclosed";
Restart BIND DNS server. Open a Terminal and enter the following :
sudo service bind9 restart
a seguito di tale modifica wiki non svolgeva aggiornamenti
quindi ho commentato le righe inserite nel file /etc/bind/named.conf.options
Prevent IP Spoofing.
Open a Terminal and enter the following :
sudo vi /etc/host.conf
Add or edit the following lines :
order bind,hosts nospoof on
Harden PHP for security
Edit the php.ini file :
sudo vi /etc/php5/apache2/php.ini
Add or edit the following lines an save :
disable_functions = exec,system,shell_exec,passthru
Restrict Apache Information Leakage.
Edit the Apache2 configuration security file :
sudo vi /etc/apache2/conf-available/security.conf
Add or edit the following lines and save :
ServerTokens Prod ServerSignature Off TraceEnable Off Header unset ETag Header always unset X-Powered-By FileETag None
Restart Apache server. Open a Terminal and enter the following :
sudo service apache2 restart
Dopo aver effettuato le modifiche anzidette ho notato che Apache non riparte. Quindi ho annullato le modifiche
Web Application Firewall - ModSecurity.
apt-get install libapache2-modsecurity apachectl -M | grep security mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf nano /etc/modsecurity/modsecurity.conf
Change the following line:
SecRuleEngine on systemctl restart apache2 rm -rf /usr/share/modsecurity-crs cd /usr/share/modsecurity-crs mv crs-setup.conf.example crs-setup.conf nano /etc/apache2/mods-enabled/security2.conf Change the file as shown below: <IfModule security2_module> SecDataDir /var/cache/modsecurity IncludeOptional /etc/modsecurity/*.conf IncludeOptional "/usr/share/modsecurity-crs/*.conf" IncludeOptional "/usr/share/modsecurity-crs/rules/*.conf </IfModule> systemctl restart apache2
Visto che wiki.tes.mi.it dava problemi a pubblicare un documento ho spento il motore
nano /etc/modsecurity/modsecurity.conf
Change the following line:
SecRuleEngine off
Protect from DDOS (Denial of Service) attacks - ModEvasive.
dal sito:https://www.server-world.info/en/note?os=Ubuntu_16.04&p=httpd2&f=8
root@www:~# apt-get -y install libapache2-mod-evasive root@www:~# a2enmod evasive
root@www:~# nano /etc/apache2/mods-enabled/evasive.conf # line 3: threshhold for the number of requests for the same page per page interval
DOSPageCount 5 # line 4: threshhold for the total number of requests for any object by the same client on the same listener per site interval
DOSSiteCount 50 # line 5: The interval for the page count threshhold
DOSPageInterval 1 # line 6: The interval for the site count threshhold
DOSSiteInterval 1 # line 7: amount of time (in seconds) that a client will be blocked for if they are added to the blocking list
DOSBlockingPeriod 300 # line 9: notification address if IP address becomes blacklisted
DOSEmailNotify root@localhost # line 11: specify log directory
DOSLogDir "/var/log/mod_evasive" root@www:~# mkdir /var/log/mod_evasive
root@www:~# chown www-data /var/log/mod_evasive
root@www:~# systemctl restart apache2
Scan logs and ban suspicious hosts - DenyHosts and Fail2Ban.
DenyHosts is a python program that automatically blocks SSH attacks by adding entries to /etc/hosts.deny.
root@apt-get install denyhosts root@nano /etc/denyhosts.conf
Change the following values as required on your server :
ADMIN_EMAIL = apache@wiki.tes.mi.it SMTP_HOST = localhost SMTP_PORT = 25 #SMTP_USERNAME=foo #SMTP_PASSWORD=bar SMTP_FROM = DenyHosts nobody@localhost #SYSLOG_REPORT=YES
Fail2ban is more advanced than DenyHosts as it extends the log monitoring to other services including SSH, Apache, Courier, FTP, and more.
Fail2ban scans log files and bans IPs that show the malicious signs -- too many password failures, seeking for exploits, etc.
Generally Fail2Ban then used to update firewall rules to reject the IP addresses for a specified amount of time, although any arbitrary other action could also be configured.
Out of the box Fail2Ban comes with filters for various services (apache, courier, ftp, ssh, etc).
root@apt-get install fail2ban root@nano /etc/fail2ban/jail.conf [sshd]
enabled = true port = 1023 filter = sshd logpath = /var/log/auth.log maxretry = 3 destemail = root@localhost
root#service fail2ban restart
Intrusion Detection - PSAD.
Check for rootkits - RKHunter and CHKRootKit.
Both RKHunter and CHKRootkit basically do the same thing - check your system for rootkits. No harm in using both. Open a Terminal and enter the following :
sudo apt-get install rkhunter chkrootkit
To run chkrootkit open a terminal window and enter :
sudo chkrootkit
To update and run RKHunter. Open a Terminal and enter the following :
sudo rkhunter --update sudo rkhunter --propupd sudo rkhunter --check
Scan open ports - Nmap.
Nmap ("Network Mapper") is a free and open source utility for network discovery and security auditing. Open a Terminal and enter the following :
sudo apt-get install nmap
Scan your system for open ports with :
nmap -v -sT localhost
SYN scanning with the following :
sudo nmap -v -sS localhost
Analyse system LOG files - LogWatch.
Logwatch is a customizable log analysis system. Logwatch parses through your system's logs and creates a report analyzing areas that you specify. Logwatch is easy to use and will work right out of the package on most systems. Open a Terminal and enter the following :
sudo apt-get install logwatch libdate-manip-perl
To view logwatch output use less :
sudo logwatch | less
Apparmor - Application Armor.
More information can be found here. Ubuntu Server Guide - Apparmor It is installed by default since Ubuntu 7.04. Open a Terminal and enter the following :
sudo apt-get install apparmor apparmor-profiles
Check to see if things are running :
sudo apparmor_status
Audit your system security - Tiger and Tripwire
Tiger is a security tool that can be use both as a security audit and intrusion detection system. Tripwire is a host-based intrusion detection system (HIDS) that checks file and folder integrity. Open a Terminal and enter the following :
sudo apt-get install tiger tripwire
To setup Tripwire good installation guides can be found on Digital Ocean here and on Unixmen here To run tiger enter :
sudo tiger
All Tiger output can be found in the /var/log/tiger To view the tiger security reports, open a Terminal and enter the following :
sudo less /var/log/tiger/security.report.*
Errore nel caricamento delle immagini
L'impossibilità di caricare immagini ha comportato le seguenti modifiche
cambiare i diritti di lettura-scrittura-esecuzione della cartella images
root@WikiVirtuale:/home/tech# chmod -R 755 images
assegnare ad apache la proprietà della cartella images
chown -R www-data:www-data images/