information gathering system for penetration testing ระบบเก็บ... · ii project...

72
ระบบเก็บรวบรวมข้อมูลเครื ่องเป าหมายเพื ่อสร้างความปลอดภัยของระบบ Information Gathering System for Penetration Testing ภัทร บรมธนรัตน์ สารนิพนธ์ฉบับนี ้เป็นส่วนหนึ ่งของการศึกษา ตามหลักสูตรวิทยาศาสตรมหาบัณฑิต สาขาวิชาความมั่นคงทางระบบสารสนเทศ คณะวิทยาการและเทคโนโลยีสารสนเทศ มหาวิทยาลัยเทคโนโลยีมหานคร ปีการศึกษา 2556

Upload: others

Post on 08-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

ระบบเกบรวบรวมขอมลเครองเปาหมายเพอสรางความปลอดภยของระบบ Information Gathering System for Penetration Testing

ภทร บรมธนรตน

สารนพนธฉบบนเปนสวนหนงของการศกษา ตามหลกสตรวทยาศาสตรมหาบณฑต สาขาวชาความมนคงทางระบบสารสนเทศ

คณะวทยาการและเทคโนโลยสารสนเทศ มหาวทยาลยเทคโนโลยมหานคร

ปการศกษา 2556

Page 2: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

I

หวขอ ระบบเกบรวบรวมขอมลเครองเปาหมายเพอปองกนความปลอดภย ของระบบ ชอนกศกษา นายภทร บรมธนรตน รหสนกศกษา 5517810013 หลกสตร วทยาศาสตรมหาบณฑต สาขาความมนคงทางระบบสารสนเทศ ปการศกษา 2556 อาจารยทปรกษา ผศ.ดร.ศภกร กงพศดาร

บทคดยอ

วตถประสงคของการศกษาคนควาอสระนเกยวกบระบบเกบรวบรวมขอมลของเวบไซต

ของเครองเปาหมายไดพฒนาขนเพอเปนเครองมอชวยในการคนหาและเกบรวบรวมขอมลตางๆ

เกยวกบเวบไซตโดยสามารถเรยกใชหลายเครองมอใหสามารถท าไดในเครองมอเดยวและชวย

ใหสะดวกสบายในการเกบรวบรวมขอมลตางๆเกยวกบเวบไซต หากผดแลเวบไซตขาดองค

ความรและความตระหนกจากภยคกคามทเกดขนในดานการรกษาความมนคงปลอดภยของ

เวบไซตกจะท าใหเกดความเสยหายและสงผลกระทบตอเวบไซตอยางมาก ดงนน โครงงานน

เปนสวนหนงของการทดสอบความมนคงปลอดภยของเวบไซตโดยทมงเนนไปทการเกบ

รวบรวมขอมลทเกยวของกบเวบไซตเปาหมายเพอน าไปหาชองโหวทสามารถเขาถงระบบเพอ

ลดความเสยงตอความเสยหายเวบไซตได

ผลทไดรบจากการด าเนนงานคอ ผใชสามารถใชในการคนหาและเกบรวบขอมล

เกยวกบเวบไซตเพอท าการตรวจสอบชองโหวและรายงานผลชองโหวของเวบไซต

Page 3: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

II

Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat Student ID 5517810013 Degree Master of science in Information System Security Year 2556 Project Advisor Asst.Prof.Dr. Supakorn Kungpisdan

ABSTRACT

The purpose of this independent study is to develop a system that assists in searching and gathering information of target systems. The proposed system integrates several functions necessary for gathering information about a target. If web administrators have no knowledge and awareness about security threats, it would be extremely dangerous and impacts may severely incur to the system. Therefore, this independent study focuses on analyzing information from the website in order to find possible vulnerabilities and actions can be taken to reduce risk to websites. According to the results of given from this project, the users can use the proposed system to search and gather website information to inspect and report the website vulnerabilities.

Page 4: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

III

กตตกรรมประกาศ

สารนพนธนไดพฒนาจนส าเรจดวยด เพราะความกรณา และก าลงใจจากหลายคน ขาพเจาขอขอบพระคณมา ณ ทน

ขอขอบพระคณ ผศ.ดร.ศภกร กงพศดาร อาจารยทปรกษาและอาจารยพงษสรย ลมมณวจตร ทกรณาเสยสละเวลาใหค าแนะน าและคอยตรวจสอบโครงงานอยสม าเสมอ และยงคอยหาตวอยางทด ๆ มาใหอกมากมาย

ขอขอบพระคณอาจารยทกๆ ทานทชวยประสทธประสาทวชาแกขาพเจาตงแตขาพเจาเขามาศกษาในทแหงน ขอบคณก าลงใจจากอาจารยทกทานทท าใหขาพเจาพฒนาโครงงานนใหส าเรจไปไดดวยด

ขอขอบพระคณพๆ เพอนๆ และทกคนทชวยแนะน าเมอมปญหาและเปนก าลงใจในยามทเราทอ

ภทร บรมธนรตน

9 มนาคม 2557

Page 5: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

IV

สารบญ หนา บทคดยอภาษาไทย………………………………………………………………………………... I บทคดยอภาษาองกฤษ………………………………………………………………………….… II กตตกรรมประกาศ……………………………………………………………………………..… III สารบญ………………………………………………………………………………………..….. IV สารบญรป……………………………………………………………………………………….. VII สารบญตาราง………………………………………………………………………................. VIII บทท 1 บทน า..................................................................................................................... 1

1.1 กลาวน า............................................................................................................. 1 1.2 ปญหาและแรงจงใจ............................................................................................ 1 1.3 แนวทางแกปญหา.............................................................................................. 1 1.4 วตถประสงคของโครงงาน.................................................................................. 2 1.5 ประโยชนคาดวาจะไดรบ................................................................................... 2 1.6 ขอบเขตของโครงงาน......................................................................................... 2 1.7 แผนงานเวลาของโครงงาน.................................................................................. 3

บทท 2 ทฤษฎทเกยวของ..................................................................................................... 5 2.1 กลาวน า............................................................................................................ 5 2.2 Security assessment....................................................................................... 5

2.2.1 Security Audit................................................................................... 5 2.2.2 Vulnerability Assessment.................................................................. 5 2.2.3 Penetration Testing........................................................................... 5

2.3 ขนตอนการทดสอบเวบแอพพลเคชน................................................................. 7 2.4 ขนตอนการเกบรวบรวมขอมลเกยวกบเวบไซต................................................... 8 2.5 ขนตอนการทดสอบของการใหบรการเวบไซต................................................... 10 2.6 Footprinting…………………………................................................................ 11

2.6.1 Open source or Passive Information Gathering............................ 11 2.6.2 Active information Gathering.......................................................... 11 2.6.3 Anonymous Footprinting................................................................ 11 2.6.4 Pseudonymous Footprinting........................................................... 11 2.6.5 Organizational or Private Footprinting............................................ 11 2.6.6 Internet Footprinting........................................................................ 11

Page 6: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

V

สารบญ (ตอ) หนา

2.7 Footprinting Methodology.............................................................................. 12 2.7.1 Internet Footprinting....................................................................... 12 2.7.2 Whois Footprinting.......................................................................... 12 2.7.3 DNS Footprinting............................................................................ 12 2.7.4 Network Footprinting...................................................................... 12 2.7.5 OS Footprinting.............................................................................. 12 2.7.6 Website Footprinting....................................................................... 12

2.8 ขอมลทไดจาก Website Footprinting............................................................... 13 2.8.1 ไอพแอดเดรส................................................................................... 13 2.8.2 ระบบปฏบตการ............................................................................... 13 2.8.3 พอรท............................................................................................... 13 2.8.4 เวอรช น............................................................................................ 13 2.8.5 ชอเซรฟเวอร.................................................................................... 13 2.8.6 ชอผลตภณฑ.................................................................................... 13

2.9 Nmap.............................................................................................................. 13 2.10 Penetration Testing Framework………....................................................... 13

2.10.1 Metasploit..................................................................................... 13 2.10.2 Open Source Security Testing Methodology Manual.................. 14 2.10.3 Open web application security project......................................... 14

2.10.3.1 ความเสยงดานการรกษาความปลอดภย Application....... 14 2.10.3.2 10 อนดบความเสยงดานเวบแอพพลเคชน 2013............. 14

2.10.4 Web Application Security Consortium......................................... 16 2.11 Whois........................................................................................................... 16

บทท 3 การออกระบบ........................................................................................................ 17 3.1 โครงสรางระบบการท างาน............................................................................... 17 3.2 หลกการท างานของระบบเกบรวบรวมขอมล..................................................... 18 3.3 ข นตอนการท างานของระบบเกบรวบรวมขอมล................................................ 19 3.4 แผนผงการท างานไฟล..................................................................................... 20 3.5 ตารางฐานขอมล.............................................................................................. 21

บทท 4 ผลการทดลอง........................................................................................................ 26 4.1 กลาวน า.......................................................................................................... 26

Page 7: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

VI

สารบญ (ตอ) หนา

4.2 การท างานระบบเกบรวบรวมขอมล.................................................................. 26 4.2.1 การท างานการสแกนเวบไซตของเครองเปาหมาย............................. 26

4.3 ชดค าสงทใชเรยกโปรแกรม nmap................................................................... 27 4.4 ชดค าสงทใชเรยกโปรแกรม whois................................................................... 28

บทท 5 สรปผลการด าเนนงาน............................................................................................ 29 5.1 กลาวน า.......................................................................................................... 29 5.2 สรปผลการด าเนนการ..................................................................................... 29 5.3 ปญหาและอปสรรค......................................................................................... 29 5.4 แนวทางการพฒนาตอ..................................................................................... 29

เอกสารอางอง.................................................................................................................... 30 ภาคผนวก.......................................................................................................................... 31

ภาคผนวก ก Source code หนา domainname3.php............................................. 32 ภาคผนวก ข Source code หนา getdomainname3.php........................................ 34 ภาคผนวก ค Source code หนา newhistory.php.................................................. 53 ภาคผนวก ง Source code หนา connectdbnmap.php........................................... 60 ภาคผนวก จ Source code หนา connectdbwhois.php.......................................... 62

Page 8: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

VII

สารบญรป หนา

รปท 2.1 ข นตอนการท า penetration ................................................................................ 6 รปท 2.2 ข นตอนการทดสอบเวบแอพพลเคชน................................................................... 7 รปท 2.3 ข นตอนการเกบรวบรวมขอมลเกยวกบเวบไซต.................................................... 8 รปท 2.4 ข นตอนการทดสอบการใหบรการเวบไซต........................................................... 10 รปท 3.1 Network diagram ............................................................................................ 17 รปท 3.2 โครงสรางของระบบเกบรวบรวมขอมลเครองเปาหมาย....................................... 18 รปท 3.3 ข นตอนการท างานระบบเกบรวบรวมขอมล........................................................ 19 รปท 3.4 แผนผงการท างานไฟล...................................................................................... 20 รปท 4.1 หนาจอการสแกนเวบไซตของเครองเปาหมาย.................................................... 26 รปท 4.2 การแสดงผลขอมลจากการสแกนเวบไซตเครองเปาหมาย................................... 27 รปท 4.3 หนาจอการดขอมลยอนหลง..............…….......................................................... 27 รปท 4.4 การแสดงผลจากการดขอมลยอนหลง...……....................................................... 28

Page 9: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

VIII

