GithubHelp home page GithubHelp logo

ctf-missfeng / bayonet Goto Github PK

View Code? Open in Web Editor NEW
1.4K 32.0 310.0 69.56 MB

bayonet是一款src资产管理系统,从子域名、端口服务、漏洞、爬虫等一体化的资产管理系统

Python 43.40% CSS 18.97% JavaScript 25.76% HTML 11.82% Shell 0.05%
chromium bayonet oneforall shodan python crawlergo xary

bayonet's Introduction

项目更新

Watchdog是bayonet优化版,重新优化了web、数据库模型,加入了多节点部署等功能,详情请查看:

https://github.com/CTF-MissFeng/Watchdog

简介

Bayonet是整合多款安全工具并以web形式展现,它辅助渗透测试人员对IT资产进行资产管理。

遇到问题,请查看lssues是否有解决方案

功能点

  • 子域名扫描:oneforall
  • 端口服务扫描:shodan+异步socket+nmap(ip数据库、CDN判断)
  • URL可用探测
  • 驱动浏览器爬虫采集数据:crawlergo
  • 被动漏洞扫描:xray

安装说明

  • Python3.7以上(推荐Python3.8)
  • 数据库(推荐postgres)
  • chromium浏览器
以Ubuntu16.04为例
  • 1、安装Python3.8以及相关编译环境(dev之类),这里推荐使用miniconda安装,并安装requirements.txt文件所需模块

  • 2、安装postgresql数据库,可将源换成国内源进行快速安装,完成后创建一个空数据库。

  • 3、安装chromium浏览器

sudo apt-get install chromium-browser
  • 4、安装nmap

使用说明

  • 1、修改config.py文件,填入数据库链接项shodan api项,其他选项选填(环境不一致需要更改选项,如nmap路径、chromium浏览器路径等,具体看配置文件)

