Skip to content

Commit

Permalink
Merge pull request hanc00l#36 from NorthKou/master
Browse files Browse the repository at this point in the history
add some instructions for elasticsearch and mongodb
  • Loading branch information
hanc00l authored Mar 17, 2017
2 parents 06aa6ed + 6ebef4c commit 0cc77c2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
68 changes: 54 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# wooyun_public
# wooyun_public
**乌云公开漏洞、知识库爬虫和搜索**

**crawl and search for wooyun.org public bug(vulnerability) and drops**
Expand All @@ -10,13 +10,13 @@
--------
+ python 2.7和pip
+ mongodb
+ scrapy
+ scrapy
+ flask 或者 tornado
+ pymongo
+ Elasticserch (搜索引擎,可选)

[在ubuntu下的安装过程(点我)](install.md)


2.爬虫(由于wooyun已不以访问,爬虫功能已不可用)
--------
Expand All @@ -28,21 +28,60 @@
-a page_max: 控制爬取的页数,默认为1,如果值为0,表示所有页面
-a local_store: 控制是否将每个漏洞离线存放到本地,默认为false
-a update:控制是否重复爬取,默认为false

+ 第一次爬取全部内容时,用scrapy crawl wooyun -a page_max=0 -a update=true

+ 平时只爬取最近的更新时,用scrapy crawl wooyun -a page_max=1,可以根据自己的爬取频率和网站更新情况调整page_max的值

+ 全部公开漏洞的列表和每个漏洞的文本内容存在mongodb中,大概约2G内容;如果整站爬全部文本和图片作为离线查询,大概需要10G空间、2小时(10M电信带宽);爬取全部知识库,总共约500M空间。(截止2015年10月)

3.搜索
3.搜索
--------
+ 漏洞搜索使用了Flask作为web server,bootstrap作为前端(8.12增加tornador web server,可配合nginx反向代理,支持高并发的应用)

+ 启动web server :在flask目录下运行./app.py,默认端口是5000

+ #### 启动Elassticsearch(如果已配置了Elasticsearch):在elasticsearch-2.3.4/bin目录下运行./elasticsearch -d (-d表示以后台方式运行)

注:elasticsearch 5.x版本需将flask/app.py中的搜索方式改为bool搜索。
即将```search_mongodb_by_es```函数中的```query_dsl```替换为如下所示

```
...
if keywords.strip() == '':
query_dsl = {
"query": {
"bool": {
"must": {
"match_all": {}
}
}
},
"sort": {"datetime": {"order": "desc"}},
"from": row_start,
"size": ROWS_PER_PAGE
}
else:
query_dsl = {
"query": {
"bool": {
"must": {
"match": {
field_name: {
'query': keywords,
'operator': 'and'
}
}
}
}
},
"sort": {"datetime": {"order": "desc"}},
"from": row_start,
"size": ROWS_PER_PAGE
}
...
```

+ 搜索:在浏览器通过http://localhost:5000进行搜索漏洞,多个关键字可以用空格分开。

+ 默认使用mongodb的数据库搜索,在进行全文搜索时比较慢,推荐安装使用Elasicsearch搜索引擎。[安装和配置Elasicsearch的方法(点我)](elasticsearch_install.md)
Expand All @@ -59,22 +98,24 @@ db.wooyun_drops.ensureIndex({"datetime":1})
5.虚拟机
------

