下巴- 客户端JavaScript的基于图的安全分析框架

taibeihacker

Moderator
基于ESPRIMA解析器的JavaScript的属性图的开源,原型实现以及Estree spidermonkey规范。 JAW可用于分析Web应用程序和基于JavaScript的程序的客户端。
该项目已根据GNU AFFERO通用公共许可证v3.0许可。请参阅此处以获取更多信息。
Jaw在https://soheilkhodayari.github.io/jaw/上提供了一个GitHub页面网站。
Release Notes:
2023年10月,JAW-V3(警长): JAW已更新以检测客户端请求劫持漏洞。 2022年7月,JAW-V2(Thetthing): JAW更新到其下一个主要版本,能够检测DOM CLOBBerbering漏洞。请参阅JAW-V2分支。 2020年12月,JAW-V1 :第一个原型版本。请参阅JAW-V1分支。

Overview of JAW​

下颌的体系结构如下所示。
JAW_6_architecture_v3.png

Test Inputs​

JAW can be used in two distinct ways:
Arbitrary JavaScript Analysis:通过指定程序的文件系统路径来建模和分析任何JavaScript程序。
Web Application Analysis:通过提供单个种子URL来分析Web应用程序。

Data Collection​

JAW具有几个启用JavaScript的Web爬网机,用于大规模收集Web资源。

HPG Construction​

使用收集的Web资源创建混合程序图(HPG),该图将导入到NEO4J数据库中。
Optionally, supply the HPG construction module with a mapping of semantic types to custom JavaScript language tokens, facilitating the category of JavaScript functions based on their purpose (e.g. HTTP request functions).

Analysis and Outputs​

查询构建的NEO4J图数据库,以进行各种分析。 JAW为数据流分析,控制流分析,可及性分析和模式匹配提供实用程序遍历。这些遍历可用于开发自定义安全分析。
下巴还包括用于检测客户端CSRF的内置遍历,DOM CLOBBERing和请求劫持漏洞。
输出将存储在与输入的文件夹中。

Setup​

The installation script relies on the following prerequisites: - Latest version of npm package manager (node js) - Any stable version of python 3.x - Python pip package manager
Afterwards, install the necessary dependencies via:
$ ./install.sh,有关详细的安装说明,请参阅此处。

Quick Start​

Running the Pipeline​

您可以在背景屏幕Via:中运行管道实例
$ python3 -m run_pipeline -conf=config.yaml CLI提供以下选项:
$ python3 -m run_pipeline -h
USAGE: run_pipeline.py [-h] [ - conf file] [ - site site] [ - 列表列表] [ - from from]
该脚本运行工具管道。
可选参数:
-h, - 赫尔普显示此帮助消息和退出
-conf文件,-c文件管道配置文件。 (Default: config.yaml)
- 网站,-s网站网站进行测试;覆盖配置文件(Default:无)
- 列表列表,-l列表网站列表要测试;覆盖配置文件(Default:无)
- 从第一个条目中,从第一个条目中考虑提供站点列表何时;覆盖配置文件(Default: -1)
- to,-t到最后一个条目,请考虑何时提供站点列表;覆盖配置文件(Default: -1)Input Config:JAW期望.YAML配置文件作为输入。有关示例,请参见Config.yaml。
Hint.The config file specifies different passes (e.g. crawling, static analysis, etc) which can be enabled or disabled for each vulnerability class. This allows running the tool building blocks individually, or in a different order (e.g. crawl all webapps first, then conduct security analysis).

Quick Example​

用于运行快速示例,演示如何构建属性图并在其上运行Cypher查询,DO:
$ python3 -m analyzes.example.example_analysis --input=$(pwd)/data/test_program/test.js

Crawling and Data Collection​

This module collects the data (i.e. JavaScript code and state values of web pages) needed for testing.如果要测试文件系统上已经有的特定JavaScript文件,则可以在此步骤skip
Jaw具有基于硒(JAW-V1),Puppeteer(JAW-V2,V3)和剧作家(JAW-V3)的爬虫。对于大多数最新功能,建议使用uppeteer或基于剧作的版本。

Playwright CLI with Foxhound​