index

  • 2、执行sh bayonet.sh脚本启动所有模块(注意,如果python3不是默认的python命令,请修改脚本为python3

index

  • 3、登录web,添加一个主域名任务,等待片刻,刷新下,就会执行子域名扫描任务

如果是服务器搭建,则访问http://服务器外网ip,如果为本机搭建则访问http://127.0.0.1 默认用户名密码:root/qazxsw@123

index

index

  • 4、扫描器子域名需要一定时间,可查看日志观察进度(logs目录下是各个模块运行日志)

index

  • 5、当子域名、端口扫描、url探测都开始工作了,会在web中显示各模块结果,现在进入扫描任务管理,选择要扫描的URL进行扫描

index

  • 6、当选择了一个URL进行安全扫描,爬虫模块启动开始驱动浏览器进行爬取,爬取完后,xray开启工作进行漏洞扫描

index

  • 7、当xray扫描进行中,如果有漏洞会实时存入数据库中,刷新漏洞管理可看到,当点击提交按钮,说明此漏洞已复现或提交给SRC(会在已提交漏洞模块中保存),若误报可删除此漏洞。

index

docker使用

$ docker search bayonet  # 查看该项目docker镜像
missfeng/bayonet    bayonet项目docker镜像

$ docker pull missfeng/bayonet:v1.2  # 拉取镜像

$ docker run -itd --name bayonet -p 5000:80 missfeng/bayonet:v1.2  # 后台启动容器

$ docker ps  # 查看已启动的容器
822374ab6f7d        bayonet:v1.2

$ docker exec -it 8223 bash  # 进入容器中 8223是容器ID:822374ab6f7d简写

# /etc/init.d/postgresql start  # 启动数据库

# cd /root/bayonet/   # 进入项目目录

# vim config.py   # 编辑配置文件,找到 shodan_api,填入该参数值;其他配置可自己配置

# sh bayonet.sh  # 启动脚本

访问本机地址: http://127.0.0.1
默认用户名密码:root/qazxsw@123

更新日志

2020年3月16日

bayonet V1.1版本完成。添加并完善了:

  • 1: 去除w13scan被动扫描器,添加xray被动扫描器
  • 2: 主域名任务可重复扫描
  • 3: 修复BUG
2020年3月04日

bayonet V1.1版本完成。添加并完善了:

  • 1:加入了WAF、CDN、ip归属地识别,进行自动跳过,节约了扫描时间
  • 2:加入了异步socket常规端口探测功能、nmap探测功能、防止shodan探测不完整
  • 3:数据表进行了关联,新增且优化了web页面设计
  • 4:爬虫采集到的子域名再次入库,URL探测支持二级目录扫描
  • 5:子域名、端口扫描、URL扫描、爬虫模块整合到一个项目以便关联
  • 6:修复了一些bug

尚未添加功能:

  • 端口服务漏洞扫描
2020年2月13日

bayonet V1.0版本完成,基本连接了这几个工具模块到一起

演示

index

index

index

index

index

bayonet's People

Contributors

ctf-missfeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bayonet's Issues

docker中更新最新版本跑不起来

更新了最新的v1.2的代码包,按照README中在docker中运行会遇到些问题

第一步会遇到文件头没有加utf8的报错,需要自己添加文件头 ,这儿反馈下
image

后面我在config文件里shodan_api 和shodan_api_key里都添加了值但是还是会报错,
image
image

数据库连接问题

SQLALCHEMY_DATABASE_URI = 'postgresql://bayonet:aCymcibCp8RN@localhost:5432/bayonet'
我的数据库配置连接没问题呀!但是就是在插入数据库的时候报错!我数据库版本为11版本

一些建议

可以增加扫ip段,敏感信息搜集模块,git、bing、google、百度等

数据库连接字符问题

师傅, 请问下关于数据库连接字符:
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:qazxsw@[email protected]/bayonet'
其中postgresql postgres qazxsw@123 bayonet这几个参数各自代表什么?
新手查了半天资料无获,谢谢~

建议加个心跳检测

一段时间使用之后发现那几个python进程偶尔会一些原因退出,或者假死
建议加一个心跳检测之类的模块,减少一些命令行运维的操作

docker postgresql start Error

root@e41801b31c12:/etc/init.d# ./postgresql start

  • Starting PostgreSQL 10 database server * Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-10-main.log -s -o -c config_file="/etc/postgresql/10/main/postgresql.conf" exited with status 1:
    2020-03-13 18:01:15.189 HKT [344] LOG: could not create IPv6 socket for address "::1": Permission denied
    2020-03-13 18:01:15.189 HKT [344] LOG: could not create IPv4 socket for address "127.0.0.1": Permission denied
    2020-03-13 18:01:15.189 HKT [344] WARNING: could not create listen socket for "localhost"
    2020-03-13 18:01:15.189 HKT [344] FATAL: could not create any TCP/IP sockets
    2020-03-13 18:01:15.189 HKT [344] LOG: database system is shut down
    pg_ctl: could not start server
    Examine the log output.
    [fail]

如何修改默认访问

我已经本地搭建成功,但是不能设置外网访问。
对5000端口已经防火墙开放成功。
想问一下大佬,如何设置。

是否有统一的proxy管理或设置

开源聚合大卡车啊!已经推荐到到我的项目
感谢开发,感谢开源!
开发不易,还没有阅读源码的,想问一下是不是有统一的proxy/proxy池支持、设置或管理,还是需要单独去每个工具里面设置,或者是在主机上设置所有的出口流量.因为现在遍地WAF...估计没怎么扫描IP就挂了.

建议:OneForAll的结果可以直接取实例对象one的属性datas

OneForAll的结果可以直接取one.datas,不用写得这么复杂的哦。

def subdomain_result(self):
sub_file = pathlib.Path(__file__).parent.resolve().joinpath('results', self.domain + '_subdomain.json')
if not sub_file.is_file():
logger.log('ALERT', '子域名文件:%s未发现' % sub_file)
return None
with open(sub_file, 'r', encoding='utf-8') as file:
tmp_str = file.read()
try:
tmp_dict = json.loads(tmp_str)
except:
logger.log('ALERT', '子域名文件:%s解析json格式错误' % sub_file)
return None

datas的结构长这样:

[{"id": null, "url": "http://freebuf.com:80", "subdomain": "freebuf.com", "port": 80, "ips": "'182.254.150.199'", "status": 200, "reason": "OK", "valid": 1, "new": 0, "title": "FreeBuf互联网安全新媒体平台", "banner": "'Server': 'Apache/2.2.21', 'Via': None, 'X-Powered-By': None"},{...}]

另外现在OneForAll支持传path参数了,对OneForAll有其他问题欢迎交流:P

好像有些问题

image
image
如上图,显示扫描完成,并且查看oneforall的日志也显示扫描完成,发现231个子域,但是在web端显示为空,一个都没有。(docker搭建并且添加了一下api接口)

docker 运行报错

执行docker run -itd --name bayonet -p 5000:80 missfeng/bayonet:v1.1
后继报错如下
docker: Error response from daemon: driver failed programming external connectivity on endpoint bayonet (0d2c5853b4bc91e0e2fae7b5c4e6c493915be166a0b421c308c4517c80cb2bb5): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 5000 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).

