Archive for Dev. (junyup2)

์ง€์‹์„ ์ฑ„์›Œ๊ฐ€๋Š” ใ€Ž๊ฐœ๋ฐœ์ž/ํ™”์ดํŠธํ•ด์ปคใ€๋ฅผ ๋ชฉํ‘œ๋กœ ์ •๋ฆฌํ•˜๋Š” ๋ธ”๋กœ๊ทธ

Practice/DVWA

[DVWA] Windows ํ™˜๊ฒฝ Docker๋ฅผ ์ด์šฉํ•œ DVWA์„ธํŒ…

Gearvirus(junyup2) 2024. 4. 7. 22:59

Windows ํ™˜๊ฒฝ Docker๋ฅผ ์ด์šฉํ•œ DVWA์„ธํŒ…

1. Docker & DVWA ์„ค์น˜

WSL ์„ค์น˜

Windows 10 ํ™˜๊ฒฝ์—์„œ Docker๋Š” Hyper-V ๋˜๋Š” WSL(Windows Subsystem for Linux)์„ ์ด์šฉํ•˜์—ฌ ๊ตฌ๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.
ํ•˜์ง€๋งŒ Hyper-V๋ฅผ ์ด์šฉํ•œ ๋ฐฉ์‹์€ Windows 10 Pro ๋ฒ„์ „์—์„œ๋งŒ ๊ฐ€๋Šฅํ•˜๊ณ  Home ๋ฒ„์ „์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค.
(๋˜ํ•œ WSL์„ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•๋ณด๋‹ค ๋ถˆ์•ˆ์ •ํ•˜๋‹ค๋Š” ํ‰๊ฐ€๊ฐ€ ์žˆ์–ด์„œ ์ฃผ๋กœ WSL์„ ์ด์šฉํ•˜์—ฌ ๊ตฌ๋™ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.)

WSL ์„ค์น˜๋ฅผ ์œ„ํ•ด cmd ์ฐฝ์„ ์—ด์–ด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

wsl --install --web-download

์œ„์˜ ๋ช…๋ น์–ด๊ฐ€ ์ž˜ ์‹คํ–‰๋˜์—ˆ์„ ๊ฒฝ์šฐ, Windows Subsystem for Linux๊ฐ€ ์„ค์น˜๋˜์—ˆ๋‹ค๋Š” ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ ๊ธฐ๋ณธ์ ์œผ๋กœ Unbuntu๊ฐ€ ์„ค์น˜๋  ๊ฒƒ์ด๋‹ค. (๊ทธ ํ›„ ์žฌ๋ถ€ํŒ…์„ ํ•ด์•ผ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋œ๋‹ค.)

 

Docker ์„ค์น˜

์•„๋ž˜์˜ ๋งํฌ์—์„œ Dcoker ์„ค์น˜ ํŒŒ์ผ์„ Windows ์šฉ์œผ๋กœ ๋‹ค์šด ๋ฐ›๋Š”๋‹ค.

https://www.docker.com/products/docker-desktop/

 

DVWA ๊ตฌ๋™

Docker๊ฐ€ ์„ค์น˜๋œ ์ƒํƒœ์—์„œ DVWA ์ด๋ฏธ์ง€๋ฅผ ๊ตฌ๋™ํ•˜๊ธฐ ์œ„ํ•ด cmd ์ฐฝ์— ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

docker run --rm -it -p 80:80 vulnerables/web-dvwa

๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰๋˜๋ฉด ์ด๋ฏธ์ง€๋ฅผ ํ•˜๋‚˜ ๊ฐ€์ ธ์˜ค๊ณ , ์›น ์„œ๋ฒ„์˜ ๋กœ๊ทธ๊ฐ€ ํ‘œ์‹œ๋˜๊ธฐ ์‹œ์ž‘ํ•œ๋‹ค.

๊ตฌ๋™ ์ƒํƒœ๋Š” Docker GUI ํŒจ๋„์ด๋‚˜, cmd ์ฐฝ์—์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋กœ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.

docker ps

์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ง์ ‘ ์ ‘์†๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

docker exec -it CONTAINER_ID /bin/bash

์œ„์™€ ๊ฐ™์ด ๊ตฌ๋™์ด ์ž˜ ๋œ ์ƒํƒœ์—์„œ ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์‹คํ–‰ํ•œ ํ›„ ์ฃผ์†Œ์ฐฝ์— localhost:80์„ ์ž…๋ ฅํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŽ˜์ด์ง€๊ฐ€ ๋‚˜์˜จ๋‹ค.

DVWA๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ธฐ๋ณธ ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ ํ•œ ํ›„ ์ง„ํ–‰ํ•œ๋‹ค.

admin / password

๋กœ๊ทธ์ธํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด ๋‚˜์˜ค๊ฒŒ ๋˜๋Š”๋ฐ Create / Reset Database ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹ค์Šตํ•  ์ˆ˜ ์žˆ๋Š” ์„น์…˜์ด ์ƒ๊ธฐ๋ฉฐ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋œ๋‹ค.

 

2. DVWA ์„ค์ • ๋ฐ ์ด๋ฏธ์ง€(patched) ์ €์žฅ

Setup์— ๋“ค์–ด๊ฐ€๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฐฝ์ด ๋‚˜์˜จ๋‹ค.

