-
Notifications
You must be signed in to change notification settings - Fork 11
/
fallout_hack.py
277 lines (215 loc) · 7.41 KB
/
fallout_hack.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import curses
import random
import time
import os
from fallout_functions import slowWrite
from fallout_functions import upperInput
################## text strings ######################
HEADER_TEXT = 'ROBCO INDUSTRIES (TM) TERMLINK PROTOCOL'
################## global "constants" ################
# number of characters for hex digits and spaces
CONST_CHARS = 16
# position of the attempt squares
SQUARE_X = 19
SQUARE_Y = 3
LOGIN_ATTEMPTS = 4
HEADER_LINES = 5
# amount of time to pause after correct password input
LOGIN_PAUSE = 3000
# starting number for hex generation
START_HEX = 0xf650
# list of possible symbols for password hiding
SYMBOLS = '!@#$%^*()_-+={}[]|\\:;\'",<>./?'
################## functions #########################
def generateHex(n):
"""
generates n numbers starting at START_HEX and increasing by 12 each time
"""
num = START_HEX
list = []
for i in range(n):
list.append(num)
num += 12
return list
def getSymbols(n):
"""
return n random symbols
"""
count = len(SYMBOLS)
result = ""
for i in range(int(n)):
result += SYMBOLS[random.randint(0, count - 1)]
return result
def getPasswords():
"""
Returns an array of strings to be used as the password and the decoys
"""
groups = []
# script file / password file location
__location__ = os.path.realpath(os.path.join(os.getcwd(),
os.path.dirname(__file__)))
# read from passwords.txt
with open(os.path.join(__location__, "passwords.txt")) as pwfile:
for line in pwfile:
if not line.strip():
groups.append([])
elif len(groups) > 0:
groups[len(groups) - 1].append(line[:-1])
passwords = groups[random.randint(0, len(groups) - 1)]
random.shuffle(passwords)
return passwords
def getFiller(length, passwords):
"""
Return a string of symbols with potential passwords mixed in
length - the length of the string to create
passwords - an array of passwords to hide in the symbols
"""
filler = getSymbols(length)
# add the passwords to the symbols
pwdLen = len(passwords[0])
pwdCount = len(passwords)
i = 0
for pwd in passwords:
# skip a distance based on total size to cover then place a password
maxSkip = int(length / pwdCount - pwdLen)
i += random.randint(maxSkip - 2, maxSkip)
filler = filler[:i] + pwd + filler[i + pwdLen:]
i += pwdLen
return filler
def initScreen(scr):
"""
Fill the screen to prepare for password entry
scr - curses window returned from curses.initscr()
"""
size = scr.getmaxyx()
height = size[0]
width = size[1]
fillerHeight = height - HEADER_LINES
hexes = generateHex(fillerHeight * 2)
hexCol1 = hexes[:fillerHeight]
hexCol2 = hexes[fillerHeight:]
# generate the symbols and passwords
fillerLength = width / 2 * fillerHeight
passwords = getPasswords()
filler = getFiller(fillerLength, passwords)
fillerCol1, fillerCol2 = filler[0:len(filler)//2], filler[len(filler)//2:]
#print(fillerCol1)
#time.sleep(15)
#print(fillerCol2)
#time.sleep(15)
# each column of symbols and passwords should be 1/4 of the screen
fillerWidth = int(width / 4)
# print the header stuff
slowWrite(scr, HEADER_TEXT)
slowWrite(scr, '\nENTER PASSWORD NOW\n\n')
slowWrite(scr, str(LOGIN_ATTEMPTS) + ' ATTEMPT(S) LEFT: ')
for i in range(LOGIN_ATTEMPTS):
scr.addch(curses.ACS_BLOCK)
slowWrite(scr, ' ')
slowWrite(scr, '\n\n')
# print the hex and filler
for i in range(fillerHeight):
slowWrite(scr, "0x%X %s" % (hexCol1[i], fillerCol1[i * fillerWidth: (i + 1) * fillerWidth]), 1)
if i < fillerHeight - 1:
scr.addstr('\n')
for i in range(fillerHeight):
scr.move(HEADER_LINES + i, int(CONST_CHARS / 2 + fillerWidth))
slowWrite(scr, '0x%X %s' % (hexCol2[i], fillerCol2[i * fillerWidth: (i + 1) * fillerWidth]), 1)
scr.refresh()
return passwords
def moveInput(scr, inputPad):
"""
moves the input pad to display all text then a blank line then the cursor
"""
size = scr.getmaxyx()
height = size[0]
width = size[1]
inputPad.addstr('\n>')
# cursor position relative to inputPad
cursorPos = inputPad.getyx()
inputPad.refresh(0, 0,
int(height - cursorPos[0] - 1),
int(width / 2 + CONST_CHARS),
int(height - 1),
int(width - 1))
def userInput(scr, passwords):
"""
let the user attempt to crack the password
scr - curses window returned from curses.initscr()
passwords - array of passwords hidden in the symbols
"""
size = scr.getmaxyx()
height = size[0]
width = size[1]
# set up a pad for user input
inputPad = curses.newpad(height, int(width / 2 + CONST_CHARS))
attempts = LOGIN_ATTEMPTS
# randomly pick a password from the list
pwd = passwords[random.randint(0, len(passwords) - 1)]
curses.noecho()
while attempts > 0:
# move the curser to the correct spot for typing
scr.move(int(height - 1), int(width / 2 + CONST_CHARS + 1))
# scroll user input up as the user tries passwords
moveInput(scr, inputPad)
guess = upperInput(scr, False, False)
cursorPos = inputPad.getyx()
# write under the last line of text
inputPad.move(cursorPos[0] - 1, cursorPos[1] - 1)
inputPad.addstr('>' + guess.upper() + '\n')
# user got password right
if guess.upper() == pwd.upper():
inputPad.addstr('>Exact match!\n')
inputPad.addstr('>Please wait\n')
inputPad.addstr('>while system\n')
inputPad.addstr('>is accessed.\n')
moveInput(scr, inputPad)
curses.napms(LOGIN_PAUSE)
return pwd
# wrong password
else:
pwdLen = len(pwd)
matched = 0
try:
for i in range(pwdLen):
if pwd[i].upper() == guess[i].upper():
matched += 1
except IndexError:
pass # user did not enter enough letters
inputPad.addstr('>Entry denied\n')
inputPad.addstr('>' + str(matched) + '/' + str(pwdLen) +
' correct.\n')
attempts -= 1
# show remaining attempts
scr.move(SQUARE_Y, 0)
scr.addstr(str(attempts))
scr.move(SQUARE_Y, SQUARE_X)
for i in range(LOGIN_ATTEMPTS):
if i < attempts:
scr.addch(curses.ACS_BLOCK)
else:
scr.addstr(' ')
scr.addstr(' ')
# Out of attempts
return None
def runLogin(scr):
"""
Start the login portion of the terminal
Returns the password if the user correctly guesses it
"""
curses.use_default_colors()
size = scr.getmaxyx()
width = size[1]
height = size[0]
random.seed()
# set screen to initial position
scr.erase()
scr.move(0, 0)
passwords = initScreen(scr)
return userInput(scr, passwords)
def beginLogin():
"""
Initialize curses and start the login process
Returns the password if the user correctly guesses it
"""
return curses.wrapper(runLogin)