Agenda ❖ DNS Concepts ❖ BIND Installation & Configuration (Labs) ❖ Domains Configuration (Labs) ❖
สำนักงานพัฒนารัฐบาลดิจิทัล · Master
เนื้อหา
หน้า 1
1
หน้า 2
Who am I ❖ ธงไชย จารุสุรเกษม ( เบิร์ด ) ❖ วิศวกรความมั่นคงปลอดภัยสารสนเทศ 2 ❖ Tongchai@ega.or.th ❖ 02 - 612 - 6000 Ext. 4307 2
หน้า 3
Agenda ❖ DNS Concepts ❖ BIND Installation & Configuration (Labs) ❖ Domains Configuration (Labs) ❖ Master(Primary) and Slave(Secondary) (Labs) ❖ DNS Attacks ❖ TSIG (Transaction Signature) (Labs) ❖ DNSSEC (Domain Name System Security Extensions) (Labs) 3
หน้า 4
DNS Concepts 4
หน้า 5
DNS Works ❖ DNS ย่อมาจาก Domain Name System หมายถึง ระบบจัดการ แปลง Name ไปเป็น IP A ddress โดยมีหลักการท างาน ดังนี้ 5
หน้า 6
DNS Types ❖ DNS แบ่งออกได้เป็น 2 ประเภท ได้แก่ ❖ Master Name Server(Primary) - เป็น ฐานข้อมูลหลักของโดเมน การเพิ่ม / แก้ไข / ลบ ข้อมูลท าที่ Master อย่าง เดียว ❖ Slave Name Server(Secondary) - จะ ท าหน้าที่ส าเนาข้อมูลมาจาก Master ตาม เวลาที่ก าหนดโดยอัตโนมัติ Name Server ข้างต้นยังสามารถแยกการท างานได้ 2 แบบ คือ ❖ Forward Lookup Zone – ท า หน้าที่ แปลง Domain Name หรือ Host Name ให้ เป็น IP Address ❖ Reverse Lookup Zone - ท า หน้าที่แปลงค่า IP Address ให้เป็น Host Name 6
หน้า 7
Name Space ❖ Name Space - บน Internet จะมีการควบคุมการตั้งชื่อต่างๆ และ IP Address ซึ่งจะต้องมีชื่อที่ไม่ซ้ ากัน แบ่งออกเป็น 2 แบบ คือ ❖ Flat Name Space - การตั้งชื่อ Name Space ไม่มีโครงสร้าง เช่น 123 . testx , asdf. 12 ❖ Hierarchical Name space - การตั้งชื่อ Name Space แบบมีโครงสร้างเป็นล าดับ ชั้น เช่น . th , . or.th , ega.or.th 7
หน้า 8
Domain Name Space ❖ Domain Name Space - มีโครงสร้างแบบล าดับชั้น เป็น Tree โดยมี Root อยู่ ด้าน บนสุด ❖ Label - ในแต่ละ node จะมี Label ก ากับอยู่ และ label ของ root จะเป็น n ull string หรือ ไม่มีชื่อ โดย node ลูกที่แตกออกมาจาก node แม่จะต้องมี label ไม่ซ้ ากับ node แม่ ❖ Domain Name – เป็นล าดับของ label โดยใช้จุด (.) เป็นตัวแยก domain name และจะอ่านจากข้างล่างขึ้นด้านบนไปยัง root 8
หน้า 9
Domain Name Space 9
หน้า 10
DNS Server and Zone ❖ DNS Server - เครื่อง คอมพิวเตอร์ หรือ โปรแกรมที่เก็บฐานข้อมูลเกี่ยวกับ Domain Name และ IP Address และ ให้บริการแปลง Domain Name ไปเป็น IP Address เมื่อ มีการร้องขอ เพื่อใช้อ้างอิงถึงที่อยู่ของเครื่องคอมพิวเตอร์ที่ มี IP Address ตรงกับ Domain ที่ร้ อง ขอ ❖ Zone - หรือ Domain คือ สิ่งเดียวกัน โดย DNS Server จะสร้างฐานข้อมูลที่เรียกว่า Z one file เพื่อเก็บข้อมูลของทุกๆ node ภายใต้ Domain นั้นๆ โดยที่ ❖ Primary Server - ท าหน้าที่เก็บ Zone file ปรับปรุง / แก้ไข / ดูแล Zone file นั้นๆ ❖ Secondary Server – ท าหน้าที่ถ่ายโอนข้อมูลเกี่ยวกับ Zone file มาจาก DNS Server อื่นๆ ( ได้ทั้ง Primary และ Secondary) ❖ Zone f ile คือ file ที่ใช้เก็บข้อมูลเกี่ยวกับ Domain โดยจะมี Resource Record เป็น ตัวบ่งบอกชนิดของ Record ที่บันทึกไว้ใน Zone file 10
หน้า 11
Resource Record ❖ A - Address record คือ record ที่ใช้ส าหรับ map Host name เป็น IP Address <host> IN A <IP - address> ❖ AAAA – Address record คือ record ที่ใช้ส าหรับ map Host name เป็น IP Address IPv 6 <host> IN AAAA <IP - address - IPv 6 > ❖ CNAME - Canonical name record คือ record ที่ใช้ map ไปอีกชื่อหนึ่ง <alias - name> IN CNAME <real - name> ❖ MX - Mail Exchange record คือ record ที่ใช้เกี่ยวกับระบบ email IN MX <preference - value> <email - server - name> 11
หน้า 12
Resource Record ❖ NS - Name Server record คือ record ที่แจ้ง name server ที่เป็น Authorize server ของ domain นั้นๆ IN NS < nameserver - name> ❖ PTR - Pointer record คือ record ที่ใช้ส าหรับ map IP Address ไปเป็น Host name <IP - address> IN PTR <host - name> 12
หน้า 13
Resource Record ❖ SOA - Start Of Authority resource record คือ record ที่เก็บ รายละเอียดว่า DNS Server ตัว ไหนท า หน้าที่ เป็น Primary server ของโดเมน นั้นรวมทั้ง กระบวนการเก็บความถี่ในการ update ข้อมูลของ Secondary server @ IN SOA <primary - name - server > < hostmaster - email> ( < serial - number> < time - to - refresh> < time - to - retry> < time - to - expire> < minimum - TTL> ) 13
หน้า 14
Forward Zone File (Example) $TTL 86400 @ IN SOA dns1.example.com. hostmaster.example.com . ( 2016081501 ; serial 21600 ; refresh after 6 hours 3600 ; retry after 1 hour 604800 ; expire after 1 week 86400 ; minimum TTL of 1 day ) IN NS dns1.example.com . IN NS dns2.example.com. IN MX 10 mail.example.com. IN MX 20 mail2.example.com . IN A 10.0.1.5 server1 IN A 10.0.1.5 server2 IN A 10.0.1.7 dns1 IN A 10.0.1.2 dns2 IN A 10.0.1.3 ftp IN CNAME server1 mail IN CNAME server1 mail2 IN CNAME server2 www IN CNAME server2 14
หน้า 15
Reverse Zone File (Example) $ TTL 86400 @ IN SOA dns 1 .example.com. hostmaster.example.com. ( 20 1 60815 01 ; serial 21600 ; refresh after 6 hours 3600 ; retry after 1 hour 604800 ; expire after 1 week 86400 ; minimum TTL of 1 day ) IN NS dns 1 .example.com. IN NS dns 2 .example.com. 20 IN PTR alice.example.com. 21 IN PTR betty.example.com. 22 IN PTR charlie.example.com. 23 IN PTR doug.example.com. 24 IN PTR ernest.example.com. 25 IN PTR fanny.example.com . 15
หน้า 16
BIND Installation & Configuration 16
หน้า 17
BIND Installation ❖ ติดตั้ง BIND [ root@master ~]# yum install bind bind - utils – y ❖ Config ให้ Service BIND run โดยอัตโนมัติ หากมีการ Restart Server [ root@master ~]# systemctl enable named Created symlink from / etc / systemd /system/multi - user.target.wants / named.service to / usr /lib/ systemd /system/ named.service . ❖ สั่งให้ Service BIND Start [ root@master ~]# systemctl start named ❖ ค าสั่งในการตรวจสอบว่า Service ท างานอยู่หรือไม่ [ root@master ~]# systemctl status named ● named.service - Berkeley Internet Name Domain (DNS) Loaded: loaded (/ usr /lib/ systemd /system/ named.service ; enabled ; vendor preset: disabled) Active: active (running) since Fri 2016 - 07 - 29 02 : 00 : 12 ICT; 3 s ago 17
หน้า 18
Iptables Configuration ❖ เพิ่ม Policy firewall ส าหรับ Service DNS [ root@master ~]# vi / etc / sysconfig / iptables # sample configuration for iptables service # you can edit this manually or use system - config - firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [ 0 : 0 ] :FORWARD ACCEPT [ 0 : 0 ] :OUTPUT ACCEPT [ 0 : 0 ] - A INPUT - m state -- state RELATED,ESTABLISHED - j ACCEPT - A INPUT - p icmp - j ACCEPT - A INPUT - i lo - j ACCEPT - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 22 - j ACCEPT - A INPUT - p tcp - m state -- state NEW - m tcp -- dport 53 - j ACCEPT - A INPUT - p udp - m state -- state NEW - m udp -- dport 53 - j ACCEPT - A INPUT - j REJECT -- reject - with icmp - host - prohibited - A FORWARD - j REJECT -- reject - with icmp - host - prohibited COMMIT 18
หน้า 19
BIND Configuration ❖ Config DNS Server ให้สามารถใช้งานได้จากเครื่อง Client [ root@master ~]# vi / etc / named.conf options { listen - on port 53 { any ; }; listen - on - v 6 port 53 { :: 1 ; }; directory "/ var /named"; dump - file "/ var /named/data/ cache_dump.db "; statistics - file "/ var /named/data/named_stats.txt"; memstatistics - file "/ var /named/data/named_mem_stats.txt"; allow - query { any ; }; ...... }; 19
หน้า 20
Domains Configuration 20
หน้า 21
Domain Configuration ❖ Config ค่า Domain [ root@master ~]# vi / etc / named.conf ..... zone " labs.test " IN { type master; file " labs.test.db "; allow - update { none; }; }; zone “ 125 . 168 . 192 .in - addr.arpa " IN { type master; file " 125 . 168 . 192 .in - addr.arpa.db "; allow - update { none; }; }; 21
หน้า 22
Forward Zone File (Create) ❖ สร้าง Forward Zone file ใหม่โดยสร้างไว้ที่ folder / var /named/ [ root@master ~]# vi / var /named/ labs.test.db $TTL 86400 @ IN SOA ns.labs.test . root.labs.test . ( 2016081501 ; serial 21600 ; refresh after 6 hours 3600 ; retry after 1 hour 604800 ; expire after 1 week 86400 ) ; minimum TTL of 1 day IN NS ns.labs.test . IN MX 10 mail.labs.test . IN MX 20 mail 2 .labs.test. IN A 192 . 168 . 125 . 134 server 1 IN A 192 . 168 . 125 . 10 server 2 IN A 192 . 168 . 125 . 20 ns IN A 192 . 168 . 125 . 134 ftp IN CNAME server 1 mail IN CNAME server 1 mail 2 IN CNAME server 2 www IN CNAME server 2 22
หน้า 23
Reverse Zone File (Create) ❖ สร้าง Reverse Zone file ใหม่โดยสร้างไว้ที่ folder / var /named/ [ root@master ~]# vi / var /named/ 125 . 168 . 192 .in - addr.arpa.db $TTL 86400 @ IN SOA ns.labs.test . root.labs.test . ( 2016081501 ; serial 21600 ; refresh after 6 hours 3600 ; retry after 1 hour 604800 ; expire after 1 week 86400 ) ; minimum TTL of 1 day IN NS ns.labs.test . 10 IN PTR server 1 .labs.test. 20 IN PTR server 2 .labs.test. 23
หน้า 24
Master(Primary) & Slave(Secondary) 24
หน้า 25
Master Server Configuration ❖ Config เพิ่มเติมในส่วนของ Zone ที่อนุญาตให้สามารถ transfer zone file ไปยัง Slave ได้ ( Config ที่ Master Server) [ root@master ~]# vi / etc/ named.conf ..... zone " labs.test " IN { type master; file " labs.test.db "; allow - update { none; }; allow - transfer { 192 . 168 . 125 . 135 ; }; }; ..... 25
หน้า 26
Slave Server Configuration ❖ Config ให้ Slave transfer zone จาก Master ( Config ที่ Slave Server) [ root@slave ~]# vi / ect / named.conf zone " labs.test " IN { type slave; masters { 192 . 168 . 125 . 134 ; }; file “/ var /named/slaves/ labs.test.db "; allow - update { none; }; }; 26
หน้า 27
DNS Attacks 27
หน้า 28
Malicious Local DNS ❖ Malicious Local DNS คือ การโจมตีโดยที่ Attacker สามารถเข้ามาควบคุม Local DNS ได้ 28
หน้า 29
DNS Cache Poisoning ❖ DNS Cache Poisoning คือ การโจมตีโดยการส่ง update cache ที่ไม่ถูกต้องลง ไปที่ Local DNS 29
หน้า 30
DNS Spoofing ❖ DNS Spoofing คือ การที่ Attacker หลอกส่งข้อมูลที่ไม่ถูกต้องให้กับ User ก่อนที่ DNS Server จะตอบกลับ 30
หน้า 31
TSIG (Transaction Signature) 31
หน้า 32
TSIG (Transaction Signature) ❖ Config TSIG เริ่มต้นจากการสร้าง Key โดยใช้ค าสั่ง [ root@master ~]# dnssec - keygen - a HMAC - MD 5 - b 128 - n HOST master.local หมายเหตุ HMAC - MD 5 คือ algorithm ในการสร้าง key 128 คือจ านวน bit ที่ใช้ master.local ชื่อของ key ที่จะสร้าง สามารถเปลี่ยนแปลงได้ เมื่อสร้างเสร็จแล้วจะได้ไฟล์ออกมา 2 ไฟล์ดังนี้ - Kmaster.local .+ 157 + 09515 .key - Kmaster.local.+ 157 + 09515 .private 32
หน้า 33
TSIG (Transaction Signature) ❖ ให้ Copy ค่า Key ออกมาจากไฟล์ [ root@master ~]# cat Kmaster.local.+ 157 + 09515 .private Private - key - format: v 1 . 3 Algorithm: 157 (HMAC_MD 5 ) Key: 2 TcRvcR 1 rggkH 5 W 3 aGGf 4 g== Bits: AAA= Created: 20160808035403 Publish: 20160808035403 Activate: 20160808035403 33
หน้า 34
TSIG (Transaction Signature) ❖ Config ค่าเพิ่มเติมที่ named.conf [ root@master ~]# vi / etc / named.conf optyions { ..... }; ..... key tsig.key { algorithm hmac - md 5 ; secret “ 2 TcRvcR 1 rggkH 5 W 3 aGGf 4 g ==” ; }; server 192 . 168 . 125 . 135 { keys { tsig.key ; }; }; ... .. หมายเหตุ ค่า server 192 . 168 . 125 . 135 คือ IP Address ของ Slave Server 34
หน้า 35
TSIG (Transaction Signature) ❖ Config ค่าเพิ่มเติมที่ named.conf ( ต่อ ) .... . zone " labs.test " IN { type master; file " labs.test.db "; allow - update { none; }; //allow - transfer { 192 . 168 . 125 . 135 ; }; allow - transfer { key tsig.key ; }; }; 35
หน้า 36
TSIG (Transaction Signature) ❖ Config ค่าเพิ่มเติมที่ named.conf (Slave Server) [ root@master ~]# vi / etc / named.conf options { ..... }; ..... key tsig.key { algorithm hmac - md 5 ; secret “ 2 TcRvcR 1 rggkH 5 W 3 aGGf 4 g==” ; }; server 192 . 168 . 125 . 134 { keys { tsig.key ; }; }; หมายเหตุ ค่า server 192 . 168 . 125 . 134 คือ IP Address ของ Master Server 36
หน้า 37
DNS SEC (Domain Name System Security Extensions) 37
หน้า 38
DNSSEC ❖ Config Enable ฟังก์ชั่น DNSSEC [ root@master ~]#vi / etc / named.conf options { ..... recursion yes; dnssec - enable yes; dnssec - validation yes ; dnssec - lookaside auto; ..... }; 38
หน้า 39
DNSSEC ❖ สร้าง Zone Signing Key(ZSK) และ Key Signing Key(KSK) ส าหรับ Signed Zone [ root@master ~]# cd / var /named/ [ root@master named]# dnssec - keygen - a rsasha 1 - b 1024 - n zone labs.test [ root@master named]# dnssec - keygen - a rsasha 1 - b 2048 - f KSK - n zone labs.test จะ ได้ไฟล์ออกมา 4 ไฟล์ ดังนี้ ZSK - Klabs.test .+ 005 + 22665 .key - Klabs.test .+ 005 + 22665 .private KSK - Klabs.test .+ 005 + 28729 .key - Klabs.test.+ 005 + 28729 .private 39
หน้า 40
DNSSEC ❖ Config Zone file ที่เราต้องการจ ะ ท า DNSSEC [ root@master ~]# vi / var /named/ labs.test.db $TTL 86400 $INCLUDE / var /named/Klabs.test .+ 005 + 22665 .key ; ZSK $INCLUDE / var /named/Klabs.test .+ 005 + 28729 .key ; KSK @ IN SOA ns.labs.test . root.labs.test . ( ..... ❖ Signing Zone File [ root@master named]# dnssec - signzone - o labs.test - t - k Klabs.test .+ 005 + 28729 Klabs.test .+ 005 + 22665 40
หน้า 41
DNSSEC ❖ ผลจากการ Signing Zone f ile Verifying the zone using the following algorithms: RSASHA 1 . Zone fully signed: Algorithm: RSASHA 1 : KSKs : 1 active, 0 stand - by, 0 revoked ZSKs : 1 active, 0 stand - by, 0 revoked labs.test.db.signed Signatures generated: 21 Signatures retained: 0 Signatures dropped: 0 Signatures successfully verified: 0 Signatures unsuccessfully verified: 0 Signing time in seconds: 0 . 007 Signatures per second: 2636 . 203 Runtime in seconds: 0 . 019 41
หน้า 42
DNSSEC ❖ Config ให้ใช้งาน Zone f ile ที่ถูก Signed แล้ว zone " labs.test " IN { type master; //file " labs.test.db "; file " labs.test.db.signed "; allow - update { none; }; //allow - transfer { 192 . 168 . 125 . 135 ; }; allow - transfer { key tsig.key ; }; }; 42
หน้า 43
DNSSEC ❖ Config ให้ Slave Server ให้ Transfer Zone เป็น . signed (Optional) zone " labs.test " IN { type slave; masters { 192 . 168 . 125 . 134 ; }; //file "/ var /named/slaves/ labs.test.db "; file "/ var /named/slaves/ labs.test.db.signed "; allow - update { none; }; }; 43
หน้า 44
DNSSEC ❖ ค่า DS ที่จะน าไปติดตั้งบน Registra [ root@master named]# cat dsset - labs.test . labs.test. IN DS 9826 5 1 D 8 E 1 A 4 DB 01 C 7 CD 35 E 410 E 1 A 9 E 2010 E 065 F 1 DBCE 2 labs.test. IN DS 9826 5 2 807 E 3 B 07 BEFC 441 EF 387520 E 8 F 96 BB 6 AF 2 F 2 A 382 F 9 D 68 BBE 891 C 385 F 502 E 0 E 6 D 44
หน้า 45
45
ข้อความถอดจากไฟล์ต้นฉบับโดยอัตโนมัติ อาจมีข้อผิดพลาด โปรดยึดต้นฉบับของหน่วยงาน