วันอังคารที่ 20 พฤศจิกายน พ.ศ. 2555

[Squid Proxy] : access_log with time acl.

[บทความกันลืม]

โจทย์จากน่วยงานแห่งหนึ่ง ต้องการายงานการใช้งาน Squid proxy (Top sites, Top users, Bandwidth used, etc.)ดังนี้
- รายงานแรก เป็นรายงานการใช้งาน Squid proxy ทั้งวัน (อันนี้ทำเป็นปกติอยู่แล้ว)
- รายงานที่สอง เป็นรายงานการใช้งาน Squid proxy เฉพาะในช่วงเวลาการทำงาน (8:30-11:59:59 น. และ 13:00-16:59:59 น.)

แนวคิด (ไม่รู้ว่าคิดดีรึยัง)
- แยก access_log ออกเป็น 2 ไฟล์ คือ access.log และ access_worktime.log ดังนี้

### แก้ไขไฟล์ squid.conf
## เพิ่ม time acl

acl  worktime_am  time  MTWHF  8:30-11:59:59
acl  worktime_pm  time  MTWHF  13:00-16:59:59 

## เขียน access_log ดังนี้

access_log  /squid/logs/access.log  squid
access_log  /squid/logs/access_worktime.log  squid  worktime_am
access_log  /squid/logs/access_worktime.log  squid  worktime_pm

## บันทึกไฟล์ แล้วทำการ reconfigure ด้วยคำสั่ง squid -k reconfigure

จากนั้นก็จะได้ Squid log มา 2 ไฟล์ไปทำรายงานด้วย Tools ที่เหมาะสมต่อไป



วันพุธที่ 22 สิงหาคม พ.ศ. 2555

[VMware] การตั้งค่า SNMP community string และการเปิดการทำงานของ SNMP บน VMware ESX ผ่าน CLI ของ VMware

[บทความกันลืม]

กำหนดให้
VMware ESX host =  vmware-host.domain.com
VMware ESX username = root
VMware ESX password = MyPassWord

SNMP community string =  SNMP-Community


ก่อนอื่นต้องไป download โปรแกรม VMware CLI มาติดตั้งก่อน 


การแก้ไข community string ให้ VMware ESX
C:\Program Files (x86)\VMware\VMware vSphere CLI\bin>vicfg-snmp.pl --server=vmware-host.domain.com --username=root --password=MyPassWord -c SNMP-Community
Changing community list to: SNMP-Community...
Complete.

การเปิดการทำงานของ SNMP บน VMware ESX
C:\Program Files (x86)\VMware\VMware vSphere CLI\bin>vicfg-snmp.pl --server=vmware-host.domain.com --username=root --password=MyPassWord --enable
Enabling agent...
Complete.

วันพุธที่ 8 กุมภาพันธ์ พ.ศ. 2555

Security : การส่ง Log ผ่าน E-Mail จากอุปกรณ์ Cisco ASA Firewall

[ บทความกันลืม ]

ในบทความนี้จะทำการส่ง E-Mail ไปยังผู้ดูแลระบบเมื่อ

- มีความพยายาม Login เข้าสู่ Firewall ทั้งที่สำเร็จ หรือไม่สำเร็จ
- มีการ Execute command เช่น config terminal

กำหนดให้
อุปกรณ์ทดสอบ : Cisco PIX-525
Software Version : 8.0(4)28

SMTP server = 10.10.10.25
SMTP server (สำรอง) = 10.10.20.25
E-Mail ผู้ดูแลระบบ = admin-firewall@komkit.net

! Configuration ของ Firewall มีดังนี้
!
smtp-server 10.10.10.25 10.10.20.25
!
logging enable
logging timestamp
!
logging device-id context-name
!
logging list Email_Alerts level alert class auth
logging list Email_Alerts level alert class config
logging list Email_Alerts level alert class session
!
logging list Email_Alerts message 109033
logging list Email_Alerts message 109034
logging list Email_Alerts message 315004
logging list Email_Alerts message 315011
logging list Email_Alerts message 605004
logging list Email_Alerts message 605005
logging list Email_Alerts message 710002
logging list Email_Alerts message 111004
logging list Email_Alerts message 113005
logging list Email_Alerts message 113012
logging list Email_Alerts message 113015
logging list Email_Alerts message 611101
logging list Email_Alerts message 611102
logging list Email_Alerts message 102001
logging list Email_Alerts message 199001
logging list Email_Alerts message 502103
logging list Email_Alerts message 613003
logging list Email_Alerts message 111008
!
!
logging from-address alert-firewall@komkit.net
logging recipient-address admin-firewall@komkit.net level information
logging mail Email_Alerts
!
end


โดย Log ที่ถูกส่งออกไปนั้น จะเป็นแบบ 1 log ต่อ 1 mail ดังนั้นควรที่จะ filter ว่าจะต้องการให้ Firewall ส่ง Log เฉพาะที่ต้องการก็เพียงพอ

