Write-up/Suninatas

써니나타스 [Suninatas] web 1번 문제 (write-up)

연양 2019. 8. 2. 16:45

suninatas 1번 문제 

 

1번 문제에 해당하는 문제로 이 해당 웹 페이지의 서버 사이트 스크립트 언어를 보여주며 문제가 시작 된다. 

결과 값이 admin이 되도록 값을 입력하면 Authkey값을 얻을 수 있다.

 

해당 페이지의 확장자를 확인 한 결과, 이 언어가 .asp라는 확장자 명을 가진 언어라는 것을 알 수 있었다.

asp언어에 사용된 함수는 총 2개 replace와 mid 함수이다. 

 

Replace(str, "str1", "str2") 해당 str에서 str1 문자열을 str 문자열로 치환  
MID(str, a1, a2)  해당 str의 a1번째 자리에서 a2 자리수 만큼의 문자열을 반환 

따라서 이를 바탕으로 소스코드를 한줄 한줄 대충 해석 하면, 

 

result = replace(str, "a", "aa") -> a를 aad로 치환

result = replace (result, "i" , "in") -> i를 in으로 치환 

result1 = mid(result,2,2) -> result에서 2번째 자리에서 2자리의 문자열을 반환 하여 result1

result2 = mid(result,4,6) -> result에서 4번째 자리에서 6자리의 문자열을 반환 하여 result2

result = result1 & result2 -> 앞서 result1과 result2에 있는 입력값을 합쳐 result

response.write result -> result 출력

if result = "admin" -> result가 admin 일 경우

  pw = "???????"  -> pw는 ? 

 

대충 이런 의미 인 것 같다. 

 

 

str에 "ai"를 넣을 경우, 

  1. str = ai를 넣어주면   result = replace (str, "a", "aad") 에서 a는 aad으로 치환해서 result에 "aadi"가 저장된다. 
  2. result = aadi이 되고, result = replace(result, "i", "in")에 따라 i는 in으로 치환해서 "aadi"에서 "aadin"으로 result에 저장된다. 
  3. result1= mid(result,2,2)로 인하여  result1에 "ad"
  4. result2 = mid(result,4,6)으로 인하여 result2에 "in" 

이 경우 result1 & result2 를 하게 되면 result에는 "adin"가 들어가기 때문에 우리가 원하는 "admin"이 될 수 없다.

따라서 m을 넣어줘야 한다고 판단 하였다. admin의 순서를 생각하여, "ami"을 넣었다.

 

str에 ami를 넣을 경우, 

 

  1. str = ami를 넣어주면 result = replace(str, "a", "aad")에서 a는 aad로 바뀌어 result에 "aadmi"가 저장된다. 
  2. result = aadmi에서 result = replace(result, "i", "in")으로 i가 in으로 치환되어 result에"aadmin"이 저장된다.
  3. result1 = mid(result, 2,2)로 인하여 result1값은 "ad"
  4. result2 = mid(result, 4,6)으로 인하여 result2의 값은 "min"

따라서 result1 & result2를 하게 되면 result에는 admin이 되기 때문에 우리가 원하는 답을 찾을 수 있다. 

 

간단하게 정리하자면, 

"ami" -> replace 함수 -> "aadmin"

result1 -> mid 함수 -> "ad"

result2 -> mid 함수 -> "min"

result -> result1(ad) & result2(min) = "admin" 

 

따라서 답은 "ami" 이다.