• Tidak ada hasil yang ditemukan

nginx Block Exploits, SQL Injections, File Injections, Spam, User Agents, Dll

N/A
N/A
Protected

Academic year: 2021

Membagikan "nginx Block Exploits, SQL Injections, File Injections, Spam, User Agents, Dll"

Copied!
30
0
0

Teks penuh

(1)

nginx – Block Exploits, SQL

Injections, File Injections,

Spam, User Agents, Dll

server { [...] ## Block SQL injections set $block_sql_injections 0; if ($query_string ~ "union.*select.*\(") { set $block_sql_injections 1; } if ($query_string ~ "union.*all.*select.*") { set $block_sql_injections 1; } if ($query_string ~ "concat.*\(") { set $block_sql_injections 1; } if ($block_sql_injections = 1) { return 403; }

## Block file injections

set $block_file_injections 0; if ($query_string ~ "[a-zA-Z0-9_]=http://") { set $block_file_injections 1; } if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") { set $block_file_injections 1; } if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") { set $block_file_injections 1; } if ($block_file_injections = 1) { return 403; }

(2)

set $block_common_exploits 0; if ($query_string ~ "(<|%3C).*script.*(>|%3E)") { set $block_common_exploits 1; } if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") { set $block_common_exploits 1; } if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") { set $block_common_exploits 1; } if ($query_string ~ "proc/self/environ") { set $block_common_exploits 1; } if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") { set $block_common_exploits 1; } if ($query_string ~ "base64_(en|de)code\(.*\)") { set $block_common_exploits 1; } if ($block_common_exploits = 1) { return 403; } ## Block spam set $block_spam 0; i f ( $ q u e r y _ s t r i n g ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") { set $block_spam 1; } i f ( $ q u e r y _ s t r i n g ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido) \b") { set $block_spam 1; } i f ( $ q u e r y _ s t r i n g ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") { set $block_spam 1; } i f ( $ q u e r y _ s t r i n g ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)

(3)

\b") { set $block_spam 1; } if ($block_spam = 1) { return 403; }

## Block user agents

set $block_user_agents 0;

# Don't disable wget if you need it to run cron jobs! #if ($http_user_agent ~ "Wget") {

# set $block_user_agents 1; #}

# Disable Akeeba Remote Control 2.5 and earlier if ($http_user_agent ~ "Indy Library") {

set $block_user_agents 1; }

# Common bandwidth hoggers and hacking tools. if ($http_user_agent ~ "libwww-perl") { set $block_user_agents 1; } if ($http_user_agent ~ "GetRight") { set $block_user_agents 1; } if ($http_user_agent ~ "GetWeb!") { set $block_user_agents 1; } if ($http_user_agent ~ "Go!Zilla") { set $block_user_agents 1; }

if ($http_user_agent ~ "Download Demon") { set $block_user_agents 1; } if ($http_user_agent ~ "Go-Ahead-Got-It") { set $block_user_agents 1; } if ($http_user_agent ~ "TurnitinBot") { set $block_user_agents 1;

(4)

} if ($http_user_agent ~ "GrabNet") { set $block_user_agents 1; } if ($block_user_agents = 1) { return 403; } [...] }

ODBC Mssql connection for php

in linux

ODBC MSSQL IN Linux

Hallo pengunjung ribhy yang mungkin punya masalah yang sama dengan saya, pecinta linux dikasih project untuk membuat aplikasi mengunakan php framework tapi database MSSQL dari pecinta jendela. Oke langsung aja deeh, pertama adalah download freetds bisa mengunakan wget, proz, links, lynx

[ r o o t @ l o c a l h o s t ] # l y n x http://downloads.sourceforge.net/project/freetds/OldFiles/free tds-0.61.tar.gz

Next, uncompress, configure and make the FreeTDS driver.

[root@localhost]# tar -xvfz freetds-0.61.tgz -C /usr/local/src [root@localhost]# cd freetds-0.61

[root@localhost]# ./configure tdsver=7.0 --with-unixodbc

(5)

[root@localhost]# make

[root@localhost]# make install [root@localhost]# make clean

Jika udah saat testing untuk koneksi ke server

[ r o o t @ l o c a l h o s t ] # / u s r / l o c a l / b i n / t s q l - S <mssql.servername.com> -U

<ValidUser>

