Skip to content

Latest commit

ย 

History

History
387 lines (309 loc) ยท 13.2 KB

SQL Injection.md

File metadata and controls

387 lines (309 loc) ยท 13.2 KB

1. SQL ์‚ฝ์ž… (SQL Injection)

1) ์ •์˜

์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ, ๊ณต๊ฒฉ์ž๊ฐ€ SQL๋ฌธ์„ ์‚ฝ์ž…ํ•ด DB๋กœ๋ถ€ํ„ฐ ์ •๋ณด ์—ด๋žŒ/์กฐ์ž‘์ด ๊ฐ€๋Šฅํ•ด์ง€๋Š” ๋ณด์•ˆ ์•ฝ์ 


2) ๊ณต๊ฒฉ ํ๋ฆ„๋„

sql ๊ณต๊ฒฉ ํ๋ฆ„๋„
[์ถœ์ฒ˜] JAVA ์‹œํ์–ด์ฝ”๋”ฉ ๊ฐ€์ด๋“œ P.3

  • ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ฐ’์„ ํ•„ํ„ฐ๋ง ์—†์ด ๋„˜๊ฒจ ๋ฐ›์€ ์ทจ์•ฝํ•œ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋™์  ์ฟผ๋ฆฌ(Dynamic Query) ์ƒ์„ฑ
  • ์˜๋„ํ•˜์ง€ ์•Š์€ ์ฟผ๋ฆฌ ์ƒ์„ฑ์œผ๋กœ ์ธํ•œ ์ •๋ณด์œ ์ถœ ๊ฐ€๋Šฅ

3) ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

  • preparedStatement ํด๋ž˜์Šค & ํ•˜์œ„ ๋ฉ”์†Œ๋“œ executeQuery(), execute(), executeUpdate() ์‚ฌ์šฉ
  • ์ž…๋ ฅ๊ฐ’ ํ•„ํ„ฐ๋ง ํ›„ ์‚ฌ์šฉ (ex. SQL ๊ตฌ๋ฌธ ์ œํ•œ, ํŠน์ˆ˜ ๋ฌธ์ž ์ œํ•œ, ๊ธธ์ด ์ œํ•œ ๋“ฑ)

4) ์˜ˆ์ œ [1]

์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ tableName๊ณผ name์˜ ๊ฐ’์„ ๋ฐ›์•„์„œ SQL ์ฟผ๋ฆฌ ์ƒ์„ฑ
name ๊ฐ’์œผ๋กœ name' OR 'a'='a ์ž…๋ ฅํ•ด ์กฐ์ž‘๋œ ์ฟผ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฌธ์ž์—ด ์ „๋‹ฌ


์•ˆ์ „ํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ(java) :
tablename๊ณผ name์— ๋Œ€ํ•œ ๊ฒ€์ฆ ์ˆ˜ํ–‰ X

PreparedStatement stmt = null;

try {
โ€ฆโ€ฆ
// ์™ธ๋ถ€ ํ™˜๊ฒฝ์—์„œ tablename๊ณผ name ์ž…๋ ฅ ๋ฐ›์Œ
String tableName = props.getProperty("jdbc.tableName");
String name = props.getProperty(" jdbc.name" );
String query = "SELECT * FROM " + tableName + " WHERE Name =" + name;

// ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ์ดํ„ฐ ๊ทธ๋Œ€๋กœ SQL์— ๋ฐ˜์˜
// ์‚ฌ์šฉ์ž๊ฐ€ name์„ ์ž…๋ ฅํ•ด ํƒ€์ธ์˜ ์ •๋ณด๋ฅผ ์—ด๋žŒํ•˜๋Š” SQL ๊ฐ€๋Šฅ
stmt = con.prepareStatement(query);
rs = stmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
โ€ฆโ€ฆ
while (rs.next()) { โ€ฆโ€ฆ }
dos.writeBytes(printStr);
} catch (SQLException sqle) { โ€ฆโ€ฆ }
finally { โ€ฆโ€ฆ }
โ€ฆโ€ฆ