สารบญตาราง หนา ตารางท 1.1 แผนงานเวลาของโครงงาน.............................................................................. 3 ตารางท 3.1 ตาราง nmap_info ของฐานขอมล Nmap...................................................... 21 ตารางท 3.2 ตาราง domain_info ของฐานขอมล Whois .................................................. 22 ตารางท 3.3 ตาราง Registrar ของฐานขอมล Whois ....................................................... 23 ตารางท 3.4 ตาราง Registrant ของฐานขอมล whois ....................................................... 24

Page 10: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

บทท 1 บทน า

1.1 กลาวน า ในปจจบนเวบไซตถกน ามาใชเพอคนหาขอมลองคความรและท ากจกรรมตางๆ เชน การดาวนโหลด (download) ขอมลและซอฟตแวรเพอประโยชนในการท างานและการคนหาองคความร ในขณะทมผใชงานเวบไซตเปนจ านวนมากเพอชวยอ านวยความสะดวกสบายโดยทไมตองเขาหองสมด ในทางตรงกนขามมภยคกคามทเกดขนกบเวบไซตเปนจ านวนมากเชนกน จงจ าเปนอยางยงทเวบไซตถกตดตงระบบรกษาความมนคงปลอดภยทด

ปญหาคอ ผดแลเวบไซตสวนใหญไมไดใหความส าคญและปองกนเรองความปลอดภยเกยวกบเวบไซต ผดแลเวบไซตขาดองคความร และความตระหนกจากภยคกคามทเกดขนในดานการรกษาความมนคงปลอดภยของเวบไซต ดงนนเวบไซตจงถกโจมต หรอ ถกบกรกไดงาย ซงสงผลกระทบและความสญเสยตอเวบไซตเปนอยางมาก

ดงนนโครงงานนถกจดท าขนเพอไดเนนการรกษาความมนคงปลอดภยของเวบไซต โดยใชกระบวนการทดลองเกบขอมลเวบไซตเพอหาชองโหวทสามารถเขาถงระบบเพอลดความเสยงตอการเสยหายตอเวบไซต

1.2 ปญหาและแรงจงใจ

ปจจบนมเครองมอทใชในการคนหาและเกบขอมลเกยวกบเวบไซตเปนจ านวนมากแตวายงยากในการใชงาน ดงนนโครงงานถกจดท าขนมาเพอสรางเครองมอทสามารถคนหาและเกบรวบรวมขอมลเกยวกบเวบไซตจ านวนมากภายในเครองมอเดยวเพอใหมความสะดวกสบายตอการใชงาน

1.3 แนวทางการแกปญหา

โครงงานถกจดท าขนมาเพอสรางเครองมอทสามารถคนหาและเกบรวบรวมขอมลเกยวกบเวบไซตจ านวนมากภายในเครองมอเดยวเพอใหมความสะดวกสบายตอการใชงาน ยกตวอยาง การสแกนตรวจสอบเครองเปาหมายเพอทจะหาวาขอมลเกยวกบเวบไซตนน เชน ตรวจสอบวาเปดพอรตใดไวบาง หรอ ตรวจสอบวาใชระบบปฏบตการแบบใด หรอ ตรวจสอบวาใชเซรฟเวอรชนดใด เพอหาชองโหวทสามารถเขาถงระบบและรายงานงานผลชองโหวเพอใหผใชทราบมชองโหวใดบางเพอลดความเสยงตอการเสยหายตอเวบไซต

Page 11: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

2

1.4 วตถประสงคของโครงงาน 1.4.1 โครงงานนถกจดท าขนเพอสรางเครองมอทชวยในการคนหาและเกบรวบรวม

ขอมลตาง ๆเกยวกบเวบไซตใหสามารถท าไดภายในเครองมอเดยวและชวยใหสะดวกสบายในการคนหาและเกบขอมลเกยวกบเวบไซต

1.4.2 เพอท าการตรวจสอบหาชองโหวและหารายงานผลชองโหวเพอผใชทราบมชองโหวใดบางและลดความเสยงตอการเสยหายตอเวบไซต

1.5 ประโยชนคาดวาจะไดรบ

1.5.1 ผใชสามารถใชเครองมอเพอใชในการคนหาและเกบรวบขอมลเกยวกบเวบไซตเพอท าการตรวจสอบชองโหวและรายงานผลชองโหวของเวบไซต

1.5.2 ผใชไดองคความรเกยวกบดานความมนคงปลอดภยของเวบไซตเพมมากขน

1.6 ขอบเขตโครงงานโครงงาน 1.6.1 สามารถศกษาการคนหาและเกบรวบรวมขอมลตางๆ ทเกยวของกบความ

มนคงปลอดภยของตวเวบเซรฟเวอร (Web Server) ของเครองเปาหมาย 1.6.2 สามารถศกษาและทดลองใชเครองมอทชวยในการคนหาและการเกบรวบรวม

ขอมลตางๆเกยวกบความมนคงปลอดภยของตวเวบเซรฟเวอรของเครองเปาหมาย 1.6.3 สามารถออกแบบโครงสรางระบบเกบรวบรวมขอมลเวบเซรฟเวอรของเครอง

เปาหมายเพอสรางความมนคงปลอดภยของระบบ 1.6.4 สามารถสรางระบบเกบรวบรวมขอมลเวบเซรฟเวอรของเครองเปาหมายเพอ

สรางความมนคงปลอดภยใหระบบ 1.6.5 ทดสอบระบบเกบรวบรวมขอมลเวบเซรฟเวอรของเครองเปาหมาย 1.6.6 สามารถสรปรายงานผลจาการเกบรวบขอมลเวบเซรฟเวอรของเครองเปาหมาย

เพอทจะลดความเสยงตอการเสยหายของเวบเซรฟเวอรของเครองเปาหมาย

Page 12: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

3

1.7 แผนงานเวลาของโครงงาน

ตารางท 1.1 แผนงานเวลาของโครงงาน

กจกรรม

ระยะเวลาตงแตเดอน เม.ษ. 2556-ก.พ.2557

เม.ย.-ม.ย.

ก.ค. ส.ค. ก.ย. ต.ค.

พ.ย. ธ.ค.

ม.ค.

ก.พ.

1.สามารถศกษาการคนหาและเกบรวบรวมขอมลตางๆทเกยวของกบความมนคงปลอดภยของตวเวบเซรฟเวอรเครองเปาหมาย

2.สามารถศกษาและทดลองใชเครองมอทชวยในการคนหาและเกบรวบรวมขอมลตางๆทเกยวกบความมนคงปลอดภยเวบเซรฟเวอรเครองเปาหมาย

3.สามารถออกแบบโครงสรางระบบเกบรวบรวมขอมลเวบเซรฟเวอรของเครองเปาหมายเพอสรางความมนคงปลอดภยของระบบ

4.สามารถสรางระบบเกบรวบรวมเวบเซรฟเวอรเครองเปาหมายเพอสรางความมนคงปลอดภยใหระบบ

Page 13: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

4

ตารางท 1.1 แผนงานเวลาของโครงงาน (ตอ)

กจกรรม

ระยะเวลาตงแตเดอน เม.ษ. 2556-ก.พ.2557

เม.ย.-ม.ย.

ก.ค. ส.ค. ก.ย. ต.ค.

พ.ย. ธ.ค.

ม.ค.

ก.พ.

5.ทดสอบระบบเกบรวบรวมขอมลเวบเซรฟเวอรเครองเปาหมาย

6.สามารถสรปรายงานผลจากการเกบรวบรวมขอมลเวบเซรฟเวอรของเครองเปาหมาย

Page 14: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

บทท 2 ทฤษฏทเกยวของ

2.1 กลาวน า

การทจะบงบอกขอมลเกยวเวบไซตมความปลอดภยนน เราตองน ามาวเคราะหมาจากพนฐาน 3 ดาน CIA [1] คอ

1.การรกษาความลบ (Confidentiality) ขอมลเปนความลบตองไมเปดเผยกบคนทไมมสทธ

2.ความถกตองแทจรง (Integrity) เพอใหแนใจวาขอมลถกตองแทจรง ตองมการตรวจสอบขอมลมการแกไขหรอไม ถาไมถกแกไขแสดงวาขอมลถกตองแทจรง

3.ความสามารถพรอมใชงาน (Availability) คนทมสทธตองการใชระบบ ระบบตองมสามารถพรอมใชงานอยเสมอ 2.2 Security Assessments

Security assessments [6] คอ การประเมนความปลอดภยของระบบ แบงออกเปน 3 ชนด

2.2.1 Security Audit การตรวจสอบความมนคงปลอดภยของระบบ 2.2.2 Vulnerability assessment การวเคราะหหาชองโหวของระบบ

การวเคราะหหาชองโหวของระบบ แบงออกเปน 4 ชนด 1. Network scanning คอ การวเคราะหชองโหวโดยการสแกนในเครอขาย

ระบบเพอหาจดออนของระบบ 2. Scanning Tools คอ การวเคราะหชองโหวโดยการใชเครองมอสแกน 3. Security Mistakes คอ การความวเคราะหชองโหวจากขอผดพลาด ของ

configuration 4. Test System/Network คอ การวเคราะหชองโหวจากการทดสอบระบบและ

เครอขาย 2.2.3 Penetration testing คอ การทดสอบการเจาะระบบโดยการหาชองโหวของระบบ

เพอใหไดขอมลของระบบ สามารถแบงออกเปน 5 ขนตอน ดงรปท 2.1

Page 15: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

6

Reconnaissance

Scanning

Gaining Access

Matining Access

Clearing track

รปท 2.1 ขนตอนการท า penetration test [3]

ขนตอนการท าการเจาะระบบสามารถ แบงออกเปน 5 ขนตอน [3] ดงน

1. Reconnaissance คอ การเกบรวบรวมขอมลเกยวกบเวบไซตเครองเปาหมาย 2. Scanning คอ การตรวจสอบคนหาขอมลเกยวกบเวบไซต เชน พอรต (port),

โพรโตคอล(protocol), ระบบปฏบตการ (operating system), เวอรช น (version) 3. Gaining Access คอ การเขาสระบบเวบไซต 4. Maintaining Access คอ การดแลการเชอมตอเวบไซต 5. Clearing track คอ การลบรองรอยการเจาะระบบเวบไซต สวนของโครงงานนจะท าสวนทเปน Reconnaissance เทานน เพอเกบรวบรวมขอมล

เกยวกบเวบไซตเครองเปาหมาย

Page 16: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

7

2.3 ขนตอนการทดสอบเวบแอพพลเคชน

Start

Information Gathering

Configuration Management

Testing

Authentication Testing

Session Management

Testingdenial-of-service

Data Validation Testing

Business Logic Testing

Authorization Testing

Web Service Testing

AJAX Testing

Document All finding

End

รปท 2.2 ขนตอนการทดสอบเวบแอพพลเคชน [5]

ขนตอนการทดสอบเวบแอพพลเคชน ม 11 ขนตอน ดงน

1. Information gathering คอ การเกบรวบรวมขอมลเกยวกบเวบแอพพลเคชน 2. Configuration Management Testing คอ การตรวจสอบ Configuration ของ web

server เชน ตรวจสอบของการ config Apache 3. Authentication Testing คอ การทดสอบ login 4. Session Management Testing คอ การทดสอบ Session 5. Authorization Testing คอ การทดสอบสทธการเขาถง 6. Business Logic Testing คอ การทดสอบกระบวนการท างานของเวบแอพพลเคชน

