Skip to content

Instantly share code, notes, and snippets.

@Reecepbcups
Created November 13, 2023 00:09
Show Gist options
  • Save Reecepbcups/f3de8e16b6a5a6ace94f7b83b398b734 to your computer and use it in GitHub Desktop.
Save Reecepbcups/f3de8e16b6a5a6ace94f7b83b398b734 to your computer and use it in GitHub Desktop.
Cosmos: Missing Mnemonic brute force
# https://x.com/kais_kat/status/1723844153685971400?s=20
# flake8: noqa
import random
import string
import subprocess
from httpx import get
# rm -rf ~/.noisd/keyring-test
BINARY = "noisd"
words = "copy soon chat crouch save tiny noise chef endless gesture impulse clip since alarm father weird deer ozone page soft devote alpha joke"
possible_words = get(
"https://raw.githubusercontent.com/bitcoin/bips/master/bip-0039/english.txt"
).text.split("\n")
def main():
for _, word in enumerate(possible_words):
try:
res = new_addr(word)
print(res)
# Expected address:
if b"nois1dn6jj35u2pku3d6dqejuk6tzdh4x9nfjuu35ry" in res:
print("missing word: ", word)
exit(1)
except Exception as e:
print(e)
continue
def new_addr(word: str) -> str:
r = "".join(random.choices(string.ascii_letters, k=10))
res = run(
f"""echo "{words} {word}" | {BINARY} keys add {r} --keyring-backend=test --output=json --recover""",
debug=True,
)
return res
def run(cmd, debug=False) -> str:
if debug:
print(f"Running: {cmd}")
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, text=False
)
try:
outs, errs = process.communicate(timeout=15)
except TimeoutError:
process.kill()
outs, errs = process.communicate()
if errs:
return errs
return outs
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment