gpt4 book ai didi

c - access() 安全漏洞

转载 作者:行者123 更新时间:2023-12-01 23:25:23 25 4
gpt4 key购买 nike

我一直在做一些 shell 编写,并遇到了关于 access() 的建议。检查文件是否存在,是否可以读取等。似乎 super 容易实现并且比stat()更快.当我开始查看它的手册页时,我注意到不建议使用它,因为它可能导致安全漏洞。手册页是这样说的:

Using access() to check if a user is authorized to e.g. open a filebefore actually doing so using open(2) creates a security hole,because the user might exploit the short time interval betweenchecking and opening the file to manipulate it.


有谁知道如何利用它,或者它是否仅与使用 open() 相关?检查文件后?我知道很多人说要使用 stat()而是 access()非常容易实现,尤其是对于我使用它的 shell。

最佳答案

那是一场 TOCTOU 竞赛(检查时间到更新时间)。恶意用户可以将他有权访问的文件替换为指向 access() 之间他无权访问的内容的符号链接(symbolic link)。和 open()来电。使用faccessat()fstat() .通常,打开一个文件一次,然后使用 f*()上的功能(例如:fchown(),...)。

关于c - access() 安全漏洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7925177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com