【python专题】需要用到dnslog的python扫描脚本该怎么编写?

admin 2024年1月28日12:00:44评论15 views字数 2454阅读8分10秒阅读模式

0x01 阅读须知

SCA御盾实验室的技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责。本文所提供的工具仅用于学习,禁止用于其他!!!

0x02 场景描述

在漏洞复现中,经常会遇到需要使用dnslog来验证漏洞师傅存在的场景,如不回显的rce,不回显的xxe,不回显的ssrf等,而此时编写漏洞的python批量扫描脚本时,同样也需要dnslog平台作为反连平台,而本文就分享如何联立dnslog平台编写脚本。

0x03 场景举例

1、获取dnslog

【python专题】需要用到dnslog的python扫描脚本该怎么编写?

2、burpsuite抓包

GET /getdomain.php?t=0.6649634107905383 HTTP/1.1Host: User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0Accept: */*Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2Accept-Encoding: gzip, deflateConnection: closeContent-Length: 2




【python专题】需要用到dnslog的python扫描脚本该怎么编写?

响应包中获取的子域名和Set-Cookie是后面需要用到的字段,因此,封装成python函数为

def get_domain():  url='http://xxxx/getdomain.php?t=0.9427873201991249'  headers={'Referer': 'http://dnslog.cn/'}  r=requests.get(url,headers=headers,timeout=5,verify=False)  domain=r.text  cookie=r.headers['Set-Cookie']  result=(domain,cookie)  return result

3、使用获取到的子域名传到漏洞poc

使用本地ping dnslog举例

import requests,osdef get_domain():  url='http://xxxx/getdomain.php?t=0.9427873201991249'  headers={'Referer': 'http://dnslog.cn/'}  r=requests.get(url,headers=headers,timeout=5,verify=False)  domain=r.text  cookie=r.headers['Set-Cookie']  result=(domain,cookie)  return result

domain,cookie=get_domain()os.system('ping '+domain)

4、获取dnslog结果

【python专题】需要用到dnslog的python扫描脚本该怎么编写?

5、burpsuite抓包

GET /getrecords.php?t=0.20682982721891463 HTTP/1.1Host: User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0Accept: */*Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2Accept-Encoding: gzip, deflateConnection: closeCookie: PHPSESSID=xxxx

【python专题】需要用到dnslog的python扫描脚本该怎么编写?

由上图可知,弱响应包中的列表里面有数据,说明打dnslog有回显了,即漏洞触发成功,反之,若响应包中为空列表,即失败。而关联子域名的参数,即为Cookie,也就是前面在响应头获取的Set-Cookie值会传到这一步的请求头Cookie中,进行关联。让其知道是哪个子域名的结果列表。

6、完整代码

import requests,osdef get_domain():  url='http://xxxx/getdomain.php?t=0.9427873201991249'  headers={'Referer': 'http://dnslog.cn/'}  r=requests.get(url,headers=headers,timeout=5,verify=False)  domain=r.text  cookie=r.headers['Set-Cookie']  result=(domain,cookie)  return result  def get_result(domain,cookie):  url='http://xxxx/getrecords.php?t=0.0701635123201233'  headers={  "Cookie":cookie  }  try:    r=requests.get(url,headers=headers,timeout=5,verify=False)    print(r.text)    if '[]'!=r.text and 'dnslog.cn' in r.text:      return True    else:      return False  except:    print("[!!!]  dnslog.cn刷新dnslog失败")    return Falsedomain,cookie=get_domain()print(domain,cookie)os.system('ping '+domain)if get_result(domain,cookie):    print('[+]打dnslog成功')else:    print('[-]打dnslog失败')

【python专题】需要用到dnslog的python扫描脚本该怎么编写?

原文始发于微信公众号(SCA御盾):【python专题】需要用到dnslog的python扫描脚本该怎么编写?

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年1月28日12:00:44
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【python专题】需要用到dnslog的python扫描脚本该怎么编写?http://cn-sec.com/archives/2438741.html

发表评论

匿名网友 填写信息