wargame

write-up 03

burrri 2023. 4. 5. 19:53

dreamhack | web hacking

01. simple_sqli

https://dreamhack.io/wargame/challenges/24/

문제의 코드를 다운받아 중요한 부분만 보면 다음과 같다. 

DATABASE = "database.db"
if os.path.exists(DATABASE) == False:
    db = sqlite3.connect(DATABASE)
    db.execute('create table users(userid char(100), userpassword char(100));')
    db.execute(f'insert into users(userid, userpassword) values ("guest", "guest"), ("admin", "{binascii.hexlify(os.urandom(16)).decode("utf8")}");')
    db.commit()
    db.close()

database에 guest:guest와 admin:(뭘라) 의 계정이 존재함을 알 수 있다. 

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        userid = request.form.get('userid')
        userpassword = request.form.get('userpassword')
        res = query_db(f'select * from users where userid="{userid}" and userpassword="{userpassword}"')
        if res:
            userid = res[0]
            if userid == 'admin':
                return f'hello {userid} flag is {FLAG}'
            return f'<script>alert("hello {userid}");history.go(-1);</script>'
        return '<script>alert("wrong");history.go(-1);</script>'

로그인시 post를 하면 userid와 userpassword를 받아와 조회한 후에 query에 담아간다.

res = query_db(f'select * from users where userid="{userid}" and userpassword="{userpassword}"')

여기서 sql injection을 하여 id만 검색하도록 하고 뒤의 userpassword부분을 주석처리해버리면 참값이 된다.

sql주석문법은 --

 

dreamhack | forensic

02. lolololologfile 

https://dreamhack.io/wargame/challenges/727/

문제의 파일은 E01파일이 담긴 zip파일이다. 문제에서 분명 pdf 파일이 삭제되었다고 헀는데 pdf 파일시그니처가 손상된 것은 아닐까해서  hxd에서 pdf 파일 시그니처를 여기저기 붙여보고 뻘짓했다 ㅎ 삭제된 파일을 복구하기 위해서 FTK imager에서 해당 파일을 열어보았다. 

image. E01 - unallocated space에서 pdf의 파일 시그니쳐(25 50 44 46)을 가진 파일을 찾았다 !

내가 hxd에서 여기저기 붙였던 25 50 44 46...

pdf의 EOF marker는 %%EOF이며, hex값은  25 25 45 4F 46 이다.

EOF를 05082 파일에서 찾을 수 있었다. 그래서 02~05파일을 Hxd에서 붙여서 pdf파일을 생성하니 플래그가 나왔다!

 

 

03. Basic_Forensics_1

https://dreamhack.io/wargame/challenges/518/

hxd를 통해 zip파일이나 png파일에 숨겨진 파일이 존재하는 지 확인했으나 별다른 파일의 시그니쳐를 발견하지 못하였다. 

그래서 png 그림 속에 메세지가 존재하겠구나 싶어서 스테가노그래피 툴을 이용하여 메세지를 찾아보았다.

 

처음에는 Stegsolve를 통해서 그림을 살펴보았다.

java -jar stegsolve.jar

stegsolve프로그램을 다운받고 stegsolve.jar가 있는 위치에서 위의 명령어를 치면 실행된다. 근데 이걸로는 뭐 별다르게 찾지 못했다ㅎ

 

그래서 스테가노그래피 해독 사이트에서 찾아보았다.

Steganography Online (stylesuxx.github.io)

 

Steganography Online

Encode message To encode a message into an image, choose the image you want to use, enter your text and hit the Encode button. Save the last image, it will contain your hidden message. Remember, the more text you want to hide, the larger the image has to b

stylesuxx.github.io

그냥 파일을 넣고 decode하니 플래그가 나온다 

▶flag : DH{Wh!te_Be4r_In_Dream_4ack}

 

 

 

'wargame' 카테고리의 다른 글

write-up 06  (0) 2023.05.18
write-up 05  (0) 2023.05.11
write-up 04  (0) 2023.05.04
write-up 02  (0) 2023.03.30
write-up 01  (0) 2023.03.23