1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

51
Oracle 9i/10g/11g 常见安全管理问题 赵元杰 北京群环域科技有限公司 2012.2

Upload: wasecurity

Post on 26-Jan-2015

164 views

Category:

Technology


8 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

Oracle 9i/10g/11g

常见安全管理问题

赵元杰

北京群环域科技有限公司

2012.2

Page 2: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

2/50

安全问题

♠与Oracle系统有关的安全

♠数据库服务器威胁

♠ DBA口令忘记问题

♠ Oracle 安全漏洞

Page 3: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

3/50

Oracle 系统安全检查

♠检查忽略的系统权限

♠检查忽略的角色

♠无限制的访问数据

♠服务问题

♠ DBA口令忘记问题

Page 4: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

4/50

检查忽略的系统权限

♠ 检查下面关键项:

♠ 无限制的表空间

♠ 使用的无限制(Quota Unlimited)

♠ 创建用户问题

♠ 使用Drop/Alter语句问题

♠ 不明确的问题

Page 5: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

5/50

检查无限制的表空间

♠ 检查是否存在无限制而带来的危险:

♠ 使用无限制表空间可创建任何表和插入任意多的数据行到表中;

♠ 找出问题:

♠ 是否存在无限制的扩展:

select grantee from dba_sys_privs

where privilege = ’UNLIMITED TABLESPACE’;

select tablespace_name, file_name, maxbytes

from dba_data_files

where autoextensible = ’YES’;

Page 6: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

6/50

检查无限制的表空间

♠ 检查是否存在下面问题:

♠ 检查所授权的表空间是否为无限制;

♠ 查询DBA_TS_QUOTAS:

select username,

tablespace_name, max_bytes

from dba_ts_quotas;

如果 max_bytes =-1 表示无限制

Page 7: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

7/50

检查创建对象问题

♠ 检查是否存在权限不当:

♠ DBA不理解不同的创建权限及隐含的授权;

♠ 查询类似的CREATE …:

♠ 比如:create public synonym, database link

♠ create any *

select distinct privilege

from dba_sys_privs

where privilege like ‘CREATE%’;

Page 8: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

8/50

检查创建对象问题

♠ 检查是否存在权限不当:

♠ DBA检查哪些人员有创建权限:

♠ 每个用户都与上面的查询比较,检查是否存在权限遗漏和权限过高;

♠ 检查最小权限规则。

select distinct privilege

from dba_sys_privs

where privilege like ‘CREATE%’;

Page 9: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

9/50

检查删除对象问题

♠ 检查是否存在DROP权限:

♠ 检查哪些用户具有CREATE/DROP权限;

♠ 查询类似的DROP …:

♠ 每个用户都与上面的查询比较,询问他们实际的权限;

♠ 授予需要的最小权限。

select *

from dba_sys_privs

where privilege like ’DROP%’

or privilege like ’ALTER%’;

Page 10: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

10/50

检查过度的许可授权问题

♠ 检查是否存在过度授权:

♠ 检查下面问题:

SQL> show user

USER IS “COOK”

SQL> select * from session privs;

EXECUTE ANY PROCEDURE

15 rows selected.

SQL> exec

dbms_repcat_admin.grant_admin_any_schema(‘COOK’);

Page 11: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

11/50

检查过度的许可授权问题

♠ 检查是否存在过度授权:

♠ 检查下面问题(继续):

SQL> select * from session_privs;

PRIVILEGE

----------------------------------------

...

DROP ANY TABLE

UPDATE ANY TABLE

DROP PUBLIC SYNONYM

CREATE ANY VIEW

DROP ANY VIEW

...

54 rows selected.

Page 12: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

12/50

检查心照不宣的问题

♠ 检查是否存在心照不宣的问题

♠ 检查下面问题:

♠ 例如:

select * from dictionary

where table_name like ’PRIV%’;

Table_Name Comments

ALL_COL_PRIVS_MADE Grants on columns for which the user is owner or

grantor

