วันศุกร์ที่ 4 กุมภาพันธ์ พ.ศ. 2554

Network, Fortigate Firewall : Enable multicast address forwarding on Fortigate Firewall

จากโจทย์วันนี้คือ ทำการเปิดการใช้งาน OSPF โดย Router ที่ run OSPF ทั้งสองตัวจะถูก Firewall ขวางอยู่ในรูปแบบ Transparent mode ดังนี้

Router1 <---> Transparent FW <---> Router2

ทั้งนี้ปัญหาที่พบคือ แม้จะเปิด Firewall policy เป็น any to any แล้วก็ตาม Routing OSPF ก็ยังไม่สามารถส่งผ่าน Firewall ไปได้ เนื่องจาก OSPF จะประกาศ Route ผ่าน Multicast address

การแก้ไข ต้องทำใน command mode ของ Fortigate ดังนี้ (หาวิธีใน GUI ไม่เจอ)

อุปกรณ์ที่ใช้
Firewall : Fortigate 3016B

FG3016-B # config system settings
FG3016-B (settings) # set multicast-skip-policy enable
FG3016-B (settings) # end
FG3016-B #

จากนั้นตรวจสอบ Routing table ใน Router ทั้งสองพบว่ามี OSPF package มาเป็นปกติ

วันศุกร์ที่ 21 มกราคม พ.ศ. 2554

Linux: ตัวอย่างการใช้งานคำสั่ง cut

ตัวอย่างข้อมูลที่ได้มา

192.168.11.12

- ต้องการแสดงผลเฉพาะ 3 ตัวอักษรแรก

cut -c 1-3 <<< "192.168.11.12"

หรือ

cut -c -3 <<< "192.168.11.12"

ผลลัพธ์
192

โดยการกำหนด -c คือการกำหนดการแสดงผลตัวอักษรลำดับที่ที่ต้อง ดังตามตัวอย่างคือ ตัวอักษรที่ 1 ถึงตัวอักษรที่ 3 และอีกตัวอย่างคือ ตั้งแต่ตัวอักษรแรกไปถึงตัวอักษรที่ 3


- ต้องการแสดงผลตั้งแต่ตัวอักษรตั้งแต่ตัวที่ 4 ไปถึงตัวสุดท้ายของแถว

cut -c 4- <<< "192.168.11.12"

ผลลัพธ์
.168.11.12


- ต้องการแสดงแบ่งข้อมูล IP ดังกล่าวให้อยู่ในรูปแบบของ A.B.C.D แล้วต้องการแสดงผลแค่ A.B.C

cut -d"." -f 1,2,3 <<< "192.168.11.12"

หรือ

cut -d"." -f 1-3 <<< "192.168.11.12"

ผลลัพธ์
192.168.11

โดยการกำหนด -d เพื่อเป็นการบอกว่าจะใช้อะไรเป็นจุดแบ่งส่วนของข้อมูล อย่างในตัวอย่างคือใช้จุด "." เป็นตัวแบ่งหมายเลข IP ออกเป็น 4 ชุด แล้วนำมาแสดงผลแค่ชุดที่ 1 - 3 เป็นต้น

ตัวอย่างอื่นๆ

ข้อมูลตั้งต้น

komkit@Server:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh

ต้องการแสดงผลชื่อ Username เท่านั้น โดยจะให้เครื่องหมาย : เป็นตัวแบ่งฟิวต่างๆออกจากกัน

komkit@Server:~$ cut -d":" -f 1 /etc/passwd
root
daemon
bin
sys
sync
games


ต้องการแสดงผลชื่อ Username และ Default shell ของแต่ละ username

komkit@Server:~$ cut -d":" -f 1,7 /etc/passwd
root:/bin/bash
daemon:/bin/sh
bin:/bin/sh
sys:/bin/sh
sync:/bin/sync
games:/bin/sh

วันอาทิตย์ที่ 16 มกราคม พ.ศ. 2554

Linux, RHEL : ติดตั้ง RHEL 6 แบบ Text mode