ทางดานธรกจ 7. Data Validation Testing คอ การตรวจสอบการรบขอมลเขา 8. denial-of-service คอ การทดสอบเครองนจะรบการโจมตจาก Denial-of-service 9. Web Service testing คอ การทดสอบการใหบรการของเวบแอพพลเคชน 10. AJAX Testing คอ การทดสอบ AJAX 11.Document All finding คอการเขยนเอกสารทงหมดทจากการเกบรวบรวมขอมล

เกยวกบเวบแอพพลเคชน

Page 17: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

8

2.4 ขนตอนการเกบรวบรวมขอมลเกยวกบเวบไซต

Start

Analyze the robots.txt file

Allowed and disallowed directories

Perform search engine

reconnaissance

Issue of web application

structure, error page produced

1

1

Identify application

Cookie information, 300 HTTP and 400 status codes,500

internal server error

Identify the web applications

Web applications, old versions of files

or artifacts

Analyze the O/P from HEAD and OPTIONS http

request

Web server software version,

scripting environment, and

OS in use

Analysis of error codes

Software versions details of databases,

bugs,and technological components

Test for recognized file types/

extensions/ directories

Web application environment

Examine source of available pages

Provide clues as to the underlying

application environments

TCP/ICMP and service fingerprint

Web application services and

associated ports

End

รปท 2.3 ขนตอนการเกบรวบรวมขอมลเกยวกบเวบไซต

Page 18: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

9

ขนตอนการเกบรวบรวมขอมลเกยวกบเวบไซต ม 9 ขนตอน [5] ดงน

1. วเคราะหไฟล robots.txt เพอดวาอนญาต หรอ ไมอนญาตใน directory 2. การเกบรวบรวมขอมลเกยวกบเวบไซตโดยใช search engine เชน google, bing

เพอดประเดนในเรองของโครงสรางเวบแอพพลเคชนและดหนาทของสงทผดพลาด (error) 3. การระบจดทเขาแอพพลเคชน เชน ดขอมลจาก Cookie, ดสถานะ code 4. อยากรวาใชเวบแอพพลเคชนใชเวอรช นใดโดยพจารณาจาก version ของ ไฟล 5. วเคราะห Output จาก head และ options ของ http request โดยดจาก เวบ

เซรฟเวอร(web server), ซอฟตแวร เวอรช นเกา, script environment และ ระบบปฏบตการทใช

6.วเคราะห โคดมความผดพลาด (error code) จาก ซอฟทแวร เวอรช นเกา , รายละเอยดของฐานขอมล, สงผดพลาด (bug) และสวนประกอบของเทคโนโลย

7.ทดสอบการชนดไฟล หรอ สวนขยายนามสกล หรอ directory เพอดสภาวะแวดลอมของเวบแอพพลเคชน

8.ตรวจสอบ source code ทพรอมใช เพอดรองรอย หรอ ชองโหวทส าคญทอยในสภาวะแวดลอมของแอพพลเคชน

9.ตรวจสอบเรอง TCP/ICMP และ เกบขอมลเกยวกบการบรการ (service) โดยการดจากการใหบรการและพอรตทเกยวของกบเวบแอพพลเคชน

Page 19: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

10

2.5 ขนตอนการทดสอบของการใหบรการเวบไซต

Start

2

Search open source for information about

the targer

Internet,newsgroups,

Bulletin boards etc.

Identify the target

2

Fingerprint Web server

Crawl Website

Enumerate web directories

Perform directory traversal attack

Use tools such as httprint,httpprecon

Use tools such as httprint,Metagoofill

Use tools such as DirBuster

Use automated tools such as

DirBuster

End

Perform Social Engineering

Social networking

Query the Whois database

Whois, Traceroute, Active Whois etc

Document all information about

the target

รปท 2.4 ขนตอนการทดสอบการใหบรการเวบไซต [4]

Page 20: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

11

ขนตอนการทดสอบของการใหบรการเวบไซต [4] มดงน 1. การระบเวบไซตเครองเปาหมาย 2. การคนหาขอมลทเปดเผยของเวบไซตเปาหมายโดยพจารณาจาก Internet,

newsgroups, bulletin boards เปนตน 3.เกบขอมลเวบไซตจาก social engineering เชน facebook, twitter เปนตน 4.การสบคนฐานขอมลของ who is โดยใชการ whois, traceroute, active whois เปน

ตน 5. การเขยนเอกสารขอมลทงหมดเกยวกบเปาหมาย 6. การเกบขอมลการใหบรการเวบโดยใชเครองมอ เชน httprint, httpprecon 7. ท า crawl website โดยใชเครองมอ httprint, Metagoofill 8. ท าการแจกแจง web directory ใชเครองมอ DirBuster 9. พจารณาการโจมต directory tranversal ใชเครองมออตโนมต เชน DirBuster

2.6 Footprinting

Footprinting [2] คอ การเกบรวบรวมขอมลเกยวกบเปาหมายเพอเปนประโยชนกอนเจาะระบบ หรอโจมตระบบใด เชน พจารณาระบบคอมพวเตอรวาใชระบบปฏบตการใด แพลตฟอรม (platform) ใด website ใด และพจารณาวนโดว (windows) มปญหาอะไรบาง โดยหาชองโหวขอมลจากสงทตองเกบ โดยมการใชเครองมอ พวก Whois, Nmap, Google hack เพอใหไดเปาหมายของขอมล ซงค าศพทควรจะรม 6 ค าหลก ๆ คอ

2.6.1 Open source or Passive Information Gathering คอ การเกบรวบรวมขอมลจากเหยอปลายทางจากแหลงทเปนสาธารณะ (public) หรอ ขอมลสาธารณะทว ๆ ไป เชน fedora มลกษณะเปนอยางไร ในขอมลทว ๆ ไปเปนสาธารณะ passive เปนโดยรวมกวาง ๆ

2.6.2 Active information Gathering คอ การเกบรวบรวมขอมลผาน social engineer โดยการเยยมชม สมภาษณ หรอ สอบถาม ยกตวอยาง เชน ถาตองการจะเจาะบรษท ก แลวกเขาไปดทเวบไซตของบรษท ก วามอะไรบาง มพนกงานชออะไรบาง โทรเขาไป call center แลวถามวาขอมลเปนยงไง เพอชไปทจดเปาหมาย

2.6.3 Anonymous Footprinting เกบไดขอมลมาจากแหลงทผใชงานระบไมไดและไมสามารถรไดวามาจากแหลงไหน แตคณรวาขอมลของคนน เชน ฟงวทย ขอมลทางลบจากผใกลชด

2.6.4 Pseudonymous Footprinting เกบรวบรวมขอมล ซงอาจจะจดพมพ ใตชอแตกตางสรางในความพยายามเพอทจะรกษาความปลอดภย

2.6.5 Organizational or Private Footprinting เกบรวบรวมขอมลจากบรษทจากบรการ e-mail

2.6.6 Internet Footprinting คอ การเกบรวบรวมขอมลดวยอนเตอรเนต

Page 21: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

12

2.7 Footprinting Methodology การเกบรวบรวมขอมลสามารถแบงออกเปน 6 วธการ หลกๆ คอ 2.7.1 Internet Footprinting วธการคนหาขอมลจากอนเตอรเนต ม 3 วธหลกๆ ดงน

1. คนหาขอมลจาก search engine เชน Google, Bing และใช คยเวรด (keyword) ทซบซอนในการหาขอมล

2. คนหาขอมลเกยวกบคน เชน people search 3. ดงขอมลจาก archive (รพฤตกรรมการเปลยนแปลงของเวบไซต)

2.7.2 Whois Footprinting การใช WHOIS lookup เพอเกบขอมลเวบไซตของเหยอปลายทาง เชน ผดแลเวบไซต

ชอใด, เกดวนใด เดอนใด และท างานบรษทใด 2.7.3 DNS Footprinting การหาขอมลเกยวกบ DNS สวนใหญจะไดมาจากเมลเซรฟเวอร ( Mailserver ) ซง

DNS จะมโครงสรางของขอมลเกยวกบ mail เชน cname, nsrecord เครองมอทนยมใชการหา DNS คอ nslookup ขอดของการใช nslookup คอ หา DNS งายด สวนขอเสยการใช nslookup คอ ส software อนๆไมไดในการวเคราะหขอมล

2.7.4 Network Footprinting การหาขอมลเกยวกบ network สวนใหญจะหา IP เพอน าขอมล IP นนไปท าการหาชอง

โหว ท าการ scan port จาก range IP ยกตวอยาง officeน protocol นได network อะไรมาใช ม subnet หรอไม เพอจะหาขอมลเกยว network footprinting หรอจะหาจาก software ทเปนTraceroute บอกจะวงไปถงปลายทาง target ผานอะไรบาง ม router, firewall หรอไม บอกถงเสนทางให TTL บอกอะไรบางอยางเกยวกบระบบปฏบตการ (Operating System) หรอ Traceroute เปนตวชวยในการหาขอมล Traceroute ไปแลวอาจจะให Trace ไปถง ip ไหนอยางไร ไดขอมลเพอจะวาด diagram network Traceroute tool เชน 3D Traceroute, Path Analyzer

2.7.5 OS Footprinting การหาเกบรวบรวมขอมลเกยวกบระบบปฏบตการ (Operating System) ของเวบไซต

เพอประโยชนในการชองโหวของเวบไซตโดยใชโปรแกรม nmap ชวยในการหาขอมล 2.7.6 Website Footprinting การเกบรวบรวมขอมลเกยวกบเวบไซต ซงรายชอหลกทตองเกบเกยวกบเวบไซต เชน

ip, port, state, service, os, version etc.

Page 22: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

13

2.8 ขอมลเกบไดจาก Website Footprinting 2.8.1 ไอพแอดเดรส (IP Address) การเกบไอพแอดเดรสใชเครองมอ ยกตวอยางเชน

ping เปนตน 2.8.2 ระบบปฏบตการ (Operating System) การเกบระบบปฏบตการใชเครองมอ

ยกตวอยางเชน nmap เปนตน 2.8.3 พอรท (Port) การเกบพอรทใชครองมอ ยกตวอยางเชน nmap เปนตน 2.8.4 เวอรช น (version) การเกบเวอรช นใชเครองมอ ยกตวอยางเชน nmap เปนตน 2.8.5 ชอเซรฟเวอร (Server name) การเกบชอเซรฟเวอรใชวธการ เชน nmap เปนตน 2.8.6 ชอผลตภณฑ (Server Product) การเกบชอผลตภณฑใชวธการ เชน nmap เปน

ตน 2.9 Nmap

Nmap [7] (Network mapper) คอ เปนโปรแกรมทใชในการสแกนตรวจสอบเครองเครอขาย ซง Nmap ถกพฒนาใหสามารถท าการสแกนเครอขายขนาดใหญไดอยางรวดเรว เพอทจะหาขอมลเกยวกบเครองปลายทางนนๆ เชน ดวาเปดพอรท (Port) ใดบาง หรอดวา ใชระบบปฏบตการ (OS) แบบใด เปนตน

ขนตอนการใชเครองมอ nmap ใชชดค าสง nmap -[scan type] -[option] [target specification] nmap –ตามดวยชนดทจะ scan -ตามoption –ระบหมายเลขไอพแอดเดรสเปาหมาย

ยกตวอยาง ชนดทจะscan เชน 1. TCP Connect() scan จะใช option –sT 2. Ping scan จะใช option -sP 3. UDP Scan จะใช option -sU 4. Version detection จะใช option [-sV] 5. OS Fingerprinting จะใช option [ -O]

2.10 Penetration Testing Framework

2.10.1 Metasploit Metasploit [8] คอ ซอฟตแวรทใชในการท าการทดสอบเจาะระบบ (penetration test)

