-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path100_NumGuess.py
More file actions
74 lines (64 loc) · 2.34 KB
/
Copy path100_NumGuess.py
File metadata and controls
74 lines (64 loc) · 2.34 KB
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
72
73
74
# Created by: Spencer McClain, NULLify
# Created for the 2013: A H4CK Odyssey event
# Description: Server Application that generates a random number for each session
# -------------------------------------------------
from twisted.internet import protocol, reactor
from twisted.protocols.basic import LineReceiver
import random
from datetime import datetime
# log file
log = 'pinGuess.log'
# Port Number
PORT = 8888
#class Echo(protocol.Protocol):
class Echo(LineReceiver):
def __init__(self, data):
rand = random.randint(0, 9999)
if len(str(rand)) < 4:
buff = ''
for i in range(4 - len(str(rand))):
buff = buff + '0'
rand = buff + str(rand)
self.number = str(rand)
#print 'The number is ' + self.number # Prints the pin to the server console
self.name = "GETUSER"
def connectionMade(self):
f = open(log, 'a')
client = self.transport.getPeer()
print 'Client connect ',
f.write('Client connect ')
print client,
f.write(str(client))
print 'at ' + str(datetime.now())
f.write('at ' + str(datetime.now()) + '\n')
self.transport.write('Team name: ')
f.close()
def dataReceived(self, data):
if self.name == "GETUSER":
self.name = data.strip()
self.transport.write('PIN: ')
else:
guess = data.strip()
#print self.name + ' guessed ' + guess
if self.number in guess:
f = open(log, 'a')
# print self.name + ' got it right!'
self.transport.write('\nYou are CORRECT! Key={KEYKEYKEYKEY}\n')
client = self.transport.getPeer()
print '\n' + self.name + ' found key'
f.write("<KEY FOUND>" + self.name + "\n")
print client,
f.write(str(client))
print 'at ' + str(datetime.now())
f.write('at ' + str(datetime.now()) + '\n')
self.transport.loseConnection()
f.close()
else:
self.transport.write('Invalid, try again!\n')
class EchoFactory(protocol.Factory):
def __init__(self):
self.number = ''
def buildProtocol(self, addr):
return Echo(self.number)
reactor.listenTCP(PORT, EchoFactory())
reactor.run()