Thursday, May 17, 2007

Replace Repositories (Ubuntu)

sudo gedit /etc/apt/sources.list

Replace everything with the following list:
## Add comments (##) in front of any line to remove it from being checked.
## Use the following sources.list at your own risk.


deb http://archive.ubuntu.com/ubuntu dapper main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu dapper main restricted universe multiverse


## MAJOR BUG FIX UPDATES produced after the final release
deb http://archive.ubuntu.com/ubuntu dapper-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu dapper-updates main restricted universe multiverse


## UBUNTU SECURITY UPDATES
deb http://security.ubuntu.com/ubuntu dapper-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted universe multiverse


## BACKPORTS REPOSITORY (Unsupported. May contain illegal packages. Use at own risk.)
deb http://archive.ubuntu.com/ubuntu dapper-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu dapper-backports main restricted universe multiverse


## PLF REPOSITORY (Unsupported. May contain illegal packages. Use at own risk.)
deb http://packages.freecontrib.org/plf dapper free non-free
deb-src http://packages.freecontrib.org/plf dapper free non-free


## CANONICAL COMMERCIAL REPOSITORY (Hosted on Canonical servers, not Ubuntu
## servers. RealPlayer10, Opera and more to come.)
deb http://archive.canonical.com/ubuntu dapper-commercial main

Then, update your repositories:
sudo apt-get update

How to install ALSA sound drivers (Slackware)

getting the driver : ftp://ftp.alsa-project.org/pub/
get the latest one :)
download this 3 file:
alsa-driver-0.4.1e.tar.gz
alsa-lib-0.4.1d.tar.gz
alsa-utils-0.4.1.tar.gz

extract them...
tar -zxf alsa-driver-0.4.1e.tar.gz
tar -zxf alsa-lib-0.4.1d.tar.gz
tar -zxf alsa-utils-0.4.1.tar.gz

./snddevices

/sbin/modprobe snd-card-sb16


Wednesday, May 16, 2007

samba configuration by bro zamri

Samba explained

I'm done setting up samba server as instructed by my boss 2 weeks ago. The mystery of SAMBA have been revealed :). I never done this before. I mean I've never done setting up one for 'production' server. I learnt a lot from internet by googling and asking on a Linux forum to get hints. I wanna share a few tips here for us.

My setup
The first thing to configure is smb.conf. I use Slackware 10.2. This file is located in /etc/samba. For your distro, you should check in /etc or /etc/samba. This file is divided into 2 categories:

  1. global setting [global]
  2. share definitions (this is where you define your sharing directories)
Let's discuss them in turn

global setting[global]

workgroup - specify workgroup of your machine
server string - specify server string ie Samba server
security - specify your security here ie share or user. share is suitable for home use. user is more secure. You have to specify username and password when you want to connect to this samba server.
hosts allow - ie 192.168.0.0/24 or 10.0.0.0/16 , specify LAN clients allowed to connect. You may want to add localhost too ie 127.0.0.1
wins server - specify WINS server to be used by this samba server for faster NetBIOS name resolution ie 192.168.0.11

There are more directives to be set but I concentrate for simple setup only.

Share Definitions
Here you can specify what directory you want to make sharing. Look at this example:

[homes]
comment = Home Directories
browseable = No
writable = Yes

[public]
comment = For Public Consumption
path = /home/samba/public
public = Yes
writable = Yes
printable = No
writelist = @staff
browseable = Yes

[Finance]
comment = Finance's Stuff
path = /home/samba/finance
valid users = @finance
public = no
writable = no
printable = no
browseable = yes
write list = @finance
create mask = 0660
directory mask = 0770
force group = @finance

------
for [Homes], it is the home directory of the user if they logged in. browseable = No states that the directory is not browseable by other users or hidden. writable = yes states that the user is given read and write permissions.

for [public], the path for this folder is /home/samba/public. You have to make sure that this directory exist and make sure the permission is set as below:

