How to scan the source code using SonarQube

บทนำ (Overview)

บทความนี้นำเสนอตัวอย่างการใช้งานโปรแกรม SonarQube สำหรับ Scan ช่องโหว่ของโปรแกรมที่เขียนโดยภาษา PHP

บทนำ (Steps)

  1. ติดตั้ง SonarQube จากบทความ How to setup SonarQube on MacOS
  2. เปิด 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
    

  3. พอ Start service ของ SonarQube แล้ว สามารถใช้งานผ่าน Web browser ได้ดังนี้ http://localhost:9000
  4. สามารถ Login โดยใช้
    user:admin
    pass:admin
    
  5. เมื่อ Login สำเร็จไปที่มุมขวาบน แล้วไปที่ My Account
  6. กรอก ชื่อ Token Name แล้วกดปุ่ม Generate
  7. ดาวน์โหลด Sourcecode PHP ที่มีช่องโหว่ http://www.dvwa.co.uk
  8. สร้างไฟล์ชื่อ 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
    
  9. จากนั้นใช้ Terminal เข้าไปยัง Folder ที่มี ไฟล์ sonar-project.properties และ ใช้คำสั่ง
    sonar-scanner 
    

  10. รอจนขึ้น Success
  11. กลับไปที่ Web browser แล้วไปที่เมนู My account | Projects จะพบผลการ Scan

 

 

ใส่ความเห็น