์•ˆ์ „ํ•œ ์ฝ”๋“œ(java) :
์™ธ๋ถ€์—์„œ ์ธ์ž๋ฅผ ๋ฐ›๋Š” preparedStatement ๊ฐ์ฒด๋ฅผ ์ƒ์ˆ˜ ์ŠคํŠธ๋ง์œผ๋กœ ์ƒ์„ฑ
setXXX ๋ฉ”์†Œ๋“œ๋กœ ์ธ์ž ๋ถ€๋ถ„ ์„ค์ •
-> ์™ธ๋ถ€์˜ ์ž…๋ ฅ์ด ์ฟผ๋ฆฌ๋ฌธ์˜ ๊ตฌ์กฐ ๋ฐ”๊พธ๋Š” ๊ฒƒ ๋ฐฉ์ง€

โ€ฆโ€ฆ
PreparedStatement stmt = null;

try {
โ€ฆโ€ฆ
String tableName = props.getProperty("jdbc.tableName");
String name = props.getProperty("jdbc.name");

//  preparedStatement๋ฅผ ํ†ตํ•œ ๋™์  ์ฟผ๋ฆฌ ์ƒ์„ฑ ๋ฐฉ์ง€
String query = "SELECT * FROM ? WHERE Name = ? " ;
stmt = con.prepareStatement(query);

// setXXX ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ์ดํ„ฐ ์„ค์ •
stmt.setString(1, tableName);
stmt.setString(2, name);
rs = stmt.executeQuery();

ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String printStr = "";
while (rs.next()) { โ€ฆโ€ฆ }
dos.writeBytes(printStr);
} catch (SQLException sqle) { โ€ฆโ€ฆ }
finally { โ€ฆโ€ฆ }
โ€ฆโ€ฆ

์•ˆ์ „ํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ(C) :
์™ธ๋ถ€ ์ž…๋ ฅ์ด SQL ํ€ด๋ฆฌ์— ์–ด๋– ํ•œ ์ฒ˜๋ฆฌ ์—†์ด ์‚ฝ์ž…๋จ

#include <stdlib.h>
#include <sql.h>
void Sql_process(SQLHSTMT sqlh)
 {
 char *query = getenv("query_string");
   SQLExecDirect(sqlh, query, SQL_NTS);
 }

์•ˆ์ „ํ•œ ์ฝ”๋“œ(C) :
์ธ์žํ™”๋œ ์ฟผ๋ฆฌ ์‚ฌ์šฉํ•ด ์ฟผ๋ฆฌ ๊ตฌ์กฐ ๋ณ€๊ฒฝ ๋ฐฉ์ง€

#include <sql.h>
 void Sql_process(SQLHSTMT sqlh)
 {
 char *query_items = "SELECT * FROM items";
 SQLExecDirect(sqlh, query_items, SQL_NTS);
 }

5) ์˜ˆ์ œ [2]

http request๋กœ๋ถ€ํ„ฐ ์‚ฌ์šฉ์ž ID์™€ ์•”ํ˜ธ ์ถ”์ถœํ•ด SQL ์ฟผ๋ฆฌ ์ƒ์„ฑ


์•ˆ์ „ํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ(java):

์‚ฌ์šฉ์ž ID๋ฅผ guest' OR ' a'='a'-- ๋กœ ์„ค์ •ํ•˜์—ฌ ์ƒ์„ฑ๋œ ์ฟผ๋ฆฌ:
SELECT * FROM members WHERE userId = 'guest' OR 'a'='a'-- AND password = ''
WHERE์ ˆ ํ•ญ์ƒ ์ฐธ -> ์˜ฌ๋ฐ”๋ฅธ ์•”ํ˜ธ๊ฐ€ ์•„๋‹ˆ์—ฌ๋„ ์‚ฌ์šฉ์ž ์ •๋ณด ์กฐํšŒ/์—ด๋žŒ ๊ฐ€๋Šฅ

โ€ฆโ€ฆ
public class SqlInjectionSample extends HttpServlet
{
    private final String GET_USER_INFO_CMD = "get_user_info";
    private Connection con;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
        ServletException, IOException
    {
        String command = request.getParameter("command");
        if (command.equals(GET_USER_INFO_CMD))
        {
            Statement stmt = con.createStatement();
            String userId = request.getParameter("user_id");
            String password = request.getParameter("password");
            String query = "SELECT * FROM members WHERE username '" + userId +
                    "' AND password = '" + password + "'";
            stmt.executeUpdate(query);

        }
        โ€ฆโ€ฆ
    }
    โ€ฆโ€ฆ

}