ปกติ RHEL ใน Version ที่ผ่านมา จะให้พิมพ์ linux text ที่ Prompt
แต่ใน Version 6 นี้ ไม่มี prompt ให้ ดังนั้นการติดตั้งแบบ text mode จึงมีวิธีการเปลี่ยนไปนิดหน่อย ดังนี้

ทำการ boot จาก DVD ตามปกติ
ที่หน้าจอต้อนรับ จะมีเมนูการติดตั้งอยู่ 2 ตัว คือ

Install or upgrade an existing system
และ
Install system with basic videon driver
และ แต่ละอันจะสามารถกด TAB เพื่อเพิ่ม option การ boot ดังนั้น เพื่อให้ทำการติดตั้งแบบ text mode ก็ให้ทำการเพิ่มคำว่า text เข้าไปข้างหลังของ Option ของแต่ละเมนู ดังนี้

เลือก
Install or upgrade an existing system <-- กด TAB

vmlinuz initrd=initrd.img text <-- เพิ่ม text แล้ว enter

หรือ

เลือก
Install system with basic videon driver <-- กด TAB

vmlinuz initrd=initrd.img xdriver=vesa nomodeset text <-- เพิ่ม text แล้ว enter


ข้อแตกต่าง
เมนูแรกเป็นการติดตั้งแบบความละเอียดสูง แม้แต่ใน Text mode
ส่วนเมนูที่สองเป็นการติดตั้งแบบใช้ VGA driver แบบความละเอียดต่ำ (แนะนำ)

ข้อสังเกตุ
RHEL 6 แบบ Text mode นี้มันเลือก Package ในการติดตั้งยังไงหว่า หาไม่เจอ...


วันศุกร์ที่ 17 ธันวาคม พ.ศ. 2553

FreeBSD : Basic user management

ระบบที่ใช้ทดสอบ FreeBSD 8.1-RELEASE amd64

- การเพิ่มบัญชีผู้ใช้ด้วยคำสั่ง adduser

FreeBSD# adduser
Username: user1
Full name: User1 Fullname
Uid (Leave empty for default):
Login group [user1]:
Login group is user1. Invite user1 into other groups? []:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]:
Home directory [/home/user1]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password: (ขณะที่พิมพ์จะมองไม่เห็น)
Enter password again: (ขณะที่พิมพ์จะมองไม่เห็น)
Lock out the account after creation? [no]:
Username : user1
Password : *****
Full Name : User1 Fullname
Uid : 1002
Class :
Groups : user1
Home : /home/user1
Home Mode :
Shell : /bin/sh
Locked : no
OK? (yes/no): yes
adduser: INFO: Successfully added (user1) to the user database.
Add another user? (yes/no): no
Goodbye!

- เปลี่ยนรหัสผ่านของ user1

FreeBSD# passwd user1
Changing local password for user1
New Password: (ขณะที่พิมพ์จะมองไม่เห็น)
Retype New Password: (ขณะที่พิมพ์จะมองไม่เห็น)

- แสดงข้อมูลของ user1

FreeBSD# id user1
uid=1002(user1) gid=1002(user1) groups=1002(user1)

หรือ

FreeBSD# pw user show user1
user1:*:1002:1002::0:0:User1 Fullname:/home/user1:/bin/sh

- แก้ไขข้อมูล user1

