Netstat: melihat serangan dari netstat: Difference between revisions

From OnnoCenterWiki
Jump to navigationJump to search
Onnowpurbo (talk | contribs)
Created page with " sumber: https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html netstat command and shell pipe feature can be used to dig out more information about particul..."
 
Onnowpurbo (talk | contribs)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
sumber: https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html
==Tanda-tanda server di serang==
Bisa dilihat menggunakan top
top
Misalnya
load average: 15.08, 18.30, 20.63
Ini misalnya terlalu tinggi sekali untuk server kita yang cuma 4 core :) ..
==Identifikasi IP penyerang==


sumber: https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html
Fitur netstat dan fitur shell pipe bisa digunakan untuk menggali lebih banyak informasi tentang koneksi alamat IP tertentu. Anda dapat menemukan total koneksi yang sudah ada, koneksi penutupan, bit SYN dan FIN dan banyak lagi. Anda juga dapat menampilkan statistik ringkasan untuk setiap protokol menggunakan netstat.
 
Tampilkan semua sambungan Internet yang ada
 
netstat -na
 
Tampilkan semua sambungan ke port 80, akan bermanfaat untuk melihat jika ada banyak sambungan dari satu buah IP penyerang,
 
netstat -an | grep :80 | sort
 
Perintah berikut, bermanfaat untuk melihat banyaknya SYNC_REC yang aktif di server. angkanya harusnya sekitar <5. Jika ada mailbom / DOS attack angkanya bisa naik lumayan tinggi,
 
netstat -n -p|grep SYN_REC | wc -l
 
Lihat daftar IP address yang terkait dengan SYNC_REC
 
netstat -n -p | grep SYN_REC | sort -u
 
Lihat daftar unik IP yang mengirimkan SYNC_REC status
 
netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'
 
Hitung jumlah sambungan dari setiap IP yang mencapai server
 
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
 
Hitung jumlah sambungan IP yang tersambung ke server menggunakan TCP atau UDP
 
netstat -anp |grep 'tcp|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
 
Cek sambungan yang ESTABLISHED saja, dan tampilkan jumlah dari setiap IP
 
netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
 
Tampilkan IP address dan jumlah sambungan ke port 80 (HTTP)
 
netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head


Output (misalnya):


215 122.163.226.243
189 114.198.236.100
156 120.63.179.245
  38 141.0.9.20
  37 49.248.0.2
  37 153.100.131.12
...
...


netstat command and shell pipe feature can be used to dig out more information about particular IP address connection. You can find out total established connections, closing connection, SYN and FIN bits and much more. You can also display summary statistics for each protocol using netstat.
Tiga (3) IP pertama cukup mencurigakan :) ...


This is useful to find out if your server is under attack or not. You can also list abusive IP address using this method.
Perintah berikut berguna untuk mengetahui apakah server anda diserang atau tidak. Anda juga bisa mencantumkan alamat IP penyerang dengan menggunakan metode ini.


  netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n
  netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n
Line 22: Line 85:
     327 TIME_WAIT
     327 TIME_WAIT


Dig out more information about a specific ip address:
==Menggali informasi lebih lanjut tentang alamat ip tertentu==


  netstat -nat |grep {IP-address} | awk '{print $6}' | sort | uniq -c | sort -n
  netstat -nat |grep {IP-address} | awk '{print $6}' | sort | uniq -c | sort -n
Line 33: Line 96:
     130 FIN_WAIT2
     130 FIN_WAIT2


Busy server can give out more information:
==Server yang sibuk dapat memberikan lebih banyak informasi==


  netstat -nat |grep 202.54.1.10 | awk '{print $6}' | sort | uniq -c | sort -n
  netstat -nat |grep 202.54.1.10 | awk '{print $6}' | sort | uniq -c | sort -n
Line 39: Line 102:
Output:
Output:


  15 CLOSE_WAIT
  15 CLOSE_WAIT
  37 LAST_ACK
  37 LAST_ACK
  64 FIN_WAIT_1
  64 FIN_WAIT_1
  65 FIN_WAIT_2
  65 FIN_WAIT_2
1251 TIME_WAIT
1251 TIME_WAIT
3597 SYN_SENT
3597 SYN_SENT
5124 ESTABLISHED
5124 ESTABLISHED


Get List Of All Unique IP Address
==Dapatkan Daftar Semua Alamat IP Unik==


To print list of all unique IP address connected to server, enter:
Untuk mencetak daftar semua alamat IP yang unik yang terhubung ke server, masukkan:


  netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq
  netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq


To print total of all unique IP address, enter:
Untuk mencetak total semua alamat IP yang unik, masukkan:


  netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq | wc -l
  netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq | wc -l