ขนตอนการท างานม 6 ขนตอน คอ 1.เลอกชดค าสงทใชในการโจมตชองโหวและตงคาชดค าสง เชน ไอพเครอง

เปาหมาย (IP Address), พอรท(Port) เปนตน 2.ตรวจสอบเครองทมชองโหวของระบบเพอจะท าการโจมตชองโหวนน

Page 23: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

14

3.เลอกและตงคา payload (payload เปนชดค าสงทใชในการควบคมเครองเปาหมายหลงจากยดเครองเสรจแลว)

4.เลอกเทคนคการเขารหส ดงนนสามารถหลกเลยง IPS เพราะ IPS ไมสนใจ payload ทเขารหส

5.ท าการ run ชดค าสงเครองเปาหมาย Metasploit ม module ทจะเปนการรนค าสง nmap ซงเปนเครองมอสแกนทนยมใชกนมากทสด แลวน าผลการ scan ดงกลาวเกบไวในฐานขอมลทถกสรางขนเพอเกบขอมลของเครองเปาหมาย 2.10.2 Open Source Security Testing Methodology Manual (OSSTMM) Open Source Security Testing Methodology Manual [9] เปนการทดสอบการเจาะ

ระบบ (penetration testing) วธหนงซงไดรบความนยมอยางแพรหลาย วธทดสอบคนหาชองโหวของระบบ ถกสรางขนโดย Pete Herzog และถกกระจายโดย Institute for Security and Open Methodologies (ISECOM) ซง OSSTM ใหส าคญทางดานธรกจ และหนาทตรวจสอบการแขงขนอยางฉลาด ยงไปกวานน สามารถเกบรวบรวมขอมลไดหลากหลาย และหนาทหลกของ OSSTM คอ สามารถคนหาขอมลวาเวบขอมลหลกเซรฟเวอร เชน เซรฟเวอรทอย 216.92.3.110 ทวป: NA(North America) รหสประเทศ: US ประเทศ United state ภมภาค PA(Pennsylvania) เมอง Pittsburgh 40.4531 ละตจด / -79.9294 เสนแวง

2.10.3 Open web application security project (OWASP) [10] คอ โอเพนซอรสของโปรเจคเวบแอพพลเคชนดานความมนคงปลอดภยซงเปนองคกรไมแสวงหาประโยชน มจดประสงคเพอสงเสรมและพฒนาการรกษาความปลอดภยของเวบแอพพลเคชน (Web Application) ใหดยงข น

2.10.3.1 ความเสยงดานการรกษาความปลอดภย Application [11] ผโจมตสามารถใชหลากหลายและแตกตางเสนทางผานเขามาใน

แอพพลเคชนเพอท าความเสยหายแกธรกจหรอองคกร แตละเสนทางแสดงมโอกาสเกดความเสยงอาจจะสนใจ หรอไมไดสนใจเพยงพอในเรองการอนญาตการเขาถงระบบ ซงบางครงเสนทางธรรมดาเหลานนถกท าเพอคนหาชองโหวทสามารถเอาเปรยบได แตบางครงอาจจะยากมากส าหรบผโจมต ในท านองเดยวกนการโจมตชองโหวอาจจะไมสรางความเสยหายใหองคกร แตในบางครงสรางความเสยหายใหองคกรอยางมาก การประเมนความเสยงองคกร คณสามารถประเมนความเสยงจากการประเมนความสมพนธผโจมต (threat agent) แนวทางการโจมต(Attack vector) จดออนของการรกษาความปลอดภยของระบบ (Security weakness) รวมทงประเมนผลกระทบทางดานเทคนคและธรกจขององคกร

2.10.3.2 10 อนดบความเสยงดานเวบแอพพลเคชน 2013 [12] 1. Injection เชน SQL, OS, LDAP ผบรกท าการแทรกชดค าสงของ

ระบบ (Command) หรอ หรอค าสงการ query เขาไปเพอเขาถงขอมลทไมไดรบอนญาต

Page 24: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

15

2. Broken Authentication and Session Management เปนฟงกชนการระบตวตน(Authentication)และการจดการ (Session)ทมชองโหว ท าใหผโจมตสามารถขโมยพาสเวรด(password), คย (Key), session ผานทางโทคเคน (token) เพอปลอมตวเปนผใชงานเขาถงระบบโดยไมไดรบอนญาต

3. Cross-Site Scripting (XSS) แฮกเกอรจะฝงสครปสทไมประสงคดผานทางเวบแอพพลเคชนทมชองโหวของเวบไซตตางๆ เมอผใชโหลดหนาเวบไซต คาส าคญบางอยางเชน cookies, username, password จะถกขโมยไป แฮกเกอรขโมยคา cookies ซงอาจจะท าใหแฮกเกอรใช cookies เพอใชแยง session ของเหยอ หรอ แกไขขอมลของ form ทใชกรอก username password สงไปยงเครอง hacker กอนทจะสงไปเวบไซตจรงๆ

4. Insecure Direct Object References เมอนกพฒนาไดเปดเผยขอมลการอางอง object ทใชในการด าเนนการ เชน ไฟล(file), ไดเรกทอรร(directory) โดยไมมการเขาควบคมการเขาถง ดงนนผโจมตสามารถใชการอางองถงขอมลโดยไมไดรบอนญาต

5. Security Misconfiguration ปญหาทเกดจากผทดแลระบบไมไดแกไขคอนฟกระบบเชน แอพพลเคชนเซรฟเวอร (application server), เวบเซรฟเวอร (webserver), ฐานขอมลของเวบเซรฟเวอร (database server) เปนตน ใหมความมนคงปลอดภย

6. Sensitive Data Exposure หลากหลายเวบแอพพลเคชนไมท าการปองกนขอมลทออนไหว (sensitive) เชน เครดตการด (credit card), แทกไอด (tax id) เปนตน ผบรกสามารถโจมตขอมลทออนไหวได

7. Missing Function Level Access หลากหลายเวบแอพพลเคชนขาดฟงกชนการควบคมการเขาถงระบบเวบแอพพลเคชน ดงนนท าใหผโจมตเขาถงระบบโดยไมไดรบอนญาต

8. Cross-site Request Forgery (CSRF) การโจมต CSRF คอ เมอเหยอลอกออน (log on) ทเวบเบราวเซอร การบงคบใหเวบเบราวเซอรของเหยอสง HTTP request ทถกปลอมแปลง รวมทง cookies และขอมลตางๆทเกยวกบการระบตวตน (Authentication) เพอท าใหเวบแอพพลเคชนมชองโหว ผโจมตบบบงคบใหใหเวบเบราวเซอรของเหยอสราง HTTP request จากชองโหวของแอพพลเคชน ซงเหยอคดวาเปนการรองขอทถกกฎหมาย

9. Using Components with Know Vulnerabilities สวนประกอบ (Components) เชน ไลบารร (libraries), เฟรมเวรค (frameworks) และซอรฟแวร โมดล (Software module) ตางๆ สวนใหญรน (run) ผานสทธพเศษ ถาสวนประกอบมชองโหวดงนนผบกรกเขาถงขอมลไดงายขนและขอมลเกดความเสยหาย ซงแอพพลเคชนใชสวนประกอบและรหลากหลายชองโหวดงนนจะตองท าการปองกนโจมตมความเปนไดและผลกระทบตอแอพพลเคชนนน

Page 25: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

16

10. Unvalidated Redirects and Forwards ผโจมตท าใหผใชเวบแอพพลเคชนเปลยนและไปยงหนาเวบไซตตางๆ เชน หนาเวบฟชชง ( phishing ) เพอเขาถงหนาเวบโดยไมไดรบอนญาต

2.10.4 Web Application Security Consortium (WASC) [13] Web Application security consortium คอ การคนหาผสนบสนนดานอตสาหกรรม

อยางมออาชพพจารณาจากแนวโนม, เทคนค, การปองกน, วธการปฏบต หรอ บทเรยนทด ตรงประเดนทเกยวกบการรกษาความปลอดภยเวบไซต เกณฑการประเมนการสแกนเวบแอพพลเคชน (The web application Security Scanner Evaluation Criteria) คอ เปนเซททท าการประเมนสแกนของเวบแอพพลเคชนเพอท าการทดสอบประสทธภาพของเวบแอพพลเคชนและระบชองโหวของเวบแอพพลเคชน เปาหมายหลกคอ เพอสรางเอกสารให vendor เพอชวยแนะน าเวบแอพพลเคชนดานการรกษาความมนคงปลอดภยอยางมออาชพระหวางท าการประเมนและสแกนเวบแอพพลเคชน เครองมอเวบสแกนเกยวกบความมนคงปลอดภยของเวบแอพพลเคชน (Web application security scanning tool) เปนเครองมออตโนมต ใชเพอทดสอบปญหาเวบแอพพลเคชน เชน Cross site script, SQL injection 2.11 Whois

Whois คอ โปรแกรมทใหบรการตรวจสอบวาโดเมนนนสรางวนใด หมดอายวนใด อพเดทวนใด ชอเซรฟเวอร ชอผรบจดชอโดเมน (domain name) ลงคเวบไซตทผรบจดชอโดเมน ชออเมลและเบอรโทรศพทของผรบจดชอโดเมน ชอผขอจดชอโดเมน ชอองคกร, ทอย, อเมล, และเบอรโทรศพทของผขอจดชอโดเมน

ชดค าสงทใช whois ตามดวยชอโดเมน เชน whois mthai.com ,whois sanook.com, whois kapook.com เปนตน

Page 26: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

บทท 3 การออกแบบระบบ

ในบทนไดกลาวถงเทคนคการออกแบบโครงสรางระบบเกบรวบรวมขอมลเครอง

เปาหมายเพอปองกนความปลอดภยของระบบโดยไดอางองจากทฤษฎบทท 2 เพอประโยชนในการเกบรวบรวมขอมลของเวบเซรฟเวอรเครองเปาหมาย

3.1 โครงสรางระบบการท างาน

รปท 3.1 Network diagram จากรปท 3.1 ไคลแอนตตองท าการรองขอใชเวบแอพพลเคชนเกบรวบรวมขอมล (web information gathering application) กอน สวน server ตองท าการตรวจสอบกอนทจะตอบสนองหนาเวบแอพพลเคชนใหกบไคลแอนต

Page 27: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

18

3.2 หลกการท างานของระบบเกบรวบรวมขอมล

รปท 3.2 โครงสรางของระบบเกบรวบรวมขอมลเครองเปาหมาย จากรปท 3.2 หลกการท างานระบบเกบรวบรวมขอมล ใหผใชท าการกรอกชอเวบไซต

ของเครองเปาหมาย แลวคลกตกลง แลวระบบท าการเรยกใชเครองมอทง 2 ชนด คอ Nmap และ Whois เพอท าการเกบรวบรวมขอมลเกยวกบเวบไซต ดงนนน าผลลพธขอมลทง 2 ชนดมาท าการจดเรยงขอมล และแสดงผลขอมลเวบไซตของเครองเปาหมายออกทางหนาจอวาเวบไซตนนสรางวนใด หมดอายวนใด อพเดทวนใด มชอเซรฟเวอรใดบาง สถานะโดเมนของเวบไซตนน เวบไซตใดทรบจดชอโดเมนของเวบไซตนน และชอบรษท,ทอย และอเมลตดตอของบรษทผทรบจดชอโดเมน ชอ, ชอบรษท, ทอย และอเมลของผขอจดชอโดเมน และสามารถตรวจสอบวามพอรดใดบาง, สถานะพอรต, ชอเซอรวส, ชอผลตภณฑ( product), ชอเวอรช น และระบบปฏบตการ และผใชสามารถกดลงค (link) history เพอดขอมลเวบไซตยอนหลงได

