ASP安全策略收集


Published:   Comment: No Comments

游戏设置

TOP100.asp

<%
set rs=server.createobject("adodb.recordset")
job=request("job")
sx=request("sx")
hk=0
if instr(job,"")<>0 then hk=1
if instr(job,"=")<>0 then hk=1
if instr(job,"%")<>0 then hk=1
if len(job)>2 then hk=1
if instr(sx,"")<>0 then hk=1
if instr(sx,"=")<>0 then hk=1
if instr(sx,"%")<>0 then hk=1
if len(sx)>9 then hk=1
if hk=1 then
response.write ""
response.end
end if
%>

下面这句看看要改的地方~~~~

<%
set rs=server.createobject("adodb.recordset")
job=left(request("job"),4)
sx=left(request("sx"),8) <---------------看看这个有什么不同

把上面的放在top100.asp文件的顶上就OK了


<%
set rs=server.createobject("adodb.recordset")
job=request("job")
sx=request("sx")
hk=0
if instr(job,"")<>0 then hk=1
if instr(job,"=")<>0 then hk=1
if instr(job,"%")<>0 then hk=1
if len(job)>2 then hk=1
if instr(sx,"")<>0 then hk=1
if instr(sx,"=")<>0 then hk=1
if instr(sx,"%")<>0 then hk=1
if len(sx)>9 then hk=1
if hk=1 then
response.write ""
response.end
end if
%>

===================================================================================

asp注入攻击特殊字符过滤

1、ASP/SQL语句注入:在多都是利用网页没有对提交的数据进行过滤而直接带入数据库!

防:注入语句大多有如下字符: , % & = ; > < 来构成SQL语句!

注意:我们要作的是对写入数据库中的每一个字段都要作过滤!是每一个,千万不怕麻烦!提

供如下过滤语句!


if instr(accountname,"")<>0 or instr(accountname,";")<>0 or instr

(accountname,"&")<>0 or instr(accountname,">")<>0 or instr(accountname,",")<>0 or

instr(accountname,"=")<>0 or instr(accountname,"%")<>0 then
response.write ""
response.end
end if


把accountname改成需要过滤字段就行了!有多个字段就要多少个如上的判断语句!

2、异地表单提交!(某此人用来突破原网页的种种限制)

防:禁止异地表单提交!在你的数据库连接文件(conn.asp)加入如下判断语句!

<%
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(server_v1,8,len(server_v2))<>server_v2 then
response.write "

<table border=1 cellpadding=20 bordercolor=black

bgcolor=#EEEEEE width=450>"
response.write ""
response.write "你提交的路径有误,禁止从站点外部提交数据请不要乱改参数!"
response.write "

"
response.end
end if
%>


jiance=玩家的ID
if instr(jiance,"")<>0 or instr(jiance,"/")<>0 or instr(jiance,"\")<>0 or instr

(jiance,",")<>0 or instr(jiance," ")<>0 or instr(jiance," ")<>0 or instr

(jiance,chr(13))<>0 or instr(jiance,"=")<>0 or instr(jiance,"(")<>0 or instr

(jiance,")")<>0 or instr(jiance,"%")<>0 or instr(jiance,"=")<>0 or instr

(jiance,"+")<>0 then
response.write ""
response.end
end if

jiance=密码
if instr(jiance,"")<>0 or instr(jiance,"/")<>0 or instr(jiance,"\")<>0 or instr

(jiance,",")<>0 or instr(jiance," ")<>0 or instr(jiance," ")<>0 or instr

(jiance,chr(13))<>0 or instr(jiance,"=")<>0 or instr(jiance,"(")<>0 or instr

(jiance,")")<>0 or instr(jiance,"%")<>0 or instr(jiance,"=")<>0 or instr

(jiance,"+")<>0 then
response.write ""
response.end
end if

jiance=角色名称
if len(jiance)>12 then
response.write ""
response.end

end if

USERZS.asp

usezs.asp 这个漏洞已经很多人知道了 我们这边一个网把的都会利用

解决办法

在这个asp里面找到

if instr(accountname,"")<>0 then response.end
if instr(accountname,"=")<>0 then response.end
if instr(accountname,"%")<>0 then response.end
if instr(accountname,"&")<>0 then response.end

后面添加

if instr(password,"")<>0 then response.end
if instr(password,"=")<>0 then response.end
if instr(password,"%")<>0 then response.end
if instr(password,"&")<>0 then response.end

完整的是

if instr(accountname,"")<>0 then response.end-----------------对账号的判断
if instr(accountname,"=")<>0 then response.end
if instr(accountname,"%")<>0 then response.end
if instr(accountname,"&")<>0 then response.end
if instr(password,"")<>0 then response.end---------------------------对密码的判断
if instr(password,"=")<>0 then response.end----------------------通常是没有对密码判

断的
if instr(password,"%")<>0 then response.end

if instr(password,"&")<>0 then response.end

CONN.asp

function CheckStr(str)
str=replace(str,"","")
str=replace(str,"=","")
str=replace(str,";","")
str=replace(str,">","")
str=replace(str,"<","")
str=replace(str,"%","")
CheckStr=str
end function


===================================================================================

asp综合问题

1、防刷新机制。
function reftime()
if request.cookies("postnow")<>"" then
if cstr(Request.Cookies("postnow"))>cstr(now-0.00003) then
response.write "由于本站启用了防刷新机制,所以请勿点击太快3秒内请勿刷新本页面。"
response.write ""
response.redirect "default.asp"
response.end
end if
end if
Response.Cookies("postnow")=now
end function


2、防止外站调用ASP页面,很多的攻击都是因此而来的。
function ChkPost()
dim server_v1,server_v2
chkpost=false
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(server_v1,8,len(server_v2))<>server_v2 then
Call ShowErr("

  • 本页面禁止由外部链接
  • 请从本站首页进入!",0,"default.asp")
    response.end
    end if
    end function


    给大家一个防止外部提交的函数
    在config.asp后面加上这样一串代码

    function ChkPost()
    dim server_v1,server_v2
    chkpost=false
    server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
    server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
    if mid(server_v1,8,len(server_v2))<>server_v2 then
    chkpost=false
    else
    chkpost=true
    end if
    end function

    然后在那些问题页面里找个合适的位置插入以下代码:

    if not ChkPost() then
    response.write "请不要尝试漏洞或者请您关闭!"
    response.end
    end if

    看不懂的朋友可以看看下面的例子:

    文件:clearpk.asp

    <%
    n=request.form("username")
    p=request.form("userchr")

    if instr(n,"")<>0 or instr(n,";")<>0 or instr(n,"&")<>0 or instr(n,"%")<>0 then
    response.write "您所输入的数据包含非法字符,对不起!"
    response.end
    end if

    if instr(p,"")<>0 or instr(p,";")<>0 or instr(p,"&")<>0 or instr(p,"%")<>0 then
    response.write "您所输入的数据包含非法字符,对不起!"
    response.end
    end if

    if n<>"" and p<>"" then
    if not ChkPost() then
    response.write "请不要尝试漏洞或者请您关闭!"
    response.end
    end if
    set rs1 = Server.CreateObject("ADODB.Recordset")
    sql="select * from Character where AccountID="&n&" and Name="&p&" and

    pklevel<>3"
    rs1.open sql,conn,1,3
    if rs1.eof or rs1.bof then

    防止通过网页修改数据库的方法之一
    对所有.asp文件进行查找,凡maxlength的地方请注意:
    把所有这样的语名通通改为maxlength=18及以下,例如角色id你只需要maxlength=10 就可以了

    ,只有身份证需要18长度,其实的全部改小就可以了。
    有的就出在了maxlength=40 在地方,别人可以在那儿打入完整的命令,并且会执行。
    另外对每个输入的地方加进判断,不让输入以下字符: " ^ < > & @ . ` = 就可以防住大多

    数的破坏。


    3、len、Left、Right识别中文
    Function Strlength(Str)
    Temp_Str=Len(Str)
    For I123424=1 To Temp_Str
    Test_Str=(Mid(Str,I123424,1))
    If Asc(Test_Str)>0 Then
    Strlength=Strlength+1
    Else
    Strlength=Strlength+2
    End If
    Next
    End Function

    Function Strleft(Str,L)
    Temp_Str=Len(Str)
    For I564654=1 To Temp_Str
    Test_Str=(Mid(Str,I564654,1))
    Strleft=Strleft&Test_Str
    If Asc(Test_Str)>0 Then
    lens=lens+1
    Else
    lens=lens+2
    End If
    If lens>=L Then Exit For
    Next
    End Function

    Function Strright(Str,L)
    Temp_Str=Len(Str)
    For i54658 = Temp_Str to 1 step -1
    Test_Str=(Mid(Str,i54658,1))
    Strright=Test_Str&Strright
    If Asc(Test_Str)>0 Then
    lens=lens+1
    Else
    lens=lens+2
    End If
    If lens>=L Then Exit For
    Next
    End Function


    4、表单过滤
    Function HTMLDeCode(Str)
    if not isnull(Str) then
    Str=replace(Str,"","")
    Str=replace(Str,"!","")
    Str=replace(Str,"&","")
    end if
    HTMLDeCode=Str
    End Function


    5、大部份表单都要采用.Form的方式如:request.form("Member_ID")很多人只是用 Request

    ("Member_ID")的方式,这样是不对滴。

    加固sql的,隐藏注册系统sa密码的方法

    前两天发了个防黑的建议贴子,很多人对不在config.asp中明文显示sa的密码的方法不是

    很明白。在这就给各位兄弟多说说

    第一步 建立文件dsn(名为mu.dsn,也可以用你想用的其他任何名字,但必须是.dsn的)

    1.可以利用odbc连接建立一个文件dsn(以前是安装MU 服务端是用"系统dsn)
    2.建立的该个文件dsn可以放在默认的C:\Program Files\Common Files\ODBC\Data Sources 中
    3.数据源的驱动程序选sql server (也就是最下面的那个)
    4.下面的步骤和在MU服务端的设置差不多,不过这儿最好使用sa登陆.
    5、建立好后用记事本打开该个文件dsn文件,打开后应该是这样的内容
    [ODBC]
    DRIVER=SQL Server (数据库驱动程序)
    UID=sa (用户名)
    DATABASE=Muonline (数据库名)
    WSID=SERVER (计算机名)
    APP=Microsoft Open Database Connectivity
    SERVER=(local) (SQL的地址,我这是本地)

    我们在后边再加上一行
    PWD=密码 (这是你的sa用户的密码)

    完整的MU.dsn文件就应该是下面的这样了

    [ODBC]
    DRIVER=SQL Server
    UID=sa
    DATABASE=Muonline
    WSID=SERVER
    APP=Microsoft Open Database Connectivity
    SERVER=(local)
    PWD=

    到这里文件dsn建立好了。 织梦内容管理系统

    第二步 更改注册(管理系统的)Conn.asp的文件内容如下(删除原来的数据库连接信息)

    <%
    on error resume next
    dim connstr
    dim conn
    set conn=server.createobject("adodb.connection")
    conn.open "FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\mu.dsn"
    errormsg="注册信息有错误......"
    if err.number<>0 then
    response.write "SQL数据库连接失败!请联系管理员解决!"
    response.end
    end if
    %>

    实际上以上的部分是更改了连接sql的方式,是用文件dsn的方式来连接
    conn.open "FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\mu.dsn"
    就是具体文件dsn的连接路径,mu.dsn是第一步建立的文件dsn名字(你可以改为你的名字和路径)
    这样,别人就没有办法通过站点或asp的漏洞来获取你的密码了(当然,如果你连c盘的文件都

    被别人看到,你的性可就糟糕透顶了)

    第三步 更改MU注册系统(网页管理系统)中config.asp文件更改开头的几句

    dbuser="sa" sql用户名

    dbpsd="bobstudio" sql用户密码

    dbname="muonline" 数据库名称默认muonline

    dbip="127.0.0.1" SQL的ip

    为下面所示,取消文件中数据库的连接内容

    dbuser="" sql用户名

    dbpsd="" sql用户密码

    dbname="" 数据库名称默认muonline

    dbip="" SQL的ip

    这样,你的sa密码就被保护起来了

  • none
    Last Modified:2023-12-13 00:45:56

    我有话说