Hi!请登陆

上帝视角:寻找网站源码

2022-6-25 116 6/25

优雅地寻找网站源码(一)

0x0 前言

渗透过程中如果能获取到网站的源代码,那么无疑开启了上帝视角。虽然之前出现过不少通过搜索引擎查找同类网站,然后批量扫备份的思路,但是却没人分享其具体过程,这里笔者便整理了自己开发分布式扫描器的目录扫描模块的一些尝试的思路,同时分享一些寻找源码的其他手段,希望能给读者带来一些新的体验。

0x1 搜索技巧

0x1.1 代码托管平台

国外的github和国内的gitee都是第三方代码托管平台,通过一些搜索技巧,我们可以从中发现很多泄露的敏感信息,其中就包括一些程序的源代码。

这里笔者对码云平时用得不多,故对此只是简单提提,下面,则重点介绍github的用法:

学习这个用法就我个人而言最大的好处是,遇到返回大量数据的时候,可以根据一些特点来过滤掉一些垃圾数据。

Github的搜索页面:https://github.com/search

(1) quick cheat sheet

基础查询:

上帝视角:寻找网站源码

搜索仓库:

上帝视角:寻找网站源码

搜索代码:

上帝视角:寻找网站源码

搜索用户:

上帝视角:寻找网站源码

(2)个人查询Dork

filename:config.phpdbpasswdfilename:.bashrcpasswordshodan\_api\_keylanguage:pythonpath:sitesdatabasespassword"baidu.com"sshlanguage:yamlfilename:file.phpadminin:pathorg:companyname"AWS\_ACCESS\_KEY_ID:"

(3)针对某个关键词查询

用双引号括起来,如"qq.com"

(4)可以使用GitDorker来自定义dork,实现自动化查询。

gitclone https://github.com/obheda12/GitDorker.gitcd GitDorkerdocker build -t gitdorker .docker run -it gitdorkerdocker run -it -v $(pwd)/tf:/tf gitdorker -tf tf/TOKENSFILE -q tesla.com -d dorks/DORKFILE -o tesladocker run -it -v $(pwd)/tf:/tf xshuden/gitdorker -tf tf/TOKENSFILE -q tesla.com -d dorks/DORKFILE -o tesla

免安装使用:

python3GitDorker.py -tf ./TF/TOKENSFILE -q ximalaya.com -d ./Dorks/alldorksv3 -o x mly
上帝视角:寻找网站源码

参考:

https://github.com/techgaun/github-dorks

https://infosecwriteups.com/github-dork-553b7b84bcf4

0x1.2 搜索引擎

Google:

XX源码XX完整包xx安装程序xx备份xx代码xx开源xx源程序xx框架xxext:rar|ext:tar.gz|ext:zip
上帝视角:寻找网站源码

0x1.3 网盘搜索

https://www.feifeipan.com/

https://www.dalipan.com/

https://www.chaonengsou.com/ 这个网站做了个集合,比较全。

上帝视角:寻找网站源码

0x2 曲线思路

如果如0x1所述,依然没办法找到源码,说明目标系统是那种小众或者商业类型的,导致没有在互联网流传广泛,故没办法搜索到。

这个时候,我们便可以采用曲线思路,通过寻找本网站根目录下的备份文件,源代码包进行下载,如果仍然没有找到,则去寻找同套系统的其他网站,扫描这些网站目录下的备份文件和源代码包,从而获取到系统源码。

我们不能做思想上的巨人,行动上的矮子,那么如何高效地完成这一过程呢? 可以划分为下面几个步骤来完成。

0x2.1 提取特征

关于特征,重点收集主页特征,即直接访问域名显示的页面,因为主页是最容易被搜索引擎爬虫爬到的,次之,则是收集主页可访问到的其他标志性页面特征。

(1) logo 特征

请求favicon.ico获取hash

上帝视角:寻找网站源码

(2) 关键词特征

网站title、网站版权信息、j avas cript关键字信息、html源码结构信息、http返回头特征。

0x2.2 资产收集

关于资产收集,除了调度自己写的脚本集成fofa,shodan,zoomeye三个平台之外,我还很喜欢使用一个工具,因为它的功能比较丰富且运行也较为稳定——-fofaviewer。

下载地址:https://github.com/wgpsec/fofa_viewer

上帝视角:寻找网站源码

0x2.3 简单fuzz

收集到资产之后,前期,我喜欢用httpx进行一些路径的简单探测

cat targets.xt|deduplicate|httpx -path /wwwroot.zip -status-code

上帝视角:寻找网站源码

相当于做一层简单的过滤,来帮助nuclei减少请求的量。

0x2.4 编写nuclei插件

阅读和学习编写插件的官方文档:Guide可知:

编写插件第一步: 插件信息

新建back-up-files.yaml文件,写入如下内容

参考:https://nuclei.projectdiscovery.io/templating-guide/template-detail 可知

id是必须的,不能包含空格,一般与文件名相同

info区域是动态的,除了name, author, des cription, severity and tags,也可以添加其他key:value,tags是支持用于nuclei检索调用的,可参照同类插件来写。

id:back-up-filesinfo:name: Find Resource Code Of Target Templateauthor: xq17severity: mediumtags: exposure,backup

编写插件的第二步:发送请求

参考:https://nuclei.projectdiscovery.io/templating-guide/protocols/http/ 可知

1.HTTP Requests start with arequestblock which specifies the start of the requests for the template.

2.Request method can be GET, POST, PUT, DELETE, etc depending on the needs.

3.Redirection conditions can be specified per each template. By default, redirects are not followed. However, if desired, they can be enabled withredirects: truein request d etails.

4.The next part of the requests is the path of the request path. Dynamic variables can be placed in the path to modify its behavior on runtime.

Variables start with{{and end with}}and are case-sensitive.

{{b aseURL}} - This will replace on runtime in the request by the original URL as specified in the target file.

{{Hostname}} - Hostname variable is replaced by the hostname of the target on runtime.

5.Headers can also be specified to be sent along with the requests. Headers are placed in form of key/value pairs. An example header configuration looks like this:

headers contains the headers for the requestheaders: Custom user-agent header User-Agent: Some-Random-User-Agent Custom request origin Origin: https://google.com

6.Body specifies a body to be sent along with the request. (发送POST包需要用到)

7.To maintain cookie b ased browser like session between multiple requests, you can simply usecookie-reuse: truein your template, Useful in cases where you want to maintain session between series of request to complete the exploit chain and to perform authenticated scans.(Session重用,作用是串联攻击链,实现登录验证再攻击)

cookie-reuse accepts boolean input andfalseasdefaultcookie-reuse:true

8.Request condition allows to check for condition between multiple requests for writing complex checks and exploits involving multiple HTTP request to complete the exploit chain.

with DSL matcher, it can be utilized by addingreq-condition: trueand numbers as suffix with respective attributes,status_code_1,status_code_3, andbody_2for example.(编写复杂攻击链)

req-condition: truematchers: -type: dsldsl: -"status\_code\_1 == 404

相关推荐