Password: <password>

Jika berhasil maka akan muncul seperti dibawah ini 1>

Untuk keluar mengunakan ctrl + C

Jika belum berhasil, coba dengan telnet port 1433 sebelumnya gunakan nmap untuk memastikan mssql open port.

[root@localhost]# telnet <mssql.servername.com> 1433 dan jika bisa ditelnet

[root@localhost]# cd /usr/local/etc

From /usr/local/etc/, edit freetds.conf. At the end of this file, add an entry something like this:

[TDS]

host = mssql.serverhost.com port = 1433

tds version = 7.0

Selanjutnya adalah seting odbc connection

Untuk yang mengunakan redhat atau sejenisnya ada settingan odbc di system menu. Dan gunakan settingan berikut ini:

Name: TDS

Description: v0.61 with Protocol v7.0 Driver: /usr/local/lib/libtdsodbc.so Setup: /usr/lib/libtdsS.so

(6)

FileUsage: 1

Rest dapat kosong, click checkmark kemudian klik OK Name: MSSQLServer

Description: TDS MSSQL (description isn't important) Servername: mssql.serverhost.com

UID: sa PWD:

Port: 1433

Jika mengunakan ubuntu, install libmyodbc mengunakan apt-get [root@localhost]# apt-get install libmyodbc

Kemudian edit odbc.ini

[root@localhost]# vi /etc/odbc.ini

[ODBC Data Sources]

odbcname = MyODBC 3.51 Driver DSN [odbcname]

Driver = /usr/lib/odbc/libmyodbc.so Description = MyODBC 3.51 Driver DSN SERVER = my.database.server.com PORT = USER = USER Password = XXXXXX Database = DBNAME OPTION = 3 SOCKET = [Default] Driver = /usr/local/lib/libmyodbc3.so Description = MyODBC 3.51 Driver DSN

SERVER = localhost PORT = USER = root Password = Database = test OPTION = 3

(7)

SOCKET = [TDS]

Driver = /usr/local/lib/libtdsodbc.so Setup = /usr/lib/libtdsS.so

Description = freeTDS v0.61 with Protocol v7.0 SERVER = localhost PORT = 1143 USER = sa Password = password Threading = 1 FileUsage = 1 CPTimeout = CPReuse =

Untuk mengetest odbc bisa mengunakan

[root@localhost]# isql -v TDS sa password +---+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---+ SQL> use Northwind 0 rows affected

SQL> SELECT TOP 1 Name from Master +---+ | Name | +---+ | Ribhy Keren | +---+ 1 rows affected SQL> quit

Untuk PHP code saya mencoba dengan mengunakan code dibawah ini --- begin

(8)

odbc_connect.php---<?

// Koneksi menginakan odbc_connetct

$connect = odbc_connect("TDS", "sa", "password") or die ("couldn't connect");

// use database

odbc_exec($connect, "use ribhy_com");

$result = odbc_exec($connect, "SELECT Name, Desc " . "FROM master");

while(odbc_fetch_row($result)){

print(odbc_result($result, "Name") .

' ' . odbc_result($result, "Desc") . "<br>\n"); }

// get result & close koneksi odbc_free_result($result); odbc_close($connect);

?>

- end odbc_connect.php --Selamat mencoba..

Postgresql disable / enable

trigger

DISABE / ENABLE PostgreSQL Session trigger

Untuk sementara mendisable PostgreSQL Session dengan query seperti berikut ini

SET session_replication_role = replica;

Untuk mengaktifkannya kembali

SET session_replication_role = DEFAULT;

DISABLE / ENABLE PostgreSQL TABLE

(9)

ALTER TABLE mytable DISABLE TRIGGER mytrigger;

Untuk mendisable postgresql semua trigger pada suatu table

ALTER TABLE mytable DISABLE TRIGGER ALL;

Untuk mengaktifkan kembali:

ALTER TABLE mytable ENABLE TRIGGER ALL;

Selamat mencoba.

Server Security : CSF (

Config Server Firewall ) on

centos 6.6

Config Server Firewall (atau CSF) adalah firewall gratis dan canggih untuk sebagian besar distro Linux dan VPS berbasis Linux. Selain fungsi dasar firewall – paket penyaringan – CSF mencakup fitur keamanan lainnya, seperti login/intrusion/flood detection. CSF termasuk UI integrasi untuk cPanel, DirectAdmin dan Webmin, tapi tutorial ini hanya mencakup penggunaan baris perintah. CSF mampu mengenali banyak serangan, seperti port scan, SYN banjir, dan login serangan brute force pada banyak layanan. Hal ini dikonfigurasi untuk memblokir klien yang terdeteksi harus menyerang server cloud untuk sementara.

Daftar lengkap sistem operasi yang didukung dan fitur dapat ditemukan di situs web ConfigServer itu.

Config Server Firewall web

(10)

Step 1: Downloading

Config Server Firewall is not currently available in Debian or Ubuntu repositories, and has to be downloaded from the ConfigServer’s website.

wget http://www.configserver.com/free/csf.tgz

This will download CSF to your current working directory. Step 2: Uncompressing

The downloaded file is a compressed from of tar package, and has to be uncompressed and extracted before it can be used. tar -xzf csf.tgz

Step 3: Installing

If you are using another firewall configuration scripts, such as UFW, you should disable it before proceeding. Iptables rules are automatically removed.

UFW can be disabled by running the following command: ufw disable

Now it is time to execute the CSF’s installer script. cd csf

sh install.sh

The firewall is now installed, but you should check if the required iptables modules are available.

perl /usr/local/csf/bin/csftest.pl

The firewall will work if no fatal errors are reported.

Note: Your IP address was added to the whitelist if possible. In addition, the SSH port has been opened automatically, even if it uses custom port. The firewall was also configured to have testing mode enabled, which means that the iptables rules will be automatically removed five minutes after starting CSF. This should be disabled once you know that your configuration works, and you will not be locked out.

Basic Configuration

CSF can be configured by editing its configuration file csf.conf in /etc/csf:

(11)

nano /etc/csf/csf.conf

The changes can be applied with command: csf -r

Step 1: Configuring ports

The less access there is to your VPS, the more secure your server is. However, not all ports can be closed as the clients must be able to use your services.

The ports opened by default are the following:

TCP_IN = “20,21,22,25,53,80,110,143,443,465,587,993,995” TCP_OUT = “20,21,22,25,53,80,110,113,443”

UDP_IN = “20,21,53”

UDP_OUT = “20,21,53,113,123” Services using the open ports: Port 20: FTP data transfer Port 21: FTP control

Port 22: Secure shell (SSH)

Port 25: Simple mail transfer protocol (SMTP) Port 53: Domain name system (DNS)

Port 80: Hypertext transfer protocol (HTTP) Port 110: Post office protocol v3 (POP3)

Port 113: Authentication service/identification protocol Port 123: Network time protocol (NTP)

Port 143: Internet message access protocol (IMAP)

Port 443: Hypertext transfer protocol over SSL/TLS (HTTPS) Port 465: URL Rendesvous Directory for SSM (Cisco)

Port 587: E-mail message submission (SMTP)

Port 993: Internet message access protocol over SSL (IMAPS) Port 995: Post office protocol 3 over TLS/SSL (POP3S)

It is possible that you are not using all of these services, so you can close the ports that are not used. I would recommend closing all ports (removing port number form the list), and then adding the ports you need.

(12)

the listed service: On any server: TCP_IN: 22,53 TCP_OUT: 22,53,80,113,443 UPD_IN: 53 UPD_OUT: 53,113,123 Apache: TCP_IN: 80,443 FTP server: TCP_IN: 20,21 TCP_OUT: 20,21 UPD_IN: 20,21 UPD_OUT:20,21 Mail server: TCP_IN: 25,110,143,587,993,995 TCP_OUT: 25,110

MySQL server (if remote access is required) TCP_IN: 3306

TCP_OUT: 3306

Note: If you are using IPv6 for your services, you should also configure TCP6_IN, TCP6_OUT, UPD6_IN, and UPD6_OUT similarly to how IPv4 ports were configured earlier.

Macam-macam serangan sql

injection

Serangan SQL Injection dapat dibagi menjadi tiga kelas berikut :

Inband : Data diekstrak menggunakan saluran yang sama yang digunakan untuk menyuntikkan kode SQL . Ini adalah jenis yang paling sederhana serangan , di mana data yang

(13)

diambil disajikan langsung di halaman web aplikasi .

Out-of -band : data yang diambil dengan menggunakan saluran yang berbeda ( misalnya , email dengan hasil query yang dihasilkan dan dikirim ke tester ) .

Inferential atau Blind : tidak ada transfer data aktual , tapi tester mampu merekonstruksi informasi dengan mengirimkan permintaan tertentu dan mengamati perilaku yang dihasilkan dari DB Server .

Untuk sukses atau tidaknya serangan SQL Injection pada website atau aplikasi berbasis web terletak dalam benar atau tidaknya sintak SQL Query. Jika aplikasi mengembalikan pesan kesalahan yang dihasilkan oleh query yang salah , maka mungkin lebih mudah bagi penyerang untuk merekonstruksi logika query asli dan, karena itu , memahami bagaimana melakukan injeksi dengan benar. Namun, jika aplikasi menyembunyikan rincian kesalahan, maka tester harus mampu untuk melakukan reverse engineering logika query.

Tentang teknik untuk mengeksploitasi kelemahan website dan aplikasi webbase dengan SQL injection memiliki lima teknik, dan juga teknik tersebut kadang-kadang dapat digunakan dengan cara digabungkan ( misalnya Union Operator dan out-of-band ) :

Union Operator: dapat digunakan ketika cacat SQL injection terjadi dalam sebuah pernyataan SELECT , sehingga memungkinkan untuk menggabungkan dua query ke dalam hasil tunggal atau hasil ditetapkan .

B o o l e a n : g u n a k a n k o n d i s i B o o l e a n ( s ) u n t u k memverifikasi apakah kondisi tertentu adalah benar atau salah .

Kesalahan berdasarkan : teknik ini memaksa database untuk menghasilkan kesalahan , memberikan penyerang atau informasi tester yang di atasnya untuk memperbaiki injeksi mereka .

Out-of -band : teknik yang digunakan untuk mengambil data dengan menggunakan saluran yang berbeda ( misalnya , membuat sambungan HTTP untuk mengirimkan hasilnya ke

(14)

server web ) .

Waktu tunda : menggunakan perintah database (misal tidur ) untuk menunda jawaban dalam pertanyaan kondisional . Ini berguna ketika penyerang tidak memiliki beberapa jenis jawaban ( hasil , output, atau kesalahan ) dari aplikasi .

apa itu macam serangan

website ( sql injection )

Apa SQL Injection ?

SQL Injection adalah serangan berbasis web yang digunakan oleh hacker untuk mencuri informasi sensitif dari organisasi melalui aplikasi web . Ini adalah salah satu yang paling umum serangan lapisan aplikasi yang digunakan saat ini . Serangan ini mengambil keuntungan dari coding yang tidak tepat aplikasi web , yang memungkinkan hacker untuk mengeksploitasi kelemahan dengan menyuntikkan perintah SQL ke dalam aplikasi web sebelumnya.

Fakta yang mendasari yang memungkinkan untuk SQL Injection adalah bahwa bidang yang tersedia untuk input pengguna dalam aplikasi web memungkinkan pernyataan SQL melewati dan berinteraksi dengan atau query database secara langsung .

Sebagai contoh, mari kita perhatikan sebuah aplikasi web yang mengimplementasikan mekanisme login berbasis form untuk menyimpan kredensial pengguna dan melakukan query SQL sederhana untuk memvalidasi setiap upaya login. Berikut adalah contoh khas :

(15)

admin123 ‘ ;

Jika penyerang mengetahui username administrator aplikasi admin , dia bisa login sebagai admin tanpa memberikan password apapun.

admin’ –

Permintaan di back-end seperti :

SELECT * FROM user WHERE username = ‘ admin’ – ‘ dan password = ‘ xxx ‘ ;

Perhatikan urutan komentar ( – ) menyebabkan query diikuti untuk diabaikan , sehingga permintaan dieksekusi setara dengan :

SELECT * FROM user WHERE username = ‘ admin ‘ ;

Jadi sandi atau perintah untuk pengecekan password akan dilewati. Berikut sedikit contoh bagaimana cara kerja sql injection pada pengecekan user dan password. Kita akan masuk ke dalam macam-macam sql injection pada bahasan selanjutnya.. Sekian..

fail2ban untuk mengamankan

server dari serangan bot

hacker | centos 6.3

(16)

Server tidak dalam isolasi dan mereka dengan server konfigurasi SSH paling dasar bisa rentan terhadap serangan brute force. fail2ban menyediakan cara untuk secara otomatis melindungi server dari tanda-tanda berbahaya. Program ini bekerja dengan memindai melalui file log dan bereaksi terhadap tindakan menyinggung seperti berulang percobaan login yang gagal.

Step 1—Install Fail2Ban

Karena fail2ban tidak ada dalam standart package dan kita harus mengambil repo EPEL yang menyediakan package tbs:

r p m - U v h

http://download.fedoraproject.org/pub/epel/6/i386/epel-release -6-7.noarch.rpm

Kemudian install fail2ban: yum install fail2ban

Step 2—Copy the Configuration File

The fail2ban file konfigurasi default adalah lokasi di / etc/fail2ban/jail.conf. konfigurasi tidak harus dilakukan dalam file itu, bagaimanapun, dan kita harus membuat salinan lokal itu.

(17)

Step 3—Configure defaults in

Jail.Local

Buka konfigurasi yang anda salin tadi: vi /etc/fail2ban/jail.local

Konfigurasi fail2ban default masih kurang begitu kejam, kita harus memodifikasinya agar menjadikannya lebih kejam.

Berikut konfigurasi standartnya. [DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not

# ban a host which matches an address in this list. Several addresses can be

# defined using space separator. ignoreip = 127.0.0.1

# "bantime" is the number of seconds that a host is banned. bantime = 3600

# A host is banned if it has generated "maxretry" during the last "findtime"

# seconds.

findtime = 600

# "maxretry" is the number of failures before a host get banned.

maxretry = 3

Masukan ip anda ke dalam ignoreip agar anda tidak di block jika melakukan kesalahan dalam menginput password login. Pemisah ip yang anda masukan mengunakan standart yaitu spasi. Langkah berikutnya adalah untuk memutuskan suatu bantime, jumlah detik yang host akan diblokir dari server jika mereka ditemukan melanggar salah satu aturan. Hal ini sangat berguna

(18)

dalam kasus bots, yang pernah dilarang, hanya akan beralih ke target berikutnya. Standarnya diatur selama 10 menit-Anda dapat meningkatkan ini untuk satu jam (atau lebih tinggi) jika Anda suka.

Maxretry adalah jumlah usaha login yang salah bahwa host mungkin memiliki sebelum mereka mendapatkan dilarang untuk panjang waktu larangan.

Findtime mengacu pada jumlah waktu yang host harus login Pengaturan default adalah 10 menit, ini berarti bahwa jika upaya tuan rumah, dan gagal, untuk login lebih dari jumlah maxretry kali dalam 10 menit ditunjuk, mereka akan dilarang.

Step 4 (Optional)—Configure the

ssh-iptables Section in Jail.Local

untuk SSH ,rincian bagian adalah hanya sedikit lebih bawah dalam konfigurasi, dan itu sudah diatur dan dihidupkan. Meskipun Anda tidak harus diminta untuk membuat untuk membuat perubahan dalam bagian ini, Anda dapat menemukan rincian tentang setiap baris di bawah ini.

[ssh-iptables] enabled = true filter = sshd

action = iptables[name=SSH, port=ssh, protocol=tcp]

s e n d m a i l - w h o i s [ n a m e = S S H , d e s t = r o o t , [email protected]]

logpath = /var/log/secure maxretry = 5

Diaktifkan hanya mengacu pada fakta bahwa SSH perlindungan aktif. Anda dapat mematikannya dengan kata “palsu”.

Filter, diatur secara default untuk sshd, mengacu pada file konfigurasi yang berisi aturan-aturan yang fail2banuses untuk menemukan pertandingan. Nama adalah versi singkat dari

(19)

e k s t e n s i f i l e . M i s a l n y a , s s h d m e n g a c u p a d a etc/fail2ban/filter.d/sshd.conf /.

Aksi menggambarkan langkah-langkah yang akan mengambil fail2ban untuk melarang alamat IP yang cocok. Sama seperti masuknya filter, setiap tindakan mengacu ke file di dalam direktori action.d. Aksi larangan default, “iptables” dapat ditemukan di / etc/fail2ban/action.d/iptables.conf.

Dalam rincian “iptables”, Anda dapat menyesuaikan fail2ban lanjut. Misalnya, jika Anda menggunakan port non-standar, Anda dapat mengubah nomor port dalam kurung untuk mencocokkan, membuat garis terlihat lebih seperti ini:

eg. iptables[name=SSH, port=30000, protocol=tcp]

Anda dapat mengubah protokol dari TCP dengan UDP di baris ini juga, tergantung pada mana yang Anda inginkan fail2ban untuk memantau.

Jika Anda memiliki mail server mengatur di server virtual pribadi Anda, fail2ban dapat email Anda ketika melarang alamat IP. Dalam kasus default, sendmail-whois mengacu pada tindakan yang terletak di / etc/fail2ban/action.d/sendmail-whois.conf. path log mengacu pada lokasi log yang fail2ban akan melacak. Maks coba garis dalam bagian SSH memiliki definisi yang sama sebagai pilihan default. Namun, jika Anda telah mengaktifkan beberapa layanan dan ingin memiliki nilai-nilai tertentu untuk masing-masing, Anda dapat mengatur max baru coba lagi jumlah untuk SSH sini.

Step 5—Restart Fail2Ban

ok selesaikan dan memulai aplikasi fail2ban: sudo service fail2ban restart

semua yang terblock dengan cara: iptables -L

(20)

semoga bermanfaat

Melihat aktif query pada

postgresql

Saya lagi iseng-iseng mau lihat query sekarang ini apa ya di postgresql trus saya coba beberapa sql query yang menselect pg_stat_activity. Tapi setelah query itu berjalan kog current query ga muncul ya? ternyata saya belum aktifkan di postgres.conf nya.

pertama set/uncomment postgres.conf stats_command_string = true

kemudian reload database, setelah itu coba select kembali pg_stat_activity.

SELECT datname,procpid,current_query FROM pg_stat_activity dan untuk postgresql 8.2

S E L E C T

datname,usename,procpid,client_addr,waiting,query_start,curren t_query FROM pg_stat_activity ;

(21)

Simple

firewall

with

netfilter / iptables

Kita terkadang sering terkena attack / serangan dari pihak yang tidak bertanggung jawab, dan tidak hanya itu mungkin saja data atau informasi kita diambil oleh orang tersebut. Sebagai seorang yang mengurusi Network dan System enginer maka dibawah ini saya berikan sedikit filtering dan blocking jaringan dari attack dan juga serangan yang tidak2. caranya cukup mudah, berikut saya berikan secara bertahap..

1 Buat file pada /etc/init.d/firewall ( bisa pakai vim, nano atau editor lainnya ) : vim /etc/init.d/firewall

Kemudian isi dengan code shell script berikut..

#! /bin/bash #

# /etc/init.d/firewall #

### BEGIN INIT INFO # Provides: firewall

# Required-Start: $network syslog # Required-Stop:

# Should-Stop:

# Default-Start: 3 4 5 # Default-Stop: 0 1 2 6

# Short-Description: Firewall configuration ### END INIT INFO

############################################################# #################

# DEFAULT POLICY SetDefaultPolicy() {

# Drop everything

(22)

iptables -P OUTPUT DROP iptables -P FORWARD DROP } ############################################################# ################# # FLUSH TABLES FlushTables() { iptables -F -t nat iptables -F -t mangle iptables -F -t filter iptables -X } ############################################################# ################# # ROUTING EnableRouting() { echo 1 > /proc/sys/net/ipv4/ip_forward } DisableRouting() { echo 0 > /proc/sys/net/ipv4/ip_forward } ############################################################# ################# # FORWARDING SetForwardingRules() {

iptables -A FORWARD -i $IF_PUB -o $IF_PRV -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -i $IF_PRV -o $IF_PUB -j ACCEPT } ############################################################# ################# # LOOPBACK SetLoopbackRules() { # Allow everything

iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT

(23)

} ############################################################# ################# # PRIVATE INTERFACES SetPrivateInterfaceRules() { # Allow everything

iptables -A INPUT -i $IF_PRV -s $NET_PRV -j ACCEPT iptables -A OUTPUT -o $IF_PRV -d $NET_PRV -j ACCEPT }

############################################################# ################

# PUBLIC INTERFACES

SetPublicInterfaceRules() {

iptables -A INPUT -i $IF_PUB -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A OUTPUT -o $IF_PUB -j ACCEPT }

############################################################# #################

# SOURCE NAT

EnableSourceNAT() {

# Then source NAT everything else

iptables -t nat -A POSTROUTING -s $NET_PRV -o $IF_PUB -j SNAT --to $IP_PUB

}

# Various ICMP SetICMP_Open() {

iptables -A INPUT -p icmp --icmp-type 0 -j ACCEPT iptables -A INPUT -p icmp --icmp-type 3 -j ACCEPT iptables -A INPUT -p icmp --icmp-type 11 -j ACCEPT iptables -A INPUT -p icmp icmp-type 8 -m limit --limit 1/second -j ACCEPT

}

# SSH (on a non-standard port) SetSSH_Open() {

(24)

--dport 2202 -j ACCEPT } ############################################################# ################# # Destination NAT # smtp SetSMTP_DNAT() {

