SHA256逆向实战,论时间戳验证的重要性

4,663 阅读3分钟

本文已参与「新人创作礼」活动, 一起开启掘金创作之路。SHA256逆向实战,论时间戳验证的重要性。今天更一篇恨的希望不要被拉走蹲号子,本篇教程仅供学习技术探讨使用,如有侵权请联系删除,网站地址

VeryCapture_20230302151243.gif

1.先抓一下包看一下有点什么

image.png

image.png 经过两次翻页发现请求参数中有三个变化参数(key,signatureHeader,timestampHeader),headers中用一个变化参数(x-wif-signature),这里注意Accept类型为json 到这一步我们看一下之后只有timestampHeader明确是一个时间戳且key是不变的,我们现在做一次请求看一下情况如何

image.png

这里时间戳过大从此可见请求时候是会对timestampHeader字段进行验证的,那么我们取一次新的参数且在100秒内使用

image.png

ok,请求没啥问题,而且发现这里没有对cookies进行验证,那么只需要解决参数中的signatureHeader以及headers中的x-wif-signature就ok了,还需要留意一点的是timestampHeader字段既然验证了那么因该不只是超时时间这么简单。

2.好,现在明确了要解决的问题我们开始找断点、追踪、逆向那一套。 在lnitiator中可见send我们点进去断点

image.png 通过追踪无果且没有可疑函数果断放弃 image.png

3.send这条路走不通我们先全局索引一下加密参数

image.png

这不是SHA-2家族的SHA256加密算法吗 VeryCapture_20230302154228.gif 其实咱们也可以从signatureHeader加密后的值可以看出八成就是sha256了64位字符,之前写博客的时候做用户注册登录用的就这sha256。前端因该用的不少,放到参数里面用的倒是见的不多。ok继续

4.断点开始今日逆向之旅

image.png 可见三个参数很明两个不变的值一个时间戳(果然对时间戳是+处理的试想时间戳和此处生成signatureHeader使用的时间戳不一致会发生什么呢)。 5.ok,现在还差一个x-wif-signature

image.png 嗨这断不断的也没什么意思了之后哪有用吧 VeryCapture_20230302155657.gif

6.现在两个参数都明确了开始写代码

老规矩先解决js,如果不习惯用这种方法可以使用python实现上篇文章中介绍了python实现常用的几种加密算法地址

function cc(t) {
    const CryptoJS = require('crypto-js');
    signatureHeader = CryptoJS.SHA256(t)
            .toString(CryptoJS.enc.Hex)
            .toUpperCase()
    return signatureHeader
};
function aa(t) {
    const CryptoJS = require('crypto-js');
    zdwwsignature = CryptoJS.SHA256(t)
      .toString(CryptoJS.enc.Hex)
      .toUpperCase();
    return zdwwsignature
};

生成两个加密参数

def get_data():
    timestampHeader = int(time.time())
    token = '23y0ufFl5YxIyGrI8hWRUZmKkvtSjLQA'
    nonce = '123456789abcdefg'
    cihui = str(timestampHeader) + token + nonce + str(timestampHeader)
    signatureHeader = get_sign(cihui)
    
    cihui = str(timestampHeader) + 'fTN2pfuisxTavbTuYVSsNJHetwq5bJvC' + 'QkjjtiLM2dCratiA' + str(timestampHeader)
    signature = get_headersign(cihui)
    
def get_sign(cihui):
    js = open("./getsign.js", "r", encoding="gbk", errors='ignore')
    line = js.readline()
    htmlstr = ''
    while line:
        htmlstr = htmlstr + line
        line = js.readline()
    ctx = execjs.compile(htmlstr)
    result = ctx.call('cc', cihui)
    return result


def get_headersign(cihui):
    js = open("./getsign.js", "r", encoding="gbk", errors='ignore')
    line = js.readline()
    htmlstr = ''
    while line:
        htmlstr = htmlstr + line
        line = js.readline()
    ctx = execjs.compile(htmlstr)
    result = ctx.call('aa', cihui)
    return result
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json; charset=UTF-8',
    'Origin': 'http://bmfw.www.gov.cn',
    'Pragma': 'no-cache',
    'Referer': 'http://bmfw.www.gov.cn/ybypmlcx/index.html',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36',
    'x-wif-nonce': 'QkjjtiLM2dCratiA',
    'x-wif-paasid': 'smt-application',
    'x-wif-signature': f'{signature}',
    'x-wif-timestamp': f'{timestampHeader}',
}
json_data = {
    'appId': 'NcApplication',
    'paasHeader': 'zdww',
    'nonceHeader': '123456789abcdefg',
    'timestampHeader': f'{timestampHeader}',
    'signatureHeader': f'{signatureHeader}',
    'page': 1,
    'page_size': 3000,  # 1487+2166+892
    'druge_type': '1',
    'medifist_type': '',
    'medisecond_type': '',
    'medicine_name': '',
    'key': 'dac066d11092301a2b833aac1048780d',
}
response = requests.post('http://bmfw.www.gov.cn/bjww/interface/interfaceJson', headers=headers,
                         json=json_data, verify=False)
print(response.json())
print(response)

image.png

image.png