PHP恶意代码注入xss模拟实现

写在前面

模拟简单的注入JS恶意代码实现xss

在网站留言或者能够提交数据到数据库中的地方,可以尝试输入代码来测试,是否能写入进去

如果提交的数据没有经过校验或处理直接写入数据库并从数据库中读出显示的页面上,此时会有机可寻

方式可以手动输入或者脚本自动填写,建议先手动测试,从微——宏,避免大批量提交一下就暴露了

确定可以注入后,就可以了,往后就不能再操作了

具体实现

准备工作要写两个页面,一个是表单提交页面,一个是留言列表展示页

通过表单页提交不经过处理的验证的数据到数据库,写入成功后到列表页查看效果

列表页实现





	
	
	
	
	
	
	



	
账号
密码
' . 'alert("不能为空")' . ''; return false; } echo ''; $hostname = "127.0.0.1"; $database = "test_test"; $username = "test_test"; $password = "test_test"; $con = mysqli_connect($hostname, $database, $username, $password); $yuming = "http://test.test"; if (!$con) { die("数据库链接错误" . mysqli_connect_error()); } $stmt = $con->prepare("INSERT INTO user_message(username, password, message) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $zhanghao, $pwd, $msg); if ($stmt->execute()) { header("Location:" . $yuming . "/msg_list.php"); exit; } else { echo ''; } ?>

列表页实现





    
    
    
    
    
    留言列表
    



    
  • 序号
  • 用户名
  • 密码
  • 留言内容
  • 备注
query($sql); while ($row = $result->fetch_assoc()) { echo '
    '; echo '
  • ' . $row['id'] . '
  • '; echo '
  • ' . $row['username'] . '
  • '; echo '
  • ' . $row['password'] . '
  • '; echo '
  • ' . $row['message'] . '
  • '; // echo '
  • ' . htmlspecialchars($row['message']) . '
  • '; echo '
  • ' . $row['other'] . '
  • '; echo '
'; } } ?>

数据库

PHP恶意代码注入xss模拟实现_第1张图片

你可能感兴趣的:(渗透,php,xss,开发语言)