iptables t nat A PREROUTING i $IF_PUB d $IP_PUB -p tc-p --d-port smt-p -j DNAT --to 192.168.1.254

i p t a b l e s - A F O R W A R D - m s t a t e - - s t a t e NEW,ESTABLISHED,RELATED -i $IF_PUB -p tcp --dport smtp -j ACCEPT

}

# pop3

SetPOP3_DNAT() {

iptables t nat A PREROUTING i $IF_PUB d $IP_PUB -p tc-p --d-port -po-p3 -j DNAT --to 192.168.10.254

i p t a b l e s - A F O R W A R D - m s t a t e - - s t a t e NEW,ESTABLISHED,RELATED -i $IF_PUB -p tcp --dport pop3 -j ACCEPT

}

# Webmail (444->443) SetWebmail_DNAT() {

iptables t nat A PREROUTING i $IF_PUB d $IP_PUB -p tc-p --d-port 444 -j DNAT --to 192.168.10.254:443

i p t a b l e s - A F O R W A R D - m s t a t e - - s t a t e NEW,ESTABLISHED,RELATED -o $IF_PRV -p tcp --dport 443 -j ACCEPT

}

# http

SetHTTP_DNAT() {

iptables t nat A PREROUTING i $IF_PUB d $IP_PUB -p tc-p --d-port htt-p -j DNAT --to 192.168.10.253

i p t a b l e s - A F O R W A R D - m s t a t e - - s t a t e NEW,ESTABLISHED,RELATED -i $IF_PUB -p tcp --dport http -j ACCEPT

(25)

}