ตัวอย่าง Log message ที่ได้รับมาใน Mail

<166>Feb 09 2012 13:44:44 single_vf : %PIX-6-605004: Login denied from 172.17.12.51/58897 to outside:172.17.12.5/ssh for user "hacker"

<165>Feb 09 2012 13:44:57 single_vf : %PIX-5-111008: User 'komkit' executed the 'enable' command.

<165>Feb 09 2012 13:58:35 single_vf : %PIX-5-111008: User 'enable_15' executed the 'configure terminal' command.

<165>Feb 09 2012 14:00:12 single_vf : %PIX-5-111008: User 'enable_15' executed the 'username admin2 password *' command.

<166>Feb 09 2012 13:10:36 single_vf : %PIX-6-315011: SSH session from 172.17.12.51 on interface outside for user "komkit" terminated normally

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

Network : เพิ่ม Perpersistent Static Route บน Windows

บนระบบ Windows ในบางกรณีที่ต้องมีหลาย Network interfaces หรือหลาย Gateway และต้องการเพิ่ม Static route เพื่อจัดการ Route ให้เป็นไปตามต้องการ สามารถทำได้ดังนี้

ระบบที่ทดสอบ Microsoft Windows 7 Professional
กำหนดให้ Destination route คือ 172.17.15.0/24
กำหนดให้ Gateway คือ 172.17.12.1

- เพิ่ม route ชั่วคราว โดย route นี้จะหายไปเมื่อระบบ reboot
C:\>route add 172.17.15.0 mask 255.255.255.0 172.17.12.1
OK!

- เพิ่ม Perpersistent Static Route โดย route นี้จะไม่หายไปเมื่อระบบ reboot
C:\>route add -p 172.17.15.0 mask 255.255.255.0 172.17.12.1
OK!

- ลบ route
C:\>route delete 172.17.15.0 mask 255.255.255.0 172.17.12.1
OK!

- ตรวจสอบ Routing table
C:\> route print

หรือ

C:\> netstat -rn


วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2554

SSH : การยกเลิกการตรวจสอบ DNS ของ Client IP

ในการใช้งาน SSH นั้น ปกติ เมื่อ Client ทำการ SSH เข้าไป SSH Server จะทำการตรวจสอบว่า Client IP นั้น ตรงกับชื่ออะไร โดยจะทำการตรวจสอบกับ DNS ซึ่งในบางครั้ง การตรวจสอบนั้นนานมาก จนกระทั่ง SSH Session Timeout ก็เคยเจอมาแล้ว ดังนั้น วันนี้มาปิดการทำงาน Function ที่ว่า ดีกว่า

- ทำการแก้ไขไฟล์ /etc/ssh/sshd_config (หรืออยู่ที่ path อื่นตามระบบนั้นๆนะครับ)
- แก้ไขแถวต่อไปนี้

เดิม
UseDNS yes

แก้เป็น
UseDNS no

บันทึกไฟล์ จากนั้นทำการ restart servive ของ SSH เป็นอันเสร็จพิธี


วันพฤหัสบดีที่ 14 กรกฎาคม พ.ศ. 2554

Network, Security : การสร้าง TACACS+ Server สำหรับใช้กับ Cisco AAA

บทความนี้เป็นการปูพื้นไว้ก่อนที่จะลืมวิธีทำ
ซึ่งบทความนี้จะว่าด้วยเรื่องการทำ Authentication อย่างเดียวก่อน ส่วน Authorization และ Accounting เอาไว้คราวหน้า

ระบบที่ใช้
Cisco Device: Cisco PIX-525
Software Version 8.0(4)28

TACACS+ Server
OS: FreeBSD 8.2 amd64
TACACS+ Server:
tac_plus4

ข้อกำหนด
- TACACS+ Server ที่ทดสอบ ติดตั้งหลัง Zone "Inside" ของ Firewall
- ให้ Inside Interface ของ Firewall = 172.17.12.5
- ให้ TACACS+ Server = 172.17.12.54

เริ่มต้นจาการติดตั้ง TACACS+ Server ดังนี้

Server# cd /usr/ports/net/tac_plus4
Server# make install
Server# rehash

Server# vi /etc/rc.conf

tac_plus_enable="YES"

จากนั้นทำการ Configure

อันดับแรกสร้าง password ที่เข้ารหัสแล้วก่อน เพื่อเอาไปใช้ใน Config โดยใช้คำสั่ง tac_pwd ดังตัวอย่าง

Server# tac_pwd
Password to be encrypted: nosecure
FWpfWvyThlezE

Server# tac_pwd
Password to be encrypted: 3Com
pKvE0HIV2X.z6

จากตัวอย่างจะได้ Password ที่ผ่านการเข้ารหัสแล้ว ซึ่งให้ทำการ Copy ส่วนนี้ไว้

จากนั้นทำการสร้าง Configuration file ดังตัวอย่าง

Server# vi /usr/local/etc/tac_plus.conf

key = "authen_by_komkit"

