B站专栏目前只支持富文本编辑器,文本编辑器就分为两种,支持markdown的和不支持markdown,惋惜的是B站的专栏并不支持markdown并且也没有计划支持,这也是能够理解,毕竟up主们并不都了解markdown,但对于一个重度md用户,用富文本编辑器是不管如何都没法忍受的,因而研究了下专栏的逻辑,找到了支持md的方案,见下文。javascript
用户在编辑专栏时,系统会实时将数据经过接口https://api.bilibili.com/x/article/creative/draft/addupdate
保存到后台,接口参数以下(curl)html
curl 'https://api.bilibili.com/x/article/creative/draft/addupdate' \ -H 'authority: api.bilibili.com' \ -H 'accept: application/json, text/javascript, */*; q=0.01' \ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' \ -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \ -H 'origin: https://member.bilibili.com' \ -H 'sec-fetch-site: same-site' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-dest: empty' \ -H 'referer: https://member.bilibili.com/article-text/home?aid=74916' \ -H 'accept-language: zh,en;q=0.9,en-US;q=0.8,zh-CN;q=0.7,nb;q=0.6,mt;q=0.5' \ -H $'cookie: xxxxxxxxx(cookie打码)' \ --data-raw 'title=%E8%BF%99%E6%98%AF%E6%A0%87%E9%A2%98&banner_url=&content=%3Cp%3E%E8%BF%99%E6%98%AF%E6%AD%A3%E6%96%87%3C%2Fp%3E&summary=%E8%BF%99%E6%98%AF%E6%AD%A3%E6%96%87&words=4&category=4&list_id=0&tid=4&reprint=0&tags=&image_urls=&origin_image_urls=&dynamic_intro=&media_id=0&spoiler=0&original=0&aid=74916&csrf=027817004f35eb34f312464c4828ca62' \ --compressed
能够看出如下几个信息java
content-type: application/x-www-form-urlencoded
能够看出几个比较重要的参数:git
{"code":0,"message":"0","ttl":1,"data":{"aid":74916}}
看到这里聪明的你就能发现能够本身伪造一个form表单进行提交,因而简单写了个表单htmlgithub
<html> <body> <form action="https://api.bilibili.com/x/article/creative/draft/addupdate" method="POST"> <input type="text" name="content" id="bcontent" value="测试是否能够经过伪造表单进行提交"/> <input type="text" name="aid" id="baid" value="74916"/> <input type="text" name="csrf" id="bcsrfid" value="027817004f35eb34f312xxxxxxxx"/> <input type="submit" value="提交" /> </form> </body> </html>
提交后返回code:0说明提交成功,进入B站后台专栏管理,确实修改为功chrome
若是没有csrf这个编号那么这个demo就是赤裸裸的csrf攻击
demo测试成功因而方案就很好作。json
大概的思路是经过js将markdown转换为html,再经过上述的表单进行提交,但用户须要提供一些必要的信息。markdown转js这里经过showdown库实现。代码也很少,这里贴出完整源码,另存为html便可api
<html> <head> <meta name="referrer" content="unsafe-url" /> <meta name="referrer" content="origin" /> <meta name="referrer" content="no-referrer-when-downgrade" /> <meta name="referrer" content="origin-when-cross-origin" /> <meta name="referrer" content="no-referrer" /> <meta charset="utf-8" /> </head> <body style="margin-top:20px;margin-left:20px;"> <h2><a target="_blank" href="http://zhengjianfeng.cn" style="color:blue">帮助文档!!!!!!!</a></h2> <p>aid:</p><input type="text" name="aid" id="aid" value="74916"/></br> <p>csrfid:</p><input type="text" name="csrfid" id="csrfid" style="width:250px" value="027817004f35eb34f312464c4828ca62"/></br> <p>markdown内容:</p> <textarea rows="20" cols="100" id="md"></textarea></br></br> <button onclick="submitForm();">提交</button> <form id="bform" action="https://api.bilibili.com/x/article/creative/draft/addupdate" method="POST"> <input type="hidden" name="content" id="bcontent" value="xxxx"/> <input type="hidden" name="aid" id="baid" value="74916"/> <input type="hidden" name="csrf" id="bcsrfid" value="027817004f35eb34f312xxxxxxxx"/> </form> <script src="showdown.js"></script> <script type="text/javascript"> function submitForm(){ var aid = document.getElementById("aid").value; var csrfid=document.getElementById("csrfid").value; document.getElementById("baid").value=aid; document.getElementById("bcsrfid").value=csrfid; var content=document.getElementById("md").value; var converter = new showdown.Converter(); var htmlcontent = converter.makeHtml(content); document.getElementById("bcontent").value=htmlcontent; document.getElementById("bform").submit(); } </script> </body> </html>
界面以下:浏览器
用户须要提供参数aid
和csrfid
,这两个参数能够经过如下方式获取bash
addupdate
这里面就包含所需参数
这里已经将页面部署到阿里云上方便你们使用,地址:http://zhengjianfeng.cn/bilibili/
缘由:当前浏览器不支持no-referrer
功能,可使用chrome或者firefox进行访问
{"code":-111,"message":"csrf 校验失败","ttl":1}
缘由:未登陆B站或者已经退出,从新登陆,根据以上方式获取最新的csrf,csrf每次登陆都不同