CTF/리버싱

[HouseplantCTF] LEMON - 리버싱 / Python

SecurityMan 2022. 6. 14. 11:00

 

계속해서 이어지는 쉬운 파이썬 리버싱 문제

 

똑같은 패턴이다.

 

조금 더 secure한걸 만들었다고 한다.

 

반응형

 

하지만 역시나 아주 쉽게 플래그를 얻을 수 있다.

 

 

주어지는 문제파일은 pass2.py 파일이다.

 

 

먼저 IDLE을 이용해 py파일을 한번 실행시켜 봤다.

 

Enter the password: 라는 문구가 나오고,

 

123을 입력해봤더니 Incorrect password! 라는 문구가 나온다.

 

그리고 나서 저번처럼 약올리는듯한 멘트를 출력한다.

 

def checkpass():
  userinput = input("Enter the password: ")
  if userinput[0:4] == "rtcp":
        if userinput[10:13] == "tHi":
            if userinput[22:25] == "cuR":
                if userinput[4:7] == "{y3":
                    if userinput[16:19] == "1nT":
                        if userinput[7:10] == "4H_":
                            if userinput[13:16] == "S_a":
                                if userinput[19:22] == "_sE":
                                    if userinput [25:27] == "3}":
                                        return True
  else:
    return False
def main():
    access = checkpass()
    if access == True:
        print("Unlocked. The flag is the password.")
        print("b-but i wunna show off my catswpeak uwu~... why wont you let me do my nya!!\noh well... good luck with the rest of the ctf :/\nbut I WANT TO SPWEAK CATGIRL NEXT TIME SO YOU BETTER LET ME >:(")
        exit()
    else:
        print("Incorrect password!")
        print("sowwy but now you gunnu have to listen to me spweak in cat giwrl speak uwu~")
        catmain()

def catmain():
    access = catcheckpass()
    if access == True:
        print("s-senpai... i unwocked it fowr you.. uwu~")
        print("t-the fwlag is... the password.. nya!")
        exit()
    else:
        print("sowwy but that wasnt quite rwight nya~")
        catmain()

def catcheckpass():
  userinput = input("pwease enter youwr password... uwu~ nya!!: ")
  if userinput[0:4] == "rtcp":
        if userinput[10:13] == "tHi":
            if userinput[22:25] == "cuR":
                if userinput[4:7] == "{y3":
                    if userinput[16:19] == "1nT":
                        if userinput[7:10] == "4H_":
                            if userinput[13:16] == "S_a":
                                if userinput[19:22] == "_sE":
                                    if userinput [25:27] == "3}":
                                        return True
  else:
    return False

access = False
main()

 

pass2.py 파일의 전체 내용은 위와 같다.

 

뭔가 길어보이는데 사실 별거 없다.

 

쓸데없는 코드로 빈칸을 많이 채워놔서 그렇게 보일 뿐이다.

 

 

main 함수먼저 살펴보면 된다.

 

access 변수에 checkpass() 변수의 실행 결과를 담아주고,

 

access에 담긴 값이 True 경우 플래그를 획득할 수 있다.

 

checkpass() 함수를 살펴보자.

 

 

checkpass() 함수를 보면 

 

userinput 변수에 사용자 입력값을 담고,

 

userinput의 각 인덱스에 위치한 값이 소스코드에 적어놓은 값과 일치하면

 

True를 리턴하도록 만들어 놓았다.

 

이건 그냥 순서 잘 맞춰서 다시 써주면 된다.

 

 

이렇게 인덱스 순서대로 쭉 배열한 뒤에 이어서 써주면 된다.

 

플래그는 rtcp{y34H_tHiS_a1nT_sEcuR3} 이다.

 

 

프로그램을 실행시키고 password에 플래그를 넣어주면

 

정상적으로 Unlocked 라고 뜨는걸 볼 수 있다.

 
반응형