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

Mssql 逆向查询

2009-5-26 12:19 662 0

摘要: 作者:oldjun & 皇子         非常不幸,拿到一个库,里面有几百张表,而且很多表都有N多字段,不想一个一个去...
关键词: nbsp closeset 一个 关键字 多字 nothingnext response rsresult liename rsbiao

作者:oldjun & 皇子         非常不幸,拿到一个库,里面有几百张表,而且很多表都有N多字段,不想一个一个去手工探测有用的表和字段,写了点SQL语句,在oldjun帮忙下有了这个脚本。作用是使用一个关键字作为搜索条件,然后遍历整个数据库,回显该关键字在库中所有位置,即所处表名与列。        直接给出代码: <title>Sql逆向查询</title><form name="Form" action="?"> <input type="text" name="keyword" value="输入要搜索的关键字"> <input type="Submit" value="提交"> </form> <%'Search a keyword from each column in each table of a database'By oldjun(http://www.oldjun.com)'Based on huangzi(http://www.2chuizi.com)'s sql'Respect for the author's work Server.ScriptTimeout=999999999Response.Buffer =trueOn Error Resume Nextkeyword=request("keyword")if keyword="" thenresponse.write "Need keyword!"response.EndEnd ifdim connSet conn = Server.CreateObject("ADODB.Connection")Dim ConnStr'ConnectionString,Pls change!ConnStr="Driver={SQL SERVER};Server=localhost;UID=bbs;PWD=bbs123456789;Database=syc163"Conn.open ConnStrconn.execute("DROP TABLE huangzi_table")conn.execute("CREATE TABLE huangzi_table(id int identity(1,1),biaoid int,biaoname nvarchar(1000))")conn.execute("insert huangzi_table select [id],[name] from sysobjects where xtype='U'") set rs =conn.execute("select count(id) as tnum from huangzi_table")tnum=rs("tnum")rs.closeset rs=nothingfor i=1 to tnum set rsbiao =conn.execute("select biaoid from huangzi_table where id="&i&"")biaoid=rsbiao("biaoid")set rst =conn.execute("select [biaoname] from huangzi_table where biaoid="&biaoid&"")tname=rst("biaoname") set rsl=conn.execute("select count([name]) as lnum from syscolumns where id="&biaoid&"")lnum=rsl("lnum") for j=1 to lnum topnum=j-1set rslie=conn.execute("select top 1 [name] from syscolumns where id="&biaoid&" and [name] not in (select top "&topnum&" [name] from syscolumns where id="&biaoid&")")liename=rslie("name")set rsresult=conn.execute("select top 1 ["&liename&"] from ["&tname&"] where CAST(["&liename&"] AS NVARCHAR(1000))='"&keyword&"'") if rsresult.bof or rsresult.eof then'response.write "Nothing-"&tname&":"&liename'response.write "<br>"elseresult=rsresult(liename)response.write "表名:"&tname&"     列名:"&liename& "   存在关键字   [" &keyword&"]"response.write "<br>"End if rslie.closeset rslie=nothingrsresult.closeset rsresult=nothingnext rsbiao.closeset rsbiao=nothingrst.closeset rst=nothingrsl.closeset rsl=nothingnext conn.execute("DROP TABLE huangzi_table")%>  
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部