Output:
Contoh Output:


  449
  449


Find Out If Box is Under DoS Attack or Not
==Cari tahu jika server kita dalam serangan DoS atau tidak==


If you think your Linux box is under attack, print out a list of open connections on your box and sorts them by according to IP address, enter:
Jika Anda menganggap kotak Linux Anda diserang, cetaklah daftar koneksi terbuka di server anda dan urutkan menurut alamat IP, masukkan:


  netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c | sort -n
  netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c | sort -n
Line 73: Line 136:
       4 12.109.42.21
       4 12.109.42.21
       6 12.191.136.3
       6 12.191.136.3
.....
...
...
...
....
...
     13 202.155.209.202
     13 202.155.209.202
     18 208.67.222.222
     18 208.67.222.222
Line 81: Line 144:
     233 127.0.0.1
     233 127.0.0.1


You can simply block all abusive IPs using iptables or just null route them.
Anda bisa memblokir semua IP penyerang menggunakan iptables atau hanya membatalkan rute mereka.
Get Live View of TCP Connections
 
==Live View dari TCP Connection==
 
Anda dapat menggunakan perintah tcptrack untuk menampilkan status koneksi TCP yang dilihatnya pada antarmuka jaringan tertentu. Tcptrack memonitor keadaan mereka dan menampilkan informasi seperti alamat negara, sumber / tujuan dan penggunaan bandwidth dalam daftar yang diurutkan dan diperbarui sangat mirip dengan perintah teratas.
 
Instalasi
 
apt-get install tcptrack
 
Tracking
 
tcptrack -i <networkInterface>
 
Delete closed connection from screen
 
tcptrack -i eth0 -r 10
 
Track port tertentu
 
tcptrack -i eth1 port 22


You can use tcptrack command to display the status of TCP connections that it sees on a given network interface. tcptrack monitors their state and displays information such as state, source/destination addresses and bandwidth usage in a sorted, updated list very much like the top command.
==Statistik Ringkasan Tampilan untuk Setiap Protokol==
Display Summary Statistics for Each Protocol


Simply use netstat -s:
Cukup menggunakan netstat -s:


  netstat -s | less
  netstat -s | less
Line 97: Line 178:
Output:
Output:


Ip:
Ip:
     88354557 total packets received
     88354557 total packets received
     0 forwarded
     0 forwarded
Line 109: Line 190:
     66 packet reassembles failed
     66 packet reassembles failed
     34 fragments failed
     34 fragments failed
Icmp:
Icmp:
     18108 ICMP messages received
     18108 ICMP messages received
     58 input ICMP message failed.
     58 input ICMP message failed.
Line 122: Line 203:
         destination unreachable: 18881
         destination unreachable: 18881
         echo replies: 10096
         echo replies: 10096
Tcp:
Tcp:
     1202226 active connections openings
     1202226 active connections openings
     2706802 passive connection openings
     2706802 passive connection openings
Line 133: Line 214:
     2044 bad segments received.
     2044 bad segments received.
     80805 resets sent
     80805 resets sent
Udp:
Udp:
     92689 packets received
     92689 packets received
     14611 packets to unknown port received.
     14611 packets to unknown port received.
     0 packet receive errors
     0 packet receive errors
     96755 packets sent
     96755 packets sent
TcpExt:
TcpExt:
     48452 invalid SYN cookies received
     48452 invalid SYN cookies received
     7357 resets received for embryonic SYN_RECV sockets
     7357 resets received for embryonic SYN_RECV sockets
Line 173: Line 254:
     6979 connections aborted due to timeout
     6979 connections aborted due to timeout


Display Interface Table
==Display Interface Table==


You can easily display dropped and total transmitted packets with netstat for eth0:
Menampilkan drop & transmit paket dengan netstat untuk eth0:


  netstat --interfaces eth0
  netstat --interfaces eth0
Line 185: Line 266:
  eth0      1500  0  2040929      0      0      0  3850539      0      0      0 BMRU
  eth0      1500  0  2040929      0      0      0  3850539      0      0      0 BMRU


Other netstat related articles / tips:


    Get Information about All Running Services Remotely
==Cara Menangani DOS attack==
    Linux / UNIX Find Out What Program / Service is Listening on a Specific TCP Port
 
Setelah memperoleh IP attacker $IPADDRESS, block menggunakan perintah
 
route add $IPADDRESS reject
route add $IPADDRESS gw 127.0.0.1 lo
 
cek


Read following man pages for the details:
route -n
 
untuk membuang $IPADDRESS dari tabel routing
 
route delete $IPADDRESS
 
