as238

proxy2ch 20220415

Apr 22nd, 2022 (edited)
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. .\proxy2ch.exe --api a6kwZ1FHfwlxIKJWCq4XQQnUTqiA1P:ZDzsNQ7PcOOGE2mXo145X6bt39WMz6 --api-auth-xua "JaneStyle/4.23" --api-auth-ua "Monazilla/1.00 JaneStyle/4.23 Windows/10.0.22000" --api-dat-ua "Monazilla/1.00 JaneStyle/4.23 Windows/10.0.22000" -c --verbose --bbscgi-lua sample.lua
  2.  
  3. ----------------------------
  4. sample.lua
  5. ----------------------------
  6. function createTableFromBody(str)
  7. local t = {}
  8. for s in string.gmatch(str, "([^&]+)") do
  9. local idx = string.find(s, "=")
  10. local name = string.sub(s, 1, idx-1)
  11. local value = string.sub(s, idx+1)
  12. t[name] = value
  13. end
  14. return t
  15. end
  16.  
  17. function createBodyFromTableWithOrder(tBody, order)
  18. order = order or {}
  19. local ret = ""
  20. for i, name in ipairs(order) do
  21. if tBody[name] ~= nil then
  22. if ret ~= "" then
  23. ret = ret .. "&"
  24. end
  25. ret = ret .. name .. "=" .. tBody[name]
  26. tBody[name] = nil
  27. end
  28. end
  29. for name, value in pairs(tBody) do
  30. if ret ~= "" then
  31. ret = ret .. "&"
  32. end
  33. ret = ret .. name .. "=" .. value
  34. end
  35. return ret
  36. end
  37.  
  38. function generatePostSignatureFromTable(tBody, userAgent, hmacKey)
  39. local bbs = tBody["bbs"] or ""
  40. local key = tBody["key"] or ""
  41. local time = tBody["time"] or ""
  42. local from = tBody["FROM"] or ""
  43. local mail = tBody["mail"] or ""
  44. local message = tBody["MESSAGE"] or ""
  45. local subject = tBody["subject"] or ""
  46. local userAgent = userAgent or ""
  47. local monaKey = proxy2ch.monaKey
  48. local unused = ""
  49. local nonce = os.time()
  50. local data = table.concat({bbs, key, time, from, mail, message, subject, userAgent, monaKey, unused, nonce}, "<>")
  51. return proxy2ch.hmacSHA256(hmacKey, data), nonce
  52. end
  53.  
  54. function willSendRequestToBbsCgi(request, host, board, thread)
  55. if string.sub(host, -#".5ch.net") ~= ".5ch.net" then
  56. return request
  57. end
  58.  
  59. local apiKey = "a6kwZ1FHfwlxIKJWCq4XQQnUTqiA1P"
  60. local hmacKey = "ZDzsNQ7PcOOGE2mXo145X6bt39WMz6"
  61. local userAgent = "Monazilla/1.00 JaneStyle/4.23 Windows/10.0.22000"
  62.  
  63. --リクエストボディをtableに変換する
  64. --"name1=value1&name=value2"形式のstringが{"name1" = "value1", "name2" = "value2"}形式のtableに変換される
  65. local tBody = createTableFromBody(request.body)
  66. --既にリクエストボディがUTF-8になっていると思われる場合はUTF-8への変換を無効にする
  67. --submitフィールドの値がUTF-8で解釈可能かどうかで判定する
  68. local shouldConvertToUTF8 = not proxy2ch.isValidAsUTF8(proxy2ch.decodeURIComponent(tBody["submit"]))
  69. --リクエストボディの各フィールドのURLエンコードを解除し、必要ならUTF-8に変換する
  70. --リクエストボディのUTF-8化が必須かどうかはUser-Agentにより異なる
  71. for name, value in pairs(tBody) do
  72. local decoded = proxy2ch.decodeURIComponent(value)
  73. tBody[name] = shouldConvertToUTF8 and proxy2ch.convertShiftJISToUTF8(decoded) or decoded
  74. end
  75. --リクエストボディとUser-Agentからリクエストのsignatureを生成する
  76. --signatureの生成元となるリクエストボディはURLエンコードを解除しておく必要がある
  77. local postSig, postNonce = generatePostSignatureFromTable(tBody, userAgent, hmacKey)
  78. --リクエストボディの各フィールドを再度URLエンコードする
  79. for name, value in pairs(tBody) do
  80. tBody[name] = proxy2ch.encodeURIComponent(value)
  81. end
  82. --tableからフィールドの順序を指定して新しいリクエストボディを生成する
  83. request.body = createBodyFromTableWithOrder(tBody, {"submit", "FROM", "mail", "MESSAGE", "bbs", "key", "time"})
  84.  
  85. request.headers = HttpHeaders.new()
  86.  
  87. request.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
  88. request.headers["X-PostSig"] = postSig
  89. request.headers["X-APIKey"] = apiKey
  90. request.headers["X-PostNonce"] = postNonce
  91. request.headers["X-MonaKey"] = proxy2ch.monaKey
  92. request.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  93. request.headers["Accept-Encoding"] = "gzip, identity"
  94. request.headers["Referer"] = "https://" .. host .. "/" .. board .. "/"
  95. request.headers["User-Agent"] = userAgent
  96.  
  97. return request
  98. end
Add Comment
Please, Sign In to add comment