最近群里好多人讨论oracle安全问题,今天找了些资料学习了下
获取oracle当前会话的一些属性 (对于sql注射的环境判断很有用哦)
sys_context 函数返回是与上下文名称空间相关的属性值。这个函数可以用在sql和pl/sql语句中。
注意: sys_context 返回的是用户会话期间的属性,所以,你无法使用它在并行的查询或实时应用集群环境。
对于名称空间和变量, 你可以定义它(们)为常量字符串,也可以定义一个变量,来代替名称空间或属性的字符串。名称空间必须是已经在数据库中定义好的, 并且相关的参数和值已经被指定到dbms_session中。名称空间必须是一个合法的sql标识符。变量名字可以是任意的字符串。它们不区分大小写, 但是长度不能超出30个字节。
函数返回的数据类型是varchar2,回归值的缺省最大长度是256个字节。你也可以通过设置函数参数length来修改这个缺省长度值。值的合法的长度范围是1到4000字节。(如果你指定的值不在这个范围内, oracle将使用缺省长度。)
oracle9i 提供了一个内置的”userenv”名称空间, 用来表示当前的会话信息。该名称空间预定义的参数如表1, 表的最后一列标识了返回值的长度。
语法:
sys_context(namespace, attribute[, length])
例子:
select sys_context (‘userenv’, ‘terminal’) terminal,
sys_context (‘userenv’, ‘language’) language,
sys_context (‘userenv’, ‘sessionid’) sessionid,
sys_context (‘userenv’, ‘instance’) instance,
sys_context (‘userenv’, ‘entryid’) entryid,
sys_context (‘userenv’, ‘isdba’) isdba,
sys_context (‘userenv’, ‘nls_territory’) nls_territory,
sys_context (‘userenv’, ‘nls_currency’) nls_currency,
sys_context (‘userenv’, ‘nls_calendar’) nls_calendar,
sys_context (‘userenv’, ‘nls_date_format’) nls_date_format,
sys_context (‘userenv’, ‘nls_date_language’) nls_date_language,
sys_context (‘userenv’, ‘nls_sort’) nls_sort,
sys_context (‘userenv’, ‘current_user’) current_user,
sys_context (‘userenv’, ‘current_userid’) current_userid,
sys_context (‘userenv’, ‘session_user’) session_user,
sys_context (‘userenv’, ‘session_userid’) session_userid,
sys_context (‘userenv’, ‘proxy_user’) proxy_user,
sys_context (‘userenv’, ‘proxy_userid’) proxy_userid,
sys_context (‘userenv’, ‘db_domain’) db_domain,
sys_context (‘userenv’, ‘db_name’) db_name,
sys_context (‘userenv’, ‘host’) host,
sys_context (‘userenv’, ‘os_user’) os_user,
sys_context (‘userenv’, ‘external_name’) external_name,
sys_context (‘userenv’, ‘ip_address’) ip_address,
sys_context (‘userenv’, ‘network_protocol’) network_protocol,
sys_context (‘userenv’, ‘bg_job_id’) bg_job_id,
sys_context (‘userenv’, ‘fg_job_id’) fg_job_id,
sys_context (‘userenv’, ‘authentication_type’) authentication_type,
sys_context (‘userenv’, ‘authentication_data’) authentication_data
from dual;
下面的语句返回登录用户的名字:
connect oe/oe
select sys_context (‘userenv’, ‘session_user’)
from dual;
sys_context (‘userenv’, ‘session_user’)
网上找的
[code]authentication_data
data being used to authenticate the login user. for x.503 certificate authenticated sessions, this field returns the context of the certificate in hex2 format.
256
note: you can change the return value of the authentication_data attribute using the length parameter of the syntax. values of up to 4000 are accepted. this is the only attribute of userenv for which oracle implements such a change.
authentication_type
how the user was authenticated:
database: username/password authentication
os: operating system external user authentication
network: network protocol or ano authentication
proxy: oci proxy connection authentication
30
bg_job_id
job id of the current session if it was established by an oracle background process. null if the session was not established by a background process.
30
client_info
returns up to 64 bytes of user session information that can be stored by an application using the dbms_application_info package.
64
current_schema
name of the default schema being used in the current schema. this value can be changed during the session with an alter session set current_schema statement.
30
current_schemaid
identifier of the default schema being used in the current session.
30
current_user
the name of the user whose privilege the current session is under.
30
current_userid
user id of the user whose privilege the current session is under
30
db_domain
domain of the database as specified in the db_domain initialization parameter.
256
db_name
name of the database as specified in the db_name initialization parameter
30
entryid
the available auditing entry identifier. you cannot use this option in distributed sql statements. to use this keyword in userenv, the initialization parameter audit_trail must be set to true.
30
external_name
external name of the database user. for ssl authenticated sessions using v.503 certificates, this field returns the distinguished name (dn) stored in the user certificate.
256
fg_job_id
job id of the current session if it was established by a client foreground process. null if the session was not established by a foreground process.
30
host
name of the host machine from which the client has connected.
54
instance
the instance identification number of the current instance.
30
ip_address
ip address of the machine from which the client is connected.
30
isdba
true if you currently have the dba role enabled and false if you do not.
30
lang
the iso abbreviation for the language name, a shorter form than the existing ‘language’ parameter.
62
language
the language and territory currently used by your session, along with the database character set, in this form:
language_territory.characterset
52
network_protocol
network protocol being used for communication, as specified in the ‘protocol=protocol’ portion of the connect string.
256
nls_calendar
the current calendar of the current session.
62
nls_currency
the currency of the current session.
62
nls_date_format
the date format for the session.
62
nls_date_language
the language used for expressing dates.
62
nls_sort
binary or the linguistic sort basis.
62
nls_territory
the territory of the current session.
62
os_user
operating system username of the client process that initiated the database session
30
proxy_user
name of the database user who opened the current session on behalf of session_user.
30
proxy_userid
identifier of the database user who opened the current session on behalf of session_user.
30
session_user
database user name by which the current user is authenticated. this value remains the same throughout the duration of the session.
30
session_userid
identifier of the database user name by which the current user is authenticated.
30
sessionid
the auditing session identifier. you cannot use this option in distributed sql statements.
30
terminal
the operating system identifier for the client of the current session. in distributed sql statements, this option returns the identifier for your local session. in a distributed environment, this is supported only for remote select statements, not for remote insert, update, or delete operations. (the return length of this parameter may vary by operating system.)