0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

sesamebot2の台本をpython(WebAPI)から実行する

Posted at

WebAPIからsesamibotの台本を実行

結論

cmd=unlock(83)に設定すればよい。(台本1)の実行。
公式のドキュメントを読んでいた人はこの一文で理解可能かもしれません。というか皆さん当然のように気づくのですかね?私は数時間溶かしました。以下補足になります。

APIの叩きかた

コードは公式ドキュメントに載っています。
uuid, secret_key, api_keyの取得もそのうち記事に残します。
ログイン > 右上のメアド > マイスペース > 左下の開発者向け と遷移することで見つけられるので、ヒントにしてください。

ドキュメントより引用

import datetime, base64, requests, json
from Crypto.Hash import CMAC
from Crypto.Cipher import AES

uuid = '3DE4DE72-AAF9-25C1-8D0F-C9E019BB060C'
secret_key = '2ebc2c087c1501480834538ff72139bc'
api_key = 'SrSOEY9mBe6Ndl7bwyVPs5TsTPFTEq9tra8Occad'

cmd = 88  # 88/82/83 = toggle/lock/unlock
history = 'test5'
base64_history = base64.b64encode(bytes(history, 'utf-8')).decode()

print(base64_history)
headers = {'x-api-key': api_key}
cmac = CMAC.new(bytes.fromhex(secret_key), ciphermod=AES)

ts = int(datetime.datetime.now().timestamp())
message = ts.to_bytes(4, byteorder='little')
message = message.hex()[2:8]
cmac = CMAC.new(bytes.fromhex(secret_key), ciphermod=AES)

cmac.update(bytes.fromhex(message))
sign = cmac.hexdigest()
# 鍵の操作
url = f'https://app.candyhouse.co/api/sesame2/{uuid}/cmd'
body = {
    'cmd': cmd,
    'history': base64_history,
    'sign': sign
}
res = requests.post(url, json.dumps(body), headers=headers)
print(res.status_code, res.text)


# certifi==2021.5.30
# chardet==4.0.0
# clr==1.0.3
# idna==2.10
# Naked==0.1.31
# pycryptodome==3.4.3
# PyYAML==5.4.1
# requests==2.25.1
# urllib3==1.26.6
cmd = 88  # 88/82/83 = toggle/lock/unlock

この部分でコマンドを変えることにより、動作をかえられます。
sesamebot2なのでとりあえずtoggle(88)に設定しましたが、これが罠でした。

どこで気づいたのか

数時間にも及ぶネットサーフィンの末、販売ページにたどりつきました(戻ってきました)。
そこには、解錠=台本0, 施錠=台本1を連想させる記載がありました。
ためしたら予想通りに動作しました。私の数時間...orz

https://jp.candyhouse.co/products/sesamebot2
image.png

最後に

ただの恥曝しかもしれませんが、数時間にわたり有志のsdkを探し、公式のsdkのコードを読み込んだ自身への供養として記事にしました。同じように気づけなかった人の助けになればいいな...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?