HTML AccessKey and Hidden XSS (Trigger AccessKey and Hidden XSS)

예전에 hidden xss 관련해서 포스팅한적이 있습니다. input 내 hidden 속성을 가질 시 일반적으로 xss가 어렵지만, 조건에 따라 동작이 가능한 XSS도 있지요. 이 기법에서 사용되는 accesskey 에 대한 이야기를 할까 합니다.

HTML AccessKey

먼저 AccessKey는 HTML내 단축키를 이용하여 각각 객체나 행위를 수행하기 위해 만들어진 속성입니다. 웹페이지 개발 시 잘 사용한다면 아주 편리한 부분들을 만들어낼 수 있습니다. 물론 공격자는 이를 이용해서 Hidden XSS를 성공 시킬 수 있겠지만요.

<html>
<body>
  <a accesskey="X" onclick="console.log('accesskey -> onclick -> console.log() function');">
</body>
</html>

이렇게 코드를 작성 후 페이지 로드, Alt+Shift+x 를 통해서 트리거 시키면.. 콘솔에 로그가 찍히는 것을 볼 수 있습니다.

accesskey -> onclick -> console.log() function

accesskey를 통해서 a 태그에 클릭, 포커스한 것과 같은 이벤트를 발생시키기 때문에 onclick 메소드가 실행되고 내부에 있던 console.log() 함수가 실행되어 로그가 찍히게 됩니다.

AccessKey letters for button and anchor elements

|Browser|Operating System|Key Combination|Button Behavior|Anchor Behavior| |——–|——–|——–|——–|——–| |Chrome 7.0.517.41|Linux|Alt + letter|Clicks the button (3)|Clicks the anchor (3)| |Chrome 7.0.517.41|Mac OS X|Control + Option + letter|Clicks the button (3)|Clicks the anchor (3)| |Chrome 7.0.517.41|Windows|Alt + letter|Clicks the button (3)|Clicks the anchor (3)| |Firefox 1.5|Windows|Alt + letter|Clicks the button (1)|Unknown| |Firefox 2|Linux|Alt + Shift + letter|Clicks the button (1)|Clicks the anchor| |Firefox 2|Mac OS X|Control + letter|Clicks the button (1)|Clicks the anchor| |Firefox 2|Windows|Alt + Shift + letter|Clicks the button (1)|Unknown| |Firefox 3|Linux|Alt + Shift + letter|Clicks the button (1)|Clicks the anchor| |Firefox 3|Mac OS X|Control + letter|Clicks the button (1)|Clicks the anchor| |Firefox 3|Windows|Alt + Shift + letter|Clicks the button (1)|Clicks the anchor| |Internet Explorer 6|Windows|Alt + letter|Sets focus on the button (2)|Unknown| |Internet Explorer 7|Windows|Alt + letter|Sets focus on the button (2)|Sets focus on the anchor (2)| |Internet Explorer 8|Windows|Alt + letter|Clicks the button (3)|Sets focus on the anchor (2)| |Internet Explorer 9 (beta)|Windows|Alt + letter|Clicks the button (3)|Sets focus on the anchor (2)| |Safari 3.1.2|Mac OS X|Control + Option + letter|Clicks the button (3)|Clicks the anchor (3)| |Safari 3.1.2|Windows|Alt + letter|Clicks the button (3)|Clicks the anchor (3)| |Safari 5.0.2|Mac OS X|Control + Option + letter|Clicks the button (3)|Clicks the anchor (3)| |Safari 5.0.2|Windows|Alt + letter|Clicks the button (3)|Clicks the anchor (3)| (https://formattc.wordpress.com/2010/11/03/browsers-and-the-html-accesskey/)

AccessKey와 Hidden XSS

AccessKey를 이용하면 키 트리거를 이용하여 어떠한 액션을 수행할 수 있습니다. 아래와 같은 코드를 작성하고 키를 트리거해 보시면..

<html>
<body>
  <input type=button accesskey="X" onclick="alert(45)">
</body>
</html>

Alt+Shift+x 시 팝업이 나타나게 됩니다. 이는 Firefox 이외에도 Chrome 등 여러 브라우저도 동일하게 동작합니다. 공격자는 이를 통해 Click 이벤트를 직접 발생시키지 않아도 다른 키 트리거를 통해 쉽게 공격코드를 실행시킬 수 있지요.

여기서 Firefox는 아주 재미있는 문제점을 가지고있습니다. AccessKey 속성의 영향력이 hidden type의 input tag에서도 적용 된다는점이죠. 이전에 Hidden XSS에서도 약간 설명드린 내용이긴 하지만 조금 더 풀어서 설명드릴까 합니다.

<html>
<body>
  <input type="hidden" accesskey="X" onclick="alert(45)">
</body>
</html>

위 코드로 페이지를 만든 후 Chrome으로 붙어서 똑같이 Alt+Shift+x로 트리거하면 스크립트가 동작하지 않습니다. 이는 accesskey를 통해 트리거 시 위에서 설명드린 내용처럼 해당 Object에 포커스가 잡히기 때문입니다. hidden type은 투명하게 처리하는 것이 아닌 페이지에서 객체가 사라지기 때문에 트리거될 수 없죠.

그러나 Firefox에서는 이 부분이 버그로 남아있습니다. 그래서 동일한 코드로 트리거 시키면 의도한 구문이 실행되게 됩니다.

Reference

https://formattc.wordpress.com/2010/11/03/browsers-and-the-html-accesskey/ http://www.hahwul.com/2016/06/web-hacking-hiddenxss-xss-in-hidden.html