ALL_TAB_PRIVS_MADE User's grants and grants on user's objects

DBA_COL_PRIVS All grants on columns in the database

DBA_ROLE_PRIVS Roles granted to users and roles

DBA_SYS_PRIVS System privileges granted to users and roles

DBA_TAB_PRIVS All grants on objects in the database

ROLE_ROLE_PRIVS Roles which are granted to roles

ROLE_SYS_PRIVS System privileges granted to roles

ROLE_TAB_PRIVS Table privileges granted to roles

Page 13: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

13/50

忽略的角色

♠默认的角色

♠带Admin Option 授权的角色

♠口令保护角色

Page 14: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

14/50

忽略的角色

♠理解创建数据库时的默认角色

♠默认的角色与Oracle版本有关

♠理解哪些权限已经授予角色:

select *

from sys.dba_role_privs;

select *

from sys.dba_sys_privs

where grantee in

(select role from

sys.dba_roles);

Page 15: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

15/50

忽略的角色

♠例如创建一个新用户,要授予:

Grant Create Session (系统权限) 或

Grant Connect (默认)

♠ Create Session: 用户可以登录

♠ Connect:

select privilege from sys.dba_sys_privs

where grantee = ’CONNECT’;

ALTER SESSION CREATE CLUSTER

CREATE DATABASE LINK CREATE SEQUENCE

CREATE SESSION CREATE SYNONYM

CREATE TABLE CREATE VIEW

Page 16: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

16/50

忽略的角色

♠用户任意用with Admin Option 给角色授权

♠如果后来从原授权者撤消权限,则连带的被授权者需要知道如何再授权问题

♠有些DBA 工具默认是Yes

♠小心使用 admin option

Page 17: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

17/50

角色的口令保护

♠角色需要口令要进行设置(启用)

♠应用中频繁登录的安全问题

♠防止用户通过Sqlplus或 其它的工具直接访问数据库表问题

♠参考Oracle安全资料

Page 18: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

18/50

非故意的访问数据库数据

♠默认口令

♠用户口令

♠备份的保护

♠保护存储过程

♠保护开发与测试环境

♠口令的可见问题

Page 19: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

19/50

非故意访问数据-默认口令

♠口令是普遍知道的或公开的

♠数据库创建时自动操作的一部分

♠不要在产品中运行 utlsampl

♠理解安装Oracle附加产品的标识问题

♠用下面的shell可找到DB服务器的 ids:

grep -i ”identified by”

$ORACLE_HOME/admin/*

Page 20: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

20/50

非故意访问数据-默认口令

♠几个常见问题: Id / password What Default Privileges

system/manager DBA DBA

sys/change_on_install Data Dictionary Pretty much everything

dbsnmp/dbsnmp Intelligent Agent Connect, resource,

(OEM) unlimited tablespace, …

mdsys/mdsys Oracle Spatial Pretty much everything

outln/outln Supports Plan Stability Unlimited tablespace,

resource, execute any proc

tracesvr/trace Trace Server Create session,

(OEM) select any table

Page 21: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

21/50

非故意访问数据-默认口令

♠ Oracle 10g 已做了改进

♠大部分的帐户都设置成 locked 和expired

♠当然 sys/system 是不能锁的

♠ dbca 提示口令

♠如果使用脚本,应该可以改变

Page 22: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

22/50

♠ Perl 脚本可发现口令: #!/usr/local/bin/perl

@ids = <DATA>; # get list of default id/passwords from data at

end of this file.

open (oratab,"</var/opt/oracle/oratab"); # get list of sids on

this system.

while (<oratab>) {

chomp; # remove newline

s/#.*//; # remove comments

s/^\s+//; # remove leading white space

s/\s+$//; # remove trailing white space

s/^\*.*//; # remove leading *

next unless length; # anything left?

($sid, $home, $yn) = split ":"; # parse out the fields

$ENV{"ORACLE_SID"} = $sid;

$ENV{"ORACLE_HOME"} = $home;

$ENV{"PATH"} = $home."/bin:/bin:/usr/bin";