Page 28: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

19

3.3 ขนตอนการท างานของระบบเกบรวบรวมขอมล

Nmap

Whois

nmap Whois

History

รปท 3.3 ขนตอนการท างานระบบเกบรวบรวมขอมล

จากรปท 3.3 ผใชตองท าการสแกนเวบไซตใหมหรอไม ถาใชใหผใชท าการกรอกชอโดเมน หรอ ชอเวบไซตและกดปมตกลงเพอท าการสแกนเวบไซต โปรแกรมจะไปเรยกเครองมอทงสองชนดคอ nmap และ whois ท าการสแกนเวบไซต และเกบรวบรวมขอมลของเวบไซตนนลงฐานขอมลแยกฐานขอมลกน จากนนดงขอมลจากทงสองฐานขอมลออกมาแสดงผลการสแกน ถาสแกนเสรจแลวกดกลบไปหนาเรมตน ดงนนผใชตองการดขอมลยอนหลงใหกดลงค history เพอท าการดขอมลยอนหลงโดยผใชตองท าการกรอกชอเวบไซต และชวงวนทเรม และวนท

Page 29: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

20

สนสด ของการสแกน ถาชวงวนมในขอมลในฐานขอมลดงนนการน าขอมลออกมาโชว ถาไมมกไมแสดงขอมลออกมาโชว และกดลงคกลบไปหนาเรมตน

3.4 แผนผงการท างานไฟล

domainname3.php Getdomainname3.php

newhistory.php Connectdbnmap.php Connectdbwhois.php

รปท 3.4 แผนผงการท างานไฟล

หนา domainname3.php คอหนาทผใชเลอกจะสแกนเวบไซตใหมหรอดขอมลยอนหลง

ถาผใชเลอกสแกนใหมจะสงขอมลไปหนา getdomainname3.php เพอท าการสแกนและเกบรวบรวมขอมลลงฐานขอมลแยกกน nmap เกบลงฐานขอมลชอ nmap สวน whois เกบลงฐานขอมล whois และท าการดงขอมลจากฐานขอมลทงสองชนดออกมาแสดงผลการสแกนออกมาแสดงวาขอมลใดบาง สวนหนา connectdbnmap.php คอหนาใชการเชอมตอ mysql และ เลอกฐานขอมลชอ nmap สวนหนา connectdbwhois.php คอหนาใชการเชอมตอ mysql และ เลอกฐานขอมลชอ whois แตถาผใชตองการดขอมลยอนหลง กดลงค history จากหนา domainname3.php ไป หนา newhistory.php เปนหนาดขอมลยอนหลงโดยทผใชตองกรอกชอเวบไซตและกรอกชวงวนเดอนปทเรมตน และสนสดของยอนหลง ถามขอมลชวงวนเดอนปทผใชเลอกดงนนการแสดงผลขอมลออกมาแสดง ถาไมมขอมลในชวงวนเดอนปทเลอกดงนนจะไมมการแสดงขอมลออกมาแสดง ทงหนา newhistory.php และ getdomainname 3.php จะมลงค home กลบไปทหนา getdomainname3.php

Page 30: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

21

3.5 ตารางฐานขอมล ฐานขอมล แบงออกเปน 2 ชนด คอ ฐานขอมล nmap และ ฐานขอมล whois ฐานขอมล

nmap ม 1 ตาราง คอ ตาราง nmap_info

ตารางท 3.1 ตาราง nmap_info ของฐานขอมล Nmap ชอฟลด ชนดขอมล ประเภทคย

Nmap_ID int(11) Primary Key

Portnumber int(11) Not Null

Protocal varchar(15) Not Null

State varchar(10) Not null

Service_name varchar(40) Not null

Service_product varchar(40) Not null

Service_version varchar(40) Not null

Service_extra_info varchar(40) Not null

Service_os_type varchar(40) Not null

hostname varchar(40) Not null

User_viewdate Date Not null

ความหมาย ชอฟลด Nmap_ID คอ ID ของ Nmap Portnumber คอ หมายเลข port Protocal คอ ชอโพรโตตอล State คอ สถานะของพอรท Service_name คอ ชอเซอรวส Service_product คอ ชอ product ของเซอรวส Service_version คอ ชอเวอรช นของเซอรวส Service_extra_info คอ ชอขอมลพเศษของเซอรวส Service_os_type คอ ชอระบบปฏบตการของเซอรวส

Page 31: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

22

hostname คอ ชอเวบไซต หรอ โดเมนทสแกน User_viewdate คอ ชอวนทของผใชเขามาสแกน

ฐานขอมล whois แบงออกเปน 3 ตาราง คอ Domain_info, Registrar และ Registrant

ตารางท 3.2 ตาราง Domain_info ของฐานขอมล whois

ชอฟลด ชนดขอมล ประเภทคย

Domain_Name Varchar(50) Primary Key

Update_Date Datetime Not null

Creation_Date Datetime Not null

Expiration_Date Datetime Not null

User_viewdate Date Not null

NameS1 varchar(50) Not null

NameS2 varchar(50) Not null

NameS3 varchar(50) Not null

NameS4 varchar(50) Not null

NameS5 varchar(50) Not null

DomainS1 varchar(50) Not null

DomainS2 varchar(50) Not null

DomainS3 varchar(50) Not null

DomainS4 varchar(50) Not null

Registrar_Whois_Server varchar(50) Foreign Key

Registar_Name varchar(50) Foreign Key

Reg_Name varchar(50) Foreign Key

Page 32: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

23

ความหมายชอฟลด Domain_Name คอ ชอโดเมน หรอ เวบไซต Update_Date คอ วนทอพเดทของโดเมน Creation_Date คอ วนทสรางของโดเมน Expiration_Date คอ วนทหมดอายของโดเมน User_viewdate คอ วนทผใชเขามาสแกน NameS1 คอ ชอเซรฟเวอร 1 NameS2 คอ ชอเซรฟเวอร 2 NameS3 คอ ชอเซรฟเวอร 3 NameS4 คอ ชอเซรฟเวอร 4 NameS5 คอ ชอเซรฟเวอร 5 Registrar_Whois_Server คอ whois server ของ ผรบจดชอโดเมน Registar_Name คอ ชอผรบจดชอโดเมน Reg_Name คอ ชอ ชอผขอจดชอโดเมน

ตารางท 3.3 ตาราง Registrar ของฐานขอมล whois

ชอฟลด ชนดขอมล ประเภทคย

Registrar_Whois_Server Varchar(50) Primary Key

Registrar_URL varchar(50) Not Null

Registrar_Name varchar(50) Primary Key

Registrar_Ab_Contact_Email Varchar(50) Not Null

Registrar_Ab_Contact_Phone varchar(50) Not Null

ความหมายชอฟลด Registrar_Whois_Server คอ whois server ของ ผรบจดชอโดเมน Registrar_URL คอ ลงคของผรบจดชอโดเมน Registrar_Name คอ ผรบจดชอโดเมน Registrar_Ab_Contact_Email คอ อเมลตดตอของผรบจดชอโดเมนRegistrar_Ab_Contact_Phone คอ เบอรโทรศพทของผรบจดชอโดเมน

Page 33: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

24

ตารางท 3.4 ตาราง Registrant ของฐานขอมล whois

ชอฟลด ชนดขอมล ประเภทคย

Reg_Name varchar(50) Primary Key

Reg_Org varchar(50) Not Null

Reg_Street1 varchar(50) Not Null

Reg_Street2 varchar(40) Not Null

Reg_City varchar(50) Not Null

Reg_State_Province varchar(50) Not Null

Reg_Postal_Code varchar(20) Not Null

Reg_Country varchar(30) Not Null

Reg_Phone varchar(15) Not null

Reg_Phone_Ext varchar(15) Not Null

Reg_Fax varchar(15) Not null

Reg_Fax_Ext varchar(15) Not null

Reg_Email varchar(40) Not Null

ความหมาย ชอฟลด Reg_Name คอ ชอผขอจดชอโดเมน Reg_Org คอ ชอองคกรของผขอจดชอโดเมน Reg_Street คอ ชอถนนของผขอจดชอโดเมน Reg_Street2 คอ ชอถนนของผขอจดชอโดเมน Reg_City คอ ชอเมองของผขอจดชอโดเมน Reg_State_Province คอ ชอรฐหรอจงหวดของผขอจดชอโดเมน Reg_Postal_Code คอ รหสไปรษณยของผขอจดชอโดเมน Reg_Country คอ ประเทศของผขอจดชอโดเมน Reg_Phone คอ เบอรโทรศพทของผขอจดชอโดเมน

Page 34: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

25

Reg_Phone_Ext เบอรตอจากเบอรโทรศพทผขอจดชอโดเมน Reg_Fax คอ เบอรโทรสารของผขอจดชอโดเมน Reg_Fax_Ext คอ เบอรตอจากเบอรโทรสารของผขอจดชอโดเมน Reg_Email คอ อเมลของผขอจดชอโดเมน

Page 35: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

บทท 4 ผลการทดลอง

4.1 กลาวน า

ระบบเกบรวบรวมขอมลเวบไซต ไดพฒนาขนโดยใช backtrack 5 R3 โดยใชภาษา PHP ฐานขอมลทใช Mysql เกบรวบรวมขอมล จะกลาวถงผลการทดลองการเกบรวบรวมขอมลของโครงงาน

4.2 การท างานของระบบเกบรวบรวมขอมล

4.2.1 การท างานการสแกนเวบไซตของเครองเปาหมาย

รปท 4.1 หนาจอการสแกนเวบไซตของเครองเปาหมาย

จากรปท 4.1 ผใชกรอกชอเวบไซตกอนแลวจงกดปม submit สมมตผใชกรอกชอ

www.mthai.com ดงนน โปรแกรมเรยกเครองมอทง 2 ชนด คอ Nmap และ Whois เพอใหเครองมอทง 2 ชนดท าการประมวลผลและเกบรวบรวมขอมลเกยวกบเวบไซต ดงนนระบบเกบรวบขอมลน าผลลพธทง 2 ชนด มาท าจดเรยงขอมลและแสดงผลขอมลออกทางหนาจอวาเกบขอมลใดเกยวกบเวบไซตบาง และม ลงค history เพอสามารถดขอมลยอนหลงได

Page 36: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

27

รปท 4.2 การแสดงผลขอมลจากการสแกนเวบไซตเครองเปาหมาย