drwxrwxr-x  root staff  /home/samba/public

this ensure that the staff group has write permission as stated by writelist = @staff. The other directives are self-explanatory.

For [finance], the path is /home/samba/finance and valid users = @finance states that only users in finance group can enter/access this directory and write list = @finance ensures that only users in finance group have read and write permissions. The "create mask" and "directory mask" ensure new and modified files and directories retain their correct permissions, and the "force group" causes all file read/writes to be the group finance regardless of what the user's primary group is, ensuring that all members can read/write/modify files. permissions. You should set the directory as :

drwxrwx---  root finance  /home/samba/finance

These are the tips that I got when I was setting up the samba server. I hope it can be useful to anyone who wanna setup a simple samba server in a LAN more secure by setting up the sharing directories correctly.

You can extend the above setup as you grasp the key concept above. The permissions of Linux directories should satisfy what you state in smb.conf or the other way around :). Otherwise it will make no sense.

Lastly, to restart the samba server , issue this command :

/etc/rc.d/rc.samba restart

or (if you use Fedora, Redhat or Mandriva)

service smbd restart

Have nice day!
___________________________________________
thanks bro zamri

my squid.conf for squidNT (ver 2.6 stable)

http_port 8080
cache_mem 64 MB
cache_swap_low 98
cache_swap_high 99
maximum_object_size 1024 MB
maximum_object_size_in_memory 7999 KB
ipcache_size 163780
ipcache_low 98
ipcache_high 99
cache_replacement_policy heap LFUDA
memory_replacement_policy heap GDSF
cache_dir ufs C:\cache 10240 16 256
cache_access_log none
cache_log none
cache_store_log none
emulate_httpd_log off
mime_table C:\Squid/etc/mime.conf
pid_filename C:\Squid/log/squid.pid
log_fqdn off
ftp_user Squid@
ftp_passive on
ftp_sanitycheck on
dns_nameservers 202.188.0.133 202.188.1.5 192.168.0.1
diskd_program C:\Squid/libexec/diskd.exe
unlinkd_program C:\Squid/libexec/unlinkd.exe
request_header_max_size 20 KB
request_body_max_size 0 KB
refresh_pattern ftp: 1440 60% 10080
refresh_pattern gopher: 1440 60% 1440
refresh_pattern -i . 0 89% 129600000 override-lastmod reload-into-ims
refresh_pattern -i \.gif 999 99% 129600000 ignore-reload reload-into-ims
refresh_pattern -i \.jpg 999 99% 129600000 ignore-reload reload-into-ims
refresh_pattern -i \.tif 999 99% 129600000 ignore-reload reload-into-ims
refresh_pattern -i \.png 999 99% 129600000 ignore-reload reload-into-ims
refresh_pattern -i \.jpeg 999 99% 129600000 ignore-reload reload-into-ims
refresh_pattern -i \.bmp 999 99% 129600000 ignore-reload reload-into-ims
refresh_pattern ^ftp: 4320 98% 129600 override-lastmod reload-into-ims
quick_abort_min 0 KB
quick_abort_max 0 KB
quick_abort_pct 100%
negative_ttl 1 minutes
positive_dns_ttl 24 hours
negative_dns_ttl 1 minutes
range_offset_limit -1 KB
half_closed_clients off
shutdown_lifetime 10 seconds
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 563 # https, snews
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 5050 # yahoo msger
acl Safe_ports port 5100 # yahoo msger webcam 5101
acl Safe_ports port 5101 # yahoo
acl Safe_ports port 5000-5010 # yahoo
acl CONNECT method CONNECT
acl MYLAN src 127.0.0.1-127.0.0.1/255.255.255.255
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl our_networks src 192.168.0.0/255.255.255.0
http_access allow our_networks
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow MYLAN
icp_access allow all
reply_body_max_size 0 allow all
cache_mgr fingerpoppin@gmail.com
cache_effective_user proxy
cache_effective_group proxy
visible_hostname OctopusNT
dns_testnames google.com
logfile_rotate 3
memory_pools off
memory_pools_limit 0
log_icp_queries off
cachemgr_passwd none
store_avg_object_size 1024 KB
store_objects_per_bucket 100
client_db off
netdb_low 900
netdb_high 1000
netdb_ping_period 5 minutes
buffered_logs off
reload_into_ims on
header_access Accept-Encoding deny all
icon_directory C:\Squid/share/icons
offline_mode off
nonhierarchical_direct off
prefer_direct off
coredump_dir C:\Squid/cache
ignore_unknown_nameservers off
client_persistent_connections on
server_persistent_connections on
pipeline_prefetch on
ie_refresh on
vary_ignore_expire on