์•ˆ์ „ํ•œ ์ฝ”๋“œ(java): makeSecureString ์ ์šฉ
SQL ๊ตฌ๋ฌธ ์ƒ์„ฑ ์ „, ์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋œ ID์™€ ์•”ํ˜ธ๋ฅผ makeSecureString ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด DB ์ฟผ๋ฆฌ ์‚ฌ์šฉ์— ์•ˆ์ „ํ•œ ํ˜•ํƒœ๋กœ ๋ณ€๊ฒฝ

makeSecureString

์ •์˜

  • 3๊ฐ€์ง€ ์ œํ•œ ์กฐ๊ฑด ์ ์šฉํ•ด ์ผ๋ฐ˜ ๋ฌธ์ž์—ด์„ ์ฟผ๋ฆฌ ์ธ์ž๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์•ˆ์ „ํ•œ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ๋Š” ๋ฉ”์†Œ๋“œ

3๊ฐ€์ง€ ์ œํ•œ ์กฐ๊ฑด

  • ID์™€ ์•”ํ˜ธ ๊ฐ™์€ ์ธ์ž์˜ ๊ธธ์ด ์ œํ•œ
    ๊ณต๊ฒฉ ๊ตฌ๋ฌธ ์ž‘์„ฑ์‹œ ์ผ๋ฐ˜์œผ๋กœ ID์™€ ์•”ํ˜ธ ๊ธธ์ด ๊ธธ์–ด์ง
    ์ธ์ž์˜ ๊ธธ์ด ์ œํ•œํ•˜์—ฌ ์ธ์ž๋ฅผ ํ†ตํ•œ ๊ณต๊ฒฉ๊ตฌ๋ฌธ ์‚ฝ์ž… ์–ด๋ ค์›€ ๋ถ€์—ฌ

  • ์ธ์ž์— SQL๋ฌธ์—์„œ ์“ฐ์ด๋Š” ์˜ˆ์•ฝ์–ด ์‚ฝ์ž… ์ œํ•œ
    Injection ๊ณต๊ฒฉ ๊ตฌ๋ฌธ ์ž‘์„ฑ์‹œ SQL๋ฌธ์—์„œ ์“ฐ๋Š” ์˜ˆ์•ฝ์–ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ์„ฑ ๋†’์Œ
    SQL ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ ๋“ฑ๋ก๊ณผ ์ธ์ž์—์„œ ๊ฐ•์ œ์  ์‚ญ์ œํ•ด ๊ณต๊ฒฉ ์ฐจ๋‹จ

  • ์ธ์ž์— ์•ŒํŒŒ๋ฒณ๊ณผ ์ˆซ์ž๋ฅผ ์ œ์™ธํ•œ ๋ฌธ์ž ์‚ฌ์šฉ ์ œํ•œ
    ๊ณต๊ฒฉ ๊ตฌ๋ฌธ ์ž‘์„ฑ์‹œ, ํŠน์ˆ˜ ๋ฌธ์ž ์‚ฌ์šฉ ๊ฐ€๋Šฅ์„ฑ ๋†’์Œ
    ์•ŒํŒŒ๋ฒณ, ์ˆซ์ž ์ œ์™ธ ๋ฌธ์ž๋ฅผ ์ธ์ž์—์„œ ๊ฐ•์ œ์  ์‚ญ์ œํ•ด ๊ณต๊ฒฉ์— ์˜ํ•œ ํ”ผํ•ด ๋ฐฉ์ง€

Regular Expression (์ •๊ทœ์‹) ์‚ฌ์šฉํ•ด 3๊ฐ€์ง€ ์ œํ•œ ์กฐ๊ฑด ์ ์šฉ

[^\\p{Alnum}] | select | delete | update | insert | create | alter | drop

  • [^\\p{Alnum}]: ์ˆซ์ž, ์•ŒํŒŒ๋ฒณ ์ œ์™ธ ๋ฌธ์ž๋“ค
  • select, delete, update, insert, create, alter, drop : SQL๋ฌธ ์˜ˆ์•ฝ์–ด
  • SQL ์˜ˆ์•ฝ์–ด๋ฅผ null string("")์œผ๋กœ ๋Œ€์ฒด

๊ทธ ์™ธ ๋ฌธ์ž์—ด ๊ธธ์ด ์ œํ•œ ๋‚ฎ์ถค, ์ •๊ทœ์‹ ํฌํ•จ ๋‹จ์–ด ๋Š˜๋ฆผ์„ ํ†ตํ•ด ๋ณด๋‹ค ์ •๋ฐ€ํ•œ ๋ฐฉ์–ด ์‹คํ˜„ ๊ฐ€๋Šฅ

