技术开发 频道

从黑客角度检验oracle数据库

    四oracle in a Web application

    1 绕过防火墙的攻击:
    防火墙的配置:
    – Block access through port 1521
    – Only allow traffic to port 80
    – Block UDP as well as TCP
    SQL 注入
    – Not specific to Oracle
    -a web programming problem
    许多管理都认为防火墙的数据库是安全的。及时是你的防护墙配置是很恰当的,也可以通过web应用程序进行攻击。这些攻击主要是由于开发应用程序者一些错误的编程所致。我们可以发现许多站点在这个方面都很脆弱。虽然因数据库不同攻击而异,但基本问题还是相同的对所有的数据库来讲。简单的一个检验你的数据库是否脆弱,是通过嵌入一个请求在没有地方,然后来验证结果。有些站点会返回语法错误。而许多只是捕获了错误,没有报道。当然这些站点仍然有脆弱,但是这些可以不被利用如果你不过任何错误消息发送反馈信息。

    2 How does it work?
    修改请求
    改变这样的查询:
    – Select * from my_table where column_x = ‘1’
    To: – Select * from my_table where column_x = ‘1’
    UNION select password from DBA_USERS
    where ‘q’=‘q’
    exploit是如何工作的?它是通过改变一个sql语句成另为一种,例如上面的例子,一个简单查询变成了2个查询。你可以嵌入第二条命令在查询中在其他的数据库中,Oracle不运行这样做,而代替的是攻击者需要去补充查询请求的结尾。注意结尾的‘q’=’q’,这样用的原因是我们可以处理第二条查询,ASP将加他加入网页的结尾,这条语句值是真的。

    3 Example JSP page

    Package myseverlets;
    <….>
    String sql = new String(“SELECT * FROM
    WebUsers WHERE Username=’” +
    request.getParameter(“username”) + “’
    AND Password=’” +
    request.getParameter(“password”) + “’”
    stmt = Conn.prepareStatement(sql)
    Rs = stmt.executeQuery()
    Exploiting the problem is much simpler if you can access the source of the web
    page. You should not be able to see this data, however there are many bugs that
    allow you to view the source, and I’m sure there are still lots that have not yet been
    discovered.
    The problem with our ASP code is that we are concatenating our SQL statement
    together without parsing out any single quotes. Parsing out single quotes is a good
    first step, but its recommended that you actually use parameterized SQL statements
    instead.

    4 有效的输入

   如果用户和密码设置为:
    – Username: Bob
    – Password: Hardtoguesspassword
    sql语句: – SELECT * FROM WebUsers WHERE
    Username=’Bob’ AND
    Password=’Hardtoguess’
    这是我们一个典型的检验机制在登陆到web site上时,然后通过select语句和数据库进行匹配,如果匹配建立,用户被鉴别。如果在我们的代码中记录集合为空,将准备一个无效的username或者password,登陆被拒绝。

    5 黑客的输入

   代替password的输入:
    – Aa’ OR ‘A’=‘A‘
    相应的sql语句:
    – SELECT * FROM WebUsers WHERE
    Username=’Bob’ AND Password=’Aa’ OR
    ‘A’=‘A’
    黑客已经进入了数据库。

    6 Selecting from other Tables
    • To select data other than the rows from the
    table being selected from
    • UNION the SQL Statement with the
    DBA_USERS view.
    这是另一个例子取得数据从其他的表中,这与当前的查询无直接联系。最好的方法是查找屏幕中包含选项的动态列表。如果这个sql只是注意一个单值,黑客不能得到其他数据。
    而且一些小技巧单一查询变成2个查询或者是把他们组合起来,这有点难道,你要匹配列数还有列的数据类型。然后一些服务器提供你一个错误的消息,使得这项是可行的。一些Error类似为:
    Number of columns does not match
    Or
    2nd column in UNION statement does not match the type of the first statement.

    7Sample ASP Page
    Dim sql
    Sql = “SELECT * FROM PRODUCT WHERE
    ProductName=’” & product_name & “’”
    Set rs = Conn.OpenRecordset(sql)
    ‘ return the rows to the browser
    Once again we have the ASP page. An attacker does not really need this, but it does
    make our lives easier for demonstration purposes. Once again we are not using
    parameterized queries, but instead are concatenating a string to build our SQL
    statement.

    8 有效的输入:
    • Set the product_name to :
    – DVD Player
    • The SQL Statement is now:
    – SELECT * FROM PRODUCT WHERE
    ProductName=’DVD Player’

    9 黑客输入:
    • Set the product_name to :
    – test’ UNION select username, password from
    dba_users where ‘a’ = ‘a
    • The SQL Statement is now:
    – SELECT * FROM PRODUCT WHERE
    ProductName=’test’ UNION select username,
    password from dba_users where ‘a’=‘a’
    黑客可以从password的拷贝中获得一些杂乱的信息,来进行暴力破解。通过添加UNION的命令和第二语句,来得到dba_users表的内容。

    10 防止SQl的注入
    验证用户的输入
    解析避免单一查询为双重查询
    使用对象参数来设在参数
    - Bind variables
    回顾升级你的CGI脚步,ASP page,etc… 建议你对web设计者制订程序的方针,主要着重使用参数化查许和对sql语句的无连接字符串。

    11 SQL Injection demo
    ASP page, IIS web server ,Oracle database 

0
相关文章