From d481d5dc89e50c3d77ed4594a60bfafbc3a06eec Mon Sep 17 00:00:00 2001 From: Box In A Box Date: Sun, 26 Sep 2021 01:47:04 +0530 Subject: [PATCH] mirrorbot: Add Additional Features - Add dump, pdump, invite, dummy Co-authored-by: saurajbot --- README.md | 30 +++- bot/__init__.py | 8 ++ bot/__main__.py | 26 ++-- bot/helper/telegram_helper/bot_commands.py | 4 + bot/modules/dummy.py | 103 ++++++++++++++ bot/modules/dump.py | 157 +++++++++++++++++++++ bot/modules/invite.py | 78 ++++++++++ bot/modules/pdump.py | 157 +++++++++++++++++++++ config_sample.env | 8 ++ 9 files changed, 558 insertions(+), 13 deletions(-) create mode 100644 bot/modules/dummy.py create mode 100644 bot/modules/dump.py create mode 100644 bot/modules/invite.py create mode 100644 bot/modules/pdump.py diff --git a/README.md b/README.md index 71d9499..813b83b 100644 --- a/README.md +++ b/README.md @@ -71,12 +71,29 @@ APM, ARJ, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, LZH, LZMA, LZMA2, MBR, MSI, MSLZ, NSIS, NTFS, RPM, SquashFS, UDF, VHD, XAR, Z. ``` +## Additional Features +- Dump Android Firmwares To GitHub Org, Publicly Or Privately +- Invite Users To Private GitHub Repos +- Generate Dummy Device-Trees And Vendor-Trees From Firmware Dump Link +- How to use /dump , /pdump , /invite , /dummy? +``` +dump: /dump +pdump: /pdump +invite: /invite Box-boi redmi_biloba_dump +dummy: /dump (optional) +``` # How to deploy? Deploying is pretty much straight forward and is divided into several steps as follows: ## Installing requirements +- Fork These Repos First: +``` +1: https://github.com/Box-boi/dumper +2: https://github.com/Box-boi/dummy +``` +- After Forking, Set The Appropriate Git-Secrets, By Taking A Look At .github/workflows/xyz.yml - Clone this repo: ``` @@ -135,6 +152,14 @@ _____REMOVE_THIS_LINE_____=True ``` Fill up rest of the fields. Meaning of each field is discussed below: ### Required Field +- `GITHUB_TOKEN`: itHub Token, Don't Leak This Token, Or Your Account Will Be Compromised!, Keep It A Secret, Get Your Token From: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token +- `GITHUB_ORG_NAME`: Your GitHub Organization Name, Where Your Dumps Will Be Stored +- `GITHUB_USER_NAME`: Your GitHub Username +- `GITHUB_DUMPER_REPO_NAME`: Leave Untouched If You Have Forked My Repos +- `GITHUB_DUMMY_REPO_NAME`: Leave Untouched If You Have Forked My Repos +- `TELEGRAM_CHANNEL_NAME`: Channel Tag Where Your Dumps Will Be Posted Example: @boxdumps +- `DUMPER_REPO_WORKFLOW_URL`: Example: https://github.com/box-automation1/dumper/actions +- `GITHUB_USER_EMAIL`: Email Of Your GitHub Account - `BOT_TOKEN`: The Telegram Bot Token that you got from [@BotFather](https://t.me/BotFather) - `TELEGRAM_API`: This is to authenticate your Telegram account for downloading Telegram files. You can get this from https://my.telegram.org. **NOTE**: DO NOT put this in quotes. - `TELEGRAM_HASH`: This is to authenticate your Telegram account for downloading Telegram files. You can get this from https://my.telegram.org @@ -194,7 +219,7 @@ Three buttons are already added including Drive Link, Index Link, and View Link, ## Bot commands to be set in [@BotFather](https://t.me/BotFather) -

+

