Python多线程编程之Git、SVN信息泄露

0x00前言

  一直想学习Python多线程利用,正好利用requests包检测Git和SVN信息泄露

0x01原理

  读取IP或者域名地址文件,通过requests包的get请求,返回http包状态为200的URL,为了解决网站错误默认页面返回也是200 OK的情况加入了字符匹配判断。可以根据需要添加功能更强的正则匹配筛选。

0x02代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import Queue
import threading
url = ["/.git/config", "/.svn/entries"]
fip = open('test_ip.txt', 'r')
queueLock = threading.Lock()
workQueue = Queue.Queue()
thread_num = 30
threads = []


class MyThread (threading.Thread):
def __init__(self, Queue,id):
threading.Thread.__init__(self)
self.q = Queue
self.id = id

def run(self):
while not workQueue.empty():
get_info(self.q.get())


def get_info(ip):
for payload in url:
target = "http://" + ip + payload
print target
try:
result = requests.get(target, timeout = 5)
if result.status_code == 200:
if result.text.find('[remote "origin"]') != -1 or result.text.find('http://svn') != -1:
queueLock.acquire()
ff = open('seccess.txt', 'a+')
ff.write(target + '\n')
queueLock.release()
break
except:
pass


def main():
for ip in fip:
workQueue.put(ip.strip())
for i in range(thread_num):
thread = MyThread(workQueue,i)
thread.start()
threads.append(thread)

for t in threads:
t.join()

if __name__ == '__main__':
main()