iptables (version bro root)

Tutorial ringkas iptables/firewall.

Resepi:

Linux kernel v 2.4.x
- iptables v 2.4 keatas
- syslog
- GNU textutils (sed, tail, uniq)

Situasi:

Jaringan
- eth0 : disambung ke LAN
- eth1 : disambung terus ke Internet.

Katakan anda menyediakan sebuah pelayan WWW/http untuk kegunaan ramai yang
disambungkan terus ke Internet. Selain dari port 80(http), anda tidak
ingin port lain diakses pada pelayan tersebut. Anda juga ingin melihat
cubaan penggodam atau ulat/cecacing yang ingin masuk ke pelayan anda pada
port lain. Apa yang anda harus lakukan?

Dengan implimentasi dinding-api, anda kena TUTUP/DROP kesemua port yang
masuk ke pelayan secara default yang datang dari Internet (katakan eth1).

CODE
# iptables -P INPUT DROP


Tapi anda kena benarkan segala sambungan masuk dari LAN anda sendiri
(katakan eth0) dan dari localhost itu sendiri.

CODE
# iptables -A INPUT -i lo -j ACCEPT

# iptables -A INPUT -i eth0 -j ACCEPT


Mmm.. dah cukup ke?. Apa kata kita cuba ping ke google.com tengok.
Alamak, tak dapat sambunglah... kenapa ye? Sebenar pelayan anda tidak
dapat menerima sahutan kembali, walaupun telah berjaya berhubung pada
destinasi host diluar. Kenapa? Sebab anda telah tutup kesemua port pada
'INPUT' tadi secara default. Jadi apa yang perlu dibuat?

Bagi memastikan segala akses keluar ke Internet dapat diterima kembali
dengan selamat. Gunalah kelebihan iptables yang bertaraf 'statefull'
firewall. Tambah je barisan canggih dibawah ini.

CODE
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT


Sekarang anda cuba ping google.com balik. iptables anda memastikan
sahutan/reply paket yang KELUAR dari pelayan kita itu dapat masuk dengan
membuka port yang berkaitan secara otomatik. Kalau dah siap, port ini akan
ditutup. Waaaaahhh.. canggihnya.... punyalah karan dan sempoi...

Ok, sekarang saya buka port 80 sahaja bagi membenarkan orang dapat
menggunakan servis http/web kita tadi.

CODE
# iptables -A INPUT -i eth1 -p tcp --dport 80 -j ACCEPT


Jadi sekarang sapa-sapa pun boleh masuk ke pelayan ke port 80 (http) tanpa
sebarang masalah. Paket yang masuk LAIN dari port 80 akan di abaikan/DROP,
sebab kita dah setkan default policy DROP diatas tadi.

Sekarang saya teringin pulak, nak tau, berapa banyak/kekerapan penggodam
atau ulat/cecacing yang ingin menceroboh ke pelayan kita ini.... Kalau
boleh kita nak log kan kedalam fail khas, katakan /var/log/warning

CODE
#iptables -A INPUT -i eth1 -j LOG --log-level 5