子域名数据接口请求异常

image

web日志:

[2020-03-25 14:10:54,477] ERROR in app: Exception on /api/src/subdomain [GET]
Traceback (most recent call last):
  File "/usr/local/bin/python3/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/bin/python3/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/bin/python3/lib/python3.8/site-packages/flask_restful/__init__.py", line 468, in wrapper
    resp = resource(*args, **kwargs)
  File "/usr/local/bin/python3/lib/python3.8/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/bin/python3/lib/python3.8/site-packages/flask_restful/__init__.py", line 583, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/root/bayonet/web/route/src/api.py", line 271, in get
    data1['loudong_count'] = len(i.src_vulnerabilitie)
AttributeError: 'SrcSubDomain' object has no attribute 'src_vulnerabilitie'
222.209.84.125 - - [25/Mar/2020 14:10:54] "GET /api/src/subdomain?page=1&limit=20&searchParams=%7B%22subdomain%22%3A%22%22%2C%22subdomain_ip%22%3A%22%22%7D HTTP/1.1" 500 -

关于使用的疑问?

您好,我使用docker的方式搭建起来环境,添加域名扫描。
添加之后,过一会可以看到域名的扫描结果,但是端口和漏洞数据没有。
请问,添加任务之后是会进行自动的端口 & 漏洞扫描吗?
个人感觉端口数据应该是可以出来的。

另外,是否能给个任务进度提示,我也不知道是不是任务没有跑完?反正等了蛮久的

Nmap程序未找到

我已经在config.py 里指定了具体路径,但是仍然提示nmap路径未找到。

image

检测的域名的ip有问题

不能准确查询到域名对应的正确的ip,和dig出来的ip不一样,我也对同一个域名用oneforall跑,得到的域名也不一致

Spyse API Key (Update)

We noticed that you used the API of one of Spyse's products most likely it was Findsubdomains, Cert DB or DNS table. We want to notify you about the release of a new and improved API key which you can find in your personal account at spyse.com. 
Unfortunately, we should stop supporting the old API a few weeks earlier, starting from Monday. Thanks for being with us.

docker运行,无法执行除子域名以外的所有动作

环境:使用docker环境,已经替换了最新的代码文件。

添加主域名以后,扫描完毕以后。tools.log就不再滚动了,端口扫描等动作也都不执行。

已经添加了shodan 的api,fofa的,zoomeye的都添加了。

tools.log最后的日志就是
02:13:19,629 [INFOR] resolve:170 - 完成异步查询子域的A记录
02:13:19,651 [INFOR] dbexport:65 - 开始进行子域名入库
02:13:20,232 [INFOR] dbexport:77 - 子域名入库完成
02:13:20,242 [INFOR] oneforall:206 - 结束运行OneForAll

w13scan.log中的日志一直在提示
不存在results目录

后续所有的动作都未执行。
请问这个应该怎么处理。

提一些小建议

1.添加域名-->2.获取子域名(添加企查查、备案信息等)[支持自行导入域名list]-->3.子域名解析ip的c段所有ip1-65535端口-->4.实时监控子域名列表,定期获取子域名。
结果支持导出功能