This web crawler employees foxhound, an instrumented version of Firefox, to perform dynamic taint tracking as it navigates through webpages.要启动爬行者,DO:
$ CD爬网
$ node crawler-taint.js --seedurl=https://google.com --maxurls=100 --headless=true --foxhoundpath=optional-foxhound-executable-path The foxhoundpath is by default set to the following directory: crawler/foxhound/firefox which contains a binary named firefox.
Note:您需要使用此版本的Foxhound构建。 JAW-V3版本中包含Ubuntu构建。

Puppeteer CLI​

启动爬行者,do:
$ CD爬网
$ node crawler.js - seedurl=https://google.com -maxurls=100 -browser=chrome -headless -headless=true,请参阅此处。有关更多信息。

Selenium CLI​

启动爬行者,do:
$ CD爬行者/HPG_CRAWLER
$ vim docker-compose.yaml#设置要在此处爬网的网站并保存
$ docker-compose构建
$ docker -compose -D请参阅此处的HPG_CRAWLER的文档以获取更多信息。

Graph Construction​

HPG Construction CLI​

用于生成给定(一组)JavaScript文件的HPG,DO:
$ node Engine/cli.js -lang=js -graphid=graph1 -input=/in/file1.js -input=/in/file2.js -output=$(pwd)/data/data/out/-mode=csv
可选参数:
-lang:输入程序的语言
-graphid:生成的HPG的标识符
-Input:输入程序的路径
- 输出:输出hpg的路径必须为i
--mode: determines the output format (csv or graphML)

HPG Import CLI​

To import an HPG inside a neo4j graph database (docker instance), do:
$ python3 -m hpg_neo4j.hpg_import -rpath=to to to to to-the-folder-the-csv-files -id=xyz -nodes=nodes.csv-eDges=rels.csv=rels.csv
$ python3 -m hpg_neo4j.hpg_import -h
USAGE: HPG_IMPORT.PY [-H] [ - -RPATH P] [-ID I] [ - NODES N] [ - EDGES E]
该脚本将属性图的CSV导入到Neo4J Docker数据库中。
可选参数:
-h, - 赫尔普显示此帮助消息和退出
- 吊车P的相对路径与包含`data`目录中的图形CSV文件的文件夹相对路径
- ID i图形或Docker容器的标识符
- 节点n节点CSV文件的名称(default: nodes.csv)
--edges E the name of the relationships csv file (default: rels.csv)

HPG Construction and Import CLI (v1)​

In order to create a hybrid property graph for the output of the hpg_crawler and import it inside a local neo4j instance, you can also do:
$ python3 -m engine.api path --js=program.js --import=bool --hybrid=bool --reqs=requests.out --evts=events.out --cookies=cookies.pkl --html=html_snapshot.htmlSpecification of Parameters:path: absolute path to the folder containing the program files for analysis (must be under the engine/outputs 文件夹)。 -js=program.js:用于分析的JavaScript程序的名称(DEFAULT: JS_PROGRAME.JS)。 -import=boo:是否应将构造的属性图导入到活动的neo4j数据库(Default: True)。 -HYBRID=BOOL:是否启用了混合模式(Default: False)。 This implies that the tester wants to enrich the property graph by input files for any of the HTML snapshot, fired events, HTTP requests and cookies, as collected by the JAW crawler. --reqs=requests.out: for hybrid mode only, name of the file containing the sequence of observed network requests, pass the string false to exclude (default: request_logs_short.out). --evts=events.out: for hybrid mode only, name of the file containing the sequence of fired events, pass the string false to exclude (default: events.out). --cookies=cookies.pkl: for hybrid mode only, name of the file containing the cookies, pass the string false to exclude (default: cookies.pkl). --html=html_snapshot.html: for hybrid mode only, name of the file containing the DOM tree snapshot, pass the string false to exclude (default: html_rendered.html).有关更多信息,您可以使用Graph Construction API:提供的帮助CLI
$ Python3 -m Engine.API -H

Security Analysis​

可以使用Cypher或NeoModel ORM查询构造的HPG。

Running Custom Graph traversals​

您应该在分析/Analysis_name中放置并运行查询。

Option 1: Using the NeoModel ORM (Deprecated)​

您可以使用NeoModel Orm查询HPG。写一个query:
(1)查看HPG数据模型和语法树。 (2)查看HPGS的ORM模型(3)请参阅提供的示例查询文件; example_query_orm.py在分析/示例文件夹中。 $ python3 -m analyzes.example.example_query_orm有关更多信息,请参阅此处。

