python安全编程之c段扫描器
该脚本主要针对⽹站c段进⾏扫描,我们在进⾏渗透测试的时候,⼀般功能少或者安全防护做的⽐较好的⽹站很难进⾏渗透,我们可以将⽬标放在他的c段上,看看同段的其他服务器搭载了⼀些什么业务,⽅便我们可以更好地进⾏渗透。
我们使⽤python编写这个脚本,设计⽅法是使⽤requests库+多线程,⾸先对段内存活ip进⾏探测,确定存活ip后,再对这些ip的端⼝进⾏请求,探测是否存在服务,如果有服务就返回存在,⽆的话就报⽆。
import requests
import threading
import queue
import sys
import ipaddr
class PortScan(threading.Thread):
def__init__(self,queue):
threading.Thread.__init__(self)
self._queue = queue
self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/55.0.2883.87 Safari/537.36',}
def run(self):
while True:
if self._pty():
breakc编程网站
try:
ip = str(self._(timeout=5))
url = '' + ip
r = (url=url,headers=self.headers,timeout=5)
status = r.status_code
if status:
sys.stdout.write("%-27s\n" % (url))
except Exception:
pass
def main():
if len(sys.argv) != 2:
print ('Usage: python %s 192.168.1.1/24'%(sys.argv[0]))
else:
threads = []
threadnum = 250        #线程数
queue = queue.queue()
cidrip = sys.argv[1]      #接收输⼊IP段
ips = ipaddr.IPNetwork(cidrip)
for ip in ips:
queue.put(ip)
for i in range(threadnum):
threads.append(PortScan(queue))
for t in threads:
t.start()
for t in threads:
t.join()
print ('ALL Finished!')
if__name__ == '__main__':
main()
这个脚本还有很多可以拓展的地⽅,如可以增加user-agent,或者可以使⽤字典对探测存活的端⼝的服务进⾏确认,后续我们可以功能进⾏扩展,完善。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。