UltraDebug

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: A C D R G Y M Z X S P
公益项目,接受捐赠
查看: 1649|回复: 0
收起左侧

[Web逆向] VBA 上传图片

[复制链接]
guixin

主题

0

回帖

UD

新手上路

UID
43
积分
34
注册时间
2022-5-18
最后登录
1970-1-1
2022-7-20 15:07:44 | 显示全部楼层 |阅读模式

@[TOC](VBA 上传图片)

问题来源于帖子:VBA怎么样通过winHttp、xmlHttp post上传图片呢 求大佬指点

整个过程并没有什么加密,比较简单,就不做什么分析了,使用Fiddler抓包查看,可以很快的用python复现

import requests
from io import BytesIO
from requests_toolbelt.multipart.encoder import MultipartEncoder

def main():
    file_name = '6da2ddc8124d0ba7045c38925eb857c0.jpeg'
    fields = {
        "image": (file_name, BytesIO(open(file_name, 'rb').read()), 'image/jpeg'),
        "fileId": file_name,
        "initialPreview": '[]',
        "initialPreviewConfig": '[]',
        "initialPreviewThumbTags": '[]'
    }
    multipart = MultipartEncoder(
        fields=fields,
        boundary='----WebKitFormBoundaryAx0QwuMECh2eIreV'
    )
    headers = {
        "X-Requested-With": "XMLHttpRequest",
        "Content-Type": multipart.content_type,
    }
    data = multipart.to_string()
    response = requests.post('https://www.imgtp.com/upload/upload.html', headers=headers, data=data)
    print(response.status_code)
    print(response.headers)
    print(response.request.headers)
    print(response.json())

if __name__ == '__main__':
    main()

基本上都是照抄,最后可以获取在线的图片地址。这么难点在于如何使用VBA来上传。 1.因为没有轮子,所有multipart 包装需要自己处理。 2.请求体包含了二进制文件

一、 为了解决第一个问题,可以在vba中生成的二进制数据(即Byte数组)与python的对比,直到两个数据完全一样。

二、因为要提交字节数组,那么必须要使用【WinHttp.WinHttpRequest.5.1】对象。

提交部分的代码如下

Sub upload()
    Const Boundary As String = "----WebKitFormBoundaryAx0QwuMECh2eIreV"
    Const file_name As String = "6da2ddc8124d0ba7045c38925eb857c0.jpeg"
    Dim image_byte() As Byte
    Dim data() As Byte
    image_byte = openbytefile(ActiveWorkbook.path & "\" + file_name)
    Dim bytes As bytearray
    Set bytes = New bytearray

    bytes.update encodeutf8("--" & Boundary & vbNewLine)
    bytes.update encodeutf8("Content-Disposition: form-data; name=""image""; filename=""" & file_name & """" & vbNewLine)
    bytes.update encodeutf8("Content-Type: image/jpeg" & vbNewLine)
    bytes.update encodeutf8(vbNewLine)
    bytes.update image_byte
还有更多的精彩内容,作者设置为付费后可见
UltraDebug免责声明
✅以上内容均来自网友转发或原创,如存在侵权请发送到站方邮件9003554@qq.com处理。
✅The above content is forwarded or original by netizens. If there is infringement, please send the email to the destination 9003554@qq.com handle.
回复 打印

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|站点地图|UltraDebug ( 滇ICP备2022002049号-2 滇公网安备 53032102000034号)

GMT+8, 2026-1-24 04:28 , Processed in 0.043809 second(s), 11 queries , Redis On.

Powered by Discuz X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表