[记录]在油猴脚本中获取discord用户凭证 | 祭夜博客
  • 欢迎光临,这个博客颜色有点多

[记录]在油猴脚本中获取discord用户凭证

记录 msojocs 4年前 (2020-07-13) 3972次浏览 已收录 1个评论 扫描二维码
文章目录[隐藏]

前言

keyjoker是一个做任务换steam Key的网站,但是任务频率极低,很容易错过。

这逼着我写脚本执行任务 #(阴险) ,里面有个discord加组任务,在此记录用户凭证的获取过程。

开始啦

常规操作,打开邀请页面,打开开发者工具(F12),进入“网络”选项,勾选保留日志

[记录]在油猴脚本中获取discord用户凭证

点击“接受邀请”,可以看到浏览器发送了有个接受请求

[记录]在油猴脚本中获取discord用户凭证

打开postman将request head复制进去,然后开始排除验证信息[记录]在油猴脚本中获取discord用户凭证

 

一番操作之后,可以发现其实只有一个authorization在起作用 #(太开心)

[记录]在油猴脚本中获取discord用户凭证

接下来就是把这个authorization 搞到手就行了,

这种一般在存储中直接就能找到。

果然,在本地存储中找到了

[记录]在油猴脚本中获取discord用户凭证

于是顺手写下localStorage.getItem('token'),但是尴尬的事情发生了:

 

[记录]在油猴脚本中获取discord用户凭证

啊这是被屏蔽了 #(流汗滑稽)

额,去搜索引擎上查了一下,找到了解决方案
Discord window.localStorage is undefined. How to get access to the localStorage on Discord page?

// If we create an <iframe> and connect it to our document, its
// contentWindow property will return a new Window object with
// a freshly created `localStorage` property. Once we obtain the
// property descriptor, we can disconnect the <iframe> and let it
// be collected — the getter function itself doesn’t depend on
// anything from its origin realm to work**.

function getLocalStoragePropertyDescriptor() {
  const iframe = document.createElement('iframe');
  document.head.append(iframe);
  const pd = Object.getOwnPropertyDescriptor(iframe.contentWindow, 'localStorage');
  iframe.remove();
  return pd;
}

// We have several options for how to use the property descriptor
// once we have it. The simplest is to just redefine it:

Object.defineProperty(window, 'localStorage', getLocalStoragePropertyDescriptor());

window.localStorage.heeeeey; // yr old friend is bak

// You can also use any function application tool, like `bind` or `call`
// or `apply`. If you hold onto a reference to the object somehow, it
// won’t matter if the global property gets deleted again, either.

const localStorage = getLocalStoragePropertyDescriptor().get.call(window);

于是轻松的获取到了

[记录]在油猴脚本中获取discord用户凭证
但是,在刷新后token竟然消失了 #(疑问)
[记录]在油猴脚本中获取discord用户凭证

啊这,难搞的说。
经过一番测试,在点击刷新按钮后token出现了,页面开始加载时,token又消失了。 #(黑线)
理论上时js的锅,于是我禁用了js,token就一直都在了
[记录]在油猴脚本中获取discord用户凭证
那就简单了,只要在discord的js加载之前执行localStorage.getItem('token')就行了啊,
简单粗暴把脚本执行时间设置为页面开始加载的时候
// @run-at document-start
测试脚本,一切OK #(滑稽)


祭夜の咖啡馆 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:[记录]在油猴脚本中获取discord用户凭证
喜欢 (2)
[1690127128@qq.com]
分享 (0)

您必须 登录 才能发表评论!

(1)个小伙伴在吐槽
  1. 那个油猴的脚本能分享一下嘛
    月亮2023-03-29 02:51 Windows 10 | Chrome 111.0.0.0