$ENV{"LD_LIBRARY_PATH"} = $home."/lib:/usr/openwin/lib";

非故意访问数据-默认口令

Page 23: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

23/50

♠ Perl 可发现默认的口令(续)

# loop through list of ids, attempting to log in.

for ($idx=0; $idx<@ids; $idx++) {

$id = $ids[$idx];

chop($id); # remove newline

@x=`sqlplus $id <<EOF

exit

EOF`;

@ReturnLines = grep(/Connected to:/,@x);

print "$id\@$sid\n" if (@ReturnLines != 0 ); # print the id

we got in with.

} # for idx

} # while oratab

close (oratab);

__END__

system/manager

sys/change_on_install

dbsnmp/dbsnmp

tracesrv/trace

非故意访问数据-默认口令

Page 24: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

24/50

♠用户采用最小的防范:

♠口令与用户标识一样

♠口令以粘贴方式

♠从 Oracle 8 开始,可以:

♠ Limit # of sessions per user

♠ Limit # of failed login attempts

♠ Limit # of times password can be reused

♠ Limit lifetime of password (口令生存期)

♠开发客户的验证函数

♠口令过期的时间长度

非故意访问数据-用户口令

Page 25: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

25/50

♠ Perl 脚本可发现琐碎的口令:

#!/usr/local/bin/perl

open (oratab,"</var/opt/oracle/oratab"); # get list of sids

on this system.

while (<oratab>) {

chomp; # remove newline

s/#.*//; # remove comments

s/^\s+//; # remove leading white space

s/\s+$//; # remove trailing white space

s/^\*.*//; # remove leading *

next unless length; # anything left?

($sid,$home,$yn) = split ":"; # parse out the fields

$ENV{"ORACLE_SID"} = $sid;

$ENV{"ORACLE_HOME"} = $home;

$ENV{"PATH"} = $home."/bin:/bin:/usr/bin";

$ENV{"LD_LIBRARY_PATH"} = $home."/lib:/usr/openwin/lib";

非故意访问数据-用户口令

Page 26: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

26/50

♠ Perl 脚本可发现琐碎的口令(续): @userids=`sqlplus -silent \/ as sysdba<<eof

set sqlprompt ""

set pagesize 0

set trimspool on

set echo off

set feedback off

select username from dba_users order by username;

exit

eof`;

for ($idx=0; $idx<@userids; $idx++) {

chop $userids[$idx];

@x=`sqlplus $userids[$idx]/$userids[$idx] <<EOF

exit

EOF`;

@ReturnLines = grep(/Connected to:/,@x);

print "$userids[$idx]\@$sid\n" if (@ReturnLines != 0 ); #

print the id we got in with.

} # for

} # while oratab

close (oratab);

非故意访问数据-用户口令

Page 27: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

27/50

♠ 拒绝用户访问包含备份脚本、数据及EXP的数据.

♠ 借助 NFS进行共享时要限制指定主机

♠ 保护物理磁带的访问

♠ 将程序、存储过程及控制等存放适当的地方

♠ 当采用远处存放时,要限制专门人员访问

♠ 一般的敏感问题

非故意访问数据-保护备份

Page 28: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

28/50

♠存储过程包含有商业逻辑问题

♠采用Oracle的 PL/SQL 实用程序转换代码

♠ Example :

$ wrap iname=mycode.sql oname=mycode.wrapped

$ sqlplus scott/tiger @mycode.wrapped

非故意访问数据-保护存储过程

Page 29: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

29/50

♠生产数据经常用于开发和测试环境

♠注意专人才访问这些数据

非故意访问数据-保护开发与测试环境

Page 30: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

30/50

♠交互式的shell帐户可用“ps -ef”看到口令

♠ sqlplus

♠ exp/imp

♠ sqlldr

♠例子:

♠不要将口令放在命令行上!

sqlplus system/manager@orcl

ps -ef | grep sqlplus

oracle 633 103 0 20:38:50 pts/4 0:00 sqlplus system/manager