Segala paket yang tidak memenuhi rules diatas tadi akan direkodkan pada
sistem log kernel pada tahap 5.

Anda kena tambah sikit barisan dibawah ke fail /etc/syslog.conf
CODE
kern.notice /var/log/warning


dan restartlah servis syslog. Contoh, RH : service syslog restart,
atau killall -HUP syslogd

Sekarang, kesemua cubaan akan direkodkan ke /var/log/warning.
Mungkin anda nak tahu, kekerapan cubaan yang telah dilakukan dan dari mana.
Dengan pengetahuan 'shell scripting' anda boleh cuba arahan dibawah

CODE
# sed -n '/Jan 9/s/.*SRC=([0-9.]*).*/1/p' /var/log/warning | sort | uniq -c | sort -n


Ianya akan mencari kesemua cubaan pada 9 Januari, mengeluarkan IP host
dengan kekerapannya sekali. Contoh pada pelayan saya disini, dan hasil
data adalah data yang sebenar.

CODE
# sed -n '/Jan 8/s/.*SRC=([0-9.]*).*/1/p' /var/log/warning | sort | uniq -c | sort -n

1 202.163.199.90

1 202.188.1.23

1 208.59.182.183

1 211.161.231.243

1 213.86.145.9

1 219.106.72.123

1 61.171.204.4

2 210.1.13.167

2 210.12.31.250

2 210.207.65.44

2 213.47.103.236

2 61.151.183.6

2 64.228.90.28

3 172.176.230.172

3 203.106.3.138

3 206.49.71.194

3 207.134.167.61

3 207.215.127.248

3 211.208.151.22

3 212.169.49.35

3 65.95.117.95

7 169.207.230.119

8 192.228.143.4

9 192.228.143.125

9 202.188.114.30

9 216.112.103.21

21 210.186.141.70

62 210.186.142.61


Oooo.. nampaknya host 210.186.142.6 ni tengah DoS pelayan saya ye.... dia nak kena nih !! . Tapi apa boleh buat, itu adalah dialup IP (kalau tak salah saya)

Waaa... bestnya... Kemudian dengan idea yang sama anda boleh dapatkan
kekerapan cubaan pada setiap port. Dibawah adalah contoh bagaimana saya
dapatkan 'TOP TEN' port yang kerap diakses dalam bulan Januari.

CODE
# sed -n '/^Jan/s/.*DPT=([0-9]*).*/1/p' /var/log/warning | sort | uniq -c | sort -n | tail -10

20 3389

22 8080

24 3128

28 445

29 57

32 1080

80 2764

125 21

172 1433

437 137


Mmmm.. nampaknya ramai juga 'peminat' yang cuba akses ke port 137 (netbios).

Lihat, nampak mudah, kan . Sapa kata Unix ini sukar? Belajar sikit dengan
tekun je, anda pun boleh buat semudah ini dan mungkin lebih baik dari ini .

Semoga tips/tutorial ini dapat digunakan bersama-sama.

Wassalamz, terima kasih.

yang benar,

root.

p/s:
Segala kod 'shell scripting' diatas dilindungi dengan lesen GPL, hakmilik
cipta terpelihara 2003, Mohammad Bahathir Hashim

iptables 2

Assalamualaikum...

Dalam artikel yang lepas, saya sudah terangkan tentang NAT yang terbahagi kepada 2 iaitu SNAT dan DNAT. Kali ini kita lihat pula extension yang terdapat didalam iptables. Antara yang menarik ialah state extension.

Apa itu extension
--------------------
Extension di sini bermaksud kod2 yang boleh dimasukkan dan ditambah ke dalam iptables supaya features tertentu dapat digunakan.

state extension
-----------------
Ia direka berdasarkan modul connection tracking di dalam kernel. Jadi pastikan anda memasukkan connection tracking module ke dalam kernel untuk membolehkan anda dapat menggunakan state extension.

Terdapat 3 'state' (status) bagi sesatu packet :

