-
[Web Hacking] Portswigger - SQL injection UNION attack, retrieving data from other tablesCoding/Hacking & Security 2023. 1. 23. 16:16
문제 링크 : https://portswigger.net/web-security/sql-injection/union-attacks/lab-retrieve-data-from-other-tables
Lab: SQL injection UNION attack, retrieving data from other tables | Web Security Academy
This lab contains an SQL injection vulnerability in the product category filter. The results from the query are returned in the application's response, so ...
portswigger.net
UNION attack을 통해 admin 계정의 비밀번호를 알아내어보자.
문제 분석
문제 사이트의 product category filter에 SQL injection이 가능하다고 한다.
'Gift' category를 선택하면 Gift에 해당하는 상품만 표시된다.
위의 URL에서 확인할 수 있듯, category filter의 parameter는 GET method를 통해 전달된다.
따라서 parameter에 적당한 query를 추가하는 방법으로 SQL injection을 시도할 수 있을 것이다.
목표
UNION attack을 사용하여 administrator 계정의 비밀번호를 알아내어보자.
이를 위해서는 우선 table의 column 개수를 알아내어야 한다.
그리고 user table에서 username과 password를 select하여 product와 UNION 구문으로 합칠 수 있을 것이다.
이를 이용해 user table의 administrator 계정이 product와 함께 화면에 출력되도록 해보자.
풀이
우선 table의 column 개수를 알아내어보자.
UNION 구문을 사용하기 위해서는 select한 값들의 개수가 동일해야만 하기 때문이다.
UNION SELECT NULL-- UNION SELECT NULL,NULL-- UNION SELECT NULL,NULL,NULL--
이런 식으로 NULL 값을 하나씩 추가해주면서 오류가 발생하지 않을 때 까지 반복하면 column의 개수를 알아낼 수 있다.
이 구문을 이용해 SQL injection을 시도하였다.
URL의 parameter 뒤에 따옴표 하나와 함께 위의 구문을 추가하고 결과를 확인해보았다.
그 결과, 위의 URL과 같이 NULL이 두 개일 때 정상적인 화면이 출력되었다.
따라서 table의 column이 두 개임을 확인할 수 있었다.
이제 아래의 query를 이용해 username과 password를 users table에서 선택하고 출력되게 할 수 있을 것이다.
UNION SELECT username,password FROM users WHERE username='administrator'--
Parameter로 위의 query를 포함한 결과이다.
이를 실행한 결과, product와 함께 administrator 계정의 password가 화면에 출력되었다.
'Coding > Hacking & Security' 카테고리의 다른 글