|
@@ -57,6 +57,46 @@ GREEN_DIFF = 10
|
|
|
# How much brighter the green channel must be (compared to the others),
|
|
|
# to be called green.
|
|
|
|
|
|
+VALID_WORDS = {
|
|
|
+ "constructor", "info", "anon", "send", "com", "root", "port", "val",
|
|
|
+ "add", "ghost", "net", "http", "status", "syscall", "part", "delete",
|
|
|
+ "datatype", "loadbytes", "setping", "size", "system", "setstats",
|
|
|
+ "join", "socket", "signal", "dir", "accountname", "decryptfile",
|
|
|
+ "intel", "xml", "connect", "sizeof", "writefile", "call", "reset",
|
|
|
+ "global", "user", "add", "remove", "count", "set", "loop", "num",
|
|
|
+ "client", "file", "channel", "right", "stat", "emit", "handle",
|
|
|
+ "buffer", "mysql", "write", "type", "list", "temp", "getfile",
|
|
|
+ "thread", "decrypt", "poly", "setcookie", "domain", "length",
|
|
|
+ "gridwidth", "upload", "get", "generatecodepack", "data",
|
|
|
+ "process", "download", "proxy", "fillgrid", "bit", "encryptfile",
|
|
|
+ "host", "ping", "event", "url", "load", "key", "changepassword",
|
|
|
+ "bufferpingset", "getfirewallchannel", "getinfo", "getping", "pass",
|
|
|
+ "newserver", "username", "generate", "userport", "init", "net",
|
|
|
+ "left", "point", "cookies", "protocol", "responder", "getkey",
|
|
|
+ "hostserver", "eventtype", "gridheight", "server", "setport",
|
|
|
+ "getpass", "loadloggedpassword", "destroybatch", "getxmlprotocol",
|
|
|
+ "channelsetpackage", "batchallfiles", "module", "response",
|
|
|
+ "serverproxy", "filetype", "urlcheck", "config", "number",
|
|
|
+ "ghostfilesystem", "disconnectserver", "emitconfiglist",
|
|
|
+ "dodecahedron", "eventlistdir", "systemportkey", "setnewproxy",
|
|
|
+ "createnewsocket", "changeusername", "tempdatapass", "blockthreat",
|
|
|
+ "statusofprocess", "patcheventlog", "newline", "dir", "bytes",
|
|
|
+ "findpackage", "package", "encode", "joinnetworkclient",
|
|
|
+ "rootcookieset", "callmodule", "sizeofhexagon", "createfilethread",
|
|
|
+ "includedirectory", "loadregisterlist", "encryptunpackedbatch",
|
|
|
+ "getpartoffile", "getdatapassword", "create2axisvector",
|
|
|
+ "create3axisvector", "disconnectchannel", "setnewid", "hexagon",
|
|
|
+ "account", "removenewcookie", "getid", "encodenewfolder",
|
|
|
+ "sendintelpass", "getlog", "command", "threat", "userid",
|
|
|
+ "wordcounter", "removeoldcookie", "hostnewserver", "disconnect",
|
|
|
+ "listconfig", "newhost", "createnewpackage", "loadaltevent", "log",
|
|
|
+ "filedir", "fileexpresslog", "decryptdatabatch", "mergesocket",
|
|
|
+ "unpacktmpfile", "uploaduserstats", "getmysqldomain",
|
|
|
+ "checkhttptype", "encrypt", "vector", "httpbuffersize",
|
|
|
+ "systemgridtype", "password", "respondertimeout", "deleteallids",
|
|
|
+ "exportconfigpackage", "export"
|
|
|
+}
|
|
|
+
|
|
|
# Check the environment, do we have all that we need?
|
|
|
if not os.path.exists("images"):
|
|
|
os.mkdir("images")
|
|
@@ -68,6 +108,15 @@ if not os.path.exists("words.yml"):
|
|
|
with open('words.yml', 'w') as f: # Create a empty yaml file
|
|
|
f.write('')
|
|
|
|
|
|
+def image_filename(difficulty, index):
|
|
|
+ return f"images/{difficulty}_{index}.png"
|
|
|
+
|
|
|
+def cleaned_filename(difficulty, index):
|
|
|
+ return f"images/{difficulty}_{index}_clean.png"
|
|
|
+
|
|
|
+def cleaner_filename(difficulty, index):
|
|
|
+ return f"images/{difficulty}_{index}_cleaner.png"
|
|
|
+
|
|
|
def download(howhard, index):
|
|
|
global sess
|
|
|
"""
|
|
@@ -75,13 +124,17 @@ def download(howhard, index):
|
|
|
|
|
|
On success, it saves the image file.
|
|
|
Failure raises ConnectionError.
|
|
|
+ Don't leave stale cleaned images around.
|
|
|
"""
|
|
|
r = sess.get(f"http://s0urce.io/client/img/word/{howhard}/{index}")
|
|
|
if r.status_code == 200:
|
|
|
- with open(f"images/{howhard}_{index}.png", "wb") as f:
|
|
|
+ # DRY
|
|
|
+ with open( image_filename(howhard, index), "wb") as f:
|
|
|
f.write(r.content)
|
|
|
- if os.path.exists(f"images/{howhard}_{index}_clean.png"):
|
|
|
- os.remove(f"images/{howhard}_{index}_clean.png")
|
|
|
+ # cleaned images? we need to delete & regenerate those.
|
|
|
+ cleaned = cleaned_filename(howhard, index)
|
|
|
+ if os.path.exists(cleaned):
|
|
|
+ os.remove(cleaned)
|
|
|
else:
|
|
|
# We did not get a 200 Okay, log this... Hmm maybe we need to make a log file?
|
|
|
# print( f'{howhard}_{index}.png ' + str(r.status_code) )
|
|
@@ -219,42 +272,6 @@ def output_image(pix, size):
|
|
|
|
|
|
return result
|
|
|
|
|
|
-def image_filename(difficulty, index):
|
|
|
- return f"images/{difficulty}_{index}.png"
|
|
|
-
|
|
|
-def cleaned_filename(difficulty, index):
|
|
|
- return f"images/{difficulty}_{index}_clean.png"
|
|
|
-
|
|
|
-def cleaner_filename(difficulty, index):
|
|
|
- return f"images/{difficulty}_{index}_cleaner.png"
|
|
|
-
|
|
|
-
|
|
|
-def image_cleaner(source, destination):
|
|
|
- image = Image.open(source)
|
|
|
- # pixels = image.load()
|
|
|
- size = image.size
|
|
|
- #print(f"Size: {size[0]} x {size[1]}")
|
|
|
-
|
|
|
- for y in range(0, size[1]):
|
|
|
- s = ""
|
|
|
- for x in range(0, size[0]):
|
|
|
- (r, g, b, _) = image.getpixel( (x,y) )
|
|
|
- high = r
|
|
|
- if b > high:
|
|
|
- high = b
|
|
|
- diff = g - high
|
|
|
- is_green = diff > 0 # GREEN_DIFF
|
|
|
-
|
|
|
- if is_green:
|
|
|
- image.putpixel( (x,y), (255,255,255,255) )
|
|
|
- else:
|
|
|
- image.putpixel( (x,y), (0, 0, 0, 255) )
|
|
|
-
|
|
|
- # if is_set(pix, x, y):
|
|
|
- # if not is_green(pix, x, y):
|
|
|
- # result.append(s)
|
|
|
- image.save(destination)
|
|
|
-
|
|
|
def run(difficult, index):
|
|
|
"""
|
|
|
run, represents a single execution of components to the image, (Actuall we do it 1 category at a time instead of just 1 single execution )
|
|
@@ -342,40 +359,32 @@ def autotrain(difficult):
|
|
|
|
|
|
with open(fileout + ".txt", "r") as fp:
|
|
|
word = fp.read().strip().lower()
|
|
|
- if (word != ''):
|
|
|
+ if (word != '') and (word in VALID_WORDS):
|
|
|
key_word[f'{difficult}_{x}'] = word
|
|
|
print(word)
|
|
|
else:
|
|
|
- print("UNKNOWN")
|
|
|
+ print("UNKNOWN", word)
|
|
|
# Output the image
|
|
|
im = Image.open(fname)
|
|
|
- pix = im.load()
|
|
|
- size = im.size
|
|
|
- img_s = output_image(pix, size)
|
|
|
- for l in img_s:
|
|
|
- print(l)
|
|
|
+ imager.output_image(im)
|
|
|
+
|
|
|
+ # pix = im.load()
|
|
|
+ # size = im.size
|
|
|
+ # img_s = output_image(pix, size)
|
|
|
+ # for l in img_s:
|
|
|
+ # print(l)
|
|
|
key_word[f'{difficult}_{x}'] = input("Word: ")
|
|
|
|
|
|
|
|
|
# Now to call all the previous functions
|
|
|
if args.download:
|
|
|
print("Downloading s0urce.io Words")
|
|
|
- print("EASY")
|
|
|
- # time.sleep(5)
|
|
|
- for e in range(0, 62):
|
|
|
- download("e", e)
|
|
|
- # time.sleep(random.randint(10, 15))
|
|
|
-
|
|
|
- print("MEDIUM")
|
|
|
- # time.sleep(5)
|
|
|
- for m in range(0, 66):
|
|
|
- download("m", m)
|
|
|
- # time.sleep(random.randint(10, 15))
|
|
|
-
|
|
|
- print("HARD")
|
|
|
- # time.sleep(5)
|
|
|
- for h in range(0, 55):
|
|
|
- download("h", h)
|
|
|
+ # smaller is better, and cleaner.
|
|
|
+ tofetch = { 'e': 62, 'm': 66, 'h': 55 }
|
|
|
+ for d, max in tofetch.items():
|
|
|
+ print(d.upper())
|
|
|
+ for i in range(0, max):
|
|
|
+ download(d, i)
|
|
|
# time.sleep(random.randint(10, 15))
|
|
|
|
|
|
if args.train:
|
|
@@ -399,9 +408,12 @@ if args.update:
|
|
|
if 'http://s0urce.io/client/img/word/' in lines[i]:
|
|
|
# This is a target line, so:
|
|
|
l = lines[i].strip().strip(':').strip('"')
|
|
|
+ # gets parts of the path
|
|
|
parts = l.split('/')
|
|
|
+ # get difficulty and index
|
|
|
dif = parts[-2]
|
|
|
index = parts[-1]
|
|
|
+ # build the key -- get the word
|
|
|
key = f'{dif}_{index}'
|
|
|
pprint(parts)
|
|
|
pprint(key)
|