บทนำ (Overview)
บทความนี้นำเสนอตัวอย่างการใช้งานโปรแกรม SonarQube สำหรับ Scan ช่องโหว่ของโปรแกรมที่เขียนโดยภาษา PHP
บทนำ (Steps)
- ติดตั้ง SonarQube จากบทความ How to setup SonarQube on MacOS
- เปิด Service SonarQube
//SonarQube //เริ่มต้น sonar start //หยุดการใช้งาน sonar stop //หรือเข้าไป Run Scrip ที่ /usr/local/Cellar/sonarqube/6.6/libexec/bin/macosx-universal-64 //MySQL //สำหรับ Start mysql.server start //สำหรับ Stop mysql.server stop //สำหรับ Restart mysql.server restart
- พอ Start service ของ SonarQube แล้ว สามารถใช้งานผ่าน Web browser ได้ดังนี้ http://localhost:9000
- สามารถ Login โดยใช้
user:admin pass:admin
- เมื่อ Login สำเร็จไปที่มุมขวาบน แล้วไปที่ My Account
- กรอก ชื่อ Token Name แล้วกดปุ่ม Generate
- ดาวน์โหลด Sourcecode PHP ที่มีช่องโหว่ http://www.dvwa.co.uk
- สร้างไฟล์ชื่อ sonar-project.properties และนำไปใส่ในโฟลเดอร์ของ Source code แล้วตั้งชื่อ Key ให้ตรงกับที่เรากำหนด
# must be unique in a given SonarQube instance sonar.projectKey=DVWA # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=DVWA sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. sonar.sources=. # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8
- จากนั้นใช้ Terminal เข้าไปยัง Folder ที่มี ไฟล์ sonar-project.properties และ ใช้คำสั่ง
sonar-scanner
- รอจนขึ้น Success
- กลับไปที่ Web browser แล้วไปที่เมนู My account | Projects จะพบผลการ Scan