Tutorial to create a free telegram bot to receive temporary email from hacked computers

Telegram has become one of the best instant messaging tools, currently being the main counterpart of WhatsApp thanks to its advanced privacy and anonymity capabilities. Even today, there are many features on the platform that might be unknown to the most inexperienced users, although they are certainly quite useful in various cases.

On this occasion, cybersecurity awareness specialists from the International Institute of Cyber Security (IICS) will show you how to create a Telegram bot to receive temporary email. Before proceeding further, we remind you that this article was prepared for informational purposes only, so IICS is not responsible for the misuse that may be made of the information contained herein. 

To get started, you need to go to the REPLIT website and register.

Registration:

Next, you’ll need to create a new Python project, cybersecurity awareness specialists say.

We will see the following image:

You will need to write the following code in the main.py file:

import logging
from aiogram import Bot, Dispatcher, executor, types
from config import API_TOKEN
import keyboard as kb
from onesec_api import Mailbox
import json
import asyncio

logging.basicConfig(level=logging.INFO)
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)


@dp.message_handler(content_types=['text'])
async def texthandler(m: types.Message):
    if m.text != ' Получить почту':
        await m.answer(f'Приветствую тебя, {m.from_user.mention}\nЭтот бот создан для быстрого получения временной почты.\nНажми на кнопу ниже ', reply_markup=kb.menu)
    elif m.text == ' Получить почту':
        ma = Mailbox('')
        email = f'{ma._mailbox_}@1secmail.com'
        await m.answer(f' Вот твоя почта: {email}\nОтправляй письмо.\nПочта проверяется автоматически, каждые 5 секунд, если придет новое письмо, мы вас об этом оповестим!\nНа 1 почту можно получить только - 1 письмо.')
        while True:
            mb = ma.filtred_mail()
            if isinstance(mb, list):
                mf = ma.mailjobs('read',mb[0])
                js = mf.json()
                fromm = js['from']
                theme = js['subject']
                mes = js['textBody']
                await m.answer(f' Новое письмо:\n<b>От</b>: {fromm}\n<b>Тема</b>: {theme}\n<b>Сообщение</b>: {mes}', reply_markup=kb.menu, parse_mode='HTML')
                break
            else:
                pass
            await asyncio.sleep(5)
 

if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True) # Запуск

Create an https://onesec_api.py file and enter the following code there:

import requests
import json	
import random
import string
import lxml.html as HT

#comment

