Python黑帽子:Burp插件编写,之最简单的Burp模糊测试

Burp提供了一系列的api,可以用于开发自己的插件。api的文档可以直接在burp的扩展处查看

Python黑帽子:Burp插件编写,之最简单的Burp模糊测试_第1张图片

插件入口:IBurpExtender+IBurpExtenderCallbacks

辅助功能: IExtensionHelpers

消息接口:IHttpRequestResponse,IRequestInfo,IResponseInfo等等

组件接口:Intruder相关和Scanner相关

 UI接口:ITab,IContextMenuFactory

java的swing图形控件库

本此代码主要利继承的是IIntruderPayloadGeneratorFactory类。对这个类的方法进行重写

插件入口:IBurpExtender+IBurpExtenderCallbacks

其中IBurpExtender类中有一个函数,用于注册,也是插件代码的开始位置。

这里用到了两个接口,一个IBurpExtender类的接口,还有一个IIntruderPayloadGeneratorFactory的接口。

继承接口只需要重写接口中的函数(python中的继承和多态),可以重定义新类,新类就是一个扩展,callbacks.registerIntruderPayloadGeneratorFactory就是声明这个类是哪个接口类的子类。(撤了那么多都是我自己的理解,一个IBurpExtender类对应一个扩展对象,IBurpExtender类里有一些自带的被继承的成员,像callbacks,其中可通过callbacks内部的注册函数。新的扩展既是IBurpExtender的子类(用于注册),又是IIntruderPayloadGeneratorFactory的子类,用于具体功能的实现)

代码如下:

创建一个类,命名为BurpExtender,继承了两个类IBurpExtender,IIntruderPayloadGeneratorFactory。继承和多态,构造函数随便,给的文档的函数自己重写一下就行。

from burp import IBurpExtender
from burp import IIntruderPayloadGeneratorFactory
from burp import IIntruderPayloadGenerator

from java.util import List, ArrayList

import random


class BurpExtender(IBurpExtender, IIntruderPayloadGeneratorFactory):
    def registerExtenderCallbacks(self, callbacks):
        self._callbacks = callbacks
        self._helpers = callbacks.getHelpers()
        callbacks.registerIntruderPayloadGeneratorFactory(self)
        return

    def getGeneratorName(self):
        return "BHP Payload Generator"

    def createNewInstance(self, attack):
        return BHPFuzzer(self, attack)


class BHPFuzzer(IIntruderPayloadGenerator):
    def __init__(self, extender, attack):
        self._extender = extender
        self._helpers = extender._helpers
        self._attack = attack
        self.max_payloads = 10
        self.num_iterations = 0
        return

    def hasMorePayloads(self):
        if self.num_iterations == self.max_payloads:
            return False
        else:
            return True

    def getNextPayload(self, current_payload):
        payload = "".join(chr(x) for x in current_payload)

        payload = self.mutate_payload(payload)

        self.num_iterations += 1
        return payload

    def reset(self):
        self.num_iterations = 0
        return

    def mutate_payload(self, original_payload):
        picker = random.randint(1, 3)
        offset = random.randint(0, len(original_payload) - 1)
        payload = original_payload[:offset]
        if picker == 1:
            payload += "'"
        if picker == 2:
            payload += ""
        if picker == 3:
            chunk_length = random.randint(len(payload[offset:]), len(payload) - 1)
            repeater = random.randint(1, 10)

            for i in range(repeater):
                payload += original_payload[offset:offset + chunk_length]
        payload += original_payload[offset:]
        return payload

你可能感兴趣的:(Python黑帽子:Burp插件编写,之最简单的Burp模糊测试)