FreeBSD# chpass user1
#Changing user information for user1.
Login: user1
Password: $1$oU.ybLTJ$V5GWxT1oXN/emCRnqgx.h0
Uid [#]: 1002
Gid [# or name]: 1002
Change [month day year]:
Expire [month day year]:
Class:
Home directory: /home/user1
Shell: /bin/sh
Full Name: User1 Fullname
Office Location:
Office Phone:
Home Phone:
Other information:

โดยจะอยู่ในรูปแบบของคำสั่ง vi


- ลบ user1 ออกจากระบบโดยคำสั่ง rmuser

FreeBSD# rmuser
Please enter one or more usernames: user1
Matching password entry:

user1:*:1002:1002::0:0:User1 Fullname:/home/user1:/bin/sh

Is this the entry you wish to remove? y
Remove user's home directory (/home/user1)? y
Removing user (user1): mailspool home passwd.

วันพฤหัสบดีที่ 16 ธันวาคม พ.ศ. 2553

Cisco, Security : banner exec และ banner motd

โจทย์ที่ต้องการ
ข้อความเตือนก่อนการ Login เข้าสู่ระบบ โดยต้องไม่บอกว่าเป็นระบบอะไร ทำอะไรอยู่ และข้อมูลอื่นๆ ที่อาจมีผลต่อความปลอดภัย

ข้อความแสดงรายละเอียดของระบบ หลังจากที่สามารถทำการ Login ได้แล้ว เช่น สถานที่ตั้งของระบบ หรือชื่อผู้ดูแลระบบ เป็นต้น

ระบบที่ใช้ทดสอบ Cisco 3660 on GNS3

ตัวอย่าง running-config

!
banner exec ^C


System Function : Core Router
System Location : Bangkok
System administrator : komkit.net

^C
banner motd ^C

!!!WARNING!!!
READ THIS BEFORE ATTEMPTING TO LOGON

This System is for the use of authorized users only. Individuals
using this computer without authority, or in excess of their authority,
are subject to having all of their activities on this system monitored
and recorded by system personnel. In the course of monitoring individuals
improperly using this system, or in the course of system maintenance,
the activities of authorized users may also be monitored. Anyone using
this system expressly consents to such monitoring and is advised that if
such monitoring reveals possible criminal activity, system personnel may
provide the evidence of such monitoring to law enforcement officials.

^C
!




ผลการทดสอบ

LocalRouter#telnet 10.0.0.1
Trying 10.0.0.1 ... Open


!!!WARNING!!!
READ THIS BEFORE ATTEMPTING TO LOGON

This System is for the use of authorized users only. Individuals
using this computer without authority, or in excess of their authority,
are subject to having all of their activities on this system monitored
and recorded by system personnel. In the course of monitoring individuals
improperly using this system, or in the course of system maintenance,
the activities of authorized users may also be monitored. Anyone using
this system expressly consents to such monitoring and is advised that if
such monitoring reveals possible criminal activity, system personnel may
provide the evidence of such monitoring to law enforcement officials.



User Access Verification

Username: komkit
Password:


System Function : Core Router
System Location : Bangkok
System administrator : komkit.net


RemoteRouter>

จากตัวอย่างจะเห็นว่า จะมีข้อความเตือนก่อนการ Login และเมื่อทำการ Login สำเร็จแล้วจึงจะเห็นข้อความอื่นๆ ที่ต้องการแสดงรายละเอียด ตามที่โจทย์ต้องการ

หมายเหตุ
หากทำการตั้งค่าของ banner motd ให้เป็นรายละเอียดของอุปกรณ์ อาจเป็นช่องทางให้ผู้บุกรุกรู้ถึงช่องทางในการบุกรุกระบบของเราได้ ดังนั้น banner motd จึงไม่ควรเป็นข้อความใดๆ ที่เป็นการเชื้อเชิญ หรือเปิดเผยข้อมูลของระบบ แต่ถ้าต้องการแสดงรายละเอียดของระบบก็ควรใส่ใน banner exec จะเหมาะสมกว่า

วันอังคารที่ 14 ธันวาคม พ.ศ. 2553

Linux : เปลี่ยนชื่อ Username และชื่อ Group

ในกรณีที่ต้องการเปลี่ยนชื่อ Login เช่น จากเดิมชื่อ user1 แต่ต้องการเปลี่ยนเป็น admin1 โดยที่ UID ยังคงเป็นหมายเลขเดิม สามารถทำได้ดังนี้

ระบบที่ใช้
OS : Ubuntu Linux 10.04.1 x64 LTS

ตรวจสอบ User เดิมด้วยคำสั่ง id
root@Linux:~# id user1
uid=1001(user1) gid=1001(user1) groups=1001(user1)


ทำการเปลี่ยนชื่อ user1 ไปเป็น admin1 ด้วยคำสั่ง usermod

root@Linux:~# usermod -l admin1 user1

ทำการตรวจสอบ User

root@Linux:~# id user1
id: user1: No such user

root@Linux:~# id admin1
uid=1001(admin1) gid=1001(user1) groups=1001(user1)

จากการตรวจสอบจะพบว่า Login ชื่อ User1 ไม่มีในระบบแล้ว ซึ่งได้เปลี่ยนเป็น admin1 แทน และยังคงใช้ uid และ Group เดิมอยู่

จากนั้นหากต้องการเปลี่ยนชื่อ Group ด้วย โดยจากเดิมชื่อ Group คือ user1 เปลียนไปเป็น admin1 แต่ยังต้องการคง Group ID ใว้เหมือนเดิม สามารถทำได้ดังนี้

root@Linux:/home# groupmod -n admin1 user1

ทำการตรวจสอบอีกครั้ง
root@Linux:/home# id admin1
uid=1001(admin1) gid=1001(admin1) groups=1001(admin1)

จะเห็นว่าทั้ง Username และ Groupname เปลี่ยนไปเป็น admin1 ตามที่ต้องการแล้ว และยังคง uid และ group id เดิมไว้


หมายเหตุ
ทั้งนี้การเปลี่ยนชื่อ Login และ Group จะไม่มีผลต่อ Configuration อื่นๆ ดังนั้นครตามไปเปลี่ยนให้เรียบร้อยด้วย เช่น Home Directory ก็ยังคงเป็น /home/user11 เหมือนเดิม

admin1:x:1001:1001:User1,,,:/home/user1:/bin/bash

ซึ่งอาจต้องทำการเปลี่ยนตาม เพื่อให้สะดวกในการใช้งาน ดังตัวอย่าง

root@Linux:~# mv /home/user1 /home/admin1

root@Linux:~# usermod -d /home/admin1 admin1

จาก 2 คำสั่งข้างต้นจะทำการเปลี่ยน Home Directory ไปเป็น /home/admin1 ตามต้องการ

admin1:x:1001:1001:User1,,,:/home/admin1:/bin/bash

วันจันทร์ที่ 13 ธันวาคม พ.ศ. 2553

Linux, Secure Shell : ระบุเวลาในการใช้งาน SSH

ในกรณีที่ต้องการระบุเวลาในการใช้งาน SSH เช่น ต้องการอนุญาตให้ user1 สามารถ Login ผ่าน SSH ได้เฉพาะวันที่จันทร์ - ศุกร์ เวลา 08.00 - 15.00 เท่านั้น ส่วนวันและเวลานอกนั้นไม่อนุญาตให้ Login ได้ เป็นต้น ซึ่งในกรณีนี้จะใช้ความสามารถของ PAM เข้ามาช่วย

ระบบที่ใช้ทดสอบ
OS : Ubuntu Linux 10.04.1 x64 LTS

โจทย์ที่ต้องการ
อนุญาตให้ user1 สามารถ login ผ่าน SSH ได้ตามเวลาที่กำหนด คือ วันจันทร์ - ศุกร์ เวลา 08.30 - 15.00 เท่านั้น

เริ่มด้วยแก้ไขไฟล์ /etc/pam.d/sshd โดยเพิ่ม

account required pam_time.so

จากนั้นแก้ไขไฟล์ /etc/security/time.conf โดยเพิ่ม

sshd;*;user1;MoTuWdThFr0830-1755

จากนั้นทำการ restart SSH

root@Linux:~# /etc/init.d/ssh restart

จากนั้นทำการทดสอบใช้งาน จะพบว่า user1 ไม่สามารถ login ได้ ส่วน user อื่นยังสามารถใช้งานได้ตามปกติ

ตัวอย่าง Log ที่เกิดขึ้นจากการ login ของ user1 นอกเวลาที่กำหนดไว้

Dec 13 18:06:34 Linux sshd[3471]: Failed password for user1 from 172.17.12.51 port 62763 ssh2

ข้อสังเกตุ
หาก user1 ได้ทำการ login ในเวลาที่กำหนด แต่ยังคง Session ไว้จนเกินเวลาที่กำหนด ระบบจะไม่ตัด Session นั้นทิ้ง