Skip to content

Instantly share code, notes, and snippets.

@robsouth84
Last active December 18, 2020 04:35
Show Gist options
  • Save robsouth84/db356338b78e7ec07dcabeb23f9e9a20 to your computer and use it in GitHub Desktop.
Save robsouth84/db356338b78e7ec07dcabeb23f9e9a20 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import time
import json
import subprocess
from string import ascii_lowercase, ascii_uppercase
ans="LVEdQPpBwr"
guess=""
##guess="LandyCane"
def del_config():
subprocess.call(["rm","vending-machines.json"])
def build_config(pw,user='elf'):
mystr = user + "\n" + pw + "\n" + pw + "\n"
subprocess.run(["./vending-machines"], universal_newlines=True,input=mystr)
def check_config() :
newpw=""
f = open("vending-machines.json")
data=json.load(f)
for x in data:
print ( x + " - " + data[x])
if data:
if data["password"]:
return data["password"]
else :
return null
else :
return null
## given a depth int parse the config,
## pull the encrypted password, and compare upto given depth.
## if matches ret true..
## else ret false
def test_str(test,dep):
del_config() ## remove config so we will be prompted for a new password
build_config(test)
np = check_config()
print ("checking at depth " + str(dep+1))
print ("Does " + np + "(" + str(np[dep]) + " match " + ans + "(" + ans[dep] +")??")
print (np[dep])
print (ans[dep])
if np[dep] == ans[dep] :
return True
else:
return False
myset = "0123456789" + ascii_lowercase + ascii_uppercase
for x in range(len(guess),len(ans)):
## if we prefill guess with first few known chars start at len of guess
## and only try to brute force remaining unkonwn vals..
print("--------------------------------------------------------")
print("--------------------------------------------------------")
print("--------------------------------------------------------")
print("looking for depth " + str(x))
print("expecting encrypt to " + ans[x])
print("--------------------------------------------------------")
print("--------------------------------------------------------")
print("--------------------------------------------------------")
time.sleep(5)
### if x== 0:
### guess="L"
### print ("skipping depth 0 as we know it is L")
### time.sleep(5)
### continue
print()
print("..check lc")
for c in myset:
pw=guess+c
print("CURR GUESS===>"+pw)
print (pw)
if test_str(pw,x) :
guess=pw
print("--------------------------------------------------------")
print("--------------------------------------------------------")
print("------------------------------ --------------------------")
print(" Found Match at depth " + str(x) + "!!! ((" + c + "))")
print("--------------------------------------------------------")
print("--------------------------------------------------------")
time.sleep(5)
break
else:
continue
print ("ending...outer loop...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment