Secure Code Review
Secure Code Review
Hello!
I am MinhTC
I am here because I “Phải đi làm”.
ROADMAP
1 2 3
01
Basic knowledge
Basic knowledge about Secure Code Review
Main contents
● Process
● Development
● Vulnerability
Như thế nào là một phần mềm an toàn?
“Một phần mềm an toàn là một phần
mềm chỉ thực hiện đúng các chức
năng mà nó được tạo ra.”
—I don’t know
Secure Code Review là gì?
“Là quá trình đánh giá mã nguồn dựa
trên một tiêu chuẩn nhất định với
mục đích tìm ra các điểm yếu bảo
mật và làm cho phần mềm an toàn.”
—I don’t know
Tell
Me
Why?
Why do you need SCR?
Prevention is better
than cure
Where and
When?
Where (When) is Secure
Code Review used?
Secure – SDLC Microsoft
Secure – SDLC OWASP
Secure – SDLC
Sources
and
Sinks
What are Sources and Sinks?
Sources and Sinks
Sources Sinks
Là những điểm tiếp nhận dữ Là các điểm thực thi dữ liệu từ
liệu từ bên ngoài Sources và có thể gây ra lỗi
Sources and Sinks
Based on Form
Automated Testing Manual Testing Hybrid Testing
● Sources, Sinks
● Sources, Sinks, Configs
● Knowledge vulnerability
● Checklist
● Coding
● Coding
● Regex
● Knowledge vulnerability
● Debug
● Regex
● Fuzzing
● Reverse
Audit Code
Sources
Config
Find vulnerability
Sources
Sinks
Implement
Definition Purpose
A regular expression (shortened as Search Sinks
regex) sometimes referred to as Search Sources
rational expression is a sequence Search every things you want
of characters that specifies a
match pattern in text.
Regex Basic
Regex Basic
Regex Example
Pattern: .*exec.*\)
Regex Example
Pattern: .*exec.*\)
Regex Example
Pattern: ^(?:(?!\/\/).)*exec(?:(?!\/\/).)*$
Regex Practice
Pattern: "(select|update|insert).*\+.*;$
ASVS Checklist
Content
● Architecture ● Data Protection
● Authentication ● Communication Security
● Session Management ● Malicious Code
● Access Control ● Business Logic
● Input Validation ● Files and Resources
● Cryptography at Rest ● Web Services
● Error Handling and Logging ● Configuration
ASVS Checklist
02
Process
Process Secure Code Review
Process
Prepare Threat modeling Report, Document
Communication, Document, Vulnerability
Important assets, Context Checklist
Common Weakness
Design document
Technical document
Instruction document
Sources: request.getParameter(),
getText(), getHeader(), RequestParam …
Pattern Database
Crawling Code - Webgoat
● Sinks: .exec(), Runtime(), executeQuery(), System.out, ${}, JWT,
login, password, username, Session
● Sources: request.getParameter(), getText(), getHeader() …
● Config Files: Application.property ..
● Use Regex for Search
Automated SCR
2 NodeJS check-dependencies
○ Programing (Multi)
○ Policy Scan
● Rules
○ Customize Rules
Manual SCR - Method
Input Execute
Analysis Result
Data Flow, Control Flow, Vulnerability, Report
Database Source Code (CodeQL CLI)
(CodeQL CLI)
Install JDK
Install JDK
Edit Environment Variable
New
Install JDK
Variable name: JAVA_HOME
Variable value: Browse to JDK
folder
Install JDK
Double Click to “Path”
New
Install JDK
Type: %JAVA_HOME%\bin
OK
Install JDK
Run Cmd and Type “Java -
version” to check
Extra CodeQL
Bundle
Click Righ Mouse file
CodeqlBundle.zip Extract
here
Environment
CodeQL
Bundle
Edit Environment Variable
New Double Click to “Path”
New Browse (to Folder
CodeQL)
Test CodeQL
Open CMD and run “codeql”
Install MVN
Extract mvn.zip
Add MVN to
Environment
Double Click to “Path”
New Browse mvn-
folder/bin
Test MVN
Open CMD and run “mvn -h”
CodeQL &
WebGoat
run “cmd” In Folder Webgoat
and run command “codeql
database create webgoat-
database-code --
language=java
”
CodeQL &
WebGoat
After that, Codeql creats a
folder name “wg-database”.
This folder contains source-
code database of webgoat
app
Execute
Run command “codeql
database analyze webgoat-
database-code
/opt/codeql/qlpacks/codeql/jav
a-queries/1.0.0/Security/CWE --
format=csv --output=result.csv
”
Result
File result.csv
Dependence
Check
Extracting DC and
Copies
Webgoat.jar to
folder /bin of DC
folder
Dependence
Check
Run cmd in DC/bin folder and
run command “dependency-
check.bat --out . --scan
webgoat-2023.4.jar”
Result
dependency-check-report.html
JDGUI
Extract JDGUI.zip and Run it
JDGUI
Drap and Drop file Webgoat.jar
to JDGUI
dnSpy
Extract dnSpy.zip and Run
dnSpy.exe
dnSpy
Drag and Drop
“AppConsole1.exe” to dnSpy
Thanks!
Do you have any questions?
[email protected]