โ€ฆโ€ฆ
public class SqlInjectionSample extends HttpServlet
{
    //์ž‘์—… type ์ง€์ •
    private final String GET_USER_INFO_CMD = "get_user_info";
    private Connection con;

    //id์™€ password ์ดˆ๋Œ€ ๊ธธ์ด ์ œํ•œ
    private final static int MAX_USER_ID_LENGTH = 8;
    private final static int MAX_PASSWORD_LENGTH = 16;

    //SQL ์˜ˆ์•ฝ์–ด์™€ ์•ŒํŒŒ๋ฒณ, ์ˆซ์ž๋ฅผ ์ œ์™ธํ•œ ๋‹ค๋ฅธ ๋ฌธ์ž ๊ฒ€์ถœํ•˜๋Š” ์ •๊ทœ์‹ ์„ค์ •
    private final static String UNSECURED_CHAR_REGULAR_EXPRESSION = "[^\\
        p{Alnum}]|select|delete|update|insert|create|alter|drop";

    private Pattern unsecuredCharPattern;

    //์ •๊ทœ์‹ ์ดˆ๊ธฐํ™”
    public void initlalize()
    {
        unsecuredCharPattern = Pattern.compile(UNSECURED_CHAR_REGULAR_EXPRESSION,
           attern.CASE_INSENSITIVE);
        //โ€ฆโ€ฆ
    }


    //์ž…๋ ฅ๊ฐ’์„ ์ •๊ทœ์‹์„ ํ†ตํ•ด ํ•„ํ„ฐ๋ง ํ›„ ์˜์‹ฌ๋˜๋Š” ๊ฒƒ์€ ์ œ๊ฑฐ
    private String makeSecureString(final String str, int maxLength)
    {
        String securestStr = str.substring(0, maxLength);
        Matcher matcher = unsecuredCharPattern.matcher(securestStr);
        return matcher.replaceAll("");
    }

    //โ€ฆโ€ฆ

    //์ž…๋ ฅ๊ฐ’์„ ํ•„ํ„ฐ๋งํ•œ ํ›„ ์ฟผ๋ฆฌ๋กœ ์ƒ์„ฑํ•ด ์ฒ˜๋ฆฌ
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException
    {
        String command = request.getParameter("command");
        if (command.equals(GET_USER_INFO_CMD))
        {
            Statement stmt = con.createStatement();
            String userId = request.getParameter("user_id");
            String password = request.getParameter("password");
            String query = "SELECT * FROM members WHERE username '" + makeSecureString(userId,
                    MAX_USER_ID_LENGTH) + "' AND password = '" + makeSecureString(password,
                    MAX_PASSWORD_LENGTH) + "'";

            stmt.executeUpdate(query);

        }
        โ€ฆโ€ฆ
    }
    โ€ฆโ€ฆ

}

์•ˆ์ „ํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ(C):
queryStr์˜ ์™ธ๋ถ€ ์ž…๋ ฅ์—์„œ user_id์™€ password์˜ ๊ฐ’์„ ์ž˜๋ผ ๊ทธ๋Œ€๋กœ SQL๋ฌธ ์ธ์ž ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ

static SQLHSTMT statmentHandle;
const char * GetParameter(const char * queryString, const char * key);
static const char * GET_USER_INFO_CMD = "get_user_info";
static const char * USER_ID_PARAM = "user_id";
static const char * PASSWORD_PARAM = "password";
static const int MAX_QUERY_LENGTH = 256;
const int EQUAL = 0;
int main(void)
{
  SQLCHAR * queryStr;
  queryStr = getenv("QUERY_STRING");
  if (queryStr == NULL)
   {
   // Error ์ฒ˜๋ฆฌ ๋ฃจํ‹ด
   ...
    }
   // ์ž…๋ ฅ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
char * command = GetParameter(queryStr, "command");
if (strcmp(command, GET_USER_INFO_CMD) == EQUAL)
 {
 // userId์™€ password ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
 const char * userId = GetParameter(queryStr, USER_ID_PARAM);
 const char * password = GetParameter(queryStr, PASSWORD_PARAM);

 char query[MAX_QUERY_LENGTH];
 sprintf(query, "SELECT * FROM members WHERE username= '%s' AND password ='%s'", userId, password);
 SQLExecDirect(statmentHandle, query, SQL_NTS);
 }
 return 0;
 }

