This repository has been archived by the owner on Feb 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hack.py
305 lines (264 loc) · 9.8 KB
/
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/python
"""
Script by Alex Iadicicco <[email protected]>
"""
import sys, os
import random
import string
import re
choice = random.choice
randint = random.randint
def dc(n, m=20):
return n < randint(0, m-1)
base_noun = [
'TCP', 'IP', 'UDP', 'BGP', 'DNS', 'ARP spoof', 'ARP', 'JavaScript',
'HTML', 'CSS', 'XML', 'SOAP', 'REST', 'SSL', 'socket', 'BSD', 'linux',
'MPI', 'OpenMP', 'SYN/ACK', 'kernel', 'ELF', 'COFF', '68000', 'x86',
'MIPS', 'ethernet', 'MAC', 'C', 'C++', 'Java', 'JSON', 'ruby',
'python', 'linked list', 'radix trie', 'hash table', 'SQL', 'makefile',
'/proc', '/dev/null', 'tty', 'regex', 'sed', 'vim', 's/// operation',
'operation', 'port scanner', 'port scan', 'lookup table', 'anti-<noun>',
'<verber> manual', '<verber> config', 'IRC', 'IRC bot', 'bootloader',
'GNU/<noun>',
]
# I suppose it would be easier to create rules for a lot of these, but
# I think LUTs are fine.
base_verb = [
( 'compile', '-s', '-d', '-r', 'compiling' ),
( 'link', '-s', '-ed', '-er', '-ing' ),
( 'assemble', '-s', '-d', '-r', 'assembling' ),
( 'load', '-s', '-ed', '-er', '-ing' ),
( 'boot', '-s', '-ed', '-er', '-ing' ),
( 'reset', '-s', 'reset', '-ter', '-ting' ),
( 'remove', '-s', '-d', '-r', 'removing' ),
( 'decompile', '-s', '-d', '-r', 'decompiling' ),
( 'unlink', '-s', '-ed', '-er', '-ing' ),
( 'disassemble', '-s', '-d', '-r', 'disassembling' ),
( 'unload', '-s', '-ed', '-er', '-ing' ),
( 'parse', '-s', '-d', '-r', 'parsing' ),
( 'archive', '-s', '-d', '-r', 'archiving' ),
( 'cherry-pick', '-s', '-ed', '-er', '-ing' ),
( 'overwrite', '-s', 'overwrote', '-r', 'overwriting' ),
( 'edit', '-s', '-ed', '-or', '-ing' ),
( 'compute', '-s', '-d', '-r', 'computing' ),
( 'release', '-s', '-d', '-r', 'releasing' ),
( 'transmit', '-s', '-ted', '-ter', '-ting' ),
( 'receive', '-s', '-d', '-r', 'receiving' ),
( 'analyze', '-s', '-d', '-r', 'analyzing' ),
( 'print', '-s', '-ed', '-er', '-ing' ),
( 'save', '-s', '-d', '-r', 'saving' ),
( 'erase', '-s', '-d', '-r', 'erasing' ),
( 'install', '-s', '-ed', '-er', '-ing' ),
( 'scan', '-s', '-ned', '-ner', '-ning' ),
( 'port scan', '-s', '-ned', '-ner', '-ning' ),
( 'nmap', '-s', '-ped', '-per', '-ping' ),
( 'DDOS', '-es', '-sed', '-ser', '-sing' ),
( 'exploit', '-s', '-ed', '-er', '-ing' ),
( 'send', '-s', 'sent', '-er', '-ing' ),
( 'write', '-s', 'wrote', '-r', 'writing' ),
( 'detect', '-s', '-ed', '-or', '-ing' ),
( 'sniff', '-s', '-ed', '-er', '-ing' ),
( 'look up', 'looks up', 'looked up', 'looker upper', 'looking up' ),
( 'check out', 'checks out', 'checked out', 'checker outer', 'checking out' ),
( 'query', 'queries', 'queried', 'querier', 'querying' ),
]
base_service = [
'Google', 'Amazon', 'Stack Overflow', 'Freenode', 'EFnet', 'Usenet',
'this old GeoCities page', 'my website', '<person>\'s website',
]
base_hack_object = [
'the <noun>', 'a(n) <noun>', 'the victim\'s <noun>', 'some <noun>',
'a(n) <verber> from <service>', '<service>\'s <noun>',
'the freeware <noun>', 'a configurable <noun>', 'a working <noun>',
'a pre-<verbed> <verber>',
]
base_tool = [
'<noun> <verber>',
'<verbed> <noun>',
'<verber>',
'<verber> for <nouns>',
'<verbing> <tool>',
'thing that <verbs>',
'thing for <verbing> <nouns>',
'pre-<noun> <verber>',
'anti-<noun> <verber>',
'<verbing> tool',
'<verber> subsystem',
'professional <verber>',
'<verber>-<verber> hybrid',
]
base_tools = [
'<noun> <verber>s',
'<verbed> <nouns>',
'<verber>s',
'<verbing> <tools>',
'things for <verbing>',
'pre-<noun> <verber>s',
]
base_person = [
'Linus Torvalds',
'Alan Cox',
'Con Colivas',
'Ingo Molnar',
'Hans Reiser',
'Ulrich Drepper',
'Larry Wall',
'William Pitcock',
'Bill Gates',
'Ken Thompson',
'Brian Khernigan',
'Dennis Ritchie',
'Eric S. Raymond',
'Richard M. Stallman',
'DPR',
'Sabu',
]
base_system = [
'Amiga', 'C-64', 'IBM PC', 'Z80', 'VAX', 'the PDP-8',
]
base_time = [
'way back', 'a few years ago', 'in the early 90\'s I think',
'when everybody had a(n) <verber>',
'before anybody knew who <person> was',
]
# <hack> is intransitive
# <tool> is singular
base_advice = [
'Try <hacking>.',
'Did you <hack> first?',
'Read up on <hacking>.',
'Check <service> for a(n) <tool>.',
'See if the <tool> has <hacked> already.',
'Did you check the <tool> config?',
'Hm, sounds like a problem with the <tool>.',
'Doesn\'t look like the <tool> is <hacking>.',
'Check the "<tool>" wiki.',
'You probably didn\'t <hack>.',
'Check the "<tool>" website.',
'<hack>, then send me the <tool> output.',
'Pastebin your <tool> config.',
'I think my <noun> has a(n) <verber>, try that.',
'<hacking> worked for me.',
'Did you enable the <tool>?',
'No, the <tool> <hacks>. You want a(n) <tool>.',
'Do you have a(n) <tool> installed?',
'A(n) <tool> is needed to <hack>.',
'<person> claims you can <hack>.',
'I heard <person> <hacks> when that happens.',
'I saw on <service>, you can <hack>.',
'A(n) <tool> might do the trick.',
'Make sure to delete your <tool>. That stuff is illegal.',
'Did you <hack> before you <hacked>?',
'Where did you <verb> the <tool> to?',
'I don\'t know. Ask the guy who wrote your <tool>. I think <person>?',
'Was this with a(n) <tool> or a(n) <tool>?',
'Please use the official <tool>.',
'That won\'t work. You can\'t just <hack>.',
'<hack>, <hack>, and THEN <hack>. Sheesh.',
'No, don\'t <hack>. <person> recently published a CVE about that.',
'<verb>, <verb>, <verb>. This is our motto.',
'Don\'t think too hard about <hacking>. The <tool> will do that.',
'There\'s a(n) <noun> exploit floating around somewhere. Check <service>.',
'Simple <tools> cannot <hack>. You need a good, solid <tool>.',
'I had a(n) <tool> for <system> <time>.',
'Sounds like you need a(n) <tool>. <person> wrote one for <service>.',
]
def simple_get(the_list):
def get_thing():
return choice(the_list)
return get_thing
get_base_verb = simple_get(base_verb)
get_noun = simple_get(base_noun)
get_service = simple_get(base_service)
get_hack_object = simple_get(base_hack_object)
get_tool = simple_get(base_tool)
get_tools = simple_get(base_tools)
get_person = simple_get(base_person)
get_base_advice = simple_get(base_advice)
get_system = simple_get(base_system)
get_time = simple_get(base_time)
def get_nouns():
n = get_noun()
if not n[-1] in string.ascii_letters:
return n + '\'s'
if n.lower()[-1] in 'xs':
return n + 'es'
return n + 's'
def compute_verb(n):
v = get_base_verb()
base = v[0]
ext = v[n]
if ext[0] == '-':
return base + ext[1:]
return ext
def make_verb(n):
def get_verb():
return compute_verb(n)
return get_verb
get_verb = make_verb(0)
get_verbs = make_verb(1)
get_verbed = make_verb(2)
get_verber = make_verb(3)
get_verbing = make_verb(4)
def make_hack(vf):
def get_hack():
return vf() + ' ' + get_hack_object()
return get_hack
def get_hacker():
return get_hack_object() + ' ' + get_verber()
get_hack = make_hack(get_verb)
get_hacks = make_hack(get_verbs)
get_hacked = make_hack(get_verbed)
get_hacking = make_hack(get_verbing)
index_get = {
'verb': get_verb,
'verbs': get_verbs,
'verbed': get_verbed,
'verber': get_verber,
'verbing': get_verbing,
'noun': get_noun,
'nouns': get_nouns,
'hack': get_hack,
'hacks': get_hacks,
'hacked': get_hacked,
'hacker': get_hacker,
'hacking': get_hacking,
'service': get_service,
'tool': get_tool,
'tools': get_tools,
'person': get_person,
'system': get_system,
'time': get_time,
}
def can_reduce(s):
return '<' in s and '>' in s
def reduction(s):
s = re.split('[<>]', s)
for i, word in enumerate(s):
if i % 2 == 0:
continue
if not word in index_get:
word = '?' + word
else:
word = index_get[word]()
s[i] = word
return ''.join(s)
def indefinite_articles(s):
s = re.sub('([aA])\\(n\\) ([AEFHILMNORSXaeiou])', '\\1n \\2', s)
s = re.sub('([aA])\\(n\\) ', '\\1 ', s)
return s
def evaluate(s):
while can_reduce(s):
s = reduction(s)
s = indefinite_articles(s)
s = s[0].upper() + s[1:]
return s
def hack_wrapper(cod, line, splitline, source, destination):
if len(splitline) > 1:
cod.reply(source, destination, "> " + evaluate(" ".join(splitline[1:])))
else:
cod.reply(source, destination, "> " + evaluate(get_base_advice()))
def initModule(cod):
cod.addBotCommand("HACK", hack_wrapper)
def destroyModule(cod):
cod.delBotCommand("HACK")