# Blocked protocols SetBlockedProtocols() {

# Block all normal irc (used by botnets) iptables -A INPUT -p tcp --dport irc -j DROP iptables -A INPUT -p udp --dport irc -j DROP

iptables -A INPUT -p tcp --dport irc-serv -j DROP iptables -A INPUT -p udp --dport irc-serv -j DROP iptables -A INPUT -p tcp --dport ircs -j DROP iptables -A INPUT -p udp --dport ircs -j DROP }

# Blocked hosts SetBlockedHosts() {

iptables -A INPUT -i $IF_PUB -s 10.220.231.236 -j REJECT --reject-with icmp-host-prohibited

iptables -A FORWARD -i $IF_PUB -s 10.220.231.236 -j REJECT --reject-with icmp-host-prohibited

}

# Blocked networks SetBlockedNetworks() {

iptables -A INPUT -i $IF_PUB -s 10.220.232.0/24 -j REJECT --reject-with icmp-net-prohibited

iptables -A FORWARD -i $IF_PUB -d $IP_PUB -s 10.220.232.0/24 -j REJECT --reject-with icmp-net-prohibited }

# Specify things to drop before logging SetPrelogDropRules() {

# DHCP

iptables -A INPUT -i $IF_PUB -p udp --sport bootps -j DROP

}

