mediciyan

在bugscan群里看到有人问有一个大文件,想探测其是否存在。如果使用curl的话,会将整个文件下载到节点,对于扫描没有任何用处,反而浪费了扫描时间。

 

于是我想到的解决办法是不使用curl,直接用底层socket,发包之后接收http head部分,然后拿到返回码之后就断开链接。不知道这样做有没有什么弊端,如果有的话,请指出。

 

下面直接贴上源码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#__author__ = \'Medici.Yan\'
#
\'\'\'测试文件是wps官网上的提供的下载安装包\'\'\'
import socketdef assign(service, arg):
    if service == "ip":
        return True, arg
def audit(arg):
    doGet(arg,\'/wdl1.cache.wps.cn/wps/download/W.P.S.4954.19.552.exe\')

def doGet(host,path):
    payload=\'\'\'GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: zh-CN,zh;q=0.8,en;q=0.6\r\n\r\n\'\'\' % (path,host)
    print payload
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    try:
        socket.setdefaulttimeout(20)#超时
        s.connect((host,80))#连接对应主机和端口
        s.send(payload)
        data=s.recv(len(payload))
        httphead=data.split(\'\r\n\')
        if \'200 OK\' in httphead[0]:
            print \'exist\'
        else:
            print \'error or not exist\'
    except Exception :
        pass
    finally:
        s.close()

if __name__ == \'__main__\':
    from dummy import *
    audit(assign(\'ip\', \'222.178.202.37\')[1])

测试结果:

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2021-12-15
  • 2021-11-20
  • 2021-08-09
  • 2021-08-09
  • 2021-11-15
  • 2022-01-16
  • 2021-06-24
猜你喜欢
  • 2018-09-01
  • 2022-01-12
  • 2021-11-01
  • 2021-11-19
  • 2021-11-06
  • 2021-12-09
  • 2021-11-20
相关资源
相似解决方案