conn fwadmin/fwadmin@//localhost:1521/freepdb1
exec dbms_sql_firewall.enable;
select status
from dba_sql_firewall_status;
STATUS
--------
ENABLED
SQL>
begin
dbms_sql_firewall.create_capture (
username => 'app_user_1',
top_level_only => true,
start_capture => true);
end;
/
-- From SQL*Plus
conn app_user_1/app_user_1@//localhost:1521/freepdb1
select * from schema_owner.t1;
select * from schema_owner.t2;
-- From SQLcl
conn app_user_1/app_user_1@//localhost:1521/freepdb1
select * from schema_owner.t1;
select * from schema_owner.t2;
conn fwadmin/fwadmin@//localhost:1521/freepdb1
set linesize 150 pagesize 40
column command_type format a12
column current_user format a15
column client_program format a45
column os_user format a10
column ip_address format a10
column sql_text format a30
select command_type,
current_user,
client_program,
os_user,
ip_address,
sql_text
from dba_sql_firewall_capture_logs
where username = 'APP_USER_1';
COMMAND_TYPE CURRENT_USER CLIENT_PROGRAM OS_USER IP_ADDRESS SQL_TEXT
------------ --------------- --------------------------------------------- ---------- ---------- ------------------------------
SELECT APP_USER_1 [email protected] (TNS V1-V3) oracle 127.0.0.1 SELECT DECODE (USER,:"SYS_B_0"
,XS_SYS_CONTEXT (:"SYS_B_1",:"
SYS_B_2"),USER) FROM SYS.DUAL
SELECT APP_USER_1 [email protected] (TNS V1-V3) oracle 127.0.0.1 SELECT * FROM SCHEMA_OWNER.T2
SELECT APP_USER_1 SQLcl tim_hall 10.0.2.2 SELECT * FROM SCHEMA_OWNER.T2
SELECT APP_USER_1 [email protected] (TNS V1-V3) oracle 127.0.0.1 SELECT * FROM SCHEMA_OWNER.T1
SELECT APP_USER_1 SQLcl tim_hall 10.0.2.2 SELECT * FROM SCHEMA_OWNER.T1
SQL>
exec dbms_sql_firewall.stop_capture('app_user_1');
exec dbms_sql_firewall.generate_allow_list ('app_user_1');
column username format a20
select *
from dba_sql_firewall_allowed_ip_addr
where username = 'APP_USER_1';
USERNAME IP_ADDRESS
-------------------- ----------
APP_USER_1 10.0.2.2
APP_USER_1 127.0.0.1
SQL>
column os_program format a50
select *
from dba_sql_firewall_allowed_os_prog
where username = 'APP_USER_1';
USERNAME OS_PROGRAM
-------------------- --------------------------------------------------
APP_USER_1 SQLcl
APP_USER_1 [email protected] (TNS V1-V3)
SQL>
column os_user format a10
select *
from dba_sql_firewall_allowed_os_user
where username = 'APP_USER_1';
USERNAME OS_USER
-------------------- ----------
APP_USER_1 oracle
APP_USER_1 tim_hall
SQL>
column sql_text format A50
select current_user,
sql_text
from dba_sql_firewall_allowed_sql
where username = 'APP_USER_1';
CURRENT_USER SQL_TEXT
--------------- --------------------------------------------------
APP_USER_1 SELECT DECODE (USER,:"SYS_B_0",XS_SYS_CONTEXT (:"S
YS_B_1",:"SYS_B_2"),USER) FROM SYS.DUAL
APP_USER_1 SELECT * FROM SCHEMA_OWNER.T2
APP_USER_1 SELECT * FROM SCHEMA_OWNER.T1
SQL>
-- Add IP address.
begin
dbms_sql_firewall.add_allowed_context (
username => 'app_user_1',
context_type => dbms_sql_firewall.ip_address,
value => '192.168.56.1');
end;
/
-- Check the allow-list.
column ip_address format a12
select *
from dba_sql_firewall_allowed_ip_addr
where username = 'APP_USER_1';
USERNAME IP_ADDRESS
-------------------- ------------
APP_USER_1 10.0.2.2
APP_USER_1 127.0.0.1
APP_USER_1 192.168.56.1
SQL>
-- Delete IP address.
begin
dbms_sql_firewall.delete_allowed_context (
username => 'app_user_1',
context_type => dbms_sql_firewall.ip_address,
value => '192.168.56.1');
end;
/
-- Check the allow-list.
select *
from dba_sql_firewall_allowed_ip_addr
where username = 'APP_USER_1';
USERNAME IP_ADDRESS
-------------------- ------------
APP_USER_1 10.0.2.2
APP_USER_1 127.0.0.1
SQL>
begin
dbms_sql_firewall.enable_allow_list (
username => 'app_user_1',
enforce => dbms_sql_firewall.enforce_all,
block => true);
end;
/
select username,
status,
top_level_only,
enforce,
block
from dba_sql_firewall_allow_lists
where username='APP_USER_1';
USERNAME STATUS TOP_LEVEL_ONLY ENFORCE BLOCK
-------------------- -------- -------------- --------------- --------------
APP_USER_1 ENABLED Y ENFORCE_ALL Y
SQL>
select sql_text,
firewall_action,
ip_address,
cause,
occurred_at
from dba_sql_firewall_violations
where username = 'APP_USER_1';
conn app_user_1/app_user_1@//localhost:1521/freepdb1
-- Unknown.
select count(*) from schema_owner.t1;
Error starting at line : 1 in command -
select count(*) from schema_owner.t1
Error at Command Line : 1 Column : 1
Error report -
SQL Error: ORA-47605: SQL Firewall violation
SQL>
-- Known.
select * from schema_owner.t1;
COUNT(*)
----------
1
SQL>
conn fwadmin/fwadmin@//localhost:1521/freepdb1
column occurred_at format a35
select sql_text,
firewall_action,
ip_address,
cause,
occurred_at
from dba_sql_firewall_violations
where username = 'APP_USER_1'
and sql_text like '%COUNT%';
SQL_TEXT FIREWAL IP_ADDRESS CAUSE OCCURRED_AT
-------------------------------------------------- ------- ------------ -------------------- -----------------------------------
SELECT COUNT (*) FROM SCHEMA_OWNER.T1 Blocked 10.0.2.2 SQL violation 03-JUL-23 09.35.55.318805 PM +00:00
SQL>
exec dbms_sql_firewall.append_allow_list('app_user_1', dbms_sql_firewall.violation_log);
conn app_user_1/app_user_1@//localhost:1521/freepdb1
select count(*) from schema_owner.t1;
COUNT(*)
----------
1
SQL>
exec dbms_sql_firewall.flush_logs;
-- Capture log entire contents.
exec dbms_sql_firewall.purge_log('app_user_1', null, dbms_sql_firewall.capture_log);
-- Violation logs older than 30 days.
exec dbms_sql_firewall.purge_log('app_user_1', systimestamp-30, dbms_sql_firewall.violation_log);
-- Capture and violation logs older than 30 days.
exec dbms_sql_firewall.purge_log('app_user_1', systimestamp-30, dbms_sql_firewall.all_logs);
-- Disable context protection.
exec dbms_sql_firewall.update_allow_list_enforcement('app_user_1', dbms_sql_firewall.enforce_context, false);
-- Disable SQL protection.
exec dbms_sql_firewall.update_allow_list_enforcement('app_user_1', dbms_sql_firewall.enforce_sql, false);
-- Disable context and SQL protection.
exec dbms_sql_firewall.update_allow_list_enforcement('app_user_1', dbms_sql_firewall.enforce_all, false);
exec dbms_sql_firewall.exclude (dbms_sql_firewall.scheduler_job);
select status, exclude_jobs
from dba_sql_firewall_status;
STATUS EXCLUDE_JOBS
-------- ------------
ENABLED Y
SQL>
exec dbms_sql_firewall.disable_allow_list ('app_user_1');
exec dbms_sql_firewall.disable;
-- Connect to the root container.
conn / as sysdba
-- Create a new tablespace.
create tablespace fw_ts datafile '/opt/oracle/oradata/FREE/fw_ts01.dbf' size 1g autoextend on next 1g;
-- Disable the SQL firewall.
exec dbms_sql_firewall.disable;
-- Move the tables.
alter table sys.sql_log$ move tablespace fw_ts;
alter table sys.event_log$ move tablespace fw_ts;
alter table sys.violation_log$ move tablespace fw_ts;
-- Enable the firewall.
exec dbms_sql_firewall.enable;
-- Check the tablespace for the log tables.
column table_name format a20
column tablespace_name format a20
select table_name, tablespace_name
from dba_tables
where table_name in ('SQL_LOG$', 'EVENT_LOG$', 'VIOLATION_LOG$')
order by 1;
TABLE_NAME TABLESPACE_NAME
-------------------- --------------------
EVENT_LOG$ FW_TS
SQL_LOG$ FW_TS
VIOLATION_LOG$ FW_TS
SQL>
conn sys/SysPassword1@//localhost:1521/freepdb1 as sysdba
column table_name format a20
column tablespace_name format a20
select table_name, tablespace_name
from dba_tables
where table_name in ('SQL_LOG$', 'EVENT_LOG$', 'VIOLATION_LOG$')
order by 1;
TABLE_NAME TABLESPACE_NAME
-------------------- --------------------
EVENT_LOG$ SYSAUX
SQL_LOG$ SYSAUX
VIOLATION_LOG$ SYSAUX
SQL>
select view_name
from dba_views
where view_name like 'DBA_SQL_FIREWALL%'
order by 1;
VIEW_NAME
--------------------------------------------------------------------------------
DBA_SQL_FIREWALL_ALLOWED_IP_ADDR
DBA_SQL_FIREWALL_ALLOWED_OS_PROG
DBA_SQL_FIREWALL_ALLOWED_OS_USER
DBA_SQL_FIREWALL_ALLOWED_SQL
DBA_SQL_FIREWALL_ALLOW_LISTS
DBA_SQL_FIREWALL_CAPTURES
DBA_SQL_FIREWALL_CAPTURE_LOGS
DBA_SQL_FIREWALL_SESSION_LOGS
DBA_SQL_FIREWALL_SQL_LOGS
DBA_SQL_FIREWALL_STATUS
DBA_SQL_FIREWALL_VIOLATIONS
11 rows selected.
SQL>
select table_name
from dba_tables
where table_name like 'FW%$'
or table_name in ('SQL_LOG$', 'EVENT_LOG$', 'VIOLATION_LOG$')
order by 1;
TABLE_NAME
--------------------------------------------------------------------------------
EVENT_LOG$
FW_ALLOW_LIST$
FW_ALLOW_LIST_CONTEXT$
FW_ALLOW_LIST_SQL$
FW_CAPTURE$
FW_STATUS$
SQL_LOG$
VIOLATION_LOG$
8 rows selected.
SQL>
-- Connect to the root container.
conn / as sysdba
-- Create a new tablespace.
create tablespace fw_ts datafile '/opt/oracle/oradata/FREE/fw_ts01.dbf' size 1g autoextend on next 1g;
-- Disable the SQL firewall.
exec dbms_sql_firewall.disable;
-- Move the tables.
alter table sys.sql_log$ move tablespace fw_ts;
alter table sys.event_log$ move tablespace fw_ts;
alter table sys.violation_log$ move tablespace fw_ts;
-- Enable the firewall.
exec dbms_sql_firewall.enable;
-- Check the tablespace for the log tables.
column table_name format a20
column tablespace_name format a20
select table_name, tablespace_name
from dba_tables
where table_name in ('SQL_LOG$', 'EVENT_LOG$', 'VIOLATION_LOG$')
order by 1;
TABLE_NAME TABLESPACE_NAME
-------------------- --------------------
EVENT_LOG$ FW_TS
SQL_LOG$ FW_TS
VIOLATION_LOG$ FW_TS
SQL>
conn sys/SysPassword1@//localhost:1521/freepdb1 as sysdba
column table_name format a20
column tablespace_name format a20
select table_name, tablespace_name
from dba_tables
where table_name in ('SQL_LOG$', 'EVENT_LOG$', 'VIOLATION_LOG$')
order by 1;
TABLE_NAME TABLESPACE_NAME
-------------------- --------------------
EVENT_LOG$ SYSAUX
SQL_LOG$ SYSAUX
VIOLATION_LOG$ SYSAUX
SQL>