...

Matteo Sgalaberni, Mi hanno bucato il server, e adesso?

by user

on
Category: Documents
12

views

Report

Comments

Transcript

Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
LINUXDAY 2013
Mi hanno bucato il server, e adesso?
Matteo Sgalaberni
ERLUG
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
1
LINUXDAY 2013
Matteo Sgalaberni
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
2
LINUXDAY 2013
C'era una volta...
Ragazzo
Server
WebApp (PHP)
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
3
LINUXDAY 2013
Obiettivo
sicurezza
reattiva
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
4
LINUXDAY 2013
Agenda
Usi e costumi
Target
Capire
Reagire
Correggere
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
5
LINUXDAY 2013
Usi e costumi
Processo
Gestione sicurezza proattiva
Ufficio Federale Aviazione Civile
Svizzera
Prevenzione
Sistemisti
Programmatori
Processo
http://www.bazl.admin.ch/themen/sicherheit/00296/index.html?lang=it
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
6
LINUXDAY 2013
E’ STATO
INSUFFICIENTE
SIETE STATI
SFONDATI!
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
7
LINUXDAY 2013
Metodo
Correzione
Niente Panico
Analisi
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
8
LINUXDAY 2013
Se hai un problema, trova la
causa e risolvilo
altrimenti riaccadrà!
quindi se non trovi da dove sono entrati e risolvi
TI RIBUCHERANNO!
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
9
LINUXDAY 2013
Perchè proprio te?!
Rubare
Modificare
Farti un danno
forse ma...
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
10
LINUXDAY 2013
per soldi
(li guadagnano loro!)
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
11
LINUXDAY 2013
Un brutto mondo!
Source:
McAfee Threats Report: First Quarter 2012 27
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
12
LINUXDAY 2013
TI SFRUTTANO PER FARE
Spam
Phishing
Advertisement
Virus
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
Malware
Data leakage
DOS
DDOS
13
LINUXDAY 2013
Target
Web Application
Account SMTP
Account FTP
Rete LAN
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
14
LINUXDAY 2013
Ma mi hanno bucato?! Come me ne accorgo?!
Server non risponde
Sito lento
Timeout servizi
Rete
Posta
Sito Web
Alert
es. Nagios/Zimbra
Abuse notification
Blacklist
IPS
IDS
Firewall
Bologna, 2013-10-26
CONOSCENZA!
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
15
LINUXDAY 2013
BRUTTO?!
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
16
LINUXDAY 2013
BRUTTO?!
server:~# ps afx|grep apache2|wc -l
593
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
17
LINUXDAY 2013
BRUTTO?!
server:~# /var/qmail/bin/qmail-qstat
messages in queue: 5963
messages in queue but not yet preprocessed: 623
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
18
LINUXDAY 2013
DIPENDE
Conoscenza
Normalità
Confronto (Analisi del delta)
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
19
LINUXDAY 2013
ma come si manifesta il
vero
MALE!?
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
20
LINUXDAY 2013
Un bel giorno sul server di Daniele
SMTP: CRITICAL - Socket timeout after 10 seconds
POP3: CRITICAL - Socket timeout after 10 seconds
HTTP: CRITICAL - Socket timeout after 10 seconds
DAAA DAAAA DAAA DAAA DAAA!
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
21
LINUXDAY 2013
Ma da dove sono “entrati”?!
FTP
SMTP
Web App / PHP
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
22
LINUXDAY 2013
FTP?!?!?
SMTP?!?
password
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
23
LINUXDAY 2013
Web App
Wordpress
Joomla
Plugins
File upload validation
Remote file execution
Attacks on application platform
Upload .jsp file into web tree - jsp code executed as web user
Upload .gif to be resized - image library flaw exploited
Upload huge files - file space denial of service
Upload file using malicious path or name - overwrite critical file
Upload file containing personal data - other users access it
Upload file containing "tags" - tags get executed as part of being "included" in a web page
<?php
if (isset( $_GET['COLOR'] ) ){
include( $_GET['COLOR'] .
'.php' );
}
?>
PHP shell
PHP backdoor
HTML/JS infected
https://www.owasp.org/index.php/Unrestricted_File_Upload
http://en.wikipedia.org/wiki/File_inclusion_vulnerability
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
24
LINUXDAY 2013
Semplice!
Informazioni: ma dove sono?!
File Creati
Log
Timestamp
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
25
LINUXDAY 2013
TRUCCO
find -ctime 0
stat files...
less files
grep
Nuovi file
File con nomi “strani”
File con contenuti “strani”
eval(base64_decode($_REQUEST['comment'])));
JS offuscato/incomprensibile
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
26
LINUXDAY 2013
php shit
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
27
LINUXDAY 2013
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
28
LINUXDAY 2013
~/$ clamscan newsp15.php
newsp15.php: PHP.Trojan.Spambot FOUND
----------- SCAN SUMMARY ----------Known viruses: 2424225
Engine version: 0.97.7
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 1.00:1)
Time: 4.204 sec (0 m 4 s)
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
29
LINUXDAY 2013
JS shit
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
30
LINUXDAY 2013
FTP
PHP shell
PHP backdoor
HTML with infected javascript
perl in CGI-BIN
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
31
LINUXDAY 2013
54.244.119.54 - - [07/Oct/2013:17:00:30 +0200] "POST /listN3A.php
HTTP/1.1" 200 717 "-" "-"
stat /httpdocs_bucato/listN3A.php
File: `listN3A.php'
Size: 7325
Blocks: 16
IO Block: 4096
regular file
Device: 808h/2056dInode: 10928437
Links: 1
Access: (0644/-rw-r--r--) Uid: (10669/fsfsadfd)
Gid: ( 2524/
psacln)
Access: 2013-10-07 16:18:07.000000000 +0200
Modify: 2013-10-04 11:19:06.000000000 +0200
Change: 2013-10-04 11:19:06.000000000 +0200
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
32
LINUXDAY 2013
zgrep listN3A.php xferlog*
xferlog.processed:Fri Oct 4 11:19:06 2013 0 37.139.47.33 7325 /var/www/vhosts/
sito1.it/httpdocs/listN3A.php b _ i r o sito1 ftp 0 * c
sesedefdfs:/opt/psa/var/log# grep 37.139.47.33 xferlog*
xferlog.processed:Tue Oct 1 12:39:35 2013 0 37.139.47.33
sito2.it/httpdocs/newsp15.php b _ i r sito1 ftp 0 * c
xferlog.processed:Thu Oct 3 12:00:08 2013 0 37.139.47.33
sito2.it/httpdocs/.htaccess b _ d r sito1 ftp 0 * c
xferlog.processed:Thu Oct 3 12:00:09 2013 0 37.139.47.33
sito2.it/httpdocs/rLlSMF.html b _ i r sito1 ftp 0 * c
xferlog.processed:Thu Oct 3 12:00:09 2013 0 37.139.47.33
sito2.it/httpdocs/aLlSMF.html b _ i r sito1 ftp 0 * c
xferlog.processed:Fri Oct 4 11:19:06 2013 0 37.139.47.33
sito1.it/httpdocs/listN3A.php b _ i r sito2 ftp 0 * c
xferlog.processed:Sun Oct 6 12:19:54 2013 0 37.139.47.33
sito1.it/httpdocs/.htaccess b _ d r sito2 ftp 0 * c
xferlog.processed:Sun Oct 6 12:19:55 2013 0 37.139.47.33
sito1.it/httpdocs/rTLsk.html b _ i r sito2 ftp 0 * c
xferlog.processed:Sun Oct 6 12:19:56 2013 0 37.139.47.33
sito1.it/httpdocs/aTLsk.html b _ i r sito2 ftp 0 * c
xferlog.processed:Sun Oct 6 12:34:09 2013 0 37.139.47.33
sito2.it/httpdocs/rLlSMF.html b _ i r sito1
Bologna, 2013-10-26
2005 /var/www/vhosts/
378 /var/www/vhosts/
400 /var/www/vhosts/
7325 /var/www/vhosts/
136 /var/www/vhosts/
378 /var/www/vhosts/
395 /var/www/vhosts/
378 /var/www/vhosts/
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
7325 /var/www/vhosts/
33
LINUXDAY 2013
Ma cosa c’era in quel file?!?
<html>
<head>
<meta http-equiv="refresh" content="2; url=http://thespeedshop.ca/
robotsfR6w/bar/index.html">
</head>
<body>
<h1>Loading...</h1>
</body>
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
34
LINUXDAY 2013
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
35
LINUXDAY 2013
server:~# /var/qmail/bin/qmail-qstat
messages in queue: 5963
messages in queue but not yet preprocessed: 623
Received: (qmail 3931 invoked by uid 33); 22 Oct 2013 11:55:22 +0200
Date: 22 Oct 2013 11:55:20 +0200
Message-ID: <20131022095520.3906.qmail@server999>
To: [email protected]
Subject: Voice Message Notification
From: "WhatsApp Messaging Service" <[email protected]>
X-PHP-Originating-Script: 10035:infoKSw.php
X-Mailer: Oudmlr(ver.3.4)
Reply-To: "WhatsApp Messaging Service" <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/
alternative;boundary="----------138243572052664B8811717"
http://php.net/manual/en/mail.configuration.php
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
36
LINUXDAY 2013
server:~# /var/qmail/bin/qmail-qstat
messages in queue: 5963
messages in queue but not yet preprocessed: 623
Received: (qmail 11447 invoked from network); 21 Oct 2013 10:24:11 +0200
Received: from hostbruttorusso.ru (HELO UserHP) (99.99.99.99)
by mioserver.it with ESMTPA; 21 Oct 2013 10:24:09 +0200
Return-Receipt-To: "Monica" <[email protected]>
From: "Monica" <[email protected]>
To: <[email protected]>
Subject: I: RQST FATTURA
Date: Mon, 21 Oct 2013 10:24:10 +0200
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----=_NextPart_000_004B_01CECE47"
X-Mailer: Microsoft Office Outlook 11
Oct 25 12:37:08 server6 smtp_auth: SMTP user [email protected] : logged in
from hostbruttorusso.ru [99.99.99.99]
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
37
LINUXDAY 2013
Risposta ad un accesso SMTP
Identifico le caselle compromesse
Cambio le password
Iptables ip logged in
Cancello le email dalla coda
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
38
LINUXDAY 2013
Un bel giorno sul server di Daniele
5671 ?
5672 ?
5673 ?
5674 ?
20388 ?
6159 ?
6908 ?
16593 ?
17308 ?
9631 ?
9632 ?
9633 ?
9634 ?
9635 ?
9636 ?
4626 ?
4671 ?
4672 ?
4673 ?
Bologna, 2013-10-26
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
SN
SN
SN
SN
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 couriertls -localfd=4 -tcpd -server
0:00 couriertls -localfd=4 -tcpd -server
0:00 couriertls -localfd=4 -tcpd -server
0:00 couriertls -localfd=4 -tcpd -server
0:00 couriertls -localfd=4 -tcpd -server
0:00 perl udpflood.pl
0:00 perl udpflood.pl
0:00 perl udpflood.pl
0:00 perl udpflood.pl
0:00 perl udpflood.pl
0:00 perl udpflood.pl
0:00 /usr/sbin/zabbix_agentd
28:24 \_ /usr/sbin/zabbix_agentd
0:00 \_ /usr/sbin/zabbix_agentd
0:00 \_ /usr/sbin/zabbix_agentd
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
39
LINUXDAY 2013
Un bel giorno sul server di Marco
5638
5655
5662
5671
5672
5673
5674
4292
4587
4588
4589
4590
4591
9631
4626
4671
4672
4673
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
Bologna, 2013-10-26
S
S
S
S
S
S
S
S
Ss
S
S
S
S
S
SN
SN
SN
SN
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:00 \_ /usr/sbin/apache2 -k start
0:21 /usr/sbin/sw-cp-serverd -f /etc/sw-cp-server/config
0:02 drwebd.real
1:10 \_ drwebd.real
1:14 \_ drwebd.real
1:10 \_ drwebd.real
1:07 \_ drwebd.real
0:00 /usr/sbin/apache2 -k start
0:00 /usr/sbin/zabbix_agentd
28:24 \_ /usr/sbin/zabbix_agentd
0:00 \_ /usr/sbin/zabbix_agentd
0:00 \_ /usr/sbin/zabbix_agentd
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
40
LINUXDAY 2013
Mani in alto!
Data collecting
Trigger - iptables log
Trigger - swatch
#!/bin/bash
echo -n "starting collecting
data..."
date
TMPFILE=`tempfile`
netstat -tanp >>$TMPFILE
lsof -n >>$TMPFILE
ps afx >>$TMPFILE
stat /tmp/* >>$TMPFILE
bzip2 $TMPFILE
echo -n "ending collecting data..."
date
echo "Trace salvato in :" $
{TMPFILE}.bz2
exit 0
perl
32373
www-data 509w
REG
170 /tmp/sess_e96a2502073e0061e5f88a9ca9bc3dab
Bologna, 2013-10-26
0
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
254,2
41
LINUXDAY 2013
MA ALMENO QUESTO FATELO
/etc/php5/apache2/php.ini
allow_url_fopen = Off
disable_functions =
"exec,system,passthru,readfile,shell_exec,escapeshellarg,es
capeshellcmd,proc_close,proc_open,ini_alter,dl,parse_ini_fi
le,show_source"
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
42
LINUXDAY 2013
E se non lo becco?!
tcpdump -s0 -w -C <maxsize> -W <maxcountfile>
tcpslice
wireshark
ngrep (live gathering)
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
43
LINUXDAY 2013
Strumenti
top
ps afx
lsof -p [PID]
netstat -tanp
stat
find -ctime 0
last
netstat -tanp
chkrootkit
rkhunter
clamav
wireshark
Intelligenza!
Conoscenza!
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
44
LINUXDAY 2013
ALLORA
analisi
pulizia
correzione
controllo
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
45
LINUXDAY 2013
GRAZIE PER L'ATTENZIONE
Le slides e le riprese audio/video
dell'intervento saranno disponibili su:
http://erlug.linux.it/linuxday/2013/
Bologna, 2013-10-26
ERLUG: Emilia Romagna Linux Users Group – http://erlug.linux.it
Matteo Sgalaberni, Mi hanno bucato il server, e adesso?
Monday, October 28, 13
46
Fly UP