atau dengan iptables,
 
iptables -A INPUT 1 -s $IPADRESS -j DROP/REJECT
service iptables restart
service iptables save
 
Sesudah routing / iptables di aktifkan, kill semua sambungan http dan restart httpd
 
killall -KILL httpd
service httpd start
/etc/init/d/apache2 restart
 
==Manual==
 
Kalau ada waktu baca-baca manual berikut,


  man netstat
  man netstat
Line 197: Line 304:
  man sed
  man sed
  man grep
  man grep
Updated for accuracy.


==Referensi==
==Referensi==


* https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html
* https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html
* http://www.mkyong.com/linux/how-to-block-attackers-ip-with-null-route-command/

Latest revision as of 23:04, 10 June 2017

sumber: https://www.cyberciti.biz/tips/netstat-command-tutorial-examples.html

Tanda-tanda server di serang

Bisa dilihat menggunakan top

top

Misalnya

load average: 15.08, 18.30, 20.63

Ini misalnya terlalu tinggi sekali untuk server kita yang cuma 4 core :) ..


Identifikasi IP penyerang

Fitur netstat dan fitur shell pipe bisa digunakan untuk menggali lebih banyak informasi tentang koneksi alamat IP tertentu. Anda dapat menemukan total koneksi yang sudah ada, koneksi penutupan, bit SYN dan FIN dan banyak lagi. Anda juga dapat menampilkan statistik ringkasan untuk setiap protokol menggunakan netstat.

Tampilkan semua sambungan Internet yang ada

netstat -na

Tampilkan semua sambungan ke port 80, akan bermanfaat untuk melihat jika ada banyak sambungan dari satu buah IP penyerang,

netstat -an | grep :80 | sort

Perintah berikut, bermanfaat untuk melihat banyaknya SYNC_REC yang aktif di server. angkanya harusnya sekitar <5. Jika ada mailbom / DOS attack angkanya bisa naik lumayan tinggi,

netstat -n -p|grep SYN_REC | wc -l

Lihat daftar IP address yang terkait dengan SYNC_REC

netstat -n -p | grep SYN_REC | sort -u

Lihat daftar unik IP yang mengirimkan SYNC_REC status

netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'

Hitung jumlah sambungan dari setiap IP yang mencapai server

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Hitung jumlah sambungan IP yang tersambung ke server menggunakan TCP atau UDP

netstat -anp |grep 'tcp|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Cek sambungan yang ESTABLISHED saja, dan tampilkan jumlah dari setiap IP

netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

Tampilkan IP address dan jumlah sambungan ke port 80 (HTTP)

netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

Output (misalnya):

215 122.163.226.243
189 114.198.236.100
156 120.63.179.245
 38 141.0.9.20
 37 49.248.0.2
 37 153.100.131.12
...
...

Tiga (3) IP pertama cukup mencurigakan :) ...

Perintah berikut berguna untuk mengetahui apakah server anda diserang atau tidak. Anda juga bisa mencantumkan alamat IP penyerang dengan menggunakan metode ini.

netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n

Output:

     1 CLOSE_WAIT
     1 established)
     1 Foreign
     3 FIN_WAIT1
     3 LAST_ACK
    13 ESTABLISHED
    17 LISTEN
   154 FIN_WAIT2
   327 TIME_WAIT

Menggali informasi lebih lanjut tentang alamat ip tertentu

netstat -nat |grep {IP-address} | awk '{print $6}' | sort | uniq -c | sort -n
     2 LAST_ACK
     2 LISTEN
     4 FIN_WAIT1
    14 ESTABLISHED
    91 TIME_WAIT
   130 FIN_WAIT2

Server yang sibuk dapat memberikan lebih banyak informasi

netstat -nat |grep 202.54.1.10 | awk '{print $6}' | sort | uniq -c | sort -n

Output:

  15 CLOSE_WAIT
  37 LAST_ACK
  64 FIN_WAIT_1
  65 FIN_WAIT_2
1251 TIME_WAIT
3597 SYN_SENT
5124 ESTABLISHED

Dapatkan Daftar Semua Alamat IP Unik

Untuk mencetak daftar semua alamat IP yang unik yang terhubung ke server, masukkan:

netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq

Untuk mencetak total semua alamat IP yang unik, masukkan:

netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq | wc -l

Contoh Output:

449

Cari tahu jika server kita dalam serangan DoS atau tidak

Jika Anda menganggap kotak Linux Anda diserang, cetaklah daftar koneksi terbuka di server anda dan urutkan menurut alamat IP, masukkan:

netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c | sort -n

Output:

   1 10.0.77.52
     2 10.1.11.3
     4 12.109.42.21
     6 12.191.136.3
