Brute force SSH Attack sample code dan antisipasinya
Artikel ini akan membahas sedikit pengetahuan mengenai brute force ssh attack sample code dan antisipasinya.
Detail penjelasan brute Force attack bisa anda temukan disni http://en.wikipedia.org/wiki/Brute_force_attack
singkatnya seperti ini, Brute Force attack salah satu jenis serangan berulang menggunakan kemungkinan2 rangkaian kata yang bertujuan untuk menembus root server anda.
Berikut contoh file generasi Brute force ssh attack http://pusathosting.com/file/brutessh2.c
silahkan coba kompile file tersebut
Identifikasi Brute Force Attack SSH
masuk ke shell sebagai root dan jalankan commands berikut
# grep sshd /var/log/secure | grep ‘invalid user’ |wc -l
13282
Artinya terdapat 13282 ssh failed login indikasi awal Brute force attack, selanjutnya perhatikan detail log file anda tersebut
#less /var/log/secure | grep “Jun 5″ | grep sshd | grep ‘invalid user’
Jun 5 21:32:08 server sshd[3139]: Failed password for invalid user admin from 83.15.49.114 port 36274 ssh2
Jun 5 14:32:37 server sshd[3144]: input_userauth_request: invalid user mysql
Jun 5 21:32:15 server sshd[3143]: Failed password for invalid user mysql from 83.15.49.114 port 37696 ssh2
Jun 5 14:32:43 server sshd[3146]: input_userauth_request: invalid user guest
Jun 5 21:32:22 server sshd[3145]: Failed password for invalid user guest from 83.15.49.114 port 39520 ssh2
Jun 5 14:32:50 server sshd[3152]: input_userauth_request: invalid user linux
Jun 5 21:32:28 server sshd[3151]: Failed password for invalid user linux from 83.15.49.114 port 41287 ssh2
Jun 5 14:32:56 server sshd[3155]: input_userauth_request: invalid user oracle
Jun 5 21:32:34 server sshd[3154]: Failed password for invalid user oracle from 83.15.49.114 port 42723 ssh2
Nah jelaslah bahwa server telah menjadi sasaran brute force ssh attack,
Langkah Antisipasi Sederhana
Contoh code shell scripting untuk menangkal brute force ssh attack dengan memanfaatkan crond dan melakukan memasukan IP penyerang dalam daftar hosts.deny
#!/bin/bash
#This script will monitor for failed login attempts and after a specified number of times add the ip to a deny list
#Chad
LOGFILE=”/var/log/secure”
HOSTSDENY=”/etc/hosts.deny”
BADCOUNT=”5″
# read logfile and look for invalid login attemps
grep sshd $LOGFILE |grep “Invalid user”| awk ‘{print $NF}’|sort|uniq -c|sort -n|sed “s/[[:space:]]*//” | while
read i
do
# read number of failed attempts
count=`echo $i | cut -d” ” -f1`
# read ip address from failed attempt
ip=`echo $i | cut -d” ” -f2`
#check hostdeny file to see if IP already exist
already=`grep $ip $HOSTSDENY | grep sshd`
#if IP does not exist add it to hostdeny file
if [ -z "$already" ]
then
if [ "$count" -ge "$BADCOUNT" ]
then
echo “sshd: “$ip >> $HOSTSDENY
fi
fi
done
Simpan file tersebut dan jalankan otomatis dengan menggunakan cron, untuk timing bergantung kebutuhan anda.
Script tersebut diatas mencatat IP address yang melakukan ssh invalid login maksimal 5 kali dan secara otomatis memasukkannya kedalam hosts.deny. IP penyerang yang tercapture tidak bisa lagi melakukan penyerangan ssh karena sudah masuk dalam daftar blacklist.
Sampai disni semoga membantu.
Baca juga artikel ini :
- linux command mencari string pada file
- Block semua IP China dengan hosts.deny
- Website diblokir Google akibat injeksi iframe
- Daftar Linux Command untuk Administrasi Server
facebook comments:

ooo jadi itu to yang buat server down beberapa hari kmrn…
hmnnn bukan boss drop nya karena DNS propagation masing-masing isp tidak sempurna… jadi web tidak bisa diakses
script ini tidak berlaku jika attacker menjalankan brute dengan user root.
kalau sudah dapat root ngapain di brute force lagi. ayak2 wae
@hadi :
maksudnya klo si hacker ngebrute pake user root script ini ga jalan… gitu lho om….