## Getting Google OAuth API credential file - Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials) @@ -361,5 +386,8 @@ Thanks to: - [`zevtyardt`](https://github.com/zevtyardt) for some direct links - [`yash-dk`](https://github.com/yash-dk) for implementation of qBittorrent on Python - [`xyou365`](https://github.com/xyou365) for Service Accounts script +- [`techyminati`](https://github.com/techyminati) for help in dump script And many more people who aren't mentioned here, but can be found in [Contributors](https://github.com/SlamDevs/slam-mirrorbot/graphs/contributors). + +This Repo Will Be Upstreamed Once A Month To [Slam Mirrorbot Source](https://github.com/SlamDevs/slam-mirrorbot/) diff --git a/bot/__init__.py b/bot/__init__.py index 0db6a02..9fc559d 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -152,6 +152,14 @@ try: AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION')) TELEGRAM_API = getConfig('TELEGRAM_API') TELEGRAM_HASH = getConfig('TELEGRAM_HASH') + GITHUB_USER_NAME = getConfig('GITHUB_USER_NAME') + GITHUB_TOKEN = getConfig('GITHUB_TOKEN') + GITHUB_DUMPER_REPO_NAME = getConfig('GITHUB_DUMPER_REPO_NAME') + GITHUB_DUMMY_REPO_NAME = getConfig('GITHUB_DUMMY_REPO_NAME') + TELEGRAM_CHANNEL_NAME = getConfig('TELEGRAM_CHANNEL_NAME') + DUMPER_REPO_WORKFLOW_URL = getConfig('DUMPER_REPO_WORKFLOW_URL') + GITHUB_ORG_NAME = getConfig('GITHUB_ORG_NAME') + GITHUB_USER_EMAIL = getConfig('GITHUB_USER_EMAIL') except KeyError as e: LOGGER.error("One or more env variables missing! Exiting now") exit(1) diff --git a/bot/__main__.py b/bot/__main__.py index f1d35ba..040607e 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -17,7 +17,7 @@ from bot.helper.telegram_helper.message_utils import * from .helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time from .helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper import button_build -from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, shell, eval, torrent_search, delete, speedtest, count, leech_settings +from .modules import authorize, list, cancel_mirror, mirror_status, mirror, dump, pdump, invite, dummy, clone, watch, shell, eval, torrent_search, delete, speedtest, count, leech_settings def stats(update, context): @@ -152,6 +152,15 @@ help_string_telegraph = f'''
/{BotCommands.StatusCommand}: Shows a status of all the downloads

/{BotCommands.StatsCommand}: Show Stats of the machine the bot is hosted on +

+/{BotCommands.DummyCommand}: Generates A Dummy Tree Using A Link To A Dump Of An Android Firmware, Example /{BotCommands.DummyCommand} dump_link dump_branch(optional) +

+/{BotCommands.InviteCommand}: Invite Users To Private GitHub Repo, Example /{BotCommands.InviteCommand} Box-boi redmi_biloba_dump (Only Owner) +

+/{BotCommands.PdumpCommand}: Dump Android Firmwares To GitHub Repo(Privately), Example /{BotCommands.PdumpCommand} firmware_link (Authorized Users Only) +

+/{BotCommands.DumpCommand}: Dump Android Firmwares To GitHub Repo, Example /{BotCommands.DumpCommand} firmware_link (Authorized Users Only) +

