본문 바로가기
Computer/Network

[Net-Hack] SQLi?

by Gill Bates 2022. 9. 14.

SQLi

 

SQL Injection이라고도 함.

DB와 연결되어 있는 웹 앱의 동적으로 생기는 구문에다가 입력 값을 조작해 DBMS(Database Management System)가 원하지 않는 값을 반환하게 하는 기법이라고 한다.

 

아래 사례를 보면 섬뜩하기 그지 없다.

의도적으로 입력값에 싱글 쿼트, 더블 대쉬 등을 입력해서 오류를 일으킨 다음 정상적인 SQL statement가 동작하지 못하도록 함으로써 해커가 탈취를 원하는 값을 돌려받는 방식으로 이루어진다.

 

예방책으로는 입력값 검증-특수문자 공백처리-과 Prepared Srtatement -쿼리에 대한 컴파일 미리 수행(비정상적인 입력값에 대응)-  등이 있다.

 

A simple example of SQL injection

Let’s see what an attacker can do with the following simple authentication example:

SELECT * FROM users WHERE user_id = 'id_supplied_by_the_user' AND password = 'password_supplied_by_the_user'

This simple SELECT statement returns all relevant user data if there is a matching ID and password record in the database. This means that if the user provides a valid ID and password, the query might return the first and last name of a user (depending on the schema of the users table). If the user provides an invalid ID and/or password, the query returns an empty data set. A developer might use this simple query to check if the user can log in.

A malicious hacker might provide the following id_supplied_by_the_user value:

admin'--

As a result, the query string sent to the database will become:

SELECT * FROM users WHERE user_id = 'admin'--' AND password = ''

The single quote completes the assignment of user_id and the double dash (–) causes the rest of the SQL statement (i.e. the password check) to be treated as a comment. Therefore, the application executes the following query:

SELECT * FROM users WHERE user_id = 'admin'

If executed, this query represents a successful SQL injection. It returns all user data for admin, potentially allowing the malicious hacker to attain unauthorized access to the application as the administrator.

 

https://www.invicti.com/learn/sql-injection-sqli/

https://medium.com/pocs/sql-injection%EC%9D%B4%EB%9E%80-3b57f2415ef4

 

 

아래는 SQL Injection을 실습해볼 수 있는 예제들이 있다:

https://www.w3schools.com/sql/sql_injection.asp

 

'Computer > Network' 카테고리의 다른 글

[Net-Sec] CAPTCHA?  (0) 2022.09.16
[Net-Sec] Bot 공격이란?  (0) 2022.09.14
[Term] Dump?  (0) 2022.09.14
[Term] SEO?  (0) 2022.09.14
[Net-Sec] DDoS란?  (0) 2022.09.14

댓글