# Log those on the public interface SetLoggingRules() {

i p t a b l e s A I N P U T i $ I F _ P U B j L O G l o g -prefix="INPUT "

(26)

--log-prefix="OUTPUT "

iptables -A FORWARD -j LOG --log-prefix="FORWARD " # iptables -t nat -A PREROUTING -i $IF_PUB -j LOG --log-prefix="nPre "

# iptables -t nat -A POSTROUTING -o $IF_PUB -j LOG --log-prefix="nPost "

# iptables -t nat -A OUTPUT -o $IF_PUB -j LOG --log-prefix="NAT OUT "

}

# Drop them all SetDropRules() {

# Reset tcp connection attempts on all other ports # This is the standard TCP behaviour for a closed port. Reading

# suggests there is no value in stealthing ports and since some are

# open on this host it doesn't seem to matter. Therefore, let's be a

# good TCP citizen

iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset

}

############################################################# #################

# SCRIPT ENTRY POINT

echo -n "Firewall configuration..." echo $1 ############################################################# ################# # ENVIRONMENT # Private interface IF_PRV=eth0 IP_PRV=192.168.1.1 NET_PRV=192.168.1.0/24 # Public interface

(27)

IF_PUB=eth1 IP_PUB=10.0.0.1 NET_PUB=10.0.0.0/24 # Others ANYWHERE=0.0.0.0/0 . /etc/rc.status rc_reset ############################################################# ################# # COMMAND LINE case "$1" in start) SetDefaultPolicy FlushTables EnableRouting SetBlockedProtocols SetBlockedNetworks SetBlockedHosts SetForwardingRules SetLoopbackRules SetPrivateInterfaceRules SetPublicInterfaceRules EnableSourceNAT SetICMP_Open SetSSH_Open SetSMTP_DNAT SetPOP3_DNAT SetWebmail_DNAT SetHTTP_DNAT