+ 虚拟机1:在2016年6月底爬的wooyun全部漏洞库和知识库内容,集成了Elasticsearch搜索,总共35G(压缩后约14G),网盘地址为: [http://pan.baidu.com/s/1kVtY2rX](http://pan.baidu.com/s/1kVtY2rX) ,提取密码:5ik7(8.5更新)
+ 虚拟机1:在2016年6月底爬的wooyun全部漏洞库和知识库内容,集成了Elasticsearch搜索,总共35G(压缩后约14G),网盘地址为: [http://pan.baidu.com/s/1kVtY2rX](http://pan.baidu.com/s/1kVtY2rX) ,提取密码:5ik7(8.5更新)

使用方法:

1、压缩包解压后是一个vmware虚拟机的镜像,可以由vmware直接打开运行;
2、由于在制作压缩包时虚拟机为“挂起”状态,当前虚拟机的IP地址可能和宿主机的IP地址段不一致,请将虚拟机重启后重新获取IP地址,虚拟机用户密码为hancool/qwe123;
3、进入wooyun_public目录,先用git更新一下到最新的代码git pull(如果提示merge冲突,先进行git reset --hard origin/master后再git pull);
4、在elasticsearch-2.3.4/bin目录下运行./elasticsearch -d (-d表示以后台方式运行)
5、进入wooyun_public/flask目录,运行./app.py;
6、打开浏览器,输入http://ip:5000,ip为虚拟机的网卡地址(使用ifconfig eth0查看)

注:推荐将mongodb升级至最新版本,可将数据部分缩减至1G以内(800M左右)。


+ 虚拟机2:已打包了一个安装了所有组件和elasticsearch搜索的虚拟机,不包含具体内容,压缩后约2.3G(由于wooyun还处于升级关闭期间,无法进行内容的爬取),网盘地址:[http://pan.baidu.com/s/1nvrS3zj](http://pan.baidu.com/s/1nvrS3zj),提取密码:2290 (8.5更新)

使用方法:

1、压缩包解压后是一个vmware虚拟机的镜像,可以由vmware直接打开运行;
2、由于在制作压缩包时虚拟机为“挂起”状态,当前虚拟机的IP地址可能和宿主机的IP地址段不一致,请将虚拟机重启后重新获取IP地址,虚拟机用户密码为hancool/qwe123;
3、在elasticsearch-2.3.4/bin目录下运行./elasticsearch -d (-d表示以后台方式运行)
Expand All @@ -90,5 +131,4 @@ db.wooyun_drops.ensureIndex({"datetime":1})

+ 本程序只用于技术研究和个人使用,程序组件均为开源程序,漏洞和知识库来源于乌云公开漏洞,版权归wooyun.org。

+ 期待雨过天晴、重开wooyun!

+ 期待雨过天晴、重开wooyun!
28 changes: 24 additions & 4 deletions elasticsearch_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,38 @@ Elasticsearch Install
```bash
sudo apt-get install openjdk-7-jdk
```

注:5.x 版本需安装```openjdk-8-jdk```

2、下载elasticseach

```bash
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.4/elasticsearch-2.3.4.tar.gz
tar xvf elasticsearch-2.3.4.tar.gz
```

亦可通过apt或者yum安装,参见

deb [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html)

rpm [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/rpm.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/rpm.html)

注:国内可使用tsinghua(清华)镜像源[https://mirrors.tuna.tsinghua.edu.cn/elasticstack/5.x/](https://mirrors.tuna.tsinghua.edu.cn/elasticstack/5.x/)

3、运行elasticsearch

```bash
cd elasticsearch-2.3.4/bin
./elasticsearch
```

亦可通过systemd启动

```
systemctl enable elasticsearch
systemctl start elasticsearch
```

4、测试一下,安装完成运行后elasticsearch会在9200端口上进行监听

```bash
Expand All @@ -48,7 +66,7 @@ curl -X GET http://localhost:9200
-------

1、编辑/etc/mongodb.conf,增加:

replSet=rs0 #这里是指定replSet的名字
oplogSize=100 #这里是指定oplog表数据大小(太大了不支持)

Expand All @@ -61,7 +79,7 @@ sudo service mongodb restart

```bash
mongo
rs.initiate( {"_id" : "rs0", "version" : 1, "members" : [ { "_id" : 0, "host" : "127.0.0.1:27017" } ]})
rs.initiate( {"_id" : "rs0", "version" : 1, "members" : [ { "_id" : 0, "host" : "127.0.0.1:27017" } ]})
```
3,搭建好replicSet之后,退出mongo shell重新登录,提示符会变成:rs0:PRIMARY>,就可以退出Mongodb
Expand Down Expand Up @@ -94,6 +112,8 @@ vi elasticsearch-2.3.4/config/elasticsearch.yml
index.analysis.analyzer.ik.type : 'ik'
index.analysis.analyzer.default.type : 'ik'
注:此部操作在5.x版本中已废弃,参见[https://github.com/medcl/elasticsearch-analysis-ik](https://github.com/medcl/elasticsearch-analysis-ik)
4、退出并重启elasticsearch
```bash
Expand Down Expand Up @@ -127,7 +147,7 @@ sudo vi /usr/local/lib/python2.7/dist-packages/mongo_connector/doc_managers/elas
```
将:
self.elastic = Elasticsearch(hosts=[url],**kwargs.get('clientOptions', {}))
修改为:
self.elastic = Elasticsearch(hosts=[url],timeout=200, **kwargs.get('clientOptions', {}))
Expand Down Expand Up @@ -167,4 +187,4 @@ vi ~/wooyun_public/flask/app.py
6、[https://github.com/medcl/elasticsearch-analysis-ik/issues/207](https://github.com/medcl/elasticsearch-analysis-ik/issues/207)
7、[https://github.com/mongodb-labs/mongo-connector/wiki/Usage%20with%20ElasticSearch](https://github.com/mongodb-labs/mongo-connector/wiki/Usage%20with%20ElasticSearch)
7、[https://github.com/mongodb-labs/mongo-connector/wiki/Usage%20with%20ElasticSearch](https://github.com/mongodb-labs/mongo-connector/wiki/Usage%20with%20ElasticSearch)
12 changes: 6 additions & 6 deletions flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ELASTICSEARCH CHOOSE
# auto: auto detect elasticsearch ,if opened then use elasticsearch,else use mongodb
# yes: always use elasticsearch
# no: not use elasticsearch
# no: not use elasticsearch
SEARCH_BY_ES = 'auto'
# flask app:
app = Flask(__name__)
Expand Down Expand Up @@ -82,7 +82,7 @@ def search_mongodb_by_es(keywords, page, content_search_by, search_by_html):
query_dsl = {
"query": {
"filtered": {
"query": {
"query": {
"match_all":{ }
}
}
Expand All @@ -91,12 +91,12 @@ def search_mongodb_by_es(keywords, page, content_search_by, search_by_html):
"from": row_start,
"size": ROWS_PER_PAGE
}
else:
else:
query_dsl = {
"query": {
"filtered": {
"query": {
"match": {
"query": {
"match": {
field_name : {
'query':keywords,
'operator':'and'
Expand All @@ -121,7 +121,7 @@ def search_mongodb_by_es(keywords, page, content_search_by, search_by_html):
urlsep = c['url'].split('//')[1].split('/')
c['url_local'] = '%s-%s.html' % (urlsep[1], urlsep[2])
page_info['rows'].append(c)

return page_info

def check_elastichsearch_open():
Expand Down

0 comments on commit 0cc77c2

Please sign in to comment.