File size: 5,127 Bytes
dfdbd3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright (C) 2020-2021 by DevsExpo@Github, < https://github.com/DevsExpo >.
#
# This file is part of < https://github.com/DevsExpo/FridayUserBot > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/DevsExpo/blob/master/LICENSE >
#
# All rights reserved.

import os
import time

import requests
from pyrogram import Client, enums, filters
from pyrogram.types import Message

from utils.config import vt_key as vak
from utils.misc import modules_help, prefix
from utils.scripts import edit_or_reply, format_exc, progress


@Client.on_message(filters.command("vt", prefix) & filters.me)
async def scan_my_file(_, message: Message):
    ms_ = await edit_or_reply(message, "`Please Wait! Scanning This File`")
    if not message.reply_to_message:
        return await ms_.edit(
            "`Please Reply To File To Scan For Viruses`",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    if not message.reply_to_message.document:
        return await ms_.edit(
            "`Please Reply To File To Scan For Viruses`",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    if vak is None:
        return await ms_.edit(
            "`You Need To Set VIRUSTOTAL_API_KEY For Functing Of This Plugin.`",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    if int(message.reply_to_message.document.file_size) > 32000000:
        return await ms_.edit(
            f"**File Too Large, Use `{prefix}vtl` instead**",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    c_time = time.time()
    downloaded_file_name = await message.reply_to_message.download(
        progress=progress,
        progress_args=(ms_, c_time, "`Downloading This File!`"),
    )

    url = "https://www.virustotal.com/vtapi/v2/file/scan"
    params = {"apikey": vak}
    files = {"file": (downloaded_file_name, open(downloaded_file_name, "rb"))}
    response = requests.post(url, files=files, params=params, timeout=10)
    try:
        r_json = response.json()
        md5 = r_json["md5"]
    except Exception as e:
        return await ms_.edit(format_exc(e))
    await ms_.edit(
        f'<b><u>Scanned {message.reply_to_message.document.file_name}</b></u>. <b>You Can Visit :</b> <a href="https://www.virustotal.com/gui/file/{md5}">Here</a> <b>In 5-10 Min To See File Report</b>'
    )
    if os.path.exists(downloaded_file_name):
        os.remove(downloaded_file_name)


@Client.on_message(filters.command("vtl", prefix) & filters.me)
async def scan_my_large_file(_, message: Message):
    ms_ = await edit_or_reply(message, "`Please Wait! Scanning This File`")
    if not message.reply_to_message:
        return await ms_.edit(
            "`Please Reply To File To Scan For Viruses`",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    if not message.reply_to_message.document:
        return await ms_.edit(
            "`Please Reply To File To Scan For Viruses`",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    if vak is None:
        return await ms_.edit(
            "`You Need To Set VIRUSTOTAL_API_KEY For Functing Of This Plugin.`",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    if int(message.reply_to_message.document.file_size) > 650000000:
        return await ms_.edit(
            "**File Too Large, exceeded Max capacity of 650MB**",
            parse_mode=enums.ParseMode.MARKDOWN,
        )
    c_time = time.time()
    downloaded_file_name = await message.reply_to_message.download(
        progress=progress,
        progress_args=(ms_, c_time, "`Downloading This File!`"),
    )

    url1 = "https://www.virustotal.com/api/v3/files/upload_url"

    headers = {"accept": "application/json", "x-apikey": vak}

    rponse = requests.get(url1, headers=headers, timeout=10)
    try:
        r_json = rponse.json()
        upl_data = r_json["data"]
    except Exception as e:
        return await ms_.edit(format_exc(e))

    url = upl_data

    files = {"file": (downloaded_file_name, open(downloaded_file_name, "rb"))}
    headers = {"accept": "application/json", "x-apikey": vak}
    response = requests.post(url, files=files, headers=headers, timeout=10)

    r_json = response.json()
    analysis_url = r_json["data"]["links"]["self"]

    url = analysis_url

    headers = {"accept": "application/json", "x-apikey": vak}

    response_result = requests.get(url, headers=headers, timeout=10)

    try:
        r_json = response_result.json()
        md5 = r_json["meta"]["file_info"]["md5"]
    except Exception as e:
        return await ms_.edit(format_exc(e))
    await ms_.edit(
        f'<b><u>Scanned {message.reply_to_message.document.file_name}</b></u>. <b>You Can Visit :</b> <a href="https://www.virustotal.com/gui/file/{md5}">Here</a> <b>In 5-10 Min To See File Report</b>'
    )
    if os.path.exists(downloaded_file_name):
        os.remove(downloaded_file_name)


modules_help["virustotal"] = {
    "vt [reply to file]*": "Scan for viruses on Virus Total (for lower file size <32MB)",
    "vtl [reply to file]*": "Scan for viruses on Virus Total (for lower file size >=32MB)",
}