หลงจากผใชท าการสแกน www.mthai.com แลวระบบเรยกโปรแกรม Whois แลวท าการเกบรวบรวมขอมลเวบไซต แลวแสดงผลขอมลดงรปท 4.2 เราจะไดขอมลเวบไซตไดดงน เวบไซตสรางวนท 12 มถนายน 1998 เวลา 23 นาฬกา เวบไซตหมดอาย วนท 11 มถนายน 2016 เวบไซตอพเดทวนท 11 ตลาคม 2013 เวบไซตมชอ server 3 ชอ NS1.MTHAI.COM, NS2.3BB.CO.TH, NS1.3BB.CO.TH สถานะโดเมนของเวบไซตม 4 ชนด 1.หามผใชเคลอนยายโดเมน 2.หามผใชอพเดทโดเมน 3.หามผใชท าโดเมนนใหมอกครง 4.หามผใชลบโดเมนน ชอผทรบของจดชอโดเมน คอบรษท GoDaddy.com, LLC มลงคผทรบจดชอโดเมนคอ www.godaddy.com, อเมล และ เบอรโทรศพทของผทรบจดดงรปท 4.2 สวนผทขอจดชอโดเมนคอ บรษท Mono Technology PCL Mono Technogy PCL ชอองคกร Mono Technology ทอย 200 หมท 4 ตกแจสมน ชน 16 แจงวฒนะ อ าเภอปากเกรด จงหวดนนทบร 11120 ประเทศไทย อเมล [email protected] และเบอรโทรศพทดงรปท 4.2 และระบบเรยกโปรแกรม nmap ท าการเกบรวบรวมขอมลเวบไซต แลวแสดงผลลพธรปแบบตาราง วนท1 เมษายน 2014 มพอรต 80 เปดอย ชอเซรฟวสเปน http ชอ product ของเซอรวส คอ Apache httpd แต พอรต 514 สถานะ กรอง มการกนดวยไฟลวอลล ชอเซอรวสเปน shell

รปท 4.3 หนาจอการดขอมลยอนหลง

Page 37: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

28

เมอผใชท าการกดลงค history จากหนาจอการสแกนเวบไซตของเครองเปาหมาย ดงรปท 4.1 กจะสงมาทหนาจอการดขอมลยอนหลง ดงรปท 4.3 ผใชจะตองท ากรอกชอเวบไซต และกรอกวนเดอนปเรมและสนสดยอนหลง เมอผใชท ากรอกเสรจกดปม submit แลวไดขอมลยอนหลง ดงรปท 4.4

รปท 4.4 การแสดงผลจากการดขอมลยอนหลง

เมอผใช เลอกวนท 19 เดอน มนาคม 2014 ถง วนท 20 เดอน มนาคม 2014 ผใชจะได

ขอมลดงรปท 4.4

4.3 ชดค าสงทใชเรยกโปรแกรม nmap ชดค าสงทใชในโปรแกรม nmap คอ $cmd=/usr/local/bin/nmap -A -T4 $ip -oX $file

หมายวา เรยกโปรแกรม nmap ท path /usr/local/bin nmap -A คอ ตรวจสอบ OS และ version สวน –T4 เพมความเรวในการสแกน ตามดวยหมายเลขไอพแอดเดรส ใหแสดงผลออกมารปแบบ XML แลวเกบลง file จากนนใชชดค าสง shell_exec("$cmd1"); หมายความวา โปรแกรม nmap จะด าเนนการไดตองเรยกใชชดค าสง shell_exec เพอสงชดค าสงดานบนท าการด าเนนการสแกนดวยโปรแกรม nmap 4.4 ชดค าสงทใชเรยกโปรแกรม whois

$cmddomain="/usr/bin/whois ".$namedomain2; หมายความวา เรยกโปรแกรม whois ทpath /usr/bin/whois ตามดวยชอโดเมน และเสรจแลวเกบไวทตวแปร $cmddomain ดงนน $outputwhois=shell_exec("$cmddomain"); หมายความวา whois จะด าเนนการไดตองใชค าสง shell_exec เพอสงชดค าสงดานบนท าการด าเนนการดวยโปรแกรม whois

Page 38: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

บทท 5 สรปผลการด าเนนงาน

5.1 กลาวน า

โครงงานนถกจดท าขนเพอใชกระบวนการทดลองเกบรวบรวมขอมลเกยวกบเวบไซตเพอหาชองโหวทสามารถเขาถงระบบเพอลดความเสยงตอการเสยหายตอเวบไซต

5.2 สรปผลการด าเนนการ จากการศกษาและจดท าระบบเกบรวบรวมขอมลเวบไซต สามารถแกไขปญหาตามบทท 1 กลาวไปตามวตถประสงคดงน

1.ผใชสามารถใชระบบเพอใชในการคนหาและเกบรวบขอมลเกยวกบเวบไซตเพอท าการตรวจสอบชองโหวและรายงานผลชองโหวของเวบไซต 2.ผใชเครองมอทชวยในการคนหาและเกบรวบรวมขอมลตางๆเกยวกบเวบไซตใหสามารถท าไดภายในเครองมอเดยวและชวยใหสะดวกสบายในการคนหาและเกบขอมลเกยวกบเวบไซต

5.3 ปญหาและอปสรรค การสแกนโปรแกรม nmap ไดจ านวนขอมลทไมแนนอน เชน จ านวนพอรต 4 พอรต

หรอ 5 พอรต ท าใหการบรหารจดการน าขอมลลงฐานขอมลคอนขางยงยาก ดงนนมการเกบขอมลแยกฐานขอมลออกจากกน 5.4 แนวทางการพฒนาตอ

1. การพฒนาการจดท ารปแบบหนา interfaceใหนาใชมากขน 2. การพฒนารวมฐานขอมลเขาดวยกน เพอใหงายตอการดงขอมลออกมาแสดง

Page 39: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

30

เอกสารอางอง

[1] Confidentiality, Integrity and Availability, [Online]. Available: http://it.med.miami.edu/x904.xml [2] CEHV7 Module 01 Introduction to Ethical Hacking.pdf, [Online]. Available: http://www.eccouncil.org/

[3] CEHV7 Module 02 Footprinting and Reconnaissance.pdf, [Online]. Available: http://www.eccouncil.org/ [4] CEHV7 Module 12 Hacking Webservers.pdf, [Online]. Available: http://www.eccouncil.org/ [5] CEHV7 Module 13 Hacking Web Application.pdf, [Online]. Available: http://www.eccouncil.org/

[6] CEHV7 Module 19 Penetration Testing.pdf, [Online]. Available: http://www.eccouncil.org/ [7] Nmap, [Online]. Available: http://nmap.org/ [8] Metasploit, [Online]. Available: http://www.metasploit.com/ [9] OSSTM, [Online]. Available: http://www.isecom.org/research/osstmm.html [10] OWASP, [Online]. Available: https://www.owasp.org/index.php/Main_Page [11] Application Risk, [Online]. Available: https://www.owasp.org/index.php/Top_10_2010-Main

[12] OWASP TOP 10 Projects 2013, [Online]. Available: https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project [13] Web Application Security Consortium http://www.webappsec.org/ http://www.webappsec.org/projects/articles/

Page 40: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

ภาคผนวก

Page 41: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

31

ภาคผนวก ก Source code หนา domainname3.php

Page 42: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

32

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <?php echo"Hello"; echo "<br>"; //<label for="domainname"></label> ?> <body> <form id="form1" name="form1" method="post" action="getdomainname3.php"> <p> Input domain name:<input type="text" name="domainname" id="domainname" /> For example, www.mthai.com </p> <input name="submit" type="submit" value="submit" /> </form> <a href="newhistory.php">History</a> </body> </html>

Page 43: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

33

ภาคผนวก ข

Source code หนา getdomainname3.php

Page 44: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

34

<?php $namedomain=""; $namedomain = $_POST['domainname']; $ip=gethostbyname($namedomain); //whois $namedomain2=trim($namedomain,"www."); $cmddomain="/usr/bin/whois ".$namedomain2;

$outputwhois=shell_exec("$cmddomain"); $r=explode("\n",$outputwhois); $f=0; $v=""; $m=array(); $n=array(); foreach($r as $line) { if(preg_match("/^[A-Z][a-zN].+: */",$line)) { $v=explode(':',$line,2); $m[$f]=$v[0]; $n[$f]=$v[1]; $f++; } } //ประกาศตวแปร $domain=""; $reg_whois_server=""; $reg_url=""; $update_date=""; $creation_date=""; $reg_exp_date=""; $registrar=""; $reg_abuse_contact_email=""; $reg_abuse_contact_phone=""; $domain_status1=""; $domain_status2=""; $domain_status3=""; $domain_status4=""; $registry_reg_id=""; $reg_name=""; $reg_org=""; $reg_street1=""; $reg_street2=""; $reg_city=""; $reg_state_or_province=""; $reg_postal_code=""; $reg_country=""; $reg_phone=""; //ประกาศตวแปร $reg_phone_ext=""; $reg_fax=""; $reg_fax_ext=""; $reg_email=""; $reg_admin_id=""; $admin_name=""; $admin_org=""; $admin_street1=""; $admin_street2="";

Page 45: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

35