oracle 656 642 0 20:39:11 pts/5 0:00 grep sqlplus

非故意访问数据-口令可见

Page 31: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

31/50

♠选择在命令行上采用投掷口令 – 减少口令的可见性:

sqlplus <<EOF

scott/tiger

@mysql.sql

exit

EOF

非故意访问数据-口令可见

Page 32: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

32/50

♠使用数据库链接( database links )要小心

♠用户有 select any table 可看到口令

select userid, password, host

from sys.link$;

非故意访问数据-口令可见

Page 33: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

33/50

服务的拒绝问题

♠借助Profile 限制数据库资源

♠ UTL_FILE_DIR 参数

♠产品的独立性问题

♠ Listeners & Name Servers

Page 34: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

34/50

借助Profile 限制数据库资源

♠ Oracle的默认 profile 是开放的:

Select resource_name,Limit from sys.dba_profiles

where profile_name = ‘DEFAULT’;

RESOURCE_NAME LIMIT

-------------------------------- ---------

COMPOSITE_LIMIT UNLIMITED

SESSIONS_PER_USER UNLIMITED

CPU_PER_SESSION UNLIMITED

CPU_PER_CALL UNLIMITED

LOGICAL_READS_PER_SESSION UNLIMITED

LOGICAL_READS_PER_CALL UNLIMITED

IDLE_TIME UNLIMITED

CONNECT_TIME UNLIMITED

PRIVATE_SGA UNLIMITED

FAILED_LOGIN_ATTEMPTS UNLIMITED

PASSWORD_LIFE_TIME UNLIMITED

PASSWORD_REUSE_TIME UNLIMITED

PASSWORD_REUSE_MAX UNLIMITED

PASSWORD_VERIFY_FUNCTION UNLIMITED

PASSWORD_LOCK_TIME UNLIMITED

PASSWORD_GRACE_TIME UNLIMITED

Page 35: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

35/50

♠为每个用户类创建专门的 profile

♠不要采用 unlimited,采用合理的限制

♠ RESOURCE_LIMIT 设置成限制方式

alter system set resource_limit = true;

借助Profile 限制数据库资源

Page 36: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

36/50

♠用于 PL/SQL 的文件 I/O

♠限制在必要的目录里

♠避免设置成 *

♠检查 UTL_FILE_DIR 路径的有效性

(避免写满整个磁盘)

♠确认目录是合理的许可

数据库服务拒绝-UTL_FILE_DIR

Page 37: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

37/50

♠在产品系统中shell帐户可以:

♠用带口令的脚本搜索文件系统

♠装载磁盘驱动器

♠执行程序, 查看内存与CPU

♠定位和读Exp和 sqlldr 文件

♠拒绝或限制在产品系统中shell帐户

数据库服务拒绝-产品独立性

Page 38: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

38/50

♠口令保护 Listeners 与 Names Servers *

♠ Oracle 10g 前, 客户端可用listener 控制关闭数据库

♠在listener.ora中设置PASSWORDS_listenername

♠ lsnrctl change_password [listener_name]

♠在names.ora 设置NAMES.PASSWORD

*note - onames is deprecated in 10g, move to OID

数据库服务拒绝- Listeners & Names Servers

Page 39: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

39/50

数据库服务器威胁

♠物理安全

♠无意的访问

♠服务器的拒绝

♠不必要的UNIX服务

♠不必要的shell帐户

Page 40: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

40/50

♠数据库服务器应该放在安全的地方

♠限制无权限的访问

♠有放火设备, 电源保护, 供水, 供热

数据库服务器威胁-物理安全

Page 41: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

41/50

♠一般可读的文件

♠设置-UID 脚本

♠ NFS 共享

数据库服务器威胁-无意的访问

Page 42: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

42/50

♠对敏感的可读的文件进行保护

♠设置UNIX 文件许可

♠ Owner (read,write,execute)

♠ Group (read,execute)

♠ World (none)

♠用chmod 命令修改许可