(28)

SetPrelogDropRules SetLoggingRules SetDropRules ;; stop) SetDefaultPolicy FlushTables SetPrivateInterfaceRules SetPublicInterfaceRules ;; restart) $0 stop $0 start ;; *) ;; esac rc_exit

2. Berikan akses untuk menjalankan script :

chmod +x /etc/init.d/firewall

3. Masukan ke chkconfig :

chkconfig add firewall untuk melihat :

chkconfig --list

jika sudah maka firewall siap untuk di jalankan serta firewall siap menangani serangan..

(29)

ini aja [dot] com

install squid3 di ubuntu

server 10.04

Ini adalah panduan singkat untuk mendirikan sebuah proxy cache transparan pada Ubuntu Server. Pada dasarnya, ada dua alasan mengapa Anda mungkin tertarik membuat proxy squid : 1. mempercepat akses web Anda

2. menghemat bandwidthAnda.

Mari berasumsi bahwa Anda sudah mengatur sebuah gateway Linux m e n g g u n a k a n i p t a b l e s . H a l i n i d i m u n g k i n k a n u n t u k menjalankan squid juga pada Windows tapi sayangnya itu sangat sulit untuk menemukan perangkat keras di mana Windows mampu bertahan lebih dari satu minggu. Kata lain, windows keluar dari ruang lingkup artikel ini. Langkah pertama adalah menginstall squid 3