Option 2: Using Cypher Queries​

您可以使用Cypher编写自定义查询。对于此:
(1)查看HPG数据模型和语法树。 (2)请参见提供的示例查询文件; example_query_cypher.py在分析/示例文件夹中。 $ python3 -m andarys.example.example_query_cypher有关更多信息,请参阅此处。

Vulnerability Detection​

本节介绍了如何配置和使用下颌进行漏洞检测以及如何解释输出。下颌包含用于检测客户端CSRF和DOM CLOBBERING的独立查询
Step 1.在输入config.yaml文件:中启用漏洞类的分析组件
request_hijacking:
启用: True
#[.]

Domclobbering:
启用: false
#[.]
CS_CSRF:
启用: false
#[.]Step 2.使用:运行管道实例
$ python3 -m run_pipeline -conf=config.yamlHint.您可以在不同屏幕下运行管道的多个实例:
$ screen -dms s1 bash -c'python3 -m run_pipeline -conf=conf1.yaml; exec sh'
$ screen -dms s2 bash -c'python3 -m run_pipeline -conf=conf2.yaml; exec sh'
$#[.]要自动生成并行配置文件,您可以使用generate_config.py脚本。

How to Interpret the Output of the Analysis?​

输出将存储在一个名为sink.flows.out的文件中,以在与输入的文件夹中。 For Client-side CSRF, for example, for each HTTP request detected, JAW outputs an entry marking the set of semantic types (a.k.a, semantic tags or labels) associated with the elements constructing the request (i.e. the program slices).例如,通过窗口。LocationIndection Point可以原谅具有语义类型['win.loc']的HTTP请求。但是,标记为['非范围']的请求是不可原谅的。
示例输出条目在:下显示
[*] tags: ['win.loc']
[*] nodeid: {'topexpression':'86','callexpression':'87','gright':'94'}
[*]位置: 29
[*]功能: AJAX
[*] template: ajaxloc +'/bearer1234/'
[*] top Expression: $ .ajax({Xhrfields: {withCredentials:'true'},url: ajaxloc +'/bearer1234/'})
1: ['win.loc']变量=ajaxloc
0 (loc:6)- var ajaxloc=window.location.href This entry shows that on line 29, there is a $.ajax call expression, and this call expression triggers an ajax request with the url template value of ajaxloc + '/bearer1234/, where the parameter ajaxloc is a program slice reading its value at line 6 from window.location.href, thus forgetable through ['win.loc']。

Test Web Application​

In order to streamline the testing process for JAW and ensure that your setup is accurate, we provide a simple node.js web application which you can test JAW with.
首先,安装依赖项VIA:
$ CD测试/测试Webapp
然后安装$ npm,然后在新的屏幕:中运行该应用程序
$ screen -dms jawwebapp bash -c'端口=6789 npm run devstart; Exec SH'

Detailed Documentation.​

有关更多信息,请访问我们的Wiki页面。以下是用于快速访问的目录。

The Web Crawler of JAW​

Web Crawlers

Data Model of Hybrid Property Graphs (HPGs)​

Property Graph Nodes Grammar and Syntax Tree Property Graph Edges

Graph Construction​

Building a Property Graph Using JAW with Neo4j Docker Container

Graph Traversals​

Running Queries Over Property Graphs

Contribution and Code Of Conduct​

Pull requests are always welcomed.该项目旨在是一个安全,受欢迎的空间,预计贡献者将遵守《贡献者的行为守则》。

Academic Publication​

如果您使用下巴进行学术研究,我们建议您引用以下论文:
@inproceedings {jaw,
title={JAW:使用混合属性图和声明性遍历研究客户端CSRF,
author={Soheil Khodayari and Giancarlo Pellegrino},
BookTitle={30th {USENIX}安全研讨会({USENIX} SECURION 21)},
年={2021},
地址={Vancouver,B.C。},
publisher={{usenix}协会},
}

Acknowledgements​

颌骨已经走了很长一段路,我们想在这里给贡献者一个当之无愧的喊叫!
@tmbrbr, @c01gide,@jndre和sepehr mirzaei。
 
返回
上方