How to securing website from common attacks
Bonus: Learn how to hack
CIA Triad, Foundation of Information Security:
Protecting sensitive information from unauthorized access.
Ensuring data accuracy and preventing unauthorized modification.
Ensuring systems and data are accessible.
SQL Injection: Break Confidentiality
Regular Expression DoS: lead to break system Availability
Broken Access Control: Break Data Integrity
Is not just about writing good code, it's about making responsible choices.
Any information that can identify an individual, either directly or in combination with other data, it's called PII (Personally Identifiable Information)
As a Developer, it's your responsibility to protect user data. Follow Regulatory Compliance: PDP (Indonesia), GDPR (EU), CCPA (California)
Validate each field
Set min/max value for number
Limit maximum item displayed in a page
Validate URL on redirect parameter
Validate URL to prevent SSRF
No Hardcoded Secrets, Use System Variables
User query builder / binding to prevent SQLi
Secure Error Handling in Production Mode
Mask Sensitive data in Log
Don’t Use Too Many External Libraries
Gitlab/Github Remote Access & integration:
Use SSH instead of HTTP
Use API token instead of your password
Limit remote scope
Gitlab/Github Use protected branch for production
Prevent direct push
GIT is store all history, don't commit sensitive information
Use system variables / .env instead of hardcoded credentials
Ignore .env, just give the sample values
Accessing Deleted Fork Data
Accessing Deleted Repo Data
Never commit or publish credentials to github, even in private repositories.
https://trufflesecurity.com/blog/anyone-can-access-deleted-and-private-repo-data-githubUse well-known base image, because it can contain malware [Link]
Use .dockerignore to:
Reduce context size & image size
Exclude .git directory
Exclude credentials file (.env)
Set correct user for running web process
Set correct permission, limit writable directory
PHP Laravel/CI: Limit php executable only to “index.php” to prevent webshell
Set correct user & permission, make only upload directory thats writable
Use HTTPS, auto redirect HTTP to HTTPS
Block known sensitive URL: .git, .env, logs, backup
Use robots.txt to prevent indexes on staging site / admin dashboard
Disable debug/error information on production
Remove server information header
Use Web Application Firewall
Use cookie instead of local storage to store credentials
Limit login attempt and OTP requests
Use captcha on login/reset password for public system
Disable sourcemap on production site
Use CSP header to prevent XSS
Use X-Frame-Options header to prevent Clickjacking
In this slide website, there are some mistakes in the development.
Instead of finding credentials like username or password, you must find the FLAG (SHA1 hash).
Example Flag:
FLAG-DEADBEEF00CFC9292AADB5842171863B6053B523
There's 3 Flags.
The sourcemap is enabled in production mode build
The GIT dir is exposed
Using chrome devtools to inspect
Clone the exposed /.git
dir using: https://github.com/arthaud/git-dumper
git clone https://github.com/arthaud/git-dumper
python -m venv venv
. ./venv/bin/activate
pip install -r requirements.txt
./git_dumper.py https://secure-web.dev.otesuto.com/ ../output
cd ../output
Walkthrough GIT histories:
clone https://github.com/gitleaks/gitleaks.git
cd gitleaks
make build
./gitleaks git -v ../output
Configuring GitLeaks to find specific credentials.
# Filename: gitleaks.toml
title = "Gitleaks FLAG finder"
useDefault = true
[[rules]]
id = "flag"
regex = '''FLAG-[a-zA-Z0-9]+'''
./gitleaks git -c ../gitleaks.toml -v ../output