0x00 前言 以前一直用别人的路径字典扫描,不如自己做一个路径字典。
0x01 字典收集思路 1.从百度谷歌进行收集,这个比较适合单点功能文件查找。 比如搜集后台路径:
从百度中获取到结果,能制作比较好的后台路径字典出来。
2.从sourceforge这样类集合了大量的源码的网站上搜集或者从mycodes.net这样网站上把所有的网站源码压缩包下载下来,然后进行搜集。
这个思路搜集出来的字典大而全。
0x02 编程实现 使用思路2,从mycodes.net这样网站上把所有的网站源码压缩包下载下来,然后进行搜集。以asp为例子。
0x01 爬取下载地址 爬去范围:http://www.mycodes.net/5/ ,结束页是http://www.mycodes.net/5/133.htm 。
使用BeautifulSoup进行提取URL下载地址,然后再使用request获取302跳转后的真正下载地址。
脚本:crawl.py
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 55 56 57 58 59 60 import urllib.requestimport bs4from bs4 import BeautifulSoupimport refrom urllib.parse import urlparsedef WriteFile (path,str ): f = open (path,"a+" ) f.write(str +"\n" ) for i in range (1 ,134 ): i = str (i) + ".htm" if (i == "1.htm" ): i = "" url = "http://www.mycodes.net/5/" + i print (url+"\n" ) response = urllib.request.urlopen(url).read() html = response.decode('gbk' ,'ignore' ) soup = BeautifulSoup(html,"html.parser" ) table = soup.find_all("table" ,width=re.compile ("97%" ), border="0" ) for a in table: name = a.find("a" ,target="_blank" ).string print (name) print (a.find("a" ,target="_blank" )["href" ]) siteUrl = a.find("a" ,target="_blank" )["href" ] response = urllib.request.urlopen(siteUrl).read() html = response.decode('gbk' ,'ignore' ) siteSoup = BeautifulSoup(html,"html.parser" ) jumpTd = siteSoup.find("td" ,class_="b4" ) jumpA = jumpTd.find("a" ) jumpUrl = jumpA['href' ] try : buff = urllib.request.urlopen(jumpUrl) print (buff.geturl()) parseResult = urlparse(buff.geturl()) path = parseResult.path regx = re.compile (r"""/.*?/(.*?(?:\.zip|rar))""" ,re.I) regxResult = re.findall(regx,path) print (regxResult[0 ]) WriteFile('url.txt' ,buff.geturl()) WriteFile('match.txt' ,regxResult[0 ]+":" +name) except : pass
0x02 下载压缩包 下载url.txt中的文件。也可以用迅雷下载,下载文件比较多,也比较大,很消耗时间。 文件:download.py
1 2 3 4 5 6 7 8 9 10 11 from urllib import requestf = open (r"url.txt" ,"r" ) lines = f.readlines() for line in lines: downUrl = line.replace('\n' ,'' ) print (downUrl) filename = downUrl.split('/' )[-1 ] print (filename) with request.urlopen(downUrl) as reponse: with open (filename, 'wb' ) as outFile: outFile.write(reponse.read())
0x03 搜集路径 其实这里使用这个方法搜集有一个弊端,而且没办法完全避免,只能规避大部分。压缩包多层目录进行打包,掺杂了一些其他的东西,导致没办法获取到源码的真正的根目录。所以导致这里最复杂。说下我遇到的问题和解决办法的历程。
最新遇到的问题:打包多层目录 www\lvyecms\index.asp 搜集到的是: www\lvyecms\index.asp 而我们需要搜集到: \index.asp
这样的情况比较好解决,最开始我用的办法是寻找到index.asp的目录为根目录,结果发现有一部分有index.asp或者有多个index.asp。导致搜集不准确。
后来我用把一个压缩包下面所有的路径,遍历一次,寻找共同的目录,然后把共同的目录去掉。 但是还是遇到问题。
再遇问题:添加了额外的目录 www\lvyecms\index.asp www\help\test.txt 搜集到的是: www\lvyecms\index.asp www\help\test.txt 而我们需要搜集的目录: \index.asp
两个目录,但是help里面什么东西都没有,导致我上面的办法失效了。我就在添加要有.asp后缀的文件的目录再去掉共同目录去掉。
再遇问题:把wap版本和电脑版本放一起类似的情况 /quickwap分类信息网/wap/wapconfig/wapheader.asp /wap1.2企业系统/aboutus.asp 导致搜集到的结果是: /quickwap分类信息网/wap/wapconfig/wapheader.asp /wap1.2企业系统/aboutus.asp 而我们需要搜集的是 /wapconfig/wapheader.asp /aboutus.asp
类似上面的问题就没办法解决了。幸好是极少数的情况。
path.py
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 import osimport zipfileimport rarfileimport ioimport sys reload(sys) sys.setdefaultencoding('gbk' ) def WriteFile (dir ): f = open ("dir.txt" , "a+" ) f.write(dir + "\n" ) for file in os.listdir("./ASP/" ): flagDir = '' dirList = [] if (os.path.splitext(file)[1 ] == ".rar" ): print ("\n" + file + "\n" ) rFileName = "./ASP/" + file r = rarfile.RarFile(rFileName, 'r' ) for filePath in r.namelist(): filePath = '/' + filePath if (filePath.split('/' )[-1 ].find('.' ) < 0 and filePath[-1 ]!='/' ): filePath = filePath + '/' if (filePath[-1 ] == '/' or filePath[-4 :] == '.asp' or filePath[-4 :] == '.mdb' ): dirList.append(filePath) if (len (dirList)>0 ): for dirPath in dirList: if (dirPath.lower().find('.asp' ) > 0 ): sameList = dirPath.split('/' ) flag = 1 for index in range (len (sameList)): for filePath in dirList: if (filePath[-1 ] != '/' ): if (filePath.find(sameList[index])<0 ): flag = 0 break if (flag == 0 ): break for index in range (1 ,index): flagDir = flagDir + '/' + sameList[index] for filePath in dirList: try : if (filePath.replace(flagDir,'' ) != '/' ): print (filePath.replace(flagDir,'' ).lower()) WriteFile(filePath.replace(flagDir,'' ).lower()) except : pass if (os.path.splitext(file)[1 ] == ".zip" ): print ("\n" + file + "\n" ) zFileName = "./ASP/" + file z = zipfile.ZipFile(zFileName, 'r' ) for filePath in z.namelist(): filePath = '/' + filePath if (filePath.split('/' )[-1 ].find('.' ) < 0 and filePath[-1 ]!='/' ): filePath = filePath + '/' if (filePath[-1 ] == '/' or filePath[-4 :] == '.asp' or filePath[-4 :] == '.mdb' ): dirList.append(filePath) if (len (dirList)>0 ): for dirPath in dirList: if (dirPath.lower().find('.asp' ) > 0 ): sameList = dirPath.split('/' ) flag = 1 for index in range (len (sameList)): for filePath in dirList: if (filePath[-1 ] != '/' ): if (filePath.find(sameList[index])<0 ): flag = 0 break if (flag == 0 ): break for index in range (1 ,index): flagDir = flagDir + '/' + sameList[index] for filePath in dirList: try : if (filePath.replace(flagDir,'' ) != '/' ): print (filePath.replace(flagDir,'' ).lower()) WriteFile(filePath.replace(flagDir,'' ).lower()) except : pass
0x03 结语 这里只是搜集了asp的,还有php之类的,就不能用上面的办法了,因为现在比如使用thinkphp框架的,该怎么搜集。就需要另外讨论了。以前的老一套也应该改革换新了。