├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── pastebot ├── __init__.py ├── bot.py ├── cli.py ├── rules │ ├── api_keys.yar │ ├── emails.yar │ ├── hashes.yar │ ├── index.yar │ └── private_keys.yar └── weibo.py ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | .idea/ 3 | __pycache__/ 4 | *.py[cod] 5 | *$py.class 6 | .DS_Store 7 | site/ 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | env/ 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *,cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | 58 | # Sphinx documentation 59 | docs/_build/ 60 | 61 | # PyBuilder 62 | target/ 63 | 64 | # pyenv python configuration file 65 | .python-version 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md 3 | exclude __pycache__ 4 | recursive-include pastebot *.yar 5 | recursive-exclude pastebot *.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pastebot 2 | 3 | [pastebot](http://weibo.com/pastebot) 是一个监控 pastebin 的敏感内容,并发微博的 bot 4 | 5 | ### 安装 6 | 7 | 使用 GitHub 安装 8 | ``` 9 | $ pip install -U git+https://github.com/fate0/pastebot.git 10 | ``` 11 | 12 | 或使用源码安装: 13 | 14 | ``` 15 | $ python setup.py install 16 | ``` 17 | 18 | ### 使用 19 | 20 | 基本命令: 21 | 22 | ``` 23 | $ pastebot 24 | Usage: pastebot [OPTIONS] COMMAND [ARGS]... 25 | 26 | Options: 27 | --version Show the version and exit. 28 | -h, --help Show this message and exit. 29 | 30 | Commands: 31 | serve 开始运行 pastebot 32 | weibo 生成 weibo access token 33 | ``` 34 | 35 | 生成 weibo access token 36 | 37 | ``` 38 | $ pastebot weibo -h 39 | Usage: pastebot weibo [OPTIONS] 40 | 41 | 生成 weibo access token 42 | 43 | Options: 44 | --key TEXT 微博 App Key [required] 45 | --secret TEXT 微博 App Secret [required] 46 | --domain TEXT 微博安全域名 [required] 47 | -h, --help Show this message and exit. 48 | 49 | $ pastebot weibo --key 1234 --secret 123123123123 --domain yourodmain.com 50 | input auth_code: asdfsdfsdf 51 | 52 | 返回 access_token: you_access_token 53 | 过期时间: 37.329166666666666h 54 | 用户 uid: 111111 55 | 56 | ``` 57 | 58 | 使用 `pastebot serve` 运行监控 59 | 60 | ``` 61 | $ pastebot serve -h 62 | Usage: pastebot serve [OPTIONS] 63 | 64 | 开始运行 pastebot 65 | 66 | Options: 67 | --tokens TEXT 微博 access tokens [required] 68 | --dsn TEXT sentry dsn 69 | --pool INTEGER 线程池大小 70 | --qps FLOAT qps 71 | --timeout FLOAT 请求 timeout 72 | -h, --help Show this message and exit. 73 | 74 | $ pastebot serve --token you_access_token1,your_access_token2 75 | ``` 76 | 77 | 因为同一个应用下的 access_token 有发送消息条数限制,所以可以设置多个 access_token 78 | 79 | ### 参考 80 | 81 | * [PasteHunter](https://github.com/kevthehermit/PasteHunter) 82 | * [dumpmon](https://github.com/jordan-wright/dumpmon) 83 | 84 | -------------------------------------------------------------------------------- /pastebot/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from __future__ import unicode_literals 5 | 6 | from pastebot.weibo import WeiBo 7 | from pastebot.bot import PasteBot 8 | 9 | 10 | __version__ = '0.1.2' 11 | -------------------------------------------------------------------------------- /pastebot/bot.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import unicode_literals, division 4 | 5 | import os 6 | import sys 7 | import time 8 | import json 9 | import yara 10 | import raven 11 | import queue 12 | import signal 13 | import logging 14 | import requests 15 | import threading 16 | from pastebot.weibo import WeiBo 17 | 18 | 19 | logger = logging.getLogger(__name__) 20 | 21 | 22 | _signames = dict((getattr(signal, signame), signame) 23 | for signame in dir(signal) 24 | if signame.startswith('SIG') and '_' not in signame) 25 | 26 | 27 | def signal_name(signum): 28 | try: 29 | if sys.version_info[:2] >= (3, 5): 30 | return signal.Signals(signum).name 31 | else: 32 | return _signames[signum] 33 | 34 | except KeyError: 35 | return 'SIG_UNKNOWN' 36 | except ValueError: 37 | return 'SIG_UNKNOWN' 38 | 39 | 40 | class PasteBot(object): 41 | def __init__(self): 42 | rule_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'rules/index.yar') 43 | self._rules = yara.compile(rule_path) 44 | self._paste_queue = queue.Queue() 45 | self._last_query_result = [] 46 | self._last_query_time = 0 47 | self._last_query_lock = threading.Lock() 48 | 49 | self._pastebin_api = "https://pastebin.com/api_scraping.php" 50 | self._stopped = False 51 | 52 | self._thread_pool = [] 53 | self._sentry_client = None 54 | self._weibo_clients = [] 55 | 56 | # 用户可设置属性 57 | self.qps = 1 58 | self.sentry_dsn = None 59 | self.request_timeout = 5 60 | self.thread_pool_size = 10 61 | self.weibo_index = 0 62 | self.weibo_access_tokens = [] 63 | 64 | @property 65 | def weibo_client(self): 66 | if not self._weibo_clients: 67 | for each_token in self.weibo_access_tokens: 68 | wb = WeiBo() 69 | wb.access_token = each_token.strip() 70 | self._weibo_clients.append(wb) 71 | 72 | return self._weibo_clients[self.weibo_index % len(self._weibo_clients)] 73 | 74 | @property 75 | def sentry_client(self): 76 | if not self._sentry_client: 77 | self._sentry_client = raven.Client(self.sentry_dsn) 78 | 79 | return self._sentry_client 80 | 81 | def _install_signal_handlers(self): 82 | signal.signal(signal.SIGINT, self.request_stop) 83 | signal.signal(signal.SIGTERM, self.request_stop) 84 | 85 | def request_stop(self, signum, _): 86 | logger.info('Got signal {0}'.format(signal_name(signum))) 87 | logger.info('Warm shut down requested') 88 | 89 | signal.signal(signal.SIGINT, self.request_force_stop) 90 | signal.signal(signal.SIGTERM, self.request_force_stop) 91 | 92 | self._stopped = True 93 | logger.info('Press Ctrl+C again for a cold shutdown.') 94 | 95 | def request_force_stop(self, signum, _): 96 | raise SystemExit 97 | 98 | def new_weibo_post(self, paste_info, results): 99 | result_types = [] 100 | result_num = 1 101 | for each_result in results: 102 | result_type = each_result.meta.get('type') 103 | if result_type: 104 | result_types.append(result_type) 105 | 106 | if len(each_result.strings) > result_num: 107 | result_num = len(each_result.strings) 108 | 109 | post_msg = "{}\n类型: {}".format(paste_info['full_url'], ",".join(result_types)) 110 | if result_num > 1: 111 | post_msg += "\n数量: {}".format(result_num) 112 | if paste_info['title']: 113 | post_msg += "\n标题: {}".format(paste_info['title']) 114 | if paste_info['user']: 115 | post_msg += "\n作者: {}".format(paste_info['user']) 116 | 117 | print(post_msg) 118 | 119 | try: 120 | result = '' 121 | for i in range(3): 122 | result = json.loads(self.weibo_client.new_post(post_msg)) 123 | if 'error' not in result: 124 | break 125 | 126 | self.weibo_index += 1 127 | else: 128 | self.sentry_client.captureMessage("post weibo error: {}".format(result)) 129 | except requests.Timeout: 130 | pass 131 | except Exception: 132 | logger.error("Unknown exception", exc_info=True) 133 | self.sentry_client.captureException() 134 | 135 | def fetch_and_parse(self): 136 | while not self._stopped: 137 | try: 138 | paste_info = self._paste_queue.get(timeout=1) 139 | except queue.Empty: 140 | continue 141 | except Exception: 142 | logger.error("Unknown exception", exc_info=True) 143 | self.sentry_client.captureException() 144 | continue 145 | 146 | logger.debug("get task %s" % paste_info) 147 | 148 | # qps 设置 149 | with self._last_query_lock: 150 | cur_time = time.time() 151 | delay_time = 1 / self.qps 152 | if cur_time - self._last_query_time < delay_time: 153 | time.sleep(delay_time - (cur_time - self._last_query_time)) 154 | 155 | self._last_query_time = time.time() 156 | 157 | try: 158 | rp = requests.get(paste_info['scrape_url'], timeout=5) 159 | except requests.Timeout: 160 | continue 161 | except Exception: 162 | logger.error("Unknown exception", exc_info=True) 163 | continue 164 | 165 | result = self._rules.match(data=rp.content) 166 | if not result: 167 | continue 168 | 169 | self.new_weibo_post(paste_info, result) 170 | 171 | def start(self): 172 | self._install_signal_handlers() 173 | 174 | for i in range(self.thread_pool_size): 175 | t = threading.Thread(target=self.fetch_and_parse) 176 | t.start() 177 | 178 | self._thread_pool.append(t) 179 | 180 | while not self._stopped: 181 | time.sleep(3) 182 | 183 | try: 184 | rp = requests.get(self._pastebin_api, timeout=self.request_timeout) 185 | pastes_info = rp.json() 186 | except requests.Timeout: 187 | continue 188 | except Exception: 189 | self.sentry_client.captureException() 190 | logger.error("Unknown exception", exc_info=True) 191 | continue 192 | 193 | for each_paste_info in pastes_info: 194 | if each_paste_info not in self._last_query_result: 195 | self._paste_queue.put(each_paste_info) 196 | logger.debug("push task") 197 | 198 | self._last_query_result = pastes_info 199 | 200 | for t in self._thread_pool: 201 | t.join() 202 | -------------------------------------------------------------------------------- /pastebot/cli.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import unicode_literals 4 | 5 | import click 6 | import pastebot 7 | 8 | click.disable_unicode_literals_warning = True 9 | CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) 10 | 11 | 12 | @click.group(context_settings=CONTEXT_SETTINGS) 13 | @click.version_option(pastebot.__version__) 14 | def main(): 15 | pass 16 | 17 | 18 | @main.command(context_settings=CONTEXT_SETTINGS) 19 | @click.option("--tokens", required=True, help="微博 access tokens") 20 | @click.option("--dsn", default=None, help="sentry dsn") 21 | @click.option("--pool", type=click.INT, default=10, help="线程池大小") 22 | @click.option("--qps", type=click.FLOAT, default=1, help="qps") 23 | @click.option("--timeout", type=click.FLOAT, default=5, help="请求 timeout") 24 | def serve(tokens, dsn, pool, qps, timeout): 25 | """开始运行 pastebot""" 26 | tokens = tokens.split(',') 27 | pb = pastebot.PasteBot() 28 | pb.weibo_access_tokens = tokens 29 | pb.sentry_dsn = dsn 30 | 31 | if pool <= 0: 32 | raise click.BadParameter("线程池大小必须大于 0") 33 | pb.thread_pool_size = pool 34 | 35 | if qps <= 0: 36 | raise click.BadParameter("qps 必须大于 0") 37 | pb.qps = qps 38 | 39 | if timeout <= 0: 40 | raise click.BadParameter("timeout 必须大于 0") 41 | pb.request_timeout = timeout 42 | 43 | pb.start() 44 | 45 | 46 | @main.command(context_settings=CONTEXT_SETTINGS) 47 | @click.option("--key", required=True, help="微博 App Key") 48 | @click.option("--secret", required=True, help="微博 App Secret") 49 | @click.option("--domain", required=True, help="微博安全域名") 50 | def weibo(key, secret, domain): 51 | """生成 weibo access token""" 52 | wb = pastebot.WeiBo() 53 | wb.app_key = key 54 | wb.app_secret = secret 55 | wb.secure_domain = domain 56 | 57 | result = wb.exchange_access_token() 58 | 59 | click.echo('返回 access_token: {}'.format(result['access_token'])) 60 | click.echo('过期时间: {}h'.format(int(result['expires_in']) / (60 * 60))) 61 | click.echo('用户 uid: {}'.format(result['uid'])) 62 | -------------------------------------------------------------------------------- /pastebot/rules/api_keys.yar: -------------------------------------------------------------------------------- 1 | rule slack_key 2 | { 3 | meta: 4 | type = "slack key" 5 | 6 | strings: 7 | $slack_key = /xoxb-\d+-\w{24}/ 8 | 9 | condition: 10 | $slack_key 11 | } -------------------------------------------------------------------------------- /pastebot/rules/emails.yar: -------------------------------------------------------------------------------- 1 | rule emails 2 | { 3 | meta: 4 | type = "邮箱" 5 | 6 | strings: 7 | $email = /\b[\w\._%+-]+@[\w\.-]+\.\w{2,10}\b/ 8 | 9 | condition: 10 | #email > 50 11 | } -------------------------------------------------------------------------------- /pastebot/rules/hashes.yar: -------------------------------------------------------------------------------- 1 | rule hash32 2 | { 3 | meta: 4 | type = "hash32" 5 | 6 | strings: 7 | $hash32 = /\b([A-Fa-f\d]{32})\b/ 8 | 9 | condition: 10 | #hash32 > 50 11 | } -------------------------------------------------------------------------------- /pastebot/rules/index.yar: -------------------------------------------------------------------------------- 1 | include "api_keys.yar" 2 | include "emails.yar" 3 | include "hashes.yar" 4 | include "private_keys.yar" -------------------------------------------------------------------------------- /pastebot/rules/private_keys.yar: -------------------------------------------------------------------------------- 1 | rule ssh_private_key 2 | { 3 | meta: 4 | type = "SSH 私钥" 5 | 6 | strings: 7 | $ssh_private_key = /BEGIN RSA PRIVATE.{640,}END RSA PRIVATE/s 8 | 9 | condition: 10 | $ssh_private_key 11 | } 12 | 13 | 14 | rule pgp_private_key 15 | { 16 | meta: 17 | type = "PGP 私钥" 18 | 19 | strings: 20 | $pgp_private_key = /BEGIN PGP PRIVATE.{640,}END PGP PRIVATE/s 21 | 22 | condition: 23 | $pgp_private_key 24 | } -------------------------------------------------------------------------------- /pastebot/weibo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import unicode_literals, division 4 | 5 | import requests 6 | import webbrowser 7 | 8 | 9 | class WeiBo(object): 10 | def __init__(self): 11 | self.app_key = None 12 | self.app_secret = None 13 | self.secure_domain = None 14 | self.auth_code = None 15 | self.access_token = None 16 | self.sina_oauth2_authorize_url = 'https://api.weibo.com/oauth2/authorize?client_id={}&redirect_uri=http://{}' 17 | self.sina_oauth2_access_token_url = 'https://api.weibo.com/oauth2/access_token' 18 | self.sina_new_post_url = 'https://api.weibo.com/2/statuses/share.json' 19 | 20 | def exchange_auth_code(self): 21 | url = self.sina_oauth2_authorize_url.format(self.app_key, self.secure_domain) 22 | webbrowser.open(url) 23 | self.auth_code = input("input auth_code: ").strip() 24 | 25 | def exchange_access_token(self): 26 | if not self.auth_code: 27 | self.exchange_auth_code() 28 | 29 | data = { 30 | 'client_id': self.app_key, 31 | 'client_secret': self.app_secret, 32 | 'grant_type': 'authorization_code', 33 | 'code': self.auth_code, 34 | 'redirect_uri': 'http://{}'.format(self.secure_domain) 35 | } 36 | 37 | rp = requests.post(self.sina_oauth2_access_token_url, data=data) 38 | result = rp.json() 39 | self.access_token = result['access_token'] 40 | return result 41 | 42 | def new_post(self, post): 43 | if not self.access_token: 44 | self.exchange_access_token() 45 | 46 | data = { 47 | 'access_token': self.access_token, 48 | "status": post 49 | } 50 | rp = requests.post(self.sina_new_post_url, data=data) 51 | return rp.text 52 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import re 5 | import ast 6 | from setuptools import setup, find_packages 7 | 8 | with open('README.md') as readme_file: 9 | readme = readme_file.read() 10 | 11 | 12 | _version_re = re.compile(r'__version__\s+=\s+(.*)') 13 | 14 | 15 | with open('pastebot/__init__.py', 'rb') as f: 16 | version = str(ast.literal_eval(_version_re.search( 17 | f.read().decode('utf-8')).group(1))) 18 | 19 | 20 | requirements = [ 21 | "click==6.7", 22 | "requests==2.18.4", 23 | "raven==6.1.0", 24 | "yara-python==3.6.3" 25 | ] 26 | 27 | setup( 28 | name='pastebot', 29 | version=version, 30 | description="pastebot", 31 | long_description=readme, 32 | author="fate0", 33 | author_email='fate0@fatezero.org', 34 | url='https://github.com/fate0/pastebot', 35 | packages=find_packages(), 36 | package_dir={}, 37 | entry_points={ 38 | 'console_scripts': [ 39 | 'pastebot=pastebot.cli:main' 40 | ] 41 | }, 42 | include_package_data=True, 43 | install_requires=requirements, 44 | license="BSD license", 45 | zip_safe=False, 46 | keywords='pastebot', 47 | classifiers=[ 48 | 'Development Status :: 2 - Pre-Alpha', 49 | 'Intended Audience :: Developers', 50 | 'License :: OSI Approved :: BSD License', 51 | 'Natural Language :: English', 52 | "Programming Language :: Python :: 2", 53 | 'Programming Language :: Python :: 2.7', 54 | 'Programming Language :: Python :: 3', 55 | 'Programming Language :: Python :: 3.4', 56 | 'Programming Language :: Python :: 3.5', 57 | 'Programming Language :: Python :: 3.6', 58 | 'Topic :: Internet :: WWW/HTTP', 59 | 'Topic :: Internet :: WWW/HTTP :: Browsers' 60 | ], 61 | ) 62 | --------------------------------------------------------------------------------