apt-get install squid3

Edit konfigurasi squid3 anda dengan mengunakan best editor yang anda sukai.

sudo vi /etc/squid3/squid.conf

Dan kemudian kita set transparant proxy dan ip host anda, atau anda bisa lihat konfigurasi saya disini

http_port 3128 transparent

(30)

acl localnet src 127.0.0.1/255.255.255.255 http_access allow our_networks

http_access allow localnet

Dimana 192.168.1.0/24 ip network anda. Selanjutnya masukan konfigurasi cache

cache_dir ufs /var/spool/squid3 7000 16 256

untuk angka pertama diatas ( 7000 ) itu adalah ukuran cache dalam satuan megabyte. setelah itu save konfigurasi yang anda edit dan restart squid anda

sudo /etc/init.d/squid3 restart

Untuk melihat informasi detail silahkan check pada url Squid wiki page. Yang perlu diingat dalam pengunaan memori dan processor di squid3 adalah fungsi dari ukuran swap. Kemudian anda harus menambahkan redirect dari HTTP-Trafic ke Proxy transparan anda.

iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.1:3128

iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

disini eth0 adalah LAN dan eth1 adalah WAN, dan ip address 192.168.1.1 adalah ip LAN server.

Setelah semuanya selesai, buat simbolik link untuk membuat sarg, clamaris agar bisa digunakan karena aplikasi tersebut masih melihat path log pada squid 2.x..

ln -s /var/log/squid3 /var/log/squid Selesai Selamat mencoba..

Referensi

Dokumen terkait