...
...
...
   13 202.155.209.202
    18 208.67.222.222
    28 0.0.0.0
   233 127.0.0.1

Anda bisa memblokir semua IP penyerang menggunakan iptables atau hanya membatalkan rute mereka.

Live View dari TCP Connection

Anda dapat menggunakan perintah tcptrack untuk menampilkan status koneksi TCP yang dilihatnya pada antarmuka jaringan tertentu. Tcptrack memonitor keadaan mereka dan menampilkan informasi seperti alamat negara, sumber / tujuan dan penggunaan bandwidth dalam daftar yang diurutkan dan diperbarui sangat mirip dengan perintah teratas.

Instalasi

apt-get install tcptrack

Tracking

tcptrack -i <networkInterface>

Delete closed connection from screen

tcptrack -i eth0 -r 10

Track port tertentu

tcptrack -i eth1 port 22

Statistik Ringkasan Tampilan untuk Setiap Protokol

Cukup menggunakan netstat -s:

netstat -s | less
netstat -t -s | less
netstat -u -s | less
netstat -w -s | less
netstat -s

Output:

Ip:
   88354557 total packets received
   0 forwarded
   0 incoming packets discarded
   88104061 incoming packets delivered
   96037391 requests sent out
   13 outgoing packets dropped
   66 fragments dropped after timeout
   295 reassemblies required
   106 packets reassembled ok
   66 packet reassembles failed
   34 fragments failed
Icmp:
   18108 ICMP messages received
   58 input ICMP message failed.
   ICMP input histogram:
       destination unreachable: 7173
       timeout in transit: 472
       redirects: 353
       echo requests: 10096
   28977 ICMP messages sent
   0 ICMP messages failed
   ICMP output histogram:
       destination unreachable: 18881
       echo replies: 10096
Tcp:
   1202226 active connections openings
   2706802 passive connection openings
   7394 failed connection attempts
   47018 connection resets received
   23 connections established
   87975383 segments received
   95235730 segments send out
   681174 segments retransmited
   2044 bad segments received.
   80805 resets sent
Udp:
   92689 packets received
   14611 packets to unknown port received.
   0 packet receive errors
   96755 packets sent
TcpExt:
   48452 invalid SYN cookies received
   7357 resets received for embryonic SYN_RECV sockets
   43 ICMP packets dropped because they were out-of-window
   5 ICMP packets dropped because socket was locked
   2672073 TCP sockets finished time wait in fast timer
   441 time wait sockets recycled by time stamp
   368562 delayed acks sent
   430 delayed acks further delayed because of locked socket
   Quick ack mode was activated 36127 times
   32318597 packets directly queued to recvmsg prequeue.
   741479256 packets directly received from backlog
   1502338990 packets directly received from prequeue
   18343750 packets header predicted
   10220683 packets header predicted and directly queued to user
   17516622 acknowledgments not containing data received
   36549771 predicted acknowledgments
   102672 times recovered from packet loss due to fast retransmit
   Detected reordering 1596 times using reno fast retransmit
   Detected reordering 1 times using time stamp
   8 congestion windows fully recovered
   32 congestion windows partially recovered using Hoe heuristic
   19 congestion windows recovered after partial ack
   0 TCP data loss events
   39951 timeouts after reno fast retransmit
   29653 timeouts in loss state
   197005 fast retransmits
   186937 retransmits in slow start
   131433 other TCP timeouts
   TCPRenoRecoveryFail: 20217
   147 times receiver scheduled too late for direct processing
   29010 connections reset due to unexpected data
   365 connections reset due to early user close
   6979 connections aborted due to timeout

Display Interface Table

Menampilkan drop & transmit paket dengan netstat untuk eth0:

netstat --interfaces eth0

Output:

Kernel Interface table
Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500   0  2040929      0      0      0  3850539      0      0      0 BMRU


Cara Menangani DOS attack

Setelah memperoleh IP attacker $IPADDRESS, block menggunakan perintah

route add $IPADDRESS reject
route add $IPADDRESS gw 127.0.0.1 lo

cek

route -n

untuk membuang $IPADDRESS dari tabel routing

route delete $IPADDRESS

atau dengan iptables,

iptables -A INPUT 1 -s $IPADRESS -j DROP/REJECT
service iptables restart
service iptables save

Sesudah routing / iptables di aktifkan, kill semua sambungan http dan restart httpd

killall -KILL httpd

service httpd start 
/etc/init/d/apache2 restart

Manual

Kalau ada waktu baca-baca manual berikut,

man netstat
man cut
man awk
man sed
man grep

Referensi