tohenk/node-awswaf
GitHub: tohenk/node-awswaf
基于 Axios 的 AWS WAF Challenge 令牌求解库,用于自动获取受 AWS WAF 保护的站点的验证令牌。
Stars: 0 | Forks: 0
# AWS WAF
[AWS WAF (Amazon Web Services Web Application Firewall) Solver](https://github.com/xKiian/awswaf) 的移植版本,使用 Axios,
并合并了一些[更改](https://github.com/pytr-org/pytr/tree/master/pytr/awswaf)。
## 用法
```
const AwsWaf = require('@ntlab/awswaf');
const axios = require('axios');
const cheerio = require('cheerio');
(async function run() {
let awsWafToken;
const headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36'
}
const url = 'https://example.com/';
const f = async (m = 'head') => {
let waf;
await axios[m](url, {headers})
.then(res => {
console.log('Token is not needed...');
})
.catch(err => {
if (err instanceof axios.AxiosError && err.status === 405) {
waf = err.response;
}
});
if (waf) {
if (m === 'head') {
await f('get');
} else if (waf.data) {
const $ = cheerio.load(waf.data);
const challengeJs = $('script[src]')
.toArray()
.map(s => $(s).attr('src'))
.filter(s => s.includes('challenge.js'))
if (challengeJs.length) {
const [, endpoint] = challengeJs[0].match(/(https:\/\/[^"]+)\/challenge\.js/);
const waf = new AwsWaf(endpoint, 'example.com', headers['user-agent']);
awsWafToken = await waf.getToken();
}
}
}
}
await f();
if (awsWafToken) {
console.log(`Got token ${awsWafToken}...`);
}
})();
```
标签:Axios, GNU通用公共许可证, MITM代理, Node.js, Web自动化, 反爬虫绕过, 网络请求库, 自定义脚本