async def on_message(message, secret_context): text = message.content[5:] if text == "": # print the help secret_context.bus.emit('secret_command', command='!help hex') else: # try to parse it as a number first try: a = int(text) embed = utils.simple_embed('hex', hex(a), utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed) except Exception as e: # it's a string a = str(text) if a.startswith("0x"): try: a = int(text, 16) embed = utils.simple_embed('hex', hex(a), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) return except Exception as e: pass r = binascii.hexlify(a.encode('utf8')) embed = utils.simple_embed('hex', r.decode('utf8'), utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed)
def run(message, secret_context, target): global wordpress_scan_target start = time.time() user_agent = get_random_agent() index = requests.get(target, headers={"User-Agent": user_agent}, verify=False) if "wp-" not in index.text: embed = utils.simple_embed( '**%s**' % target, 'does not appear to be powered by wordpress', discord.Color.red()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed)) wordpress_scan_target = '' else: version = check_version(target, user_agent, index) embed = utils.simple_embed('**%s**' % target, 'wordpress version found: **%s**' % version, discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed)) try: check_backup_files(message, secret_context, target, user_agent) check_xml_rpc(message, secret_context, target, user_agent) check_directory_listing(message, secret_context, target, user_agent) check_robots(message, secret_context, target, user_agent) full_path_disclose(message, secret_context, target, user_agent) enumerate_users(message, secret_context, target, user_agent) if version is not None: list_wp_version_vuln(message, secret_context, target, version) enumerate_plugins(message, secret_context, index) enumerate_themes(message, secret_context, index) end = time.time() total = end - start embed = utils.simple_embed( '**%s**' % target, 'wordpress scan finished in: %s' % '{0:%H:%M:%S}'.format(total), discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed)) except Exception as e: embed = utils.simple_embed('error', str(e), discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed)) wordpress_scan_target = ''
async def on_post_merge(message, secret_context, db_pull_doc): try: user_doc = user.User.objects.get(git_user_id=db_pull_doc.user_id) reward_points = db_pull_doc.required_points / 15.5 reward_points = float("{0:.2f}".format(reward_points)) # add points user_doc.points += reward_points user_doc.points = float("{0:.2f}".format(user_doc.points)) user_doc.save() if user_doc.discord_mention: desc = '**' + str( reward_points ) + '** given to: **' + user_doc.discord_mention + '**' else: desc = '**' + str( reward_points ) + '** given to: **' + user_doc.discord_name + '**' embed = utils.simple_embed('points attribution', desc, discord.Color.green()) await secret_context.discord_client.send_message(message.channel, embed=embed) except user.DoesNotExist as e: pass
def check_backup_files(message, secret_context, target, user_agent): backup = [ 'wp-config.php~', 'wp-config.php.save', '.wp-config.php.bck', 'wp-config.php.bck', '.wp-config.php.swp', 'wp-config.php.swp', 'wp-config.php.swo', 'wp-config.php_bak', 'wp-config.bak', 'wp-config.php.bak', 'wp-config.save', 'wp-config.old', 'wp-config.php.old', 'wp-config.php.orig', 'wp-config.orig', 'wp-config.php.original', 'wp-config.original', 'wp-config.txt', 'wp-config.php.txt', 'wp-config.backup', 'wp-config.php.backup', 'wp-config.copy', 'wp-config.php.copy', 'wp-config.tmp', 'wp-config.php.tmp', 'wp-config.zip', 'wp-config.php.zip', 'wp-config.db', 'wp-config.php.db', 'wp-config.dat', 'wp-config.php.dat', 'wp-config.tar.gz', 'wp-config.php.tar.gz', 'wp-config.back', 'wp-config.php.back', 'wp-config.test', 'wp-config.php.test' ] for b in backup: r = requests.get(target + b, headers={"User-Agent": user_agent}, verify=False) if "200" in str(r) and "404" not in r.text: embed = utils.simple_embed( '**%s**' % target, 'found config backup: **%s**' % target + b, discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
async def _restart(self): print('----------------------------') print('secRet bot is now restarting') print('----------------------------') await self.secret_context.discord_client.send_message( self.secret_context.secret_channel, embed=utils.simple_embed('restart', 'restarting secRet dBot', utils.random_color())) os.execv(sys.executable, [sys.executable.split("/")[-1]] + sys.argv)
async def fetch(self, message, discord_client, package_name): try: store_info = self.cli.api.details(package_name) icon = None color = utils.random_color() for img in store_info['images']: if img['imageType'] == 4: icon = img['url'] break if icon: response = requests.get(icon) if response.status_code == 200: if not os.path.exists('files'): os.mkdir('files') with open("files/tmp_gplay_icon.png", 'wb') as f: f.write(response.content) color_thief = ColorThief("files/tmp_gplay_icon.png") dominant_color = color_thief.get_color(quality=1) color = int(utils.rgb_to_hex(dominant_color), 16) embed = utils.simple_embed(store_info['title'], store_info['docId'], color) if icon: embed.set_thumbnail(url=icon) embed.add_field(name='author', value=store_info['author']) embed.add_field(name='version code', value=str(store_info['versionCode'])) embed.add_field(name='uploaded', value=store_info['uploadDate']) embed.add_field(name='downloads', value=store_info['numDownloads'].replace('downloads', '')) embed.add_field(name='rating', value=str(store_info['aggregateRating']['starRating'])) embed.add_field(name='comments', value=str(store_info['aggregateRating']['commentCount'])) embed.add_field(name='type', value=store_info['category']['appType']) embed.add_field(name='category', value=store_info['category']['appCategory']) await discord_client.send_message(message.channel, embed=embed) except gplaycli.RequestError as e: embed = utils.simple_embed('google play', 'package **' + package_name + '** not found', discord.Color.red()) embed.set_thumbnail(url=self.play_icon_url) await discord_client.send_message(message.channel, embed=embed) except Exception as e: embed = utils.simple_embed('google play', 'error on package **' + package_name + '**. ' + str(e), discord.Color.red()) embed.set_thumbnail(url=self.play_icon_url) await discord_client.send_message(message.channel, embed=embed)
async def merge_pr(message, secret_context, db_pull_doc): git_pr = secret_context.git_repo.get_pull(db_pull_doc.pull_number) if git_pr and git_pr.mergeable: embed = discord.Embed(title=db_pull_doc.pull_title, type='rich', description=db_pull_doc.user_name, color=discord.Color.green()) for discord_id, vote in db_pull_doc.votes.items(): embed.add_field(name=vote['name'], value=str(vote['points']), inline=True) await secret_context.discord_client.send_message(message.channel, embed=embed) status = git_pr.merge() if status.merged: db_pull_doc.delete() embed = utils.simple_embed( 'success', status.sha + ' **merged**. scheduled for next auto-update', discord.Color.green()) await secret_context.discord_client.send_message(message.channel, embed=embed) await on_post_merge(message, secret_context, db_pull_doc) else: embed = utils.simple_embed('error', status.message, discord.Color.red()) await secret_context.discord_client.send_message(message.channel, embed=embed) else: if git_pr.merge: embed = utils.simple_embed('info', 'the pr has already been merged', discord.Color.blue()) else: embed = utils.simple_embed( 'error', 'the pr can\'t be merged. check conflicts and resolve them!', discord.Color.green()) await secret_context.discord_client.send_message(message.channel, embed=embed)
def check_xml_rpc(message, secret_context, target, user_agent): r = requests.get(target + "xmlrpc.php", headers={"User-Agent": user_agent}, verify=False) if "200" in str(r) and "404" not in r.text: embed = utils.simple_embed( '**%s**' % target, 'found xml-rpc interface: **%s**' % target + "xmlrpc.php", discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
def list_wp_version_vuln(message, secret_context, target, version): # Load json file with open('secret/api/wordpress/wordpresses.json') as data_file: data = json.load(data_file) if version not in data: embed = utils.simple_embed( '**%s**' % target, 'wordpress version not in db. update wordpress vuln db and try again', discord.Color.red()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed)) if not data[version]["vulnerabilities"]: versions = data.keys() for v in versions: if v[:4] in version and is_lower(version, v, False): version = v embed = utils.simple_embed('**%s**' % target, 'wordpress core vulnerabilities', discord.Color.green()) count = 0 for vuln in data[version]["vulnerabilities"]: count += 1 embed.add_field(name=vuln['vuln_type'], value=vuln['title'] + ' - ' + str(vuln['id']), inline=False) for ref_key in vuln['references'].keys(): for ref in vuln['references'][ref_key]: if ref_key != 'url': embed.add_field(name='reference', value=ref_key.capitalize() + ' - ' + ref) else: embed.add_field(name='reference', value=ref) if count > 0: secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
async def on_message(message, secret_context): parts = message.content.split(" ") if len(parts) < 2: # print the help secret_context.bus.emit('secret_command', command='!help gif') else: if parts[1] == 'random': r = requests.get('http://api.giphy.com/v1/gifs/random?api_key=' + API_KEY) if r.status_code == 200: rs = json.loads(r.content.decode('utf8')) embed = utils.simple_embed('gif', 'random', utils.random_color()) embed.set_image(url=rs['data']['image_url']) await secret_context.discord_client.send_message( message.channel, embed=embed) elif parts[1] == 'search': try: q = str.join(" ", parts[2]) off = 0 if len(parts) > 3: try: off = int(parts[3]) except Exception as e: pass r = requests.get( 'http://api.giphy.com/v1/gifs/search?api_key=' + API_KEY + '&q=' + q + '&limit=1&offset=' + str(off)) if r.status_code == 200: rs = json.loads(r.content.decode('utf8')) for item in rs['data']: embed = utils.simple_embed(item['slug'], item['source'], utils.random_color()) embed.set_image(url=item['images']['original']['url']) await secret_context.discord_client.send_message( message.channel, embed=embed) except Exception as e: pass
async def on_message(self, message, lang): try: cmd = message.content if lang == 'python': cmd = cmd.replace('```python', '') cmd = cmd.replace('```', '') exec(cmd) elif lang == 'javascript': execjs.eval(cmd) # await self.discord_client.delete_message(message) except Exception as e: embed = utils.simple_embed('error', str(e), discord.Color.red()) await self.secret_context.discord_client.send_message(message.channel, embed=embed)
async def commands_history(self, message): cmd_list = message.content.split(" ") if len(cmd_list) == 1: embed = utils.build_default_embed('commands history', '-', discord.Color.teal(), icon=False) for log in command_log.CommandLog.objects[:10]: embed.add_field(name=log.user_name, value=log.command, inline=False) await self.secret_context.discord_client.send_message(message.channel, embed=embed) else: if cmd_list[1] == 'clear': c = command_log.CommandLog.objects.count() command_log.CommandLog.drop_collection() await self.secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('done', "removed " + str(c) + " entries", discord.Color.dark_green()))
async def on_ready(self): print('----------------------------') print('secRet bot connected') print('----------------------------') embed = utils.simple_embed('secRet dBot', 'services initialized', utils.random_color()) embed.set_author(name='secret', url='http://secret.re', icon_url=utils.ICON) embed.set_thumbnail(url=utils.ICON) embed.add_field(name="!help", value="initial help") embed.add_field(name="!commands", value="available commands") await self.secret_context.discord_client.send_message( self.secret_context.secret_channel, embed=embed)
async def roll(self, message): """ simple roll accepting max as first arg """ parts = message.content.split(" ") max = 100 if len(parts) > 1: try: max = int(parts[1]) except Exception as e: pass embed = utils.simple_embed('roll', '**' + str(random.randint(0, max)) + '**', utils.random_color()) await self.secret_context.discord_client.send_message(message.channel, embed=embed)
async def search(self, message, discord_client, q): results = self.cli.search(q, 3) if results is None: embed = utils.simple_embed('google play', 'no apps found for: **' + q + '**', discord.Color.red()) embed.set_thumbnail(url=self.play_icon_url) await discord_client.send_message(message.channel, embed=embed) else: # remove headers results.pop(0) embed = utils.simple_embed('google play', 'results for: **' + q + '**', discord.Color.red()) embed.set_thumbnail(url=self.play_icon_url) await discord_client.send_message(message.channel, embed=embed) for pkg in results: embed = utils.simple_embed(pkg[0], pkg[5], utils.random_color()) embed.add_field(name='creator', value=pkg[1]) embed.add_field(name='last update', value=pkg[4]) embed.add_field(name='downloads', value=pkg[3].replace(' downloads', '')) embed.add_field(name='size', value=pkg[2]) embed.add_field(name='version', value=pkg[6]) embed.add_field(name='rating', value=pkg[7]) await discord_client.send_message(message.channel, embed=embed)
async def update_vuln_db(message, secret_context): if not os.path.exists('secret/api/wordpress'): os.mkdir('secret/api/wordpress') update_url = "https://data.wpscan.org/" update_files = [ 'local_vulnerable_files.xml', 'local_vulnerable_files.xsd', 'timthumbs.txt', 'user-agents.txt', 'wp_versions.xml', 'wp_versions.xsd', 'wordpresses.json', 'plugins.json', 'themes.json' ] embed = utils.simple_embed('wordpress', 'updating vulnerability database', discord.Color.green()) await secret_context.discord_client.send_message(message.channel, embed=embed) for f in update_files: embed = utils.simple_embed('wordpress', 'downloading %s' % f, utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed) utils.download_raw_file(update_url + f, "secret/api/wordpress/" + f) unzip_file("secret/api/wordpress/user-agents.txt") unzip_file("secret/api/wordpress/timthumbs.txt")
def check_robots(message, secret_context, target, user_agent): r = requests.get(target + "robots.txt", headers={"User-Agent": user_agent}, verify=False) if "200" in str(r) and "404" not in r.text: embed = utils.simple_embed( '**%s**' % target, 'robots is available at: **%s**' % target + "robots.txt", discord.Color.green()) lines = r.text.split('\n') for l in lines: if "Disallow:" in l: embed.add_field(name='disallow', value=l, inline=False) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
def full_path_disclose(message, secret_context, target, user_agent): r = requests.get(target + "wp-includes/rss-functions.php", headers={ "User-Agent": user_agent }, verify=False).text regex = re.compile("Fatal error:.*? in (.*?) on", re.S) matches = regex.findall(r) if matches: embed = utils.simple_embed( '**%s**' % target, 'full path disclose in **%s** exposing: %s' % (target + "wp-includes/rss-functions.php", matches[0].replace( '\n', '')), discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
def enumerate_themes(message, secret_context, index): regex = re.compile('wp-content/themes/(.*?)/.*?[css|js].*?ver=([0-9\.]*)') match = regex.findall(index.text) theme = {} for m in match: theme_name = m[0] theme_name = theme_name.replace('-master', '') theme_name = theme_name.replace('.min', '') theme_version = m[1] if m[0] not in theme.keys(): theme[m[0]] = m[1] with open('secret/api/wordpress/themes.json') as data_file: data = json.load(data_file) embed = utils.simple_embed(theme_name, theme_version, utils.random_color()) if theme_name in data.keys(): if is_lower(theme_version, data[theme_name]['latest_version'], False): embed.add_field(name='latest version', value=data[theme_name]['latest_version'], inline=False) for vuln in data[theme_name]['vulnerabilities']: if 'fixed_in' in vuln.keys() and ( vuln['fixed_in'] is None or is_lower( theme_version, vuln['fixed_in'], True)): embed.add_field(name=vuln['vuln_type'] + ' | ' + vuln['title'] + ' (' + str(vuln['id']) + ')', value="fixed in %s" % vuln['fixed_in'], inline=False) for ref_key in vuln['references'].keys(): for ref in vuln['references'][ref_key]: if ref_key != 'url': embed.add_field( name='reference', value=ref_key.capitalize() + ' - ' + ref) else: embed.add_field(name='reference', value=ref) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
def check_directory_listing(message, secret_context, target, user_agent): directories = [ "wp-content/uploads/", "wp-content/plugins/", "wp-content/themes/", "wp-includes/", "wp-admin/" ] dir_name = ["Uploads", "Plugins", "Themes", "Includes", "Admin"] for directory, name in zip(directories, dir_name): r = requests.get(target + directory, headers={"User-Agent": user_agent}, verify=False) if "Index of" in r.text: embed = utils.simple_embed( '**%s**' % target, 'directory listing is enabled for: **%s**' % target + directory, discord.Color.green()) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
def enumerate_users(message, secret_context, target, user_agent): r = requests.get(target + "wp-json/wp/v2/users", headers={"User-Agent": user_agent}, verify=False) if "200" in str(r): embed = utils.simple_embed('**%s**' % target, 'enumerated users', discord.Color.green()) try: users = json.loads(r.content.decode('utf8')) except Exception: return for user in users: embed.add_field(name=user['name'] + " - " + user['slug'], value=user['id'], inline=False) secret_context.main_loop.create_task( secret_context.discord_client.send_message(message.channel, embed=embed))
async def on_message(message, secret_context): parts = message.content.split(" ") if len(parts) < 2: # print the help secret_context.bus.emit('secret_command', command='!help wpscan') else: if parts[1] == 'update': await update_vuln_db(message, secret_context) else: if not os.path.exists('secret/api/wordpress'): await update_vuln_db(message, secret_context) global wordpress_scan_target if wordpress_scan_target is not '': embed = utils.simple_embed( 'wpscan', 'another scan is currently running on **%s**' % wordpress_scan_target, discord.Color.red()) await secret_context.discord_client.send_message( message.channel, embed=embed) return if parts[1] == 'scan': target = parts[2] else: target = parts[1] if target[-1] != '/': target = target + '/' if not target.startswith('http'): target = 'http://' + target wordpress_scan_target = target requests.packages.urllib3.disable_warnings() t = Thread(target=run, args=(message, secret_context, target)) t.start()
async def git(message, secret_context): parts = message.content.split(" ") if len(parts) < 2: await print_git_help(secret_context.bus) else: if parts[1] == 'commits': await get_last_commits(message, secret_context) elif parts[1] == 'link': await link_git(message, secret_context) elif parts[1] == 'search': try: what = parts[2] if what == 'user': try: git_user = secret_context.git_client.legacy_search_users( parts[3])[0] embed = discord.Embed(title="search result", type='rich', description=parts[3], color=utils.random_color()) embed.set_author(name=git_user.login, url='https://github.com/' + git_user.login) embed.set_thumbnail(url=git_user.avatar_url) embed.add_field(name='id', value=str(git_user.id), inline=False) if git_user.type is not None: embed.add_field(name='type', value=git_user.type) embed.add_field(name='followers', value=str(git_user.followers)) if git_user.contributions is not None: embed.add_field(name='contributions', value=str(git_user.contributions)) if git_user.bio is not None: embed.add_field(name='bio', value=git_user.bio, inline=False) await secret_context.discord_client.send_message( message.channel, embed=embed) except Exception as e: embed = utils.simple_embed('info', 'no user found', discord.Color.blue()) await secret_context.discord_client.send_message( message.channel, embed=embed) except Exception as e: # just don't reply pass elif parts[1] == 'unlink': try: user.User.objects.get(discord_id=message.author.id).delete() embed = utils.simple_embed( 'success', 'you are now unlinked and your points are back to 0', discord.Color.green()) await secret_context.discord_client.send_message( message.channel, embed=embed) except user.DoesNotExist: embed = utils.simple_embed( 'info', 'you are not linked with any github id', discord.Color.blue()) await secret_context.discord_client.send_message( message.channel, embed=embed)
async def link_git(message, secret_context): parts = message.content.split(" ") try: git_nick_name = parts[2] try: u = user.User.objects.get(discord_id=message.author.id) embed = utils.simple_embed( 'info', 'you are already linked to **' + u.git_user_name + '**', discord.Color.blue()) await secret_context.discord_client.send_message(message.channel, embed=embed) except user.DoesNotExist: try: try: u = user.User.objects.get(git_user_name=git_nick_name) if u.discord_id: embed = utils.simple_embed( 'error', '**' + git_nick_name + '** already linked with: ' + str(u.discord_id), discord.Color.red()) await secret_context.discord_client.send_message( message.channel, embed=embed) else: u.discord_id = message.author.id u.discord_name = message.author.display_name u.discord_mention = message.author.mention u.save() embed = utils.simple_embed( 'success', u.git_user_name + ' has been linked to ' + message.author.id, discord.Color.green()) await secret_context.discord_client.send_message( message.channel, embed=embed) except user.DoesNotExist: git_user = secret_context.git_client.legacy_search_users( git_nick_name)[0] r = 'yes' if r == 'yes' or r == 'y': u = user.User(git_user_id=git_user.id, git_user_name=git_user.login, discord_id=message.author.id, discord_name=message.author.display_name, discord_mention=message.author.mention) try: u.save() embed = utils.simple_embed( 'success', u.git_user_name + ' has been linked to ' + message.author.id, discord.Color.green()) await secret_context.discord_client.send_message( message.channel, embed=embed) except user.NotUniqueError as e: u = user.User.objects.get( git_user_id=git_user.login) embed = utils.simple_embed( 'error', '**' + git_user.login + '** already linked with: ' + str(u.discord_id), discord.Color.red()) await secret_context.discord_client.send_message( message.channel, embed=embed) except Exception as e: embed = utils.simple_embed('info', 'no user found', discord.Color.blue()) await secret_context.discord_client.send_message( message.channel, embed=embed) except Exception as e: desc = 'link your github with **!git link *git_user_name**' await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('info', desc, discord.Color.blue())) embed = utils.simple_embed('error', desc, discord.Color.blue()) await secret_context.discord_client.send_message(message.channel, embed=embed) pass
async def on_member_remove(self, member): embed = utils.simple_embed('Welcome', member.mention + ' has left', utils.random_color()) await self.secret_context.discord_client.send_message( self.secret_context.welcome_channel, embed=embed)
async def on_message(message, secret_context): parts = message.content.split(" ") p_len = len(parts) if p_len < 2: # print the help secret_context.bus.emit('secret_command', command='!help wiki') elif p_len > 2: cmd = parts[1] q = str.join(" ", parts[2:]) if cmd == 'search': r = wikipedia.search(q) if len(r) > 0: embed = utils.simple_embed('wikipedia', 'search results for: **' + q + '**', discord.Color.lighter_grey()) embed.set_thumbnail(url=WIKI_ICON) for result in r: embed.add_field(name=result, value='!wikipedia fetch **' + result + '**', inline=False) await secret_context.discord_client.send_message( message.channel, embed=embed) else: embed = utils.simple_embed('wikipedia', 'no results for: **' + q + '**', discord.Color.red()) embed.set_thumbnail(url=WIKI_ICON) await secret_context.discord_client.send_message( message.channel, embed=embed) elif cmd == 'fetch': try: r = wikipedia.page(q) color = utils.random_color() img = WIKI_ICON if len(r.images) > 0: m_img = r.images f_img = None while len(m_img) > 0: img = m_img[0] m_img.pop(0) if str(img).endswith('.png') or str(img).endswith( '.jpg') or str(img).endswith('.jpeg'): f_img = img break if f_img: response = requests.get(img) if response.status_code == 200: if not os.path.exists('files'): os.mkdir('files') with open("files/tmp_wiki_icon.png", 'wb') as f: f.write(response.content) color_thief = ColorThief("files/tmp_wiki_icon.png") dominant_color = color_thief.get_color(quality=1) color = int(utils.rgb_to_hex(dominant_color), 16) embed = utils.simple_embed(q, r.summary, color) embed.set_thumbnail(url=img) await secret_context.discord_client.send_message( message.channel, embed=embed) except wikipedia.PageError as e: embed = utils.simple_embed('wikipedia', 'no results for: **' + q + '**', discord.Color.red()) embed.set_thumbnail(url=WIKI_ICON) await secret_context.discord_client.send_message( message.channel, embed=embed) except wikipedia.DisambiguationError as e: embed = utils.simple_embed( 'wikipedia', 'no results for: **' + q + '**. Use !wiki search *keywords and ' 'provide a working page to fetch.', discord.Color.red()) embed.set_thumbnail(url=WIKI_ICON) await secret_context.discord_client.send_message( message.channel, embed=embed)
async def on_message(message, secret_context): parts = message.content.split(" ") if len(parts) < 2: # print the help secret_context.bus.emit('secret_command', command='!help cloudsolve') else: domain = str(parts[1]) if domain.startswith('http://'): domain.replace('http://', '') elif domain.startswith('https://'): domain.replace('https://', '') if not utils.is_valid_domain(domain): embed = utils.simple_embed( 'cloudsolve', ('**%s** is not a valid domain' % domain), utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed) elif not uses_cloudflare(domain): embed = utils.simple_embed( 'cloudsolve', ('"%s" is not behind CloudFlare' % domain), discord.Color.red()) await secret_context.discord_client.send_message(message.channel, embed=embed) else: embed = utils.simple_embed( 'cloudsolve', ('**%s** appear to be behind CloudFlare' % domain), discord.Color.green()) await secret_context.discord_client.send_message(message.channel, embed=embed) embed = utils.simple_embed( 'cloudsolve', ('trying to exploit **%s** certificates' % domain), utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed) certs = exploit_certificates(domain, secret_context) if len(certs) > 0: embed = utils.simple_embed( 'cloudsolve', ('%d certificates matching **%s** found' % (len(certs), domain)), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) embed = utils.simple_embed( 'cloudsolve', ('looking for ipv4 hosts on **%s**' % domain), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) hosts = find_ipv4_hosts(certs, secret_context) hosts = filter_cloudflare_ips(hosts) if len(hosts) is 0: embed = utils.simple_embed('cloudsolve', ( '**%s** looks not exploitable. todo: bruteforce domain' % domain), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) else: embed = utils.simple_embed( 'cloudsolve', ('%d ipv4 hosts found on **%s**' % (len(hosts), domain)), utils.random_color()) for h in hosts: embed.add_field(name=h, value='ipv4', inline=True) await secret_context.discord_client.send_message( message.channel, embed=embed) origins = find_origins(domain, hosts) embed = utils.simple_embed( 'cloudsolve', ('looking for origins on **%s**' % domain), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) if len(origins) is 0: embed = utils.simple_embed('cloudsolve', ( 'did not found any origin server for **%s**. todo: bruteforce ' 'domain' % domain), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) else: embed = utils.simple_embed( 'cloudsolve', ('found %d origins for **%s**' % (len(origins), domain)), utils.random_color()) for o in origins: embed.add_field(name=o[0], value=o[1], inline=False) await secret_context.discord_client.send_message( message.channel, embed=embed) else: embed = utils.simple_embed( 'cloudsolve', ('no certificates found for **%s**' % domain), utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed)
async def pr(message, secret_context): parts = message.content.split(" ") if len(parts) == 1: await print_pr_help(message, secret_context.discord_client, secret_context.git_repo) else: if parts[1] == 'check': try: id = int(parts[2]) try: db_pull_doc = pull_vote.PullVote.objects.get(pull_id=id) if db_pull_doc.points >= db_pull_doc.required_points: await check_merge(message, secret_context, db_pull_doc) else: prq = secret_context.git_repo.get_pull( db_pull_doc.pull_number) await print_pr(message, secret_context.discord_client, prq, db_pull_doc) except pull_vote.DoesNotExist as e: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('error', 'pull request not found', discord.Color.red())) except Exception as e: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('error', 'usage: !pr check *pull_id', discord.Color.red())) elif parts[1] == 'downvote': try: id = int(parts[2]) try: db_pull_doc = pull_vote.PullVote.objects.get(pull_id=id) vote_points = -1 user_name = '' try: vote_points, user_name = calculate_vote_points( message, len(db_pull_doc.votes), db_pull_doc.required_points) except Exception as e: pass if vote_points < 0: desc = 'link your github with **!git link *git_user_name**' await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('info', desc, discord.Color.blue())) elif message.author.id in db_pull_doc.votes: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed( 'error', 'you already voted this pr', discord.Color.red())) else: db_pull_doc.points -= vote_points db_pull_doc.points = float("{0:.2f}".format( db_pull_doc.points)) db_pull_doc.votes[message.author.id] = { 'created': time.time(), 'name': user_name, 'points': vote_points, } db_pull_doc.save() embed = utils.simple_embed( 'success', '**' + str(vote_points) + '** points removed.\nTotal points: **' + str(db_pull_doc.points) + '**' + '\nRequired points: **' + str(db_pull_doc.required_points) + '**', discord.Color.green()) await secret_context.discord_client.send_message( message.channel, embed=embed) except pull_vote.DoesNotExist as e: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('error', 'pull request not found', discord.Color.red())) except Exception as e: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('error', 'usage: !pr downvote *pull_id', discord.Color.red())) elif parts[1] == 'upvote': try: id = int(parts[2]) try: db_pull_doc = pull_vote.PullVote.objects.get(pull_id=id) vote_points = -1 user_name = '' try: vote_points, user_name = calculate_vote_points( message, len(db_pull_doc.votes), db_pull_doc.required_points) except Exception as e: pass if vote_points < 0: desc = 'link your github with **!git link**' await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('info', desc, discord.Color.blue())) elif message.author.id in db_pull_doc.votes: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed( 'error', 'you already voted this pr', discord.Color.red())) else: db_pull_doc.points += vote_points db_pull_doc.points = float("{0:.2f}".format( db_pull_doc.points)) if db_pull_doc.points >= db_pull_doc.required_points: db_pull_doc.points = db_pull_doc.required_points db_pull_doc.votes[message.author.id] = { 'created': time.time(), 'name': user_name, 'points': vote_points, } db_pull_doc.save() embed = utils.simple_embed( 'success', '**' + str(vote_points) + '** points added.\nTotal points: **' + str(db_pull_doc.points) + '**' + '\nRequired points: **' + str(db_pull_doc.required_points) + '**', discord.Color.green()) await secret_context.discord_client.send_message( message.channel, embed=embed) if db_pull_doc.points >= db_pull_doc.required_points: try: u = user.User.objects.get( git_user_id=db_pull_doc.user_id) embed = utils.simple_embed( 'success', 'pr ' + db_pull_doc.pull_title + ' by **' + u.discord_mention + '** has been accepted.', discord.Color.green()) except Exception as e: embed = utils.simple_embed( 'success', 'pr ' + db_pull_doc.pull_title + ' by **' + db_pull_doc.user_name + '** has been accepted.', discord.Color.green()) await secret_context.discord_client.send_message( message.channel, embed=embed) await check_merge(message, secret_context, db_pull_doc) except pull_vote.DoesNotExist as e: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('error', 'pull request not found', discord.Color.red())) except Exception as e: await secret_context.discord_client.send_message( message.channel, embed=utils.simple_embed('error', 'usage: !pr upvote *pull_id', discord.Color.red()))
async def help(message, discord_client, cmd_maps, shortcuts_map): """ :param message: discord message :param discord_client: discord client :param cmd_maps: array with all command maps :return: """ parts = message.content.split(" ") if len(parts) < 2: embed = discord.Embed( title='', type='rich', description= "goal is to build me as an automated **bot** with whatever feature " "people would like to code. I'll soon run on a virtual" " machine with **root** privileges," "but meanwhile, I can already do something:\n\n** **", color=discord.Colour.dark_red()) embed.set_thumbnail(url=utils.ICON) embed.set_author(name="secRet", url="https://secret.re") embed.add_field(name="!commands", value="something to interact with me", inline=False) embed.add_field(name="!devme", value="info and help about coding features", inline=False) embed.add_field(name="!rules", value="a world without rules... mhhh chaos", inline=False) await discord_client.send_message(message.channel, embed=embed) else: cmd = parts[1] found = False if cmd in shortcuts_map: cmd = shortcuts_map[cmd] for map in cmd_maps: if cmd in map: found = True cmd_object = map[cmd] color = utils.random_color() embed = discord.Embed(title=cmd, type='rich', description=cmd_object['description'], color=color) if 'author' in cmd_object: embed.add_field(name='author', value=cmd_object['author'], inline=False) await discord_client.send_message(message.channel, embed=embed) if 'sub_commands' in cmd_object: embed = discord.Embed(title='sub commands', type='rich', description='** **', color=color) for sub in cmd_object['sub_commands']: description = '** **' if 'description' in sub: description = sub['description'] embed.add_field(name='!' + cmd + ' ' + sub['name'], value=description, inline=False) await discord_client.send_message(message.channel, embed=embed) break if not found: embed = utils.simple_embed('error', 'command not found', discord.Color.red()) await discord_client.send_message(message.channel, embed=embed)
async def on_message(message, secret_context): parts = message.content.split(" ") try: location_code = int(parts[1]) r = requests.get("https://api.accuweather.com/currentconditions/v1/" + str(location_code) + "?apikey=" + API_KEY + "&details=true&getphotos=true") j = json.loads(r.content.decode('utf8')) if 'code' in j: embed = utils.simple_embed( 'accuweather', 'location id not found. use ' '!weather search *city_name to get the city code', utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed) else: obj = j[0] embed = utils.simple_embed( 'accuweather', 'weather conditions for: **' + parts[1] + '**', utils.random_color()) embed.add_field(name='condition', value=obj['WeatherText'], inline=False) embed.add_field( name='update time', value=datetime.fromtimestamp( obj['EpochTime']).strftime('%Y-%m-%d %H:%M:%S'), inline=False) ct = obj['Temperature']['Metric']['Value'] cf = obj['Temperature']['Imperial']['Value'] ct_r = obj['RealFeelTemperature']['Metric']['Value'] cf_r = obj['RealFeelTemperature']['Imperial']['Value'] embed.add_field(name='temperature', value=str(ct) + ' **C** | ' + str(cf) + ' **F**') embed.add_field(name='real feel', value=str(ct_r) + ' **C** | ' + str(cf_r) + ' **F**') embed.add_field(name='humidity', value=str(obj['RelativeHumidity']) + '%') embed.add_field(name='cloud cover', value=str(obj['CloudCover']) + '%') embed.add_field(name='wind direction', value=str(obj['Wind']['Direction']['Degrees']) + obj['Wind']['Direction']['English']) embed.add_field( name='wind speed', value=str(obj['Wind']['Speed']['Metric']['Value']) + ' km/h') embed.set_thumbnail(url=obj['Photos'][0]['PortraitLink']) await secret_context.discord_client.send_message(message.channel, embed=embed) except Exception as e: if len(parts) < 1: embed = utils.simple_embed( 'accuweather', 'use !weather search *city_name to get the city code', utils.random_color()) await secret_context.discord_client.send_message(message.channel, embed=embed) else: if len(parts) > 2 and parts[1] == 'search': parts = parts[2:] q = str.join(" ", parts) r = requests.get( "https://api.accuweather.com/locations/v1/cities/autocomplete.json?apikey=" + API_KEY + "&language=en&q=" + q) j = json.loads(r.content.decode('utf8')) if len(j) == 0: embed = utils.simple_embed( 'accuweather', 'no city found for **' + q + '**', utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed) else: embed = utils.simple_embed('accuweather', 'results for **' + q + '**', utils.random_color()) for city in j: embed.add_field(name=city['LocalizedName'], value=city['Key'], inline=True) await secret_context.discord_client.send_message( message.channel, embed=embed) else: embed = utils.simple_embed( 'accuweather', 'use !weather search *city_name to get the city code', utils.random_color()) await secret_context.discord_client.send_message( message.channel, embed=embed)