Chrome执行JS脚本进行接口请求的方法--完成很多需要复杂授权接口的hack

背景:

最近在工作中经常遇到需要在网页上进行重复操作的场景,比如注册大量账户,新建多个子账户之类的操作,都是在一个网站中进行类似重复的操作,但是又很难通过接口去实现,因为网站的授权认证特别麻烦,有各种校验,有些还是第三方登录,比如Google Auth,要通过接口请求去模拟登录异常困难。

问题:

 1、需要在网页上进行重复操作,但实际是调用一个重复的接口;

2、网站的权限校验比较复杂;

解决思路:

通过在Chrome的console中自定义JavaScript的方法,然后通过循环执行调用这个接口传入不同参数来实现我们的目的;

实现步骤:

1、在console中定义函数,请求参数是form表单的情况:

PS:我们这里解决的是通过请求注册接口注册多个账户

const test_register = async () => {
  const uri = 'https://xxx.xxxx.xxx.xxx/system/register_ajax/'
  for (let i = 1000; i < 2000; i ++) {
    const searchParams = new URLSearchParams();
    searchParams.set('username', `user${i}`)
    searchParams.set('password', 'xxxxx')
    searchParams.set('email', `user${i}@gmail.com`)
    searchParams.set('country_code', '000')
    searchParams.set('phone', `000000${i}`)
    await fetch(uri, {
      method: 'POST',
      credentials: 'include',
      body: searchParams,
      headers: {
        "x-csrftoken": "OIYahxxxxxJfafHN0xxxxxxelc098L"
      }
    })
  }
}

2、执行函数:

test_register()

注意事项:

如果请求的接口是JSON格式的话参数应该这样定义:

const add_members = async () => {
      let uri = "https://xxxx.xxx.xxxxxx.com/api/v1/member/?CSRF_TOKEN=xxxxxxxx-4bb2-47a7-aa01-xxxxxxxx"
      for (let i = 6; i < 11; i ++) {
        let post_body = {"parm1":"value", "account_name":`member${i}`, "password":"xxxxxxxxxxxx", "confirmPassword":"", "nick_name":`member${i}`, "email":`member${i}@gmail.com`,"phonePrefix":"+86","phone":`+861345664700${i}`}
        await fetch(uri, {
          method: 'POST',
          credentials: 'same-origin',  //注意这个 [MUST]submit cookies in same origin, if not add this field request will not add cookies
          body: JSON.stringify(post_body)
        })
      }
    }

 

转载于:https://www.cnblogs.com/l33klin/p/9164188.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值