设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

吐槽编程问题的五张漫画

2014-7-17 15:09| 发布者: joejoe0332| 查看: 6577| 评论: 0|原作者: 轻如纸张|来自: 伯乐在线

摘要: 大家可能知道,我时常活跃于Stack Overflow——当今最热门的程序员问答网站。该网站的好同志们公开了他们的数据,任何人都可以通过这个页面查询他们的数据库:data.stackexchange.com,那里的很多问题和回答都配上了X ...


#1 老妈的逆袭 (96次引用)

一个没安好心的老妈给他儿子取的这个名字,只要输入到未防范SQL注入的数据库里,就能把数据库搞坏。

这种事不是第一次听说了,你可以读一读这篇真人真事:搜索一个叫Null的客户把程序整崩了

同时,也有一些人,爱尔兰血统的人(可能是有Null这个名字—译者注),在注册网站的时候,被矫枉过正的SQL注入预防手段弄得很不高兴。

被顶最多的评论来自这个帖子:

SQL注入演示页面


我在为我的学生们创建一个SQL注入演示页面。我写了一个登录页面,但是我好像没法进行注入。下面是我写的页面代码。我已经试过在username字段写入多个语句以绕过SQLi。我还能想到的就只有使用子查询,或者把我的代码漏洞再搞大一点。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php // Check to see if there was a request method that is a post type
if ($_SERVER[&#039;REQUEST_METHOD&#039;] == &#039;POST&#039;)
{
    // Check to see if username field is null
    if (!empty($_POST[&#039;username&#039;])) {
 
    // Connect to the server using credentials
    $con = mysql_connect(&#039;localhost&#039;,&#039;root&#039;,&#039;sqlcool1&#039;);
    // If the connection was not successful
    if (!$con){
        echo &#039;OUCH&#039;;
        die(&#039;Could not connect: &#039;.mysql_error());
    }
    // Select the correct database from the server
    $db = mysql_select_db(&#039;injectme&#039;,$con);
    // Pass a sql query through the table to pull the user field that was entered in the form
    // Return the results in an array
    $sql = mysql_query(&#039;SELECT * FROM user WHERE username = "&#039; . $_POST[&#039;username&#039;] . &#039;"&#039;);
    $row = mysql_fetch_row($sql);
 
    // compare $row["password"] to $_post["password"]
    // if they match it&#039;s good: log them in
    // if not, they&#039;re beat: don&#039;t log them in
 
    if ($_POST["username"] == $row[1] && $_POST["password"] == $row[2]) {
    // do something to let them know that it worked
    echo(&#039;<html>
        <head>
            <meta http-equiv="refresh" content="3; url=search.php">
        </head>
        <body>
            <p style="color:green">logged in</p>
        </body>
    </html>&#039;);
    else {
        // do something to let them know it didn&#039;t work
        echo(&#039;<p style="color: red">Invalid username or password.</p>&#039;);
        echo(&#039;<form name="login" action="login.php" method="POST">
            Username: <input type="text" name="username"><br>
            Password: <input type="password" name="password"><br>
            <input type="submit" name="submit_button" value="Submit">
            <button type="submit" formaction="register.php">Register</button>
        </form>&#039;);
    }
    //Close the connected session with the server
    mysql_close($con);
 
    else {
 
        // Repost Form
        echo (&#039;<p style="color: red"> No username / password provided.</p>&#039;);
        echo(&#039;<form name="login" action="login.php" method="POST">
            Username: <input type="text" name="username"><br>
            Password: <input type="password" name="password"><br>
            <input type="submit" name="submit_button" value="Submit">
            <button type="submit" formaction="register.php">Register</button>
            </form>&#039;);
        }
    }
    else
    {
        echo(&#039;<form name="login" action="login.php" method="POST">
            Username: <input type="text" name="username"><br>
            Password: <input type="password" name="password"><br>
            <input type="submit" name="submit_button" value="Submit">
            <button type="submit" formaction="register.php">Register</button>
        </form>&#039;);
    }
?>


  这位作者很奇葩地想故意把代码写得能被SQL注入,结果却做不到……


原文链接: EXPLAIN EXTENDED   翻译: 伯乐在线 - 轻如纸张
译文链接: http://blog.jobbole.com/73411/


酷毙

雷人
1

鲜花

鸡蛋

漂亮

刚表态过的朋友 (1 人)

  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部