class Mailbox:
    """Main operation with 1secmail.com api:
    'get' - get all mail in box
    'read' - read message in box (need message id)
    'del' - clear mailbox, all messages be removed!
    """
    
    def __init__(self,mail_name):
        """Constructor"""
        self.API = 'https://www.1secmail.com/api/v1/'
        self.s = requests.Session()
        
        if mail_name == '':
            self._mailbox_ = self.rand_pass()
            #print(f'use mailbox: {self._mailbox_}@1secmail.com')
        else:
           self._mailbox_ = mail_name #change to your own test mailbox
        
    def rand_pass(password=False):
        """Generate a random password or random mail"""
        
        if password:
            special = string.punctuation
        else:
            special = "abcdefghijklmnopqrstuvwxyz1234567890"
        
        randomSource = string.ascii_letters + string.digits
        password = ""
        for i in range(9):
            password += random.choice(randomSource)

        return password


    def mailjobs (self, action, id=None):
        """Main operation with 1secmail.com api:
        'get' - get all mail in box
        'read' - read message in box (need message id)
        'del' - clear mailbox, all messages be removed!
        """
        
        mail_list = 'error'
        
        act_ilst = ['getMessages','deleteMailbox','readMessage']
        act_dict = {
            'get':act_ilst[0],
            'del':act_ilst[1],
            'read':act_ilst[2]
        }
            
        if action in ['read', 'readMessage'] and id is None:
            print ('Need message id for reading')
            return mail_list
        
        if action in act_dict:
            action = act_dict[action]
        elif action in act_ilst:
            pass
        else:
            print (f'Wrong action: {action}')
            return mail_list
        
        if action == 'readMessage':
            mail_list = self.s.get(self.API,
                    params={'action':action,
                        'login':self._mailbox_,
                        'domain':'1secmail.com',
                        'id':id
                        }
                    )
        if action == 'deleteMailbox':
            mail_list = self.s.post('https://www.1secmail.com/mailbox/',
                    data={'action':action,
                        'login':self._mailbox_,
                        'domain':'1secmail.com'
                        }
                    )
        if action == 'getMessages':
            mail_list = self.s.get(self.API,
                    params={'action':action,
                        'login':self._mailbox_,
                        'domain':'1secmail.com'
                        }
                    )
                    
        return mail_list


    def filtred_mail (self, domain=True, subject=True, id=True, date=True):
        """Simpled mail filter, all params optional"""
            
        ma = self.mailjobs('get')
        out_mail = []
        if ma != 'error':
            #print(ma.url)
            list_ma = ma.json()
            for i in list_ma:
                if id != True:
                    id_find = i['id'].find(id) != -1
                else:
                    id_find = id
                if date != True:
                    dat_find = i['date'].find(date) != -1
                else:
                    dat_find = date
                if domain != True:
                    dom_find = i['from'].lower().find(domain.lower()) != -1
                else:
                    dom_find = domain
                if subject != True:     
                    sub_find = i['subject'].lower().find(subject.lower()) != -1
                else:
                    sub_find = subject
                if sub_find and dom_find and id_find and dat_find:
                    out_mail.append(i['id'])
            
            if len(out_mail) >0:
                return out_mail
            else:
                return 'not found'
        else:
            return ma


    def clear_box(self, domain, subject, clear=True):
        """Clear mail box if we find some message"""

        ma = self.filtred_mail(domain, subject)
        if isinstance(ma, list):
            ma = self.mailjobs('read', ma[0])
            if ma != 'error':
                if clear: print('clear mailbox')
                if clear: x = self.mailjobs ('del')
                return ma
            else:
                return ma
        else:
            return ma


    def get_link(self, domain, subject, x_path='//a', clear=True):
        """Find link inside html mail body by x-path and return link"""

        ma = self.clear_box(domain, subject, clear)
        if ma != 'error' and ma != 'not found':
            mail_body = ma.json()['body']
        else:
            return ma   
        #try:
        web_body = HT.fromstring(mail_body)   
        #except Type_of_Exception:
        #    print("except")
        child = web_body.xpath(x_path)[0]
        return child.attrib['href']
    
    
if __name__ == "__main__":
    """Easy test"""
    #random box
    ma = Mailbox('')
    #user box
    ma = Mailbox('api.test')
    mb = ma.filtred_mail()
    print('all mail id: ', mb)
    
    if isinstance(mb, list):
        print(mb[0])
        mf = ma.mailjobs('read',mb[0])
        print('first mail: ',mf.json()['body'])
    else:
        mf = 'not found'
  
    print ("if email from gmail.com contain 'Restore password' subject - return restore link and clear mailbox")
    rl = ma.get_link('gmail.com', 'Restore password')
    print ('return link:', rl)

Next, create an https://keyboard.py file and enter the following code:

from aiogram import types



menu = types.ReplyKeyboardMarkup(resize_keyboard=True)
menu.add(
    types.KeyboardButton(' Получить почту')
)

Then the tricky part follows, cybersecurity awareness experts say. You will need to create an https://config.py file and enter your Telegram bot token into API_TOKEN for space 123.

API_TOKEN = '123' # token number

Once all these steps are complete, press the Run button:

Let’s verify that the tool has been installed correctly:

Everything is ready. Finally, cybersecurity awareness experts recommend using this bot only for legitimate purposes, such as preventing your email inbox from becoming infested with annoying messages.

To learn more about information security risks, malware variants, vulnerabilities and information technologies, feel free to access the International Institute of Cyber Security (IICS) websites.