漏洞分析CVE202220705ImproperSessionManagementVulnerabilityCVE202220707CommandInjection参考链接前言 这个RCE漏洞利用链的实现是由几个逻辑洞的结合而导致的,这几天我花了一些时间复现了一遍,在此记录一下。固件解压 我下载的是RV345v1。0。03。24,从官网下载到压缩包解压之后可以看到它的rootfs是ubi格式的img。之前我都是使用kali里的binwalk对其进行解压可以直接得到解压之后的文件系统。但是由于前几天我的虚拟机坏了,不得不进行重装,但是我还没有装kali。故找了一下提取ubi格式的方式。在github上有一个项目:https:github。comnlitsmeubidump,通过里面的ubidump。py可以很轻松地提取出ubi格式的文件。命令如下:python3ubidump。pys。0。ubi漏洞分析CVE202220705ImproperSessionManagementVulnerability CVE202220705ImproperSessionManagementVulnerability,是由于nginx的配置不当导致的。nginx的配置文件是etcnginxnginx。conf,如下userwwwdata;workerprocesses4;errorlogdevnull;events{workerconnections1024;}http{accesslogoff;errorlogvarlognginxerror。logerror;upstreamjsonrpc{server127。0。0。1:9000;}upstreamrest{server127。0。0。1:8008;}Forwebsocketproxyserverincludevarnginxconf。dproxy。websocket。conf;includevarnginxsitesenabled;} 可以发现它又加载了:varnginxconf。dproxy。websocket。conf和varnginxsitesenabled,但是固件解压出来的rootfs里的var目录有些问题,所以笔者只能根据别人的文章找一下漏洞发生的配置文件。结合rest。url。conf和proxy。conf来看。locationapi{proxypasshttp:rest;includevarnginxconf。dproxy。conf;}locationapioperationsciscosbfile:filecopy{proxypasshttp:rest;includevarnginxconf。dproxy。conf;proxyreadtimeout3600;proxysendtimeout3600;}locationapioperationsciscosbfile:formfileupload{setdeny1;if(httpauthorization!){setdeny0;}if(deny1){return403;}uploadpassformfileupload;uploadstoretmpupload;uploadstoreaccessuser:rwgroup:rwall:rw;uploadsetformfielduploadfieldname。nameuploadfilename;uploadsetformfielduploadfieldname。contenttypeuploadcontenttype;uploadsetformfielduploadfieldname。pathuploadtmppath;uploadaggregateformfielduploadfieldname。md5uploadfilemd5;uploadaggregateformfielduploadfieldname。sizeuploadfilesize;uploadpassformfield。34;;uploadcleanup400404499500505;uploadresumableon;}locationrestconf{proxypasshttp:rest;includevarnginxconf。dproxy。conf;}locationrestconfoperationsciscosbfile:filecopy{proxypasshttp:rest;includevarnginxconf。dproxy。conf;proxyreadtimeout3600;proxysendtimeout3600;}proxyhttpversion1。1;proxysetheaderHosthttphost;proxysetheaderXRealIPremoteaddr;proxysetheaderXForwardedForproxyaddxforwardedfor;proxysetheaderXForwardedProtoscheme;proxysetheaderAuthorizationhttpauthorization;proxysetheaderAcceptEncoding;proxysetheaderConnection;proxysslsessionreuseoff;servernameinredirectoff; 如果我们请求中Authorization不为空,此时setdeny0,就可以向下调用upload模块。它会在调用formfileupload前,把文件上传到tmpupload下。并且由于没有设置level,它的存储格式类似tmpupload0000000001。至此我们可以实现任意文件上传至tmpupload。 我们接着向下分析,可以在rootfsetcnginxconf。d下找到web。upload。conf如下:locationformfileupload{includeuwsgiparams;proxybufferingoff;uwsgimodifier19;uwsgipass127。0。0。1:9003;uwsgireadtimeout3600;uwsgisendtimeout3600;}locationupload{setdeny1;if(ftmpwebsessiontokencookiesessionid){setdeny0;}if(deny1){return403;}uploadpassformfileupload;uploadstoretmpupload;uploadstoreaccessuser:rwgroup:rwall:rw;uploadsetformfielduploadfieldname。nameuploadfilename;uploadsetformfielduploadfieldname。contenttypeuploadcontenttype;uploadsetformfielduploadfieldname。pathuploadtmppath;uploadaggregateformfielduploadfieldname。md5uploadfilemd5;uploadaggregateformfielduploadfieldname。sizeuploadfilesize;uploadpassformfield。34;;uploadcleanup400404499500505;uploadresumableon;} 我们可以发现其对upload进行了cookiesessionid的检验,但是并没有对formfileupload进行检验。我们看一下formfileupload的后端处理程序。启动脚本(uwsgilauncher)如下:!binshetcrc。commonexportUWSGIPLUGINDIRusrlibuwsgipluginsstart(){uwsgiminietcuwsgijsonrpc。iniuwsgiminietcuwsgiblockpage。iniuwsgiminietcuwsgiupload。ini}stop(){killall9uwsgi} 我们再去找一下etcuwsgiupload。ini〔uwsgi〕pluginscgiworkers1master1uidwwwdatagidwwwdatasocket127。0。0。1:9003buffersize4096cgiwwwcgibinupload。cgicgiallowedext。cgicgiallowedext。plcgitimeout300ignoresigpipetrue 从上述文件中我们可以知道formfileupload它对应的后端处理程序是wwwcgibinupload。cgi。因此我们可以无条件访问upload。cgi。 同时上述配置文件中我们可以看到检查了tmpwebsessiontokencookiesessionid文件是否存在。但是存在缺陷,就是这里的cookiesessionid是用户在http请求中传进去的一个值,它并没有检查是否存在。。。。,也就是说我们可以通过跨目录来导致授权绕过。如:我们可以传递。。。。。。etcfirmwareversion。 同时也可以看到在upload。cgi里对sessionid进行了检查,限制了它的字符,但是并没有考虑到传多个sessionid的情况。因为这里的sessionid是遍历HTTPCOOKIE并且取出它最后一个sessionid作为实际的sessionid使用,所以我们可以传两个sessionid。前一个用来绕过web。upload。conf里的判断,后一个当作正常的数据用来通过upload。cgi的判断。这样也可以实现无条件访问upload。cgi。 我们接着看upload。cgi 传入适当的参数可以使得我们有能力任意文件移动到tmpwww下,通过这两个漏洞我们也可以伪造出一个session。CVE202220707CommandInjection 我们继续查看upload。cgi。 这个漏洞可以使得任意命令执行。参考链接https:bestwing。mePwning20a20Cisco20RV3402020E6BC8FE6B49EE58886E69E90EFBC88CVE20222070520E5928C20CVE202220707。htmlhttps:blog。relyze。com202204pwningciscorv340with4bugchain。htmlhttps:paper。seebug。org1890https:onekey。comblogadvisoryciscorv34xauthenticationbypassremotecommandexecutionhttps:nosec。orghomedetail4985。html fromhttps:www。secpulse。comarchives197154。html