์œ„์—์„œ ๋ณด๋ฉด ์„ค์น˜ ์งํ›„์˜ DVWA๋Š” ๋‹ค์Œ์˜ ๋‘ ๊ฐ€์ง€ ๊ธฐ๋Šฅ  PHP function allow_url_include: Disabled , reCAPTCHA key: Missing ์ด ๋น„ํ™œ์„ฑํ™” ๋˜์–ด ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•˜์—ฌ ํ™œ์„ฑํ™” ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ณ  ์ด ์ž‘์—… ๋‚ด์—ญ์„ ์ €์žฅํ•ด๋ณด๋ ค ํ•œ๋‹ค.

 

PHP allow_url_include ํ™œ์„ฑํ™”

PHP ์„ค์ •์„ ์ˆ˜์ •ํ•˜๊ธฐ ์œ„ํ•ด cmd ์ฐฝ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Docker ์ด๋ฏธ์ง€ ๋‚ด์˜ ํŒŒ์ผ์„ Host PC๋กœ ๊ฐ€์ ธ์˜จ๋‹ค.

docker cp CONTAINER_ID:/etc/php/7.0/apache2/php.ini .

php.ini ํŒŒ์ผ์„ ํ˜„์žฌ ์œ„์น˜์— ๋ณต์‚ฌํ•˜์—ฌ ๋ฉ”๋ชจ์žฅ์—์„œ ์ˆ˜์ • ํ›„ ๋‹ค์‹œ ๋ถ™์—ฌ๋„ฃ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ •ํ•œ๋‹ค.

(์ง์ ‘ ์ ‘์†ํ•˜์—ฌ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ๋‚ด๋ถ€์— vi๊ฐ™์€ ๋ฌธ์„œ ํŽธ์ง‘๊ธฐ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.)

์œ„์™€ ๊ฐ™์ด allow_url_include ํ•ญ๋ชฉ์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ Off๋กœ ์„ค์ •๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ On์œผ๋กœ ์ˆ˜์ • ํ›„ ์ €์žฅํ•œ๋‹ค.

๊ทธ ํ›„ cmd ์ฐฝ์—์„œ docker cp ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํŒŒ์ผ์„ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•œ ํ›„ ์ง์ ‘ ์ ‘์†ํ•˜์—ฌ ์‰˜์—์„œ apache๋ฅผ ์žฌ์‹œ์ž‘ํ•œ๋‹ค.

docker cp php.ini CONTAINER_ID:/etc/php/7.0/apache2/php.ini
docker exec -it CONTAINER_ID bash

# service apache restart

๊ทธ ํ›„ DVWA์— ๋‹ค์‹œ ์ ‘์†ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด allow_url_include๊ฐ€ ํ™œ์„ฑํ™”๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

reCAPTCHA ํ™œ์„ฑํ™”

๋‹ค์Œ ๋งํฌ์— ์ ‘์†ํ•œ๋‹ค.

https://www.google.com/recaptcha/admin/create

์‚ฌ์ดํŠธ์—์„œ ์œ„์™€๊ฐ™์ด ์„ค์ •ํ•˜์—ฌ ์ƒ์„ฑํ•ด์ค€๋‹ค.

๋„๋ฉ”์ธ์— localhost๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์–ด์•ผ localhost ๋„๋ฉ”์ธ์—์„œ ์ž‘๋™ํ•œ๋‹ค.

์„ค์ •์„ ์™„๋ฃŒํ–ˆ๋‹ค๋ฉด ๊ณต๊ฐœํ‚ค(์‚ฌ์ดํŠธํ‚ค)์™€ ๋น„๋ฐ€ํ‚ค๊ฐ€ ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง€๊ฒŒ ๋œ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์„ค์ •ํŒŒ์ผ์„ ๋ณต์‚ฌํ•ด์™€์„œ ๊ณต๊ฐœํ‚ค์™€ ๋น„๋ฐ€ํ‚ค๋ฅผ ์ž…๋ ฅํ•ด์ค€ ๋’ค ์ €์žฅํ•˜๊ณ  docker cp๋ช…๋ น์–ด๋กœ ๋‹ค์‹œ ๋ถ™์—ฌ๋„ฃ์–ด์ค€๋‹ค.

docker cp CONTAINER_ID:/var/www/html/config/config.inc.php .

docker cp config.inc.php CONTAINER_ID:/var/www/html/config/config.inc.php

์„ค์ • ์™„๋ฃŒ ํ›„ DVWA์— ์žฌ์ ‘์†ํ•˜๋ฉด reCAPTCHA key๊ฐ€ ์ž‘์„ฑ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์œ„์™€ ๊ฐ™์ด CAPTCHA๊ฐ€ ์ž‘๋™ํ•˜๋Š” ๊ฒƒ๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Patched ๋ฒ„์ „์œผ๋กœ ์ด๋ฏธ์ง€ ์ €์žฅ

์œ„์˜ ์ž‘์—…์„ ๋ณ„๋„์˜ ์ด๋ฏธ์ง€๋กœ ์ €์žฅํ•˜์—ฌ, ์ถ”ํ›„ ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜๊ธฐ์œ„ํ•ด cmd ์ฐฝ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

docker commit CONTAINER_ID vulnerables/web-dvwa:patched
docker images

์œ„์™€ ๊ฐ™์ด TAG๊ฐ€ patched๋กœ ๋ณ€๊ฒฝ๋œ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜์žˆ๋‹ค.

ํ•ด๋‹น ๋ฒ„์ „์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

docker run --rm -it -d -p 127.0.0.1:80:80 vulnerables/web-dvwa:patched

์งˆ๋ฌธ ํ™˜์˜, ์ˆ˜์ • ๋ฐ ๋ณด์™„์— ๋Œ€ํ•œ ์ง€์  ํ™˜์˜