''' help = Telegraph(access_token=telegraph_token).create_page( title='Slam Mirrorbot Help', @@ -162,27 +171,16 @@ help = Telegraph(access_token=telegraph_token).create_page( help_string = f''' /{BotCommands.PingCommand}: Check how long it takes to Ping the Bot - /{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by Owner & Sudo of the bot) - /{BotCommands.UnAuthorizeCommand}: Unauthorize a chat or a user to use the bot (Can only be invoked by Owner & Sudo of the bot) - /{BotCommands.AuthorizedUsersCommand}: Show authorized users (Only Owner & Sudo) - /{BotCommands.AddSudoCommand}: Add sudo user (Only Owner) - /{BotCommands.RmSudoCommand}: Remove sudo users (Only Owner) - /{BotCommands.RestartCommand}: Restart the bot - /{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports - /{BotCommands.SpeedCommand}: Check Internet Speed of the Host - /{BotCommands.ShellCommand}: Run commands in Shell (Only Owner) - /{BotCommands.ExecHelpCommand}: Get help for Executor module (Only Owner) - /{BotCommands.TsHelpCommand}: Get help for Torrent search module ''' @@ -214,6 +212,10 @@ botcmds = [ (f'{BotCommands.ListCommand}','Searches files in Drive'), (f'{BotCommands.StatusCommand}','Get Mirror Status message'), (f'{BotCommands.StatsCommand}','Bot Usage Stats'), + (f'{BotCommands.DumpCommand}','Dump Android Firmware To GitHub Repo [Authorized Users only]'), + (f'{BotCommands.PdumpCommand}','Dump Android Firmware To GitHub Private Repo [Authorized Users only]'), + (f'{BotCommands.InviteCommand}','Invite Users To Private GitHub Repos [owner/sudo only]'), + (f'{BotCommands.DummyCommand}','Generates A Dummy Tree Using A Link To A Dump Of An Android Firmware [Authorized Users only]'), (f'{BotCommands.PingCommand}','Ping the Bot'), (f'{BotCommands.RestartCommand}','Restart the bot [owner/sudo only]'), (f'{BotCommands.LogCommand}','Get the Bot Log [owner/sudo only]'), diff --git a/bot/helper/telegram_helper/bot_commands.py b/bot/helper/telegram_helper/bot_commands.py index 1c6a930..26a79f9 100644 --- a/bot/helper/telegram_helper/bot_commands.py +++ b/bot/helper/telegram_helper/bot_commands.py @@ -44,6 +44,10 @@ class _BotCommands: self.QbUnzipLeechCommand = 'qbunzipleech' self.QbZipLeechCommand = 'qbzipleech' self.LeechWatchCommand = 'leechwatch' + self.DumpCommand = 'dump' + self.PdumpCommand = 'pdump' + self.DummyCommand = 'dummy' + self.InviteCommand = 'invite' self.LeechTarWatchCommand = 'leechtarwatch' self.LeechZipWatchCommand = 'leechzipwatch' diff --git a/bot/modules/dummy.py b/bot/modules/dummy.py new file mode 100644 index 0000000..2b990d1 --- /dev/null +++ b/bot/modules/dummy.py @@ -0,0 +1,103 @@ +import os +import sys +from functools import wraps +from bot import LOGGER, dispatcher +from bot import OWNER_ID, GITHUB_USER_NAME, SUDO_USERS, AUTHORIZED_CHATS, GITHUB_TOKEN, GITHUB_DUMMY_REPO_NAME, TELEGRAM_CHANNEL_NAME, GITHUB_USER_EMAIL, dispatcher, DB_URI +from telegram import ParseMode, Update +from telegram.ext import CallbackContext, CommandHandler, Filters +from telegram.ext.dispatcher import run_async +from bot.helper.telegram_helper.bot_commands import BotCommands +from bot.helper.ext_utils.db_handler import DbManger +from bot.helper.telegram_helper.filters import CustomFilters +from bot.helper.telegram_helper.message_utils import sendMessage + +AUTHORIZED_CHATS.add(OWNER_ID) +import subprocess +import string +import random + +bashfile=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) +bashfile='/tmp/'+bashfile+'.sh' +#CHAT_ID = update.effective_chat.id +f = open(bashfile, 'w') +s = """#!/bin/bash +ORIGINAL_PATH=$(pwd) +ORIGINAL_GIT_USER_EMAIL=$(git config user.email) +ORIGINAL_GIT_USER_NAME=$(git config user.name) +echo "$1" | grep -e '^\(https\?\|ftp\)://.*$' > /dev/null; +CODE=$1 +set -- $CODE +GITHUB_TOKEN=$1 +GITHUB_USER_NAME=$2 +GITHUB_REPO_NAME=$3 +GITHUB_USER_EMAIL=$4 +TELEGRAM_CHANNEL_NAME=$5 +CURRENT_CHAT_ID=$6 +URL=$7 +BRANCH=$8 +URL_WITHOUT_HTTPS=$(echo "$URL" |sed 's/https\?:\/\///') +NEW_URL=https://${GITHUB_USER_NAME}:${GITHUB_TOKEN}@${URL_WITHOUT_HTTPS} #just incase its a dump from own private org +DUMP_NAME=$(echo $URL_WITHOUT_HTTPS | sed 's/.*\///') +git config --global user.email "$GITHUB_USER_EMAIL" +git config --global user.name "$GITHUB_USER_NAME" +git config --global credential.helper cache +git ls-remote "$NEW_URL" > /dev/null 2>&1 +if [ "$?" -ne 0 ]; then echo "[ERROR] "$NEW_URL" is not a git repo" && exit 1; fi +git clone --depth=1 --single-branch --quiet https://${GITHUB_USER_NAME}:${GITHUB_TOKEN}@github.com/${GITHUB_USER_NAME}/${GITHUB_REPO_NAME} ~/tempdirectorysirbro +cd ~/tempdirectorysirbro +rm -rf BRANCH.txt URL.txt CURRENT_CHAT_ID.txt +echo "$CURRENT_CHAT_ID" > CURRENT_CHAT_ID.txt +echo "${URL}" > URL.txt +if [[ "${BRANCH}" == "" ]] ; then touch BRANCH.txt ; else echo "${BRANCH}" > BRANCH.txt && git add BRANCH.txt ; fi +git add URL.txt CURRENT_CHAT_ID.txt +git commit -m "Generate Dummy Tree Using $DUMP_NAME" +git push -f --quiet https://${GITHUB_USER_NAME}:${GITHUB_TOKEN}@github.com/${GITHUB_USER_NAME}/${GITHUB_REPO_NAME} +cd ${ORIGINAL_PATH} +rm -rf ${GITHUB_REPO_NAME} +git config --global user.email "$ORIGINAL_GIT_USER_EMAIL" +git config --global user.name "$ORIGINAL_GIT_USER_NAME" +""" +f.write(s) +f.close() +os.chmod(bashfile, 0o755) +bashcmd=bashfile +for arg in sys.argv[1:]: + bashcmd += ' '+arg + +def dummy(update: Update, context: CallbackContext): + message = update.effective_message + cmd = message.text.split(' ', 1) + CHAT_ID=message.chat_id + print(CHAT_ID) + if len(cmd) == 1: + message.reply_text('Please Provide a Direct Link to an Android Dump') + return + cmd = cmd[1] + process = subprocess.Popen( + bashcmd + ' ' + '"' + GITHUB_TOKEN + ' ' + GITHUB_USER_NAME + ' ' + GITHUB_DUMMY_REPO_NAME + ' ' + GITHUB_USER_EMAIL + ' ' + TELEGRAM_CHANNEL_NAME + ' ' + str(CHAT_ID) + ' ' + cmd + '"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = process.communicate() + reply = '' + stderr = stderr.decode() + stdout = stdout.decode() + if stdout: + reply += f"*Generating Dummy Device-Tree, It will be availaible on \n\n{TELEGRAM_CHANNEL_NAME}*\n\n '{stdout}'\n" + LOGGER.info(f"Shell - {bashcmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_DUMMY_REPO_NAME} {GITHUB_USER_EMAIL} {TELEGRAM_CHANNEL_NAME} {str(CHAT_ID)} {cmd} - {stdout}") + if stderr: + reply += f"*Stderr*\n`{stderr}`\n" + LOGGER.error(f"Shell - {bashcmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_DUMMY_REPO_NAME} {GITHUB_USER_EMAIL} {TELEGRAM_CHANNEL_NAME} {str(CHAT_ID)} {cmd} - {stderr}") + if len(reply) > 3000: + with open('shell_output.txt', 'w') as file: + file.write(reply) + with open('shell_output.txt', 'rb') as doc: + context.bot.send_document( + document=doc, + filename=doc.name, + reply_to_message_id=message.message_id, + chat_id=message.chat_id) + else: + message.reply_text(reply, parse_mode=ParseMode.MARKDOWN) + + +DUMMY_HANDLER = CommandHandler(['dmy', 'dummy'], dummy, + filters=CustomFilters.owner_filter | CustomFilters.authorized_user | CustomFilters.sudo_user, run_async=True) +dispatcher.add_handler(DUMMY_HANDLER) diff --git a/bot/modules/dump.py b/bot/modules/dump.py new file mode 100644 index 0000000..8139b49 --- /dev/null +++ b/bot/modules/dump.py @@ -0,0 +1,157 @@ +import os +import sys +from functools import wraps +from bot import LOGGER, dispatcher +from bot import OWNER_ID, GITHUB_USER_NAME, SUDO_USERS, AUTHORIZED_CHATS, GITHUB_TOKEN, GITHUB_DUMPER_REPO_NAME, TELEGRAM_CHANNEL_NAME, DUMPER_REPO_WORKFLOW_URL, GITHUB_USER_EMAIL, dispatcher, DB_URI +from telegram import ParseMode, Update +from telegram.ext import CallbackContext, CommandHandler, Filters +from telegram.ext.dispatcher import run_async +from bot.helper.telegram_helper.bot_commands import BotCommands +from bot.helper.ext_utils.db_handler import DbManger +from bot.helper.telegram_helper.filters import CustomFilters +from bot.helper.telegram_helper.message_utils import sendMessage + +AUTHORIZED_CHATS.add(OWNER_ID) +import subprocess +import string +import random + +bashfile=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) +bashfile='/tmp/'+bashfile+'.sh' +#CHAT_ID = update.effective_chat.id +f = open(bashfile, 'w') +s = """#!/bin/bash +DUMP_TYPE=public #Set this to either public or private #Fork This Repo and also fork this repo: https://github.com/mirrordump/dumpyara.git +##DO NOT EDIT +DUMMY_VARIABLE=1 +ORIGINAL_PATH=$(pwd) +ORIGINAL_GITHUB_USER_EMAIL=$(git config user.email) +ORIGINAL_GITHUB_USER_NAME=$(git config user.name) +URL=$1 +GIT_TOKEN=$2 +GITHUB_USER_NAME=$3 +GITHUB_REPO_NAME=$4 +GITHUB_USER_EMAIL=$5 +TELEGRAM_CHANNEL_NAME=$6 +DUMPER_REPO_WORKFLOW_URL=$7 +CHAT_ID=$8 +USER_ID=$9 +USER_FIRST_NAME=${10} +USER_TAG=${11} + +git config --global user.email "$GITHUB_USER_EMAIL" +git config --global user.name "$GITHUB_USER_NAME" +git config --global credential.helper cache +if [[ $URL == *://*/* ]] ; then true ; else echo "Incorrect Link Format! Do Not Abuse This Feature!" && exit 1 ; fi +SIZE=$(curl -sI --head --location $URL | grep -i content-length | awk '{print $2}') && SIZE=`echo $SIZE | sed 's/\\r//g'` #removing \r due to html +HUMAN_SIZE=$(timeout 0.5s numfmt --to=iec $SIZE) && HUMAN_SIZE=$(echo $HUMAN_SIZE'B') +if [ -z $SIZE ]; then + echo "Dump Failed! + You Havent Provided A Proper link, Do Not Abuse This Feature With Your Random Requests, You Might Lose Access To This Feature If You Abuse It!" + exit 1 +fi +if [[ $SIZE -lt 400000000 ]]; then + echo "Your File is Too Small $HUMAN_SIZE. It Can Also Be Possible That Your Link Failed Auto-Verification And Hence Is Unsupported, In That Case, Try Mirroring It And Then Dumping!" + exit 1 +fi +rm -rf $GITHUB_REPO_NAME +git clone --quiet --depth=1 --single-branch https://$GITHUB_USER_NAME:$GIT_TOKEN@github.com/$GITHUB_USER_NAME/$GITHUB_REPO_NAME.git +CHECK=$(tail -n 1 $GITHUB_REPO_NAME/.github/workflows/dumpyara.yml) +echo ' 'ROM_URL: $URL >> CHECK.txt +VERIFY=$(tail -n 1 CHECK.txt) && rm CHECK.txt +if [ "$CHECK" == "$VERIFY" ] +then + echo " + DUMP FAILED! The Link Provided was Previously Dumped Already, Please do not Misuse this Feature! + " + exit 1 +elif [ "$DUMP_TYPE" == private ] +then + cd $GITHUB_REPO_NAME/.github/workflows && sed -i '$d' dumpyara.yml + echo ' 'ROM_URL: $URL >> dumpyara.yml + cd ../.. && echo 'Dummy File To Push Dumped Firmware to Private Github Repo' > private.txt + echo "$CHAT_ID" > CHAT_ID.txt + echo "$USER_ID" > USER_ID.txt + echo "$USER_TAG" > USER_TAG.txt + echo "$USER_FIRST_NAME" > USER_FIRST_NAME.txt + git add -f . + echo $URL > CLEAN.txt && CLEAN=$(sed 's/^.*\///' CLEAN.txt) && CLEAN=$(echo "${CLEAN%.*}") && rm CLEAN.txt + git commit --quiet -m "Dump $CLEAN" + git push --quiet -f https://$GITHUB_USER_NAME:$GIT_TOKEN@github.com/$GITHUB_USER_NAME/$GITHUB_REPO_NAME + echo "$DUMPER_REPO_WORKFLOW_URL" +elif [ "$DUMP_TYPE" == public ] +then + cd $GITHUB_REPO_NAME/.github/workflows && sed -i '$d' dumpyara.yml + echo ' 'ROM_URL: $URL >> dumpyara.yml + cd ../.. && rm -rf private.txt + echo "$CHAT_ID" > CHAT_ID.txt + echo "$USER_ID" > USER_ID.txt + echo "$USER_TAG" > USER_TAG.txt + echo "$USER_FIRST_NAME" > USER_FIRST_NAME.txt + git add -f . + echo $URL > CLEAN.txt && CLEAN=$(sed 's/^.*\///' CLEAN.txt) && CLEAN=$(echo "${CLEAN%.*}") && rm CLEAN.txt + git commit --quiet -m "Dump $CLEAN" + git push --quiet -f https://$GITHUB_USER_NAME:$GIT_TOKEN@github.com/$GITHUB_USER_NAME/$GITHUB_REPO_NAME + echo "$DUMPER_REPO_WORKFLOW_URL" +else + echo " + Fill in the Variable 'DUMP_TYPE with either public or private! + " + exit 1 +fi +#CLEANUP TIME! +git config --global user.email "$ORIGINAL_GITHUB_USER_EMAIL" +git config --global user.name "$ORIGINAL_GITHUB_USER_NAME" +cd $ORIGINAL_PATH +rm -rf $GITHUB_REPO_NAME +""" +f.write(s) +f.close() +os.chmod(bashfile, 0o755) +bashcmd=bashfile +for arg in sys.argv[1:]: + bashcmd += ' '+arg + +def dump(update: Update, context: CallbackContext): + message = update.effective_message + cmd = message.text.split(' ', 1) + CHAT_ID=message.chat_id + USER_ID = f"{message.from_user.id}" + FIRST_NAME = f"{message.from_user.first_name}" + if message.from_user.username: + USER_TAG = f"@{message.from_user.username}" + else: + USER_TAG = f"none" + print(CHAT_ID) + if len(cmd) == 1: + message.reply_text('Please Provide a Direct Link to an Android Firmware') + return + cmd = cmd[1] + process = subprocess.Popen( + bashcmd + ' ' + '"' + cmd + '" "' + GITHUB_TOKEN + '" "' + GITHUB_USER_NAME + '" "' + GITHUB_DUMPER_REPO_NAME + '" "' + GITHUB_USER_EMAIL + '" "' + TELEGRAM_CHANNEL_NAME + '" "' + DUMPER_REPO_WORKFLOW_URL + '" "' + str(CHAT_ID) + '" "' + USER_ID + '" "' + FIRST_NAME + '" "' + USER_TAG + '"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = process.communicate() + reply = '' + stderr = stderr.decode() + stdout = stdout.decode() + if stdout: + reply += f"*Dumping Your Given Firmware, Please wait, Dump will be availaible on \n\n{TELEGRAM_CHANNEL_NAME}*\n\n '{stdout}'\n" + LOGGER.info(f"Shell - {bashcmd} {cmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_DUMPER_REPO_NAME} {GITHUB_USER_EMAIL} {TELEGRAM_CHANNEL_NAME} {DUMPER_REPO_WORKFLOW_URL} {str(CHAT_ID)} - {stdout}") + if stderr: + reply += f"*Stderr*\n`{stderr}`\n" + LOGGER.error(f"Shell - {bashcmd} {cmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_DUMPER_REPO_NAME} {GITHUB_USER_EMAIL} {TELEGRAM_CHANNEL_NAME} {DUMPER_REPO_WORKFLOW_URL} {str(CHAT_ID)} - {stderr}") + if len(reply) > 3000: + with open('shell_output.txt', 'w') as file: + file.write(reply) + with open('shell_output.txt', 'rb') as doc: + context.bot.send_document( + document=doc, + filename=doc.name, + reply_to_message_id=message.message_id, + chat_id=message.chat_id) + else: + message.reply_text(reply, parse_mode=ParseMode.MARKDOWN) + + +DUMP_HANDLER = CommandHandler(['dmp', 'dump'], dump, + filters=CustomFilters.owner_filter | CustomFilters.authorized_user | CustomFilters.sudo_user, run_async=True) +dispatcher.add_handler(DUMP_HANDLER) diff --git a/bot/modules/invite.py b/bot/modules/invite.py new file mode 100644 index 0000000..87718b0 --- /dev/null +++ b/bot/modules/invite.py @@ -0,0 +1,78 @@ +import os +import sys +from functools import wraps +from bot import LOGGER, dispatcher +from bot import OWNER_ID, GITHUB_USER_NAME, SUDO_USERS, AUTHORIZED_CHATS, GITHUB_TOKEN, GITHUB_ORG_NAME, dispatcher, DB_URI +from telegram import ParseMode, Update +from telegram.ext import CallbackContext, CommandHandler, Filters +from telegram.ext.dispatcher import run_async +from bot.helper.telegram_helper.bot_commands import BotCommands +from bot.helper.ext_utils.db_handler import DbManger +from bot.helper.telegram_helper.filters import CustomFilters +from bot.helper.telegram_helper.message_utils import sendMessage + +AUTHORIZED_CHATS.add(OWNER_ID) +import subprocess +import string +import random + +bashfile=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) +bashfile='/tmp/'+bashfile+'.sh' +#CHAT_ID = update.effective_chat.id +f = open(bashfile, 'w') +s = """ +PERMISSION=push +echo "$1" | grep -e '$' > /dev/null; +CODE=$1 +set -- $CODE +GITHUB_TOKEN=$1 +GITHUB_USER_NAME=$2 +GITHUB_ORG_NAME=$3 +INVITEE_USERNAME=$4 +REPO_TO_INVITE=$5 +bash curl -i -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_ORG_NAME/$REPO_TO_INVITE/collaborators/$INVITEE_USERNAME" -X PUT -d "{\"permission\":\"$PERMISSION\"}" 2>&1 | grep message || echo "Sent Invite To $INVITEE_USERNAME to Join $REPO_TO_INVITE" +""" +f.write(s) +f.close() +os.chmod(bashfile, 0o755) +bashcmd=bashfile +for arg in sys.argv[1:]: + bashcmd += ' '+arg + +def invite(update: Update, context: CallbackContext): + message = update.effective_message + cmd = message.text.split(' ', 1) + CHAT_ID=message.chat_id + print(CHAT_ID) + if len(cmd) == 1: + message.reply_text('Please Provide Username And Repo Name To Invite A GitHub User') + return + cmd = cmd[1] + process = subprocess.Popen( + bashcmd + ' ' + '"' + GITHUB_TOKEN + ' ' + GITHUB_USER_NAME + ' ' + GITHUB_ORG_NAME + ' ' + cmd + '"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = process.communicate() + reply = '' + stderr = stderr.decode() + stdout = stdout.decode() + if stdout: + reply += f"*Inviting User To Mentioned GitHub Repo*\n\n '{stdout}'\n" + LOGGER.error(f"Shell - {bashcmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_ORG_NAME} {cmd}- {stderr}") + if stderr: + reply += f"*Stderr*\n`{stderr}`\n" + LOGGER.error(f"Shell - {bashcmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_ORG_NAME} {cmd}- {stderr}") + if len(reply) > 3000: + with open('shell_output.txt', 'w') as file: + file.write(reply) + with open('shell_output.txt', 'rb') as doc: + context.bot.send_document( + document=doc, + filename=doc.name, + reply_to_message_id=message.message_id, + chat_id=message.chat_id) + else: + message.reply_text(reply, parse_mode=ParseMode.MARKDOWN) + + +INVITE_HANDLER = CommandHandler(['inv', 'invite'], invite, + filters=CustomFilters.owner_filter | CustomFilters.sudo_user, run_async=True) +dispatcher.add_handler(INVITE_HANDLER) diff --git a/bot/modules/pdump.py b/bot/modules/pdump.py new file mode 100644 index 0000000..ee1077b --- /dev/null +++ b/bot/modules/pdump.py @@ -0,0 +1,157 @@ +import os +import sys +from functools import wraps +from bot import LOGGER, dispatcher +from bot import OWNER_ID, GITHUB_USER_NAME, SUDO_USERS, AUTHORIZED_CHATS, GITHUB_TOKEN, GITHUB_DUMPER_REPO_NAME, TELEGRAM_CHANNEL_NAME, DUMPER_REPO_WORKFLOW_URL, GITHUB_USER_EMAIL, dispatcher, DB_URI +from telegram import ParseMode, Update +from telegram.ext import CallbackContext, CommandHandler, Filters +from telegram.ext.dispatcher import run_async +from bot.helper.telegram_helper.bot_commands import BotCommands +from bot.helper.ext_utils.db_handler import DbManger +from bot.helper.telegram_helper.filters import CustomFilters +from bot.helper.telegram_helper.message_utils import sendMessage + +AUTHORIZED_CHATS.add(OWNER_ID) +import subprocess +import string +import random + +bashfile=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) +bashfile='/tmp/'+bashfile+'.sh' +#CHAT_ID = update.effective_chat.id +f = open(bashfile, 'w') +s = """#!/bin/bash +DUMP_TYPE=private #Set this to either public or private #Fork This Repo and also fork this repo: https://github.com/mirrordump/dumpyara.git +##DO NOT EDIT +DUMMY_VARIABLE=1 +ORIGINAL_PATH=$(pwd) +ORIGINAL_GITHUB_USER_EMAIL=$(git config user.email) +ORIGINAL_GITHUB_USER_NAME=$(git config user.name) +URL=$1 +GIT_TOKEN=$2 +GITHUB_USER_NAME=$3 +GITHUB_REPO_NAME=$4 +GITHUB_USER_EMAIL=$5 +TELEGRAM_CHANNEL_NAME=$6 +DUMPER_REPO_WORKFLOW_URL=$7 +CHAT_ID=$8 +USER_ID=$9 +USER_FIRST_NAME=${10} +USER_TAG=${11} + +git config --global user.email "$GITHUB_USER_EMAIL" +git config --global user.name "$GITHUB_USER_NAME" +git config --global credential.helper cache +if [[ $URL == *://*/* ]] ; then true ; else echo "Incorrect Link Format! Do Not Abuse This Feature!" && exit 1 ; fi +SIZE=$(curl -sI --head --location $URL | grep -i content-length | awk '{print $2}') && SIZE=`echo $SIZE | sed 's/\\r//g'` #removing \r due to html +HUMAN_SIZE=$(timeout 0.5s numfmt --to=iec $SIZE) && HUMAN_SIZE=$(echo $HUMAN_SIZE'B') +if [ -z $SIZE ]; then + echo "Dump Failed! + You Havent Provided A Proper link, Do Not Abuse This Feature With Your Random Requests, You Might Lose Access To This Feature If You Abuse It!" + exit 1 +fi +if [[ $SIZE -lt 400000000 ]]; then + echo "Your File is Too Small $HUMAN_SIZE. It Can Also Be Possible That Your Link Failed Auto-Verification And Hence Is Unsupported, In That Case, Try Mirroring It And Then Dumping!" + exit 1 +fi +rm -rf $GITHUB_REPO_NAME +git clone --quiet --depth=1 --single-branch https://$GITHUB_USER_NAME:$GIT_TOKEN@github.com/$GITHUB_USER_NAME/$GITHUB_REPO_NAME.git +CHECK=$(tail -n 1 $GITHUB_REPO_NAME/.github/workflows/dumpyara.yml) +echo ' 'ROM_URL: $URL >> CHECK.txt +VERIFY=$(tail -n 1 CHECK.txt) && rm CHECK.txt +if [ "$CHECK" == "$VERIFY" ] +then + echo " + DUMP FAILED! The Link Provided was Previously Dumped Already, Please do not Misuse this Feature! + " + exit 1 +elif [ "$DUMP_TYPE" == private ] +then + cd $GITHUB_REPO_NAME/.github/workflows && sed -i '$d' dumpyara.yml + echo ' 'ROM_URL: $URL >> dumpyara.yml + cd ../.. && echo 'Dummy File To Push Dumped Firmware to Private Github Repo' > private.txt + echo "$CHAT_ID" > CHAT_ID.txt + echo "$USER_ID" > USER_ID.txt + echo "$USER_TAG" > USER_TAG.txt + echo "$USER_FIRST_NAME" > USER_FIRST_NAME.txt + git add -f . + echo $URL > CLEAN.txt && CLEAN=$(sed 's/^.*\///' CLEAN.txt) && CLEAN=$(echo "${CLEAN%.*}") && rm CLEAN.txt + git commit --quiet -m "Dump $CLEAN" + git push --quiet -f https://$GITHUB_USER_NAME:$GIT_TOKEN@github.com/$GITHUB_USER_NAME/$GITHUB_REPO_NAME + echo "$DUMPER_REPO_WORKFLOW_URL" +elif [ "$DUMP_TYPE" == public ] +then + cd $GITHUB_REPO_NAME/.github/workflows && sed -i '$d' dumpyara.yml + echo ' 'ROM_URL: $URL >> dumpyara.yml + cd ../.. && rm -rf private.txt + echo "$CHAT_ID" > CHAT_ID.txt + echo "$USER_ID" > USER_ID.txt + echo "$USER_TAG" > USER_TAG.txt + echo "$USER_FIRST_NAME" > USER_FIRST_NAME.txt + git add -f . + echo $URL > CLEAN.txt && CLEAN=$(sed 's/^.*\///' CLEAN.txt) && CLEAN=$(echo "${CLEAN%.*}") && rm CLEAN.txt + git commit --quiet -m "Dump $CLEAN" + git push --quiet -f https://$GITHUB_USER_NAME:$GIT_TOKEN@github.com/$GITHUB_USER_NAME/$GITHUB_REPO_NAME + echo "$DUMPER_REPO_WORKFLOW_URL" +else + echo " + Fill in the Variable 'DUMP_TYPE with either public or private! + " + exit 1 +fi +#CLEANUP TIME! +git config --global user.email "$ORIGINAL_GITHUB_USER_EMAIL" +git config --global user.name "$ORIGINAL_GITHUB_USER_NAME" +cd $ORIGINAL_PATH +rm -rf $GITHUB_REPO_NAME +""" +f.write(s) +f.close() +os.chmod(bashfile, 0o755) +bashcmd=bashfile +for arg in sys.argv[1:]: + bashcmd += ' '+arg + +def pdump(update: Update, context: CallbackContext): + message = update.effective_message + cmd = message.text.split(' ', 1) + CHAT_ID=message.chat_id + USER_ID = f"{message.from_user.id}" + FIRST_NAME = f"{message.from_user.first_name}" + if message.from_user.username: + USER_TAG = f"@{message.from_user.username}" + else: + USER_TAG = f"none" + print(CHAT_ID) + if len(cmd) == 1: + message.reply_text('Please Provide a Direct Link to an Android Firmware') + return + cmd = cmd[1] + process = subprocess.Popen( + bashcmd + ' ' + '"' + cmd + '" "' + GITHUB_TOKEN + '" "' + GITHUB_USER_NAME + '" "' + GITHUB_DUMPER_REPO_NAME + '" "' + GITHUB_USER_EMAIL + '" "' + TELEGRAM_CHANNEL_NAME + '" "' + DUMPER_REPO_WORKFLOW_URL + '" "' + str(CHAT_ID) + '" "' + USER_ID + '" "' + FIRST_NAME + '" "' + USER_TAG + '"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = process.communicate() + reply = '' + stderr = stderr.decode() + stdout = stdout.decode() + if stdout: + reply += f"*Dumping Your Given Firmware(Privately), Please wait, Dump will be availaible on \n\n{TELEGRAM_CHANNEL_NAME}*\n\n '{stdout}'\n" + LOGGER.info(f"Shell - {bashcmd} {cmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_DUMPER_REPO_NAME} {GITHUB_USER_EMAIL} {TELEGRAM_CHANNEL_NAME} {DUMPER_REPO_WORKFLOW_URL} {str(CHAT_ID)} - {stdout}") + if stderr: + reply += f"*Stderr*\n`{stderr}`\n" + LOGGER.error(f"Shell - {bashcmd} {cmd} {GITHUB_TOKEN} {GITHUB_USER_NAME} {GITHUB_DUMPER_REPO_NAME} {GITHUB_USER_EMAIL} {TELEGRAM_CHANNEL_NAME} {DUMPER_REPO_WORKFLOW_URL} {str(CHAT_ID)} - {stderr}") + if len(reply) > 3000: + with open('shell_output.txt', 'w') as file: + file.write(reply) + with open('shell_output.txt', 'rb') as doc: + context.bot.send_document( + document=doc, + filename=doc.name, + reply_to_message_id=message.message_id, + chat_id=message.chat_id) + else: + message.reply_text(reply, parse_mode=ParseMode.MARKDOWN) + + +PDUMP_HANDLER = CommandHandler(['pdmp', 'pdump'], pdump, + filters=CustomFilters.owner_filter | CustomFilters.authorized_user | CustomFilters.sudo_user, run_async=True) +dispatcher.add_handler(PDUMP_HANDLER) diff --git a/config_sample.env b/config_sample.env index 27bd949..dac6649 100644 --- a/config_sample.env +++ b/config_sample.env @@ -4,6 +4,14 @@ _____REMOVE_THIS_LINE_____=True # Please read this for filling instructions: https://github.com/SlamDevs/slam-mirrorbot#setting-up-config-file # REQUIRED CONFIG +GITHUB_TOKEN = "" #GitHub Token, Don't Leak This Token, Or Your Account Will Be Compromised!, Keep It A Secret, Get Your Token From: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token +GITHUB_ORG_NAME = "" #Your GitHub Organization Name +GITHUB_USER_NAME = "" #Your GitHub Username +GITHUB_DUMPER_REPO_NAME = "dumper" #Leave Untouched If You Have Forked My Repos +GITHUB_DUMMY_REPO_NAME = "dummy" #Leave Untouched If You Have Forked My Repos +TELEGRAM_CHANNEL_NAME = "" #Channel Tag Where Your Dumps Will Be Posted Example: @boxdumps +DUMPER_REPO_WORKFLOW_URL = "" #Example: https://github.com/box-automation1/dumper/actions +GITHUB_USER_EMAIL = "" #Email Of Your GitHub Account BOT_TOKEN = "" GDRIVE_FOLDER_ID = "" OWNER_ID =