You are on page 1of 2

THỰC HÀNH KIỂM THỬ BẢO MẬT ỨNG DỤNG WEB

LỖ HỔNG CSRF, ỨNG DỤNG VÀO CHỨC NĂNG THÊM MỚI SÁCH

1. Viết một trang để hack bằng CSRF chức năng THÊM MỚI SÁCH (Xem
trong slide CSRF phần hack bằng POST)
2. Lấp lỗ hổng

https://titanwolf.org/Network/Articles/Article?AID=94f26e3d-0c58-434a-
a2df-a367a9174319

GIẢI PHÁP chống csrf tích hợp vào jsp/servlet

Sinh thẻ csrf token bằng một số ngẫu nhiên, lưu vào bộ nhớ chung Session
(quản lý phiên)

Số này lưu vào trường ẩn trong form

Sau này khi submit form, phía server lấy số đó trong session ra để so

The solution is as follows:

1. Generate random numbers.

<%

SecureRandom random = SecureRandom.getInstance ("SHA1PRNG");


long seq = random.nextLong ();

String random = "" + seq;

session.setAttribute ("random_session", random);

%>

2. Use the hidden field to pass the comparison value.

<input type = "hidden" name = "random_form" value = <% = random% >>

</input>

3. The servlet controller gets the parameter comparison.

VIEW IMAGE

String random_form=request.getParameter("random_form");
String random_session=(String)request.getSession().getAttrib
ute("random_session");
out.println ("random_form:"+random_form);
out.println ("random_session:"+random_session);
if(random_form!=null&&random_session!=null&&random_form.equ
alsIgnoreCase (random_session)) {
//business
}

You might also like