SQL injection hands-on for CTF beginners: http://beginner-sqli.m1z0r3.ctf.ryotosaito.com/
This repository consists of Laravel, a php framework.
- Docker
- docker-compose
- Nginx (for reverse proxy, optional)
cp .env.example .env
# edit .env
docker-compose build
docker-compose run -v $PWD/.env:/var/www/beginner-sqli/.env score_server php artisan key:generate
docker-compose up
- Laravel 5.6 Requirements
- PHP >= 7.1.3
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
- Ctype PHP Extension
- JSON PHP Extension
- PHP Composer
- FPM PHP Extension
- MySQL Server
- Nginx
Edit my.cnf.
cat << EOF > /etc/my.cnf
[[email protected]]
datadir=/var/lib/mysqld/mysql.7.sqli
socket=/var/lib/mysqld/mysql.7.sqli/mysql.sock
log-error=/var/log/mysqld.7.sqli.log
pid-file=/var/run/mysqld/mysqld.7.sqli.pid
skip-networking
EOF
Prepare directory.
mkdir /var/lib/mysqld/mysql.7.sqli
chown mysql: /var/lib/mysqld/mysql.7.sqli
Run tutorial7 DB (ex. CentOS).
systemctl start [email protected]
systemctl enable [email protected]
If you haven't run MySQL server before, run submission DB (ex. CentOS).
systemctl start mysqld
systemctl enable mysqld
# cd to installation directory
git clone https://github.com/ryotosaito/beginner-sqli.git
cd beginner-sqli
cp .env.example .env
Edit .env APP_*, CHALLENGE_URL, CHALLENGE7_*.
- APP_*
- Flag-submission server
- Challenge_URL
- Problem server
- Challenge7_*
- Only challenge 7 uses MySQL that you have installed. So you must specify MySQL connection information.
Sample .env
APP_NAME="Beginners' SQLi"
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_URL=http://your.submission.server.url
CHALLENGE_URL=http://your.problem.server.url
CHALLENGE7_DSN="mysql:dbname=m1z0r3;unix_socket=/var/lib/mysqld/mysql.7.sqli/mysql.sock"
CHALLENGE7_USERNAME=root
CHALLENGE7_PASSWORD=your_db_password
# This DB (submission DB) is differ from tutorial7 DB.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=beginner_sqli
DB_USERNAME=root
DB_PASSWORD=your_db_password
composer install
php artisan migrate
php artisan db:seed --class=ChallengeSeeder
php artisan key:generate
Example /etc/nginx/nginx.conf
server {
listen 80;
server_name your.problem.server.url;
location / {
root /path/to/beginner-sqli/challenges;
index index.php;
}
location ~ \.php$ {
root /path/to/beginner-sqli/challenges;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/beginner-sqli/challenges/$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.sqlite$ {
deny all;
}
}
See https://laravel.com/docs/5.6/deployment#server-configuration
php-fpm
nginx # or nginx -s reload