$admin_city=""; $admin_state_or_provice=""; $admin_postal_code=""; $admin_country=""; $admin_phone=""; $admin_phone_ext=""; $admin_fax=""; $admin_fax_ext=""; $admin_email=""; $reg_tech_id=""; $tech_name=""; $tech_org=""; $tech_street1=""; $tech_street2=""; $tech_city=""; $tech_state_or_province=""; $tech_postal_code="";$tech_country=""; $tech_phone=""; $tech_phone_ext=""; $tech_fax=""; $tech_fax_ext=""; $tech_email=""; $nameserver1=""; $nameserver2=""; $nameserver3=""; $nameserver4=""; $nameserver5=""; $lastupdatewhoisdb=""; $pleasenote="";$other=""; $count=0; $count1=0; $count2=0; $count3=0; $count4=0; for($j=0;$j<$f;$j++) {

if($m[$j]=="Domain Name") { $domain=$n[$j]; }

else if($m[$j]=="Registrar WHOIS Server") { $reg_whois_server=$n[$j]; }

else if($m[$j]=="Registrar URL") { $reg_url=$n[$j];

} else if($m[$j]=="Update Date")

{ $update_date=$n[$j];

} else if($m[$j]=="Creation Date") { $creation_date=$n[$j]; } else if($m[$j]=="Registrar Registration Expiration Date") {

Page 46: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

36

$reg_exp_date=$n[$j]; } else if($m[$j]=="Registrar") { $registrar=$n[$j]; } else if($m[$j]=="Registrar Abuse Contact Email") {

$reg_abuse_contact_email=$n[$j]; } else if($m[$j]=="Registrar Abuse Contact Phone") {

$reg_abuse_contact_phone=$n[$j]; } else if($m[$j]=="Domain Status") {

if($count=='0') { $domain_status1=$n[$j]; }

if($count=='1') { $domain_status2=$n[$j]; } if($count=='2') {

$domain_status3=$n[$j]; }

if($count=='3') { $domain_status4=$n[$j]; } $count++; }

Page 47: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

37

else if($m[$j]=="Registry Registrant ID") {

$registry_reg_id=$n[$j]; } else if($m[$j]=="Registrant Name") { $reg_name=$n[$j];

} else if($m[$j]=="Registrant Organization") { $reg_org=$n[$j]; }

else if($m[$j]=="Registrant Street") {

if($count1=='0') { $reg_street1=$n[$j]; } if($count1=='1') { $reg_street2=$n[$j]; } $count1++; } else if($m[$j]=="Registrant City") {

$reg_city=$n[$j]; } else if($m[$j]=="Registrant State/Province") { $reg_state_or_province=$n[$j]; } else if($m[$j]=="Registrant Postal Code") {

Page 48: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

38

$reg_postal_code=$n[$j]; }

else if($m[$j]=="Registrant Country") {

$reg_country=$n[$j]; } else if($m[$j]=="Registrant Phone")

{ $reg_phone=$n[$j];

} else if($m[$j]=="Registrant Phone Ext") { $reg_phone_ext=$n[$j]; } else if($m[$j]=="Registrant Fax") {

$reg_fax=$n[$j]; } else if($m[$j]=="Registrant Fax Ext") { $reg_fax_ext=$n[$j]; } else if($m[$j]=="Registrant Email") { $reg_email=$n[$j]; } else if($m[$j]=="Registry Admin ID") { $reg_admin_id=$n[$j]; } else if($m[$j]=="Admin Name") { $admin_name=$n[$j]; }

Page 49: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

39

else if($m[$j]=="Admin Organization") { $admin_org=$n[$j]; } else if($m[$j]=="Admin Street") {

if($count2=='0') { $admin_street1=$n[$j]; } if($count2=='1') { $admin_street2=$n[$j]; } $count2++; } else if($m[$j]=="Admin City") {

$admin_city=$n[$j]; } else if($m[$j]=="Admin State/Province") { $admin_state_or_provice=$n[$j]; } else if($m[$j]=="Admin Postal Code") { $admin_postal_code=$n[$j]; } else if($m[$j]=="Admin Country") {

$admin_country=$n[$j]; } else if($m[$j]=="Admin Phone") {

Page 50: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

40

$admin_phone=$n[$j]; } else if($m[$j]=="Admin Phone Ext") { $admin_phone_ext=$n[$j]; } else if($m[$j]=="Admin Fax") { $admin_fax=$n[$j]; } else if($m[$j]=="Admin Fax Ext") { $admin_fax_ext=$n[$j];

} else if($m[$j]=="Admin Email") {

$admin_email=$n[$j]; } else if($m[$j]=="Registry Tech ID") {

$reg_tech_id=$n[$j]; } else if($m[$j]=="Tech Name") {

$tech_name=$n[$j]; } else if($m[$j]=="Tech Organization") { $tech_org=$n[$j]; } else if($m[$j]=="Tech Street") {

if($count3=='0') {

Page 51: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

41

$tech_street1=$n[$j]; }

if($count3=='1') {

$tech_street2=$n[$j]; }

$count3++; } else if($m[$j]=="Tech City") {

$tech_city=$n[$j]; } else if($m[$j]=="Tech State/Province") {

$tech_state_or_province=$n[$j]; } else if($m[$j]=="Tech Postal Code") { $tech_postal_code=$n[$j]; } else if($m[$j]=="Tech Country") { $tech_country=$n[$j]; } else if($m[$j]=="Tech Phone") { $tech_phone=$n[$j];

} else if($m[$j]=="Tech Phone Ext") {

$tech_phone_ext=$n[$j]; } else if($m[$j]=="Tech Fax") {

Page 52: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

42

$tech_fax=$n[$j]; } else if($m[$j]=="Tech Fax Ext") {

$tech_fax_ext=$n[$j]; } else if($m[$j]=="Tech Email") {

$tech_email=$n[$j]; } else if($m[$j]=="Name Server") {

if($count4=='0') { $nameserver1=$n[$j]; } if($count4=='1') { $nameserver2=$n[$j]; } if($count4=='2') { $nameserver3=$n[$j]; } if($count4=='3') { $nameserver4=$n[$j]; } if($count4=='4') { $nameserver5=$n[$j]; }

$count4++; }

Page 53: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

43

else if($m[$j]=="Last update of WHOIS database") {

$lastupdatewhoisdb=$n[$j]; } else if($m[$j]=="Please note") {

$pleasenote=$n[$j]; } else {

$other=$n[$j]; } } // Insert and Update database whois include("connectdbwhois.php"); //Registrant $sql="select * from Registrant where Reg_name='$reg_name'"; $query=mysql_query($sql); $row=mysql_num_rows($query);

if($row==0) {

$sql="insert into Registrant (Reg_Name, Reg_Org, Reg_Street1, Reg_Street2, Reg_City, Reg_State_Province, Reg_Postal_Code, Reg_Country, Reg_Phone,Reg_Phone_Ext,Reg_Fax,Reg_Fax_Ext,Reg_Email) VALUES('$reg_name','$reg_org', '$reg_street1', '$reg_street2', '$reg_city', '$reg_state_or_province','$reg_postal_code', '$reg_country', '$reg_phone', '$reg_phone_ext','$reg_fax', '$reg_fax_ext','$reg_email')"; mysql_query($sql); }

Page 54: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

44

else { $sql="update Registrant set Reg_Org='$reg_org', Reg_Street1='$reg_street1', Reg_Street2='$reg_street2', Reg_City='$reg_city',Reg_State_Province='$reg_state_or_provine',Reg_Postal_Code='$reg_postal_code',Reg_Country='$reg_country',Reg_Phone='$reg_phone',Reg_Phone_Ext='$reg_phone_ext',Reg_Fax='$reg_fax',Reg_Fax_Ext='$reg_fax_ext',Reg_Email='$reg_email' where Reg_name='$reg_name'"; mysql_query($sql); } //Registrar $sql="select * from Registrar where Registrar_Whois_Server ='$reg_whois_server' and Registrar_URL, Registrar_Name='$registrar'"; $query=mysql_query($sql); $row=mysql_num_rows($query); if($row==0) { $sql="insert into Registrar (Registrar_Whois_Server, Registrar_URL, Registrar_Name,Registrar_Ab_Contact_Email,Registrar_Ab_Contact_Phone) VALUES('$reg_whois_server','$reg_url','$registrar','$reg_abuse_contact_email','$reg_abuse_contact_phone')"; mysql_query($sql); } else { $sql="update Registrar set Registrar_URL='$reg_url',Registrar_Ab_Contact_Email='$reg_abuse_contact_email',Registrar_Ab_Contact_Phone='$reg_abuse_contact_phone' where Registrar_Whois_Server='$reg_whois_server' and Registrar_URL, Registrar_Name='$registrar'"; mysql_query($sql);

Page 55: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

45

} //table Domain_info $sql="select * from Domain_info where Domain_name='$domain'"; $query=mysql_query($sql); $row=mysql_num_rows($query); if($row==0) { $sql="insert into Domain_info(Domain_Name,Update_Date,Creation_Date,Expiration_Date,Last_Update,User_viewdate,NameS1,NameS2,NameS3,NameS4,NameS5,DomainS1,DomainS2,DomainS3,DomainS4,Registrar_Whois_Server,Registrar_Name,Reg_Name) VALUES('$domain','$update_date','$creation_date','$reg_exp_date','$lastupdatewhoisdb',NOW(),'$nameserver1','$nameserver2','$nameserver3','$nameserver4','$nameserver5','$domain_status1','$domain_status2','$domain_status3','$domain_status4','$reg_whois_server','$registrar','$reg_name')"; mysql_query($sql); } else { $sql="update Domain_info set Update_Date='$update_date',Creation_Date='$creation_date',Expiration_Date='$reg_exp_date',Last_Update='$lastupdatewhoisdb',User_viewdate=NOW(),NameS1='$nameserver1',NameS2='$nameserver2',NameS3='$nameserver3',NameS4='$nameserver4',NameS5='$nameserver5',DomainS1='$domain_status1',DomainS2='$domain_status2',DomainS3='$domain_status3',DomainS4='$domain_status4',Registrar_Whois_Server='$reg_whois_server',Registrar_Name='$registrar',Reg_Name='$reg_name' where Domain_name='$domain'"; mysql_query($sql); } // Select data $sql="select * from Domain_info where Domain_Name='$domain'"; $queryDomain=mysql_query($sql);

Page 56: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

46

$rowDomain=mysql_fetch_array($queryDomain); $find=$rowDomain['Reg_Name']; $sql="select * from Registrant where Reg_Name='$find'"; $queryRegt=mysql_query($sql); $find=$rowDomain['Registrar_Whois_Server']; $find1=$rowDomain['Registrar_Name']; $sql="select * from Registrar where Registrar_Whois_Server='$find' and Registrar_Name='$find1'"; $queryRegr=mysql_query($sql); $rowRegt=mysql_fetch_array($queryRegt); $rowRegr=mysql_fetch_array($queryRegr); ?> //show data in table <table align="center" width="1000" > <tr>

<td align="center" colspan="3"><B><FONT SIZE=8><?php echo $rowDomain['Domain_Name']; ?></FONT></B></td> </tr> <tr> <td ><?php echo "Creation Date: ".$rowDomain['Creation_Date']; ?></td> <td ><?php echo "Expiration Date: ".$rowDomain['Expiration_Date']; ?></td> <td ><?php echo "Update Date:".$rowDomain['Update_Date']; ?></td> </tr> <tr>

<td colspan="3"><?php echo "Name Server: ".$rowDomain['NameS1']; if($rowDomain['NameS2']!=null) echo ", ".$rowDomain['NameS2']; if($rowDomain['NameS3']!=null) echo ", ".$rowDomain['NameS3']; if($rowDomain['NameS4']!=null) echo ", ".$rowDomain['NameS4']; if($rowDomain['NameS5']!=null) echo ", ".$rowDomain['NameS5']; ?></td>

Page 57: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

47

</tr> <tr>

<td colspan="3"><?php echo "Domain Status: ".$rowDomain['DomainS1']; if($rowDomain['DomainS2']!=null) echo ", ".$rowDomain['DomainS2']; if($rowDomain['DomainS3']!=null) echo ", ".$rowDomain['DomainS3']; if($rowDomain['DomainS4']!=null) echo ", ".$rowDomain['DomainS4']; ?></td> </tr> </table> <br> <table align="center" width="1000" > <tr> <td colspan="3"><B><FONT SIZE=3>REGISTRAR</FONT></B></td> </tr> <tr> <td colspan="1"><?php echo "Name:".$rowRegr['Registrar_Name'];?></td> <td colspan="1"><?php echo "URL:".$rowRegr['Registrar_URL'];?></td> <td colspan="1"><?php echo "Server:".$rowRegr['Registrar_Whois_Server'];

?></td> </tr> <tr> <td colspan="1"><?php echo "Email:".$rowRegr['Registrar_Ab_Contact_Email']; ?></td> <td colspan="1"><?php echo "Phone:".$rowRegr['Registrar_Ab_Contact_Phone']; ?></td> <tr> </table> <br> <table align="center" width="1000" > <tr> <td colspan="3"><B><FONT SIZE=3>REGISTRANT</FONT></B></td> </tr> <tr>

Page 58: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

48

<td colspan="3"><?php echo "Name:".$rowRegt['Reg_Name'];?></td> </tr> <tr> <td colspan="3"><?php echo "Organization:".$rowRegt['Reg_Org'];?></td> </tr> <tr> <td colspan="3"><?php echo "Address:".$rowRegt['Reg_Street1']; if($rowRegt['Reg_Street2']!=null) echo " ".$rowRegt['Reg_Street2']; if($rowRegt['Reg_City']!=null) echo " ".$rowRegt['Reg_City']; if($rowRegt['Reg_State_Province']!=null) echo " ".$rowRegt['Reg_State_Province']; if($rowRegt['Reg_Postal_Code']!=null) echo " ".$rowRegt['Reg_Postal_Code']; if($rowRegt['Reg_Country']!=null) echo " ".$rowRegt['Reg_Country']; ?></td> </tr> <tr> <td colspan="1"><?php echo "Email:".$rowRegt['Reg_Email'];?></td> <td colspan="1"><?php echo "Phone:".$rowRegt['Reg_Phone'];

if($rowRegt['Reg_Phone_Ext']!=null) echo " Ext. ".$rowRegt['Reg_Phone_Ext'];?></td> <td colspan="1"><?php echo "Fax:".$rowRegt['Reg_Fax']; if($rowRegt['Reg_Fax_Ext']!=null) echo " Ext. ".$rowRegt['Reg_Fax_Ext'];?></td> </tr> </table> // part nmap <?php

$protocal=""; $port_id=""; $state="";

Page 59: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

49