user = komkit {
login = des "FWpfWvyThlezE"
}

user = cisco {
login = des "pKvE0HIV2X.z6"
}

จากนั้นทำการ save file แล้วทำการ restart service

Server# /usr/local/etc/rc.d/tac_plus restart
Stopping tac_plus.
Starting tac_plus.

ตรวจสอบว่า Service ทำงานแล้ว

Server# netstat -anL
Proto Listen Local Address
tcp4 0/0/128 *.49


ต่อไปทำการเพิ่ม Configuration บน Cisco PIX-525

- กำหนดค่า parameter เบื้องต้นเกี่ยวกับ TACACS+ Server

aaa-server aaa-172.17.12.54 protocol tacacs+
aaa-server aaa-172.17.12.54 (inside) host 172.17.12.54
timeout 30
key authen_by_komkit


- นำค่าที่กำหนดไว้มาใช้งานกับ SSH

aaa authentication ssh console aaa-172.17.12.54

จากนั้นทดสอบการ remote ไปยัง Cisco Firewall โดยผ่าน SSH

login as: cisco
cisco@172.17.12.5's password: 3Com <--- ขณะที่พิมพ์จะมองไม่เห็น
Type help or '?' for a list of available commands.
pixfirewall>

หากมีการพยายามเข้าถึง แต่ไม่มี Username นั้นๆ หรือใส่ Password ผิด จะเกิด Log ที่ TACACS+ Server ดังนี้

Jul 14 19:53:19 Server tac_plus[1054]: login failure: root 172.17.12.5 (172.17.12.5) 5
Jul 14 19:53:26 Server tac_plus[1055]: login failure: cisco 172.17.12.5 (172.17.12.5) 6

หลังจากทดสอบว่าสามารถใช้งานได้แล้ว ก็ทำการ save config ของ Cisco Firewall ให้เรียบร้อย

คำสั่งอื่นๆ ที่น่าสนใจ

pixfirewall# show aaa-server aaa-172.17.12.54
Server Group: aaa-172.17.12.54
Server Protocol: tacacs+
Server Address: 172.17.12.54
Server port: 49
Server status: ACTIVE, Last transaction at 13:16:40 UTC Thu Jul 14 2011
Number of pending requests 0
Average round trip time 0ms
Number of authentication requests 8
Number of authorization requests 0
Number of accounting requests 0
Number of retransmissions 0
Number of accepts 4
Number of rejects 4
Number of challenges 1
Number of malformed responses 0
Number of bad authenticators 0
Number of timeouts 0
Number of unrecognized responses 0



วันจันทร์ที่ 20 มิถุนายน พ.ศ. 2554

Linux: ตรจสอบ CPU, RAM และ Hardware อื่นๆ บน Linux ด้วย dmidecode

จากที่เครื่องเขียนเรื่องการตรวจสอบ Serial No. ของเครื่องด้วยคำสั่ง dmidecode ไว้ที่ http://khamsawat.blogspot.com/2010/08/serial-number-service-tag-server.html
วันนี้ลองมาต่อว่า dmidecode ให้ข้อมูลอะไรเพิ่มเติมอีก

ระบบที่ใช้
Ubuntu 9.10

คำสั่งที่ใช้
Linux# dmidecode

ตัดออกมาเฉพาะ Output ที่สนใจ

- System Information
Manufacturer: Dell Computer Corporation
Product Name: PowerEdge 860
Serial Number: 2XXXXXS

- Processor Information
Socket Designation: PROC
Type: Central Processor
Family: Pentium D
Manufacturer: Intel
Version: Intel(R) Pentium(R) D CPU 3.00GHz
Voltage: 1.5 V
External Clock: 800 MHz
Max Speed: 3800 MHz
Current Speed: 3000 MHz
Status: Populated, Enabled
Upgrade: Socket LGA775
L1 Cache Handle: 0x0700
L2 Cache Handle: 0x0701
L3 Cache Handle: 0x0702
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Core Count: 2
Core Enabled: 2
Thread Count: 2
Characteristics:
64-bit capable

- Onboard devices
On Board Device 1 Information
Type: Video
Status: Enabled
Description: Embedded ATI ES1000 Video
On Board Device 2 Information
Type: Ethernet
Status: Enabled
Description: Broadcom 5721J Ethernet
On Board Device 3 Information
Type: Ethernet
Status: Enabled
Description: Broadcom 5721J Ethernet

- RAM type
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Single-bit ECC
Maximum Capacity: 8 GB
Error Information Handle: Not Provided
Number Of Devices: 4

Handle 0x1100, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: 72 bits
Data Width: 64 bits
Size: 1024 MB
Form Factor: DIMM
Set: 1
Locator: DIMM1_A
Bank Locator: Not Specified
Type: DDR2
Type Detail: Synchronous
Speed: 533 MHz (1.9 ns)
Manufacturer: 7F7F7F0B00000000
Serial Number: A7530E19
Asset Tag: 0D0702
Part Number: NT1GT72U8PA0BY-37B