Dockerfile
FROM archlinux
RUN pacman --noconfirm -Syu python python-pip
MAINTAINER F4 <[email protected]>
COPY . /app/
RUN pip install -r requirements.txt
WORKDIR /app/PythonSSS/
RUN echo "B{flag}" > /root/root.txt
ENTRYPOINT python /app/PythonSSS/server.py
Requirements
prettytable==3.3.0
SourceCode
import socket,threading, os
from prettytable import PrettyTable
class ThreadedServer(object):
def __init__(self, host, port):
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind((self.host, self.port))
def userInfo(self, client, address, clidir):
getName = '[+] Digite seu nome: '
if not client.send(getName.encode()):
os.system(f'rm -rf ./notes{clidir}')
name = client.recv(1024)
if not name:
os.system(f'rm -rf ./notes{clidir}')
name = str(name.decode('UTF-8')).strip('\\n')
info = f'[+] Olá {name}, você é meu cliente Nº {clidir}\\n[+] Atenção! Você será desconectado se ficar inativo por mais de 3 minutos\\n'
client.send(info.encode())
def banner(self, client, address):
banner = '''
██████╗ ██╗ ██╗████████╗██╗ ██╗ ██████╗ ███╗ ██╗
██╔══██╗╚██╗ ██╔╝╚══██╔══╝██║ ██║██╔═══██╗████╗ ██║
██████╔╝ ╚████╔╝ ██║ ███████║██║ ██║██╔██╗ ██║
██╔═══╝ ╚██╔╝ ██║ ██╔══██║██║ ██║██║╚██╗██║
██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║
╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
███████╗██╗ ██╗██████╗ ███████╗██████╗ ███████╗███████╗ ██████╗██╗ ██╗██████╗ ███████╗ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗
██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██╔════╝██╔════╝██║ ██║██╔══██╗██╔════╝ ██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗
███████╗██║ ██║██████╔╝█████╗ ██████╔╝ ███████╗█████╗ ██║ ██║ ██║██████╔╝█████╗ ███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝
╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗ ╚════██║██╔══╝ ██║ ██║ ██║██╔══██╗██╔══╝ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗
███████║╚██████╔╝██║ ███████╗██║ ██║ ███████║███████╗╚██████╗╚██████╔╝██║ ██║███████╗ ███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║
╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝
<𝒷𝓎: 𝔽𝟜>
<𝕙𝕥𝕥𝕡𝕤://𝕓𝕖𝕒𝕔𝕠𝕟𝕤.𝕒𝕚/𝕗𝟜_𝕫𝕫𝕫>
'''
client.send(banner.encode())
def listen(self):
self.sock.listen(5)
while True:
client, address = self.sock.accept()
client.settimeout(180)
threading.Thread(target = self.menu,args = (client,address)).start()
def ExtensionTreatment(self, name):
if "." in name:
TreatedName = name.replace('.', '')
TreatedName = TreatedName.replace('\\n', '')
FinalName = TreatedName + ".txt"
return FinalName
else:
FinalName = name + ".txt"
FinalName = FinalName.replace('\\n', '')
return FinalName
def CriarNota(self, client, address, clidir):
CriarNotaSend1 = '\\n[+] Conteúdo da nova anotação: '
client.send(CriarNotaSend1.encode())
CriarNotaRecv1 = client.recv(1024).decode('UTF-8')
CriarNotaSend2 = '[+] Nome da nova anotação (Ex: Exemplo): '
client.send(CriarNotaSend2.encode())
CriarNotaRecv2 = client.recv(1024).decode('UTF-8')
TreatedName = self.ExtensionTreatment(CriarNotaRecv2)
with open(f'./notes{clidir}/{TreatedName}', 'w') as file:
file.write(CriarNotaRecv1)
ConfirmSend = '[+] Anotação criada com sucesso!\\n'
client.send(ConfirmSend.encode())
def ListarNotas(self, client, address, clidir):
table = PrettyTable()
table.field_names = ['Arquivos']
with os.popen(f'ls ./notes{clidir}') as f:
for line in f.readlines():
table.add_row([line])
client.send(str(table).encode())
def LerNota(self, client, address, clidir):
LerNotaSend = '\\n[+] Nome da anotação que deseja ler (Ex: Exemplo): '
client.send(LerNotaSend.encode())
notetable = PrettyTable()
notetable.field_names = ['Arquivo', 'Conteúdo']
file = client.recv(1024).decode('UTF-8')
if ".." in file:
TreatedFile = file.replace('\\n', '')
TreatedFile = TreatedFile.replace('.', '')
with os.popen(f'cat ./notes{clidir}/{TreatedFile}') as f:
notetable.add_row([TreatedFile,f.read()])
client.send(str(notetable).encode())
else:
TreatedFile = file.replace('\\n', '')
TreatedFile = TreatedFile + '.txt'
with os.popen(f'cat ./notes{clidir}/{TreatedFile}') as f:
notetable.add_row([TreatedFile, f.read()])
client.send(str(notetable).encode())
def menu(self, client, address):
cli = str(client)
start = cli.index('=')
end = cli.index(',')
clidir = cli[start+1:end]
os.system(f'mkdir ./notes{clidir}')
self.banner(client, address)
self.userInfo(client, address, clidir)
while True:
menutable = PrettyTable()
menutable.field_names = ['Nº', 'Descrição']
menutable.add_row(['1', 'Criar anotação'])
menutable.add_row(['2', 'Listar Anotações'])
menutable.add_row(['3', 'Ler anotação'])
menutable.add_row(['4', 'Sair'])
menuinit = '\\n' + str(menutable) + '\\n+---+------------------+\\n| # | '
if not client.send(menuinit.encode()):
break
MenuRecv = client.recv(1024)
if not MenuRecv:
break
MenuOption = MenuRecv.decode('UTF-8').replace('\\n', '')
end = '+---+------------------+\\n'
client.send(end.encode())
if str(MenuOption) == '1':
self.CriarNota(client, address, clidir)
elif str(MenuOption) == '2':
self.ListarNotas(client, address, clidir)
elif str(MenuOption) == '3':
self.LerNota(client, address, clidir)
elif str(MenuOption) == '4':
client.close()
break
else:
msg = 'Opção Inválida'
client.send(msg.encode())
pass
os.system(f'rm -rf ./notes{clidir}')
if __name__ == "__main__":
ThreadedServer('',4444).listen()
import socket, os
IP = '0.0.0.0'
PORT = 4444
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((IP,PORT))
s.listen(5)
client, addr = s.accept()
print('Conexao recebida de ',addr)
def ExtensionTreatment(name):
if "." in name:
TreatedName = name.replace('.', '')
TreatedName = TreatedName.replace('\\n', '')
FinalName = TreatedName + ".txt"
return FinalName
else:
FinalName = name + ".txt"
FinalName = FinalName.replace('\\n', '')
return FinalName
def InjectionTreatment(name):
if "$" in name or ";" in name:
TreatedName = name.replace('$', '')
TreatedName = TreatedName.replace(';', '')
TreatedName = TreatedName.replace('\\n', '')
return TreatedName
else:
FinalName = FinalName.replace('\\n', '')
return FinalName
def ReadFileTreatment(file):
if ".." in file:
TreatedFile = file.replace('\\n', '')
TreatedFile = TreatedFile.replace('.', '')
with os.popen(f'cat ./notes/{TreatedFile}') as f:
client.send(f.read().encode())
else:
TreatedFile = file.replace('\\n', '')
TreatedFile = TreatedFile + '.txt'
with os.popen(f'cat ./notes/{TreatedFile}') as f:
client.send(f.read().encode())
def CriarNota():
CriarNotaSend1 = 'Conteudo da nova anotacao: '
client.send(CriarNotaSend1.encode())
CriarNotaRecv1 = client.recv(1024).decode('UTF-8')
CriarNotaSend2 = 'Nome da nova anotacao (Ex: Exemplo): '
client.send(CriarNotaSend2.encode())
CriarNotaRecv2 = client.recv(1024).decode('UTF-8')
TreatedName = ExtensionTreatment(CriarNotaRecv2)
with open(f'./notes/{TreatedName}', 'w') as file:
file.write(CriarNotaRecv1)
def ListarNotas():
with os.popen('ls ./notes') as f:
client.send(f.read().encode())
def LerNota():
LerNotaSend = 'Nome da anotacao que deseja ler (Ex: Exemplo): '
client.send(LerNotaSend.encode())
LerNotaRecv = client.recv(1024).decode('UTF-8')
ReadFileTreatment(LerNotaRecv)
def menu():
menuinit = """
PythonSuperSecureServer | Desenvolvido por F4, o estagiario.
<https://github.com/RonaldLSB>
1 - Criar uma anotacao
2 - Listar anotacoes Existentes
3 - Ler Anotacao
4 - sair
Escolha uma opcao: """
client.send(menuinit.encode())
MenuRecv = client.recv(1024)
MenuOption = MenuRecv.decode('UTF-8')
MenuOption = MenuOption.replace('\\n', '')
if str(MenuOption) == '1':
CriarNota()
elif str(MenuOption) == '2':
ListarNotas()
elif str(MenuOption) == '3':
LerNota()
elif str(MenuOption) == '4':
client.close()
while True:
try:
menu()
except:
print('Tentando reconectar . . .')
client, addr = s.accept()
print('Conexao recebida de ', addr)