apache中对非站点目录的访问限制
apache设置中有一段
Alias /test "/var/www/web2/test"
Options FollowSymLinks Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
如果此时 /var/www/web2/test 目录中有一个php下载的页面
down.php大概是这样:
$filename=$_GET["file"];<br /> <br /> ob_end_clean();<br /> header("Expires: 0");<br /> if(!$file = @fopen($filename,'r')){<br /> echo 'read error';<br /> exit();<br /> }<br /> <br /> flock($file,LOCK_SH);<br /> $filesize=filesize($filename);<br /> <br /> Header("Content-type: application/octet-stream");<br /> Header("Accept-Ranges: bytes");<br /> Header("Accept-Length: ".$filesize);<br /> Header("Content-Disposition: attachment; filename=" . $file_name);<br /> if($filesize>0)<br /> {<br /> echo fread($file,$filesize);<br /> }<br /> fclose($file);<br /> ob_get_contents();<br /> ob_end_clean();<br /> exit;
这个页面测试有很大的漏洞, 客户在浏览器输入down.php?file=../../../etc/xxx
类似的就能下载系统的文件。
请问如何配置apache让站点只能访问自身目录以及子目录,不能访问其他目录?
------解决方案--------------------
apache 本身没有这个功能,也不需要这个功能
因为 apache 只是个二传手
你可以在 php.ini 中配置
open_basedir = 允许访问的路径列表
也可以将 open_basedir 放在 apache 的 httpd.conf 或 .htaccess 中
php_admin_value open_basedir 允许访问的路径列表

tostartaphpsession,usesesses_start()attheScript'Sbeginning.1)placeitbeforeanyOutputtosetThesessionCookie.2)useSessionsforuserDatalikeloginstatusorshoppingcarts.3)regenerateSessiveIdStopreventFentfixationAttacks.s.4)考虑使用AttActAcks.s.s.4)

会话再生是指在用户进行敏感操作时生成新会话ID并使旧ID失效,以防会话固定攻击。实现步骤包括:1.检测敏感操作,2.生成新会话ID,3.销毁旧会话ID,4.更新用户端会话信息。

PHP会话对应用性能有显着影响。优化方法包括:1.使用数据库存储会话数据,提升响应速度;2.减少会话数据使用,只存储必要信息;3.采用非阻塞会话处理器,提高并发能力;4.调整会话过期时间,平衡用户体验和服务器负担;5.使用持久会话,减少数据读写次数。

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

phpientifiesauser'ssessionusessessionSessionCookiesAndSessionIds.1)whiwSession_start()被称为,phpgeneratesainiquesesesessionIdStoredInacookInAcookInamedInAcienamedphpsessidontheuser'sbrowser'sbrowser.2)thisIdAllowSphptptpptpptpptpptortoreTessessionDataAfromtheserverMtheserver。

PHP会话的安全可以通过以下措施实现:1.使用session_regenerate_id()在用户登录或重要操作时重新生成会话ID。2.通过HTTPS协议加密传输会话ID。3.使用session_save_path()指定安全目录存储会话数据,并正确设置权限。

phpsessionFilesArestoredIntheDirectorySpecifiedBysession.save_path,通常是/tmponunix-likesystemsorc:\ windows \ windows \ temponwindows.tocustomizethis:tocustomizEthis:1)useession_save_save_save_path_path()


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

Dreamweaver CS6
视觉化网页开发工具

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 Linux新版
SublimeText3 Linux最新版