聲明
出品|先知社區(ID:l3yx)
以下內容,來自先知社區的l3yx作者原創,由于傳播,利用此文所提供的信息而造成的任何直接或間接的后果和損失,均由使用者本人負責,長白山攻防實驗室以及文章作者不承擔任何責任。
CVE-2022-40309
Apache Archiva是一個存儲庫管理軟件,2.2.9以下版本在刪除或者下載Artifact時,可以在目錄或者文件名中注入目錄穿越符,導致任意目錄刪除/任意文件讀取漏洞。
影響范圍
Apache Archiva < 2.2.9
環境搭建
https://archive.apache.org/dist/archiva/2.2.8/binaries/apache-archiva-2.2.8-bin.zip
https://codeload.github.com/apache/archiva/zip/refs/tags/archiva-2.2.8
./bin/archiva console或.\bin\archiva.bat console
可以提前在conf/wrapper.conf添加如下配置,方便IDEA遠程調試
wrapper.java.additional.9=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
首次運行需要添加Admin用戶,注意需要勾選Validated復選框:
http://127.0.0.1:8080/#open-admin-create-box
漏洞復現
前置條件是需要用戶擁有archiva-delete-artifact操作權限,使用首次添加的系統管理員賬號或者角色為Repository Manager - internal的賬號都可,其次需要存儲庫中有Artifact
先上傳一個Artifact到Archiva Managed Internal Repository
可以抓到如下DELETE請求
DELETE /restServices/archivaServices/repositoriesService/project/internal/com.test/test
在projectid后面添加POC%2f..%2f..%2f..%2-f..%2f..%2fdata,這將刪除Archiva根目錄下的data目錄
DELETE /restServices/archivaServices/repositoriesService/project/internal/com.test/test%2f..%2f..%2f..%2f..%2f..%2fdata
漏洞分析
入口在 org.apache.archiva.rest.api.services.RepositoriesService#deleteProject
@Path ("project/{repositoryId}/{groupId}/{projectId}")@DELETE@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })@RedbackAuthorization (noPermission = true)Boolean deleteProject( @PathParam ("groupId") String groupId, @PathParam ("projectId") String projectId,? ? ? ? ? ? ? ? ? ? ? @PathParam ("repositoryId") String repositoryId )? ? throws ArchivaRestServiceException;? ? org.apache.archiva.rest.services.DefaultRepositoriesService#deleteProject
public Boolean deleteProject( String groupId, String projectId, String repositoryId )? ? throws ArchivaRestServiceException{...? ? if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )? ? {? ? ? ? throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );????}...? ? try? ? {????????ManagedRepositoryContent?repository?=?repositoryFactory.getManagedRepositoryContent(?repositoryId?);? ? ? ? repository.deleteProject( groupId, projectId );? ? }...}
isAuthorizedToDeleteArtifacts?限制登錄用戶需要有archiva-delete-artifact權限
在repository.deleteProject( groupId, projectId )中直接拼接了目錄名進行刪除
org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent#deleteProject
漏洞修復
https://github.com/apache/archiva/commit/930460424c715f52a7cb5eef5b084a7a8ef31fb5#diff
bde5305e671d2bdf9f05df227a6fa706f87b911c28799575537f806a063a9134R95
歡迎關注長白山攻防實驗室微信公眾號
定期更新優質文章分享