2023. 10. 11. 13:44ㆍBig data application
1. SQL injection
1.1 개요
- SQL injection이란 악의적인 사용자가 보안상 취약점을 이용하여 임의의 SQL문을 주입하고 실행되게 하여 데이터베이스가 비정상적인 동작을하도록 조작하는 행동
SQL injection examples
There are a wide variety of SQL injection vulnerabilities, attacks, and techniques, which arise in different situations. Some common SQL injection examples include:
- Retrieving hidden data, where you can modify an SQL query to return additional results.
- Subverting application logic, where you can change a query to interfere with the application's logic.
- UNION attacks, where you can retrieve data from different database tables.
- Examining the database, where you can extract information about the version and structure of the database.
- Blind SQL injection, where the results of a query you control are not returned in the application's responses.
1.2 공격 종류 및 방법(Error based SQL injection)
1) ' OR 1=1 --
- SELECT * FROM Users WHERE id=”INPUT1” AND password = ‘INPUT2’

2) Union based SQL Injection
- SQL 에서 Union 키워드는 두 개의 쿼리문에 대한 결과를 통합해서 하나의 테이블로 보여주게 하는 키워드임
- 정상적인 쿼리문에 Union 키워드를 사용하여 인젝션에 성공하면, 원하는 쿼리문을 실행할 수 있을 것이다
- Union Injection을 성공하기 위해서는 두가지 조건이 있음 (데이터 형이 같아야되고, 데이터 컬럼 수가 같아야됨)

- 위의 사진에서 보이는 쿼리문은 Board 라는 테이블에서 게시글을 검색하는 쿼리문이다.
- 입력 값을 title과 contents 컬럼의 데이터랑 비교한 뒤 비슷한 글자가 있는 게시글 출력
- 입력 값으로 Union 키워드와 함께 컬럼 수를 맞춰서 SELECT 구문을 넣어주게 되면 두 쿼리문이 합쳐져서 하나의 테이블로 보여지게 됨
- 현재 인젝션 한 구문은 사용자의 id 와 passwd를 요청하는 쿼리문이다.
- 인젝션이 성공하게 되면, 사용자의 개인정보가 게시글과 함께 화면에 보여지게 된다
3) Union based SQL Injection