$service_name=""; $service_product=""; $service_version=""; $service_extrainfo=""; $service_os_type="";

//command nmap

$file="/var/www/collectip/$ip.xml"; $cmd1="/usr/local/bin/nmap -A -T4 $ip -oX $file"; //run command nmap

shell_exec("$cmd1"); $xml_load=simplexml_load_file($file); $i=1; foreach($xml_load as $a) {

if($i==4) { $num_port=sizeof($a->ports->port);

for($j=0;$j<$num_port;$j++) { $protocal=$a->ports->port[$j][protocol]; $port_id=$a->ports->port[$j][portid]; $state=$a->ports->port[$j]->state[state]; $service_name=$a->ports->port[$j]->service[name]; $service_product=$a->ports->port[$j]->service[product]; $service_version=$a->ports->port[$j]->service[version]; $service_extrainfo=$a->ports->port[$j]->service[extrainfo]; $service_ostype=$a->ports->port[$j]->service[ostype]; //insert into table nmap info include("connectdbnmap.php"); $sql_insert_nmap_info="INSERT INTO nmap_info(Portnumber,Protocal,State,Service_name,Service_product,Service_version,Service_extra_info,Service_os_type,hostname,User_viewdate)VALUES('$port_id','$protoc

Page 60: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

50

al','$state','$service_name','$service_product','$service_version','$service_extrainfo','$service_ostype','$namedomain',NOW())"; $query_insert_nmap_info=mysql_query($sql_insert_nmap_info); } } $i++;

} // show data nmap in table <table width="1000" border="1" align="center" name="table2"> <tr> <th width="10%">Date</th> <th width="6%">Port</th> <th width="8%">State</th> <th width="17%">Service name</th> <th width="17%">Service product</th> <th width="17%">Service version</th> <th width="17%">Service extra info</th> <th width="8%">OS type</th> </tr> <?php

include("connectdbnmap.php"); $datestart=$dateend=date('y-m-d'); $websitename=$_POST['domainname']; $sql_select_webname="SELECT DISTINCT User_viewdate,Portnumber,State,Service_name,Service_product,Service_version,Service_extra_info,Service_os_type FROM nmap_info WHERE hostname='$websitename'AND User_viewdate BETWEEN '$datestart' AND '$dateend' ORDER By User_viewdate,Portnumber"; $query_nmap=mysql_query($sql_select_webname); $numrow=mysql_num_rows($query_nmap);

Page 61: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

51

for($i=0;$i<$numrow;$i++) { $row_nmap=mysql_fetch_array($query_nmap); ?> <tr> <td ><?=$row_nmap['User_viewdate'];?></td> <td ><?=$row_nmap['Portnumber'];?></td> <td ><?=$row_nmap['State'];?></td> <td ><?=$row_nmap['Service_name'];?></td> <td ><?=$row_nmap['Service_product'];?></td> <td ><?=$row_nmap['Service_version'];?></td> <td ><?=$row_nmap['Service_extra_info'];?></td> <td ><?=$row_nmap['Service_os_type'];?></td> </tr> <?php } ?> </table> <a href="domainname3.php" align="center">Home</a> </form> </body> </html>

Page 62: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

52

ภาคผนวก ค Source code หนา newhistory.php

Page 63: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

53

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="newhistory.php" method="post" name="history"> <table width="800" border="0" align="center" name="table1"> <tr> <td width="40%" >Website Name:<input name="websitename" type="text" value=""/></td> <?php $d=date('d'); $m=date('m'); $y="20".date('y'); ?> <td> Date : dd<input name="daystart" type="text" style="width:15px" maxlength="2" value="<?php echo $d?>"/> /mm<input name="monthstart" type="text" style="width:15px" maxlength="2" value="<?php echo $m?>"/> /yyyy<input name="yearstart" type="text" style="width:30px" maxlength="4" value="<?php echo $y?>"/> to : dd<input name="dayend" type="text" style="width:15px" maxlength="2" value="<?php echo $d?>"/> /mm<input name="monthend" type="text" style="width:15px" maxlength="2" value="<?php echo $m?>"/> /yyyy<input name="yearend" type="text" style="width:30px" maxlength="4" value="<?php echo $y?>"/> <input name="submit" type="submit" value="submit"/></td> </tr> </table> <table align="center" >

Page 64: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

54

<tr align="center"> <td align="center" > ****************************************************************** </td></tr> </table> <?php $websitename=$_POST['websitename']; $daystart=$_POST['daystart']; $monthstart=$_POST['monthstart']; $yearstart=$_POST['yearstart']; $datestart=$yearstart."-".$monthstart."-".$daystart; $dayend=$_POST['dayend']; $monthend=$_POST['monthend']; $yearend=$_POST['yearend']; $dateend=$yearend."-".$monthend."-".$dayend;

include("connectdbwhois.php"); //New Select $Domain_Name=trim($websitename,"www."); $Domain_Name=" ".strtoupper($Domain_Name); $sql="select * from Domain_info where Domain_Name='$Domain_Name'"; $queryDomain=mysql_query($sql); $rowDomain=mysql_fetch_array($queryDomain); $find=$rowDomain['Reg_Name']; $sql="select * from Registrant where Reg_Name='$find'"; $queryRegt=mysql_query($sql); $find=$rowDomain['Registrar_Whois_Server']; $find1=$rowDomain['Registrar_Name']; $sql="select * from Registrar where Registrar_Whois_Server='$find' and Registrar_Name='$find1'"; $queryRegr=mysql_query($sql); $rowRegt=mysql_fetch_array($queryRegt); $rowRegr=mysql_fetch_array($queryRegr); ?> <table align="center" width="1000" >

Page 65: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

55

<tr> <td align="center" colspan="3"><B><FONT SIZE=8> <?php echo $rowDomain['Domain_Name'];?></FONT></B></td> </tr> <tr> <td > <?php echo "Creation Date: ".$rowDomain['Creation_Date']; ?></td> <td ><?php echo "Expiration Date: ".$rowDomain['Expiration_Date'];?></td> <td ><?php echo "Update Date:".$rowDomain['Update_Date'];?></td> </tr> <tr> <td colspan="3"><?php echo "Name Server: ".$rowDomain['NameS1']; if($rowDomain['NameS2']!=null) echo ", ".$rowDomain['NameS2']; if($rowDomain['NameS3']!=null) echo ", ".$rowDomain['NameS3']; if($rowDomain['NameS4']!=null) echo ", ".$rowDomain['NameS4']; if($rowDomain['NameS5']!=null) echo ", ".$rowDomain['NameS5']; ?></td> </tr> <tr> <td colspan="3"><?php echo "Domain Status: ".$rowDomain['DomainS1']; if($rowDomain['DomainS2']!=null) echo ", ".$rowDomain['DomainS2']; if($rowDomain['DomainS3']!=null) echo ", ".$rowDomain['DomainS3']; if($rowDomain['DomainS4']!=null) echo ", ".$rowDomain['DomainS4']; ?></td> </tr> </table> <br> <table align="center" width="1000" > <tr> <td colspan="3"><B><FONT SIZE=3>REGISTRAR</FONT></B></td> </tr>

Page 66: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

56

<tr> <td colspan="1"><?php echo "Name:".$rowRegr['Registrar_Name'];?></td> <td colspan="1"><?php echo "URL:".$rowRegr['Registrar_URL'];?></td> <td colspan="1"><?php echo "Server:".$rowRegr['Registrar_Whois_Server']; ?></td> </tr> <tr> <td colspan="1"><?php echo "Email:".$rowRegr['Registrar_Ab_Contact_Email']; ?></td> <td colspan="1"><?php echo "Phone:".$rowRegr['Registrar_Ab_Contact_Phone']; ?></td> <tr> </table> <br> <table align="center" width="1000" > <tr> <td colspan="3"><B><FONT SIZE=3>REGISTRANT</FONT></B></td> </tr> <tr> <td colspan="3"><?php echo "Name:".$rowRegt['Reg_Name'];?></td> </tr> <tr> <td colspan="3"><?php echo "Organization:".$rowRegt['Reg_Org'];?></td> </tr> <tr> <td colspan="3"><?php echo "Address:".$rowRegt['Reg_Street1']; if($rowRegt['Reg_Street2']!=null) echo " ".$rowRegt['Reg_Street2']; if($rowRegt['Reg_City']!=null) echo " ".$rowRegt['Reg_City']; if($rowRegt['Reg_State_Province']!=null) echo " ".$rowRegt['Reg_State_Province']; if($rowRegt['Reg_Postal_Code']!=null) echo " ".$rowRegt['Reg_Postal_Code'];

Page 67: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

57

if($rowRegt['Reg_Country']!=null) echo " ".$rowRegt['Reg_Country']; ?></td> </tr> <tr> <td colspan="1"><?php echo "Email:".$rowRegt['Reg_Email']; ?></td> <td colspan="1"><?php echo "Phone:".$rowRegt['Reg_Phone']; if($rowRegt['Reg_Phone_Ext']!=null) echo " Ext. ".$rowRegt['Reg_Phone_Ext']; ?></td> <td colspan="1"><?php echo "Fax:".$rowRegt['Reg_Fax']; if($rowRegt['Reg_Fax_Ext']!=null) echo " Ext. ".$rowRegt['Reg_Fax_Ext'];?></td> </tr> </table> <?php //show nmap ?> <table width="1000" border="1" align="center" name="table2"> <tr> <th width="10%">Date</th> <th width="6%">Port</th> <th width="8%">State</th> <th width="17%">Service name</th> <th width="17%">Service product</th> <th width="17%">Service version</th> <th width="17%">Service extra info</th> <th width="8%">OS type</th> </tr> <?php include("connectdbnmap.php"); $sql_select_webname="SELECT DISTINCT User_viewdate,Portnumber,State,Service_name,Service_product,Service_version,Servic

Page 68: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

58

e_extra_info,Service_os_type FROM nmap_info WHERE hostname='$websitename'AND User_viewdate BETWEEN '$datestart' AND '$dateend' ORDER By User_viewdate,Portnumber"; //echo $sql_select_webname."\n"; $query_nmap=mysql_query($sql_select_webname); $numrow=mysql_num_rows($query_nmap); for($i=0;$i<$numrow;$i++) { $row_nmap=mysql_fetch_array($query_nmap); ?> <tr> <td ><?=$row_nmap['User_viewdate'];?></td> <td ><?=$row_nmap['Portnumber'];?></td> <td ><?=$row_nmap['State'];?></td> <td ><?=$row_nmap['Service_name'];?></td> <td ><?=$row_nmap['Service_product'];?></td> <td ><?=$row_nmap['Service_version'];?></td> <td ><?=$row_nmap['Service_extra_info'];?></td> <td ><?=$row_nmap['Service_os_type'];?></td> </tr> <?php } ?> </table> </form> <a href="domainname3.php">Home</a> </body> </html>

Page 69: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

59

ภาคผนวก ง Source code หนา connectdbnmap.php

Page 70: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

60

<?php $conn2=mysql_connect("localhost","root","toor")or die("cannot connect mysql"); $db2=mysql_select_db("nmap") or die("cannot select db"); ?>

Page 71: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

61

ภาคผนวก จ Source code หนา connectdbwhois.php

Page 72: Information Gathering System for Penetration Testing ระบบเก็บ... · II Project title Information Gathering System for Penetration Testing Student Mr. Pattara Boromtanarat

62

<?php

$conn=mysql_connect("localhost","root","toor")or die("cannot connect mysql"); $db=mysql_select_db("whois")or die("cannot select db");

?>