PHP CSRF Attack

后端 未结 3 1474
执笔经年
执笔经年 2020-12-09 14:28

I want to know if this code is strong enough to prevent CSRF attack on PHP Form?



        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 14:54

    I’d say it suffices for the given purpose.

    The values returned by uniqid(mt_rand(), true) should be up to 33 bytes:

    • up to 10 bytes prefix from mt_rand
    • 8 bytes system time in seconds
    • 5 bytes current microseconds
    • 10 bytes from the internal linear congruence generator php_combined_lcg

    However, these 33 bytes do not provide 264 bits of entropy but way less:

    • log2(231-1) ≈ 31 bits for the mt_rand prefix
    • system time is known (e.g. Date response header field)
    • microseconds can only have one of 106 values, so log2(106) ≈ 20 bits
    • LCG value is log2(109) ≈ 30

    This sums up to almost 81 unknown bits. To brute force this, one would need on average 281/2 ≈ 1.2·1024 guesses that result in a given token when hashed. The data to process would be approximately 8·1013 TB. With a todays computer, you should be able to run this in approximately 5.215·1017 seconds.

    This should be sufficient to render an attack impracticable.

提交回复
热议问题