์•ˆ์ „ํ•œ ์ฝ”๋“œ(C):
makeSecureString ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์œ„ํ—˜ํ•œ SQL ์ƒ์„ฑ ์œ ๋ฐœํ•˜๋Š” ๋‹จ์–ด/ํŠน์ˆ˜๋ฌธ์ž ์ œ๊ฑฐ
static const int๋กœ ์„ ์–ธํ•œ MAX_USER_ID_LENGTH์™€ MAX_PASSWORD_LENGTH์— ์„ค์ •ํ•œ ๊ฐ’์„ ๋ฒ—์–ด๋‚˜๋Š” ๋ฌธ์ž๋Š” ์ œ๊ฑฐ๋จ
regexec ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์ •๊ทœ์‹์— ๊ทผ๊ฑฐํ•ด ์œ„ํ—˜ ๋ฌธ์ž๋Š” ์ œ๊ฑฐํ•˜๊ณ  ๊ทธ ์•ž๋’ค๋ฅผ ์—ฐ๊ฒฐํ•จ

 const char * GetParameter(const char * queryString, const char * key);
 static const char * GET_USER_INFO_CMD = "get_user_info";
 static const char * USER_ID_PARAM = "user_id";
 static const char * PASSWORD_PARAM = "password";
 static const int MAX_QUERY_LENGTH = 256;
 static const int MAX_USER_ID_LENGTH = 8;
 static const int MAX_PASSWORD_LENGTH = 16;
 const char * makeSecureString(const char *str, int maxLength);
 const int EQUAL = 0;
 int main(void)
 {
 // ํ•„ํ„ฐ๋ง์— ์‚ฌ์šฉํ•  ์ •๊ทœ์‹ ์„ค์ •
 int reti = regcomp(&unsecurePattern, "[^[:alnum:]]|select|delete|update|insert|create|alter|drop", REG_ICASE | REG_EXTENDED);

 // ์ •๊ทœ์‹ ์„ค์ •์ด ์‹คํŒจํ–ˆ์„ ๊ฒฝ์šฐ ๋‚˜๋จธ์ง€ ํผ๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š๊ณ  ๊ฐ•์ œ ์ข…๋ฃŒํ•จ
 if (reti)
 {
 fprintf(stderr, "Could not compile regex\n");
 exit(1);
 }

 SQLCHAR * queryStr;
 queryStr = getenv("QUERY_STRING");
 if (queryStr == NULL)
 {
 // ์ž…๋ ฅ๊ฐ’์ด null์ธ ๊ฒฝ์šฐ Error ์ฒ˜๋ฆฌ
 ...
 }
 char * command = GetParameter(queryStr, "command");
 if (strcmp(command, GET_USER_INFO_CMD) == EQUAL)
 {
 // ๊ฐ ์ž…๋ ฅ๊ฐ’์„ ์ชผ๊ฐ  ํ›„ makeSecureStringํ•จ์ˆ˜๋กœ ํ•„ํ„ฐ๋ง ๊ฑฐ์ณ ๊ฒ€์ฆ
 const char * userId = GetParameter(queryStr, USER_ID_PARAM);
 userId = makeSecureString(userId, MAX_USER_ID_LENGTH);
 const char * password = GetParameter(queryStr, PASSWORD_PARAM);
 password = makeSecureString(password, MAX_PASSWORD_LENGTH);

 char query[MAX_QUERY_LENGTH];
 sprintf(query, "SELECT * FROM members WHERE username= '%s' AND password ='%s'", userId, password);
 SQLExecDirect(statmentHandle, query, SQL_NTS);
 free(userId);
 free(password);
 }
 regfree(&unsecurePattern);

 return EXIT_SUCCESS;
 }
 // ์ž…๋ ฅ๊ฐ’์„ ํ•„ํ„ฐ๋งํ•ด ๊ฒ€์ฆํ•˜๋Š” ๋ฃจํ‹ด
 const char * makeSecureString(const char *str, int maxLength)
 {
 char * buffer = (char *) malloc(maxLength + 1);
 char * originalStr = (char *)malloc(maxLength + 1);
 strncpy(originalStr, str, maxLength);
 originalStr[maxLength] = NULL;
 regmatch_t mt;
 const char * currentPos = originalStr;
 //โ€ƒ์ •๊ทœ์‹์— ๋งค์นญ๋˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ๊ทธ ๋ถ€๋ถ„ ๊ฑด๋„ˆ๋›ฐ๋Š” ํ˜•ํƒœ๋กœ ๋ฌธ์ž์—ด ๋ณ€๊ฒฐ
 while (regexec(&unsecurePattern, currentPos, 1, &mt, REG_NOTBOL) == 0)
 {
   strncat(buffer, currentPos, mt.rm_so);
   currentPos += mt.rm_eo;
 }
 strcat(buffer, currentPos);
 free(originalStr);
 return buffer;
}