♠用umask命令为Oracle帐户设置默认可创建文件

数据库服务器威胁-无意的访问

Page 43: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

43/50

♠保护样例

♠新创建的用户脚本 find $ORACLE_HOME –type f

–exec grep –il “identified by” {} \;

♠ sqlplus 脚本可带口令 find /u01/app/oracle/admin –type f

–exec grep –il “sqlplus” {} \;

♠ sqlldr脚本可带口令 find /u01/app/oracle/admin –type f

–exec grep –il “sqlldr” {} \;

♠ EXP/IMP 脚本 find /u01/app/oracle/admin –type f

–exec egrep –il “exp|imp” {} \;

数据库服务器威胁-无意的访问

Page 44: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

44/50

♠ 风险

♠ 潜在允许用户变为root cp /usr/bin/sh /tmp/.mysh

chmod 4755 /tmp/.mysh

ls $*

-rwsr-xr-x 1 root other 88620 .mysh

♠ 防止方法

♠ 最小化有管理功能的用户

♠ 离开时保持终端是锁的

♠ 在PATH上不要用 “.”

♠ 设置 UID 脚本来审计系统 find / -local –perm –004000 –type f –print

数据库服务器威胁-设置UID脚本

Page 45: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

45/50

♠ NFS 是一个机制,它可使一台可用的服务器的文件系统到其它的系统上

♠在共享时小心:

♠只共享指定的主机,不要整个网络

♠如果可能则以只读方式共享

♠以最低的级别共享,不要整个磁盘

♠例如:

♠ share -o ro=client[:client]… pathname

数据库服务器威胁-NFS共享

Page 46: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

46/50

♠网络或系统组要特殊处理

♠ DBA 协助…

♠从不同的机器监视数据库和服务器

♠开发、测试与产品服务器分开

♠与系统和网络管理员沟通

数据库服务器威胁-服务拒绝

Page 47: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

47/50

♠多数 unix 服务人员否知道安全漏洞

♠最小化以共享方式使用

♠ FTP必要?

♠查看 /etc/rc* 与 inetd.conf 消除不必要的服务

♠ http://www.samag.com/documents/s=1152/s

am0104i/0104i.htm

数据库服务器威胁-不必要的UNIX服务

Page 48: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

48/50

♠考虑口令文件的每一行

/etc/passwd

♠删除不需要的标识( ids )

数据库服务器威胁-不必要的shell帐户

Page 49: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

49/50

DBA口令忘记的处理

♠ Oracle 8i/9i/10g/11g版本(方法1):

♠ 可采用svrmgrl登录可直接修改口令:

♠ 这种方法其实是Oracle的漏洞:

svrmgrl

SVRMGR>connect internal

(如果提示回答口令,则输入oracle)

SVRMGR>grant connect to system identified by new_pass;

New_pass 是新口令(字母数字式串).

Page 50: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

50/50

DBA口令忘记的处理

♠ Oracle 8i/9i/10g/11g版本(方法2):

♠ 用orapwd实用程序修改SYS帐户口令;

♠ orapwd实用程序,可修改SYS口令;

♠ orapwd实用程序的语法:

orapwd file=<filename>password=<password.entries=<users>

Where file_name of password file (mand),

Password-password for SYS and INTERNAL (mand),

Entries –maximum number of distinct DBA and OPERs(opt),

There are no space around the equal-to(=) character.

这里:

file 是密码文件的路径和名字;

password 是进入SYS的管理员的口令;

entries 是可存放管理员帐户的数目。 entries=10

Page 51: 1.oracle 9i/10g/11g 常见安全管理问题 (50 页)

51/50

DBA口令忘记的处理

♠ Oracle 8i/9i/10g/11g(方法2):

♠ orapwd实用程序的例子:

$orapwd file=$ORACLE_HOME/ORACLE/intra.passwd

password=zhao_yuan_jie entries=30

这个命令建立一个密码文件 intra.passwd ,

可以记录30个数据库管理员的密码

SYS帐户的口令为zhao_yuan_jie。