1. NEW --> paket dari satu sambungan (connection) baru. Untuk paket yang tidak dibalas oleh server dan dihantar balik juga dianggap sebagai NEW.
2. ESTABLISHED --> paket yang telah datang sebelumnya dan telah dibalas oleh server. Jadi paket yang datang dalam sambungan yang sama, akan dikelaskan sebagai ESTABLISHED.
3. RELATED --> paket yang tidak bersangkutan dengan sambungan tertentu tetapi mempunyai hubungkait dengan sambungan tertentu. Kebanyakannya berkaitan dengan FTP data connections.
4. INVALID --> paket yang bukan sebahagian sambungan tertentu dan tidak boleh dikaitkan dengan sambungan tertentu disebabkan oleh paket yang tidak sah atau tidak cukup memory.

Jadi dengan menggunakan status pada paket yang diklasifikasikan oleh
connection tracking, kita boleh menggunakan peraturan tertentu.

Cuba lihat contoh dibawah :

CODE
#iptables -A FORWARD -o ppp0 -j ACCEPT


Contoh di atas membenarkan (-j ACCEPT) paket dari LAN kita ke luar (internet) melalui interface ppp0 (modem) (-o ppp0).

Lihat pula contoh dibawah :

CODE
#iptables -A FORWARD -i ppp0 -m state --state ESTABLISHED,RELATED -j ACCEPT


Contoh diatas hanya membenarkan paket (-j ACCEPT) masuk melalui interface ppp0.

Kod connection tracking tidak men'drop' paket. Paket yang rosak atau yang tidak difahami akan diklasifikasikan sebagai INVALID. Ianya tugas iptables untuk menentukan nasib paket sebegini , samada nak drop dan sebagainya.

Semoga artikel pendek ini dapat dijadikan panduan untuk kawan2 semua mendalami iptables. Wassalam

[end of Part2]
_____________________________________
thanks to bro zamri

iptables

Bermula dari Linux kernel 2.0, ramai yang menggunakan PC menggantikan router dan firewall komersil. Bagi yang mempunyai rangkaian yang kecil dan sederhana, PC dengan Linux adalah sangat sesuai menjadi gateway/router. Apabila kernel berubah, perubahan berlaku kepada kod NAT dan yang terlibat :

1. Linux kernel 2.0.x --> ipfwadm
2. Linux kernel 2.2.x --> ipchains
3. Linux kernel 2.4.x --> iptables

Saya akan menceritakan tentang iptables dalam kernel 2.4.x.

iptables mempunyai 3 'built-in chains' :

1. INPUT 2. OUTPUT 3. FORWARD

Paket2 pula dipecahkan kepada 3 jenis :

1. paket yang berhenti di firewall
2. paket yang datang dari firewall
3. paket yang melalui firewall

PC linux kita jadikan firewall dan katakan anda mempunyai satu rangkaian (LAN) seperti di cybercafe. firewall ini juga adalah gateway kepada semua PC dalam LAN untuk ke internet. gateway sahaja yang mempunyai sambungan ke internet dengan mendail ke ISP dengan modem (ppp0).

Senario 1:
-----------
Anda hendak semua PC dalam LAN mendapat internet dengan berkongsi sambungan internet melalui gateway. Katakan gateway mempunyai IP dinamik.

CODE
#iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE


Dengan target MASQUERADE (-j MASQUERADE), kita memberitahu iptables, jika sambungan internet terputus, lupakan sambungan lama dengan IP lama, dan gantikan dengan buat sambungan baru dengan IP baru (dengan peraturan yang sama).

Senario 2:
-----------
Sama macam senario 1 tetapi gateway mempunyai IP tetap (fixed IP/static IP). Katakan IP itu ialah 1.2.3.4

CODE
#iptables -t nat -A POSTROUTING -o ppp0 -j SNAT --to-source 1.2.3.4