是否考虑搭建多台服务器分布式任务

第一版:
将子域名扫描、爬虫、漏洞扫描,分布布置到不同服务器进行工作,然后把数据统一返回web界面。
第二版:
然后在考虑,多节点形式,比如同时用3个w13scan扫描漏洞,然后在推送到web界面。

端口入库SQL错误

17:18:40,606 [ALERT] Run:63 - 端口入库SQL错误:(psycopg2.errors.ForeignKeyViolation) insert or update on table "src_ports" violates foreign key constraint "src_ports_subdomain_fkey"
DETAIL: Key (subdomain)=(xxx.com) is not present in table "src_subdomain".

[SQL: INSERT INTO src_ports (subdomain_ip, subdomain, port, service, product, version, flag, brute, port_time) VALUES (%(subdomain_ip)s, %(subdomain)s, %(port)s, %(service)s, %(product)s, %(version)s, %(flag)s, %(brute)s, %(port_time)s) RETURNING src_ports.id]
[parameters: {'subdomain_ip': '110.110.110.110', 'subdomain': 'xxx.com', 'port': 80, 'service': 'http', 'product': '', 'version': '', 'flag': False, 'brute': False, 'port_time': '2020-03-24 17:18:40'}]
(Background on this error at: http://sqlalche.me/e/gkpj)
Traceback (most recent call last):
File "run_portscan.py", line 4, in
tools.portscan.Run.port_main()
File "/root/bayonet/tools/portscan/Run.py", line 91, in port_main
WriteSubDomain(results)
File "/root/bayonet/tools/portscan/Run.py", line 40, in WriteSubDomain
sql_subdomain = SrcSubDomain.query.filter(SrcSubDomain.subdomain_ip == results.subdomain_ip).all()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/attributes.py", line 282, in get
return self.impl.get(instance_state(instance), dict_)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/attributes.py", line 705, in get
value = state._load_expired(state, passive)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/state.py", line 660, in _load_expired
self.manager.deferred_scalar_loader(self, toload)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/loading.py", line 987, in load_scalar_attributes
raise orm_exc.ObjectDeletedError(state)
sqlalchemy.orm.exc.ObjectDeletedError: Instance '<SrcSubDomain at 0x7fd6ae270370>' has been deleted, or its row is otherwise not present.

一个小建议

在创建任务的时候,增加一栏用用于填写黑名单来排除不在奖励范围内的域名。
如:*.test.qq.com ,排除test.qq.com下的子域名。对于一些资产比较多src还是可以减少挺多不在范围内的域名,不用再去扫描这些域名的端口和目录等,也有助于提升速度

app.py里面PORT端口是指多少

app.py里面port端口是多少,这个端口,我看用于xray的webhook输出,想确认一下是多少。
我想是否可以在服务器里面搭建一个把漏洞推送到微信那边,通过server酱。
image

crawlergo代理

crawlergo有一个可以设置代理的选项--push-to-proxy
建议可以直接用这个代理上xray,不然爬取的流量还要用python再放一遍

建议每次读取数据库前做一下缓存刷新

实际使用中,有时候我会手动想让OneForALL 某些域名,urlscan对某些端口再跑一次。我会直接修改数据库的flag, 这个时候需要手动重启Run.py,因为缓存问题。所以,建议在扫描之前的读取数据库的时候刷新一下缓存。比如下面的地方,加一行代码commit一下。
比如:

def ReadPort():
    # 刷新缓存
    DB.session.commit()

在云服务器上docker部署后,宿主机无法访问

用两台机器分别拉取了容器下来,配置分别为阿里云轻量服务器ubuntu18.04.4和腾讯云服务器ubuntu18.04.1,
docker run -itd --name bayonet -p 5000:5000 missfeng/bayonet:v1.2
我是讲端口映射放到5000的。
在容器内部执行curl http://127.0.0.1能够正常返回页面内容,但是在宿主机执行curl http://127.0.0.1:5000返回的则是Empty reply from server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.