6) ์˜ˆ์ œ [3] : Blind SQL injection ๊ณต๊ฒฉ ๊ตฌ๋ฌธ

ํŠน์ •ํ•œ ์ฝ”๋“œ๋ฅผ ์„ ๋ณ„ํ•ด ๋ง‰๋Š” ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ์— ์˜๊ฑฐํ•œ ํ•„ํ„ฐ๋ง ๋ฐฉ์‹ ์‚ฌ์šฉ์‹œ ๋‹ค์–‘ํ•œ ํ˜•ํƒœ์˜ SQL ํ•จ์ˆ˜ ์ด์šฉํ•œ ๊ณต๊ฒฉ๋ฐฉ๋ฒ•์„ ์ฐธ๊ณ ํ•ด์•ผ ํ•จ
ํ•„ํ„ฐ๋ง ์ฝ”๋“œ์˜ ์™„์„ฑ๋„๋Š” ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ์ž‘์„ฑ์ž๊ฐ€ ์–ผ๋งˆ๋‚˜ ๊ณต๊ฒฉ ํŒจํ„ด์„ ๋งŽ์ด ์•Œ๊ณ  ์žˆ๋Š๋ƒ์— ๋”ฐ๋ผ ์ขŒ์šฐ๋จ

๊ณต๊ฒฉ ๊ตฌ๋ฌธ ์„ค๋ช…
IF (1=1) SELECT 'true' ELSE SELECT 'false' ์œ„ํ—˜ํ•œ ๊ตฌ๋ฌธ ํ—ˆ์šฉ
SELECT CHAR(0x66) ์œ„ํ—˜ํ•œ ํ•จ์ˆ˜์‚ฌ์šฉ ํ—ˆ์šฉ (๋‹ค๋ฅธ blind sql ๊ณต๊ฒฉ๊ตฌ๋ฌธ์— ์ž์ฃผ ์ด์šฉ๋จ)
SELECT CONCAT(CHAR(75),CHAR(76),CHAR(77)) ์œ„ํ—˜ํ•œ ํ•จ์ˆ˜์‚ฌ์šฉ ํ—ˆ์šฉ
SELECT ASCII('a') ์œ„ํ—˜ํ•œ ํ•จ์ˆ˜์‚ฌ์šฉ ํ—ˆ์šฉ
SELECT header, txt FROM news UNION ALL SELECT name, pass FROM members ์œ„ํ—˜ํ•œ ๊ตฌ๋ฌธ ํ—ˆ์šฉ
INSERT INTO members(id, user, pass) VALUES(1, "+SUBSTRING(@@version,1,10) , 10) ์‹œ์Šคํ…œ ์ •๋ณด ๋…ธ์ถœ
exec master..xp_cmdshell 'dir' ์œ„ํ—˜ํ•œ ๋ช…๋ น์–ด ์‚ฌ์šฉ(์‹œ์Šคํ…œ down)
SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>78-- True, False๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ๊ฐ’์„ ์œ ์ถ”ํ•  ์ˆ˜ ์žˆ์Œ
IF (SELECT * FROM login) BENCHMARK(1000000,MD5(1)) ์‹œ์Šคํ…œ ์ž์› ์†Œ๋ชจ ์œ ๋„
WAITFOR DELAY '0:0:10'-- ์‹œ์Šคํ…œ ์ž์› ์†Œ๋ชจ ์œ ๋„
MD5(), SHA1(), PASSWORD(), ENCODE(), COMPRESS(), ROW_COUNT(), SCHEMA(), VERSION() ์œ„ํ—˜ํ•œ ํ•จ์ˆ˜ ์‚ฌ์šฉ
bulk insert foo from '\YOURIPADDRESS\C$\x.txt' Windows UNC Share๋ฅผ ์•…์šฉ