Kita lihat terms dibawah :
SNAT (Source NAT)
----------------------
- menukarkan source destination dalam paket. Dalam paket yang dihantar ke internet dari LAN dalam contoh di atas, source IP (alamat komputer penghantar) ditukar kepada alamat gateway. Dengan cara ini, komputer penerima tidak tahu penghantar sebenar. Dia hanya tahu , penghantar ialah gateway. (Ini salah satu cara IP spoofing dilakukan)

Dari kedua-dua senario di atas, dapatlah kita fahami bahawa masquerading ialah salah satu bentuk SNAT.

DNAT (Destination NAT)
---------------------------
- menukarkan alamat destinasi dalam paket untuk sesuatu sambungan (connection). Lihat senario di bawah :

Senario 3
-----------
Anda hendak komputer luar dari LAN anda mencapai webserver anda yang berada dalam LAN. Katakan anda menggunakan private IP 192.168.0.2 untuk webserver anda.

CODE
#iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport www -j DNAT

--to-dest 192.168.0.2


Senario 4
-----------
Anda hendak komputer luar mencapai webserver anda yang juga bertindak sebagai gateway kepada LAN anda iaitu gateway dan webserver ialah komputer yang sama. Anda mahukan sesiapa capai webserver anda di gateway ini, anda hendak redirectkan paket supaya pergi ke port 8080 (biasanya squid dameon menunggu di sini).
CODE
#iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport www

-j REDIRECT --to-port 8080


Arahan diatas digunakan untuk menukarkan IP destinasi dengan port 80 (www) kepada IP destinasi yang sama tetapi port yang berlainan (8080).


Saya rasa cukup setakat ini dulu. Kalau ada masa nanti saya akan sambung dengan extension modules untuk iptables terutamanya state extension.

Enjoy!
-------------------------------------------------------------------------------
thanks to bro zamri

Transparent Proxy (Squid)

Setting up transparent proxy server

Hi all,

Today, while setting up ip for my internal network, i found out that i have run out of IPs and the internet access was very slow. I ran into a situation called "bottleneck". A situation where a road becomes narrow with heavy traffic. How to speed up this? The answer is proxy server.

On with the theory
Proxy server is a server that can cache visited web pages. Dynamic web pages are not cached. When a client access a website, the proxy server , on behalf of the client access the website and cache it. the next the client or other client wants to connect to the site, the proxy server just give the cached site to the client. Thus reducing the response time from the actual site.

Transparent proxy
In a normal proxy case, you have to set manually for each client to connect to outside. It is not a practical solution if you have a lot of workstations + many apps to connect to the internet. What is more practical solution? The answer is "transparent proxy" and now iptables comes into play.

What you have to do first?
1. Setup a server
OS : Linux (whatever flavor you want)
proxy server : Squid (install the latest one)
utilities : netfilter packages (for iptables)

Squid.conf
Your squid.conf location is dependent on how you install squid package. If u use source code and compile it without tweaking ./configure options, meaning it is in /usr/local/squid/etc. If you use your package manager, it is in /etc. Wherever it is, you have to edit it before you can use it as a transparent proxy.

What to edit
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
acl lan src 192.168.1.1 192.168.2.0/24
http_access allow localhost
http_access allow lan

Please change "lan" to suit your network environment. This file is heavily documented. Please read the comments before you change anything unless you know what you're doing.

I don't want to explain in detail on how to setup linux for your server. Please consult your spesific Linux distribution HOWTOs and FAQs. After you have complete setting up Linux, you should setup SQUID. More information on squid, pls visit http://www.squid-cache.org. squid usually readily packaged for your distro. You should check that first whether you can just install it from CD. If not, you have to download from the link above.

After you have edited squid.conf, this is the iptables command you should run on the proxy server.

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
provided that your proxy server is using port 3128. If not, change it accordingly.
---------------------------------------------------------------------------------------
thanks to bro zamri