Skip to content

Instantly share code, notes, and snippets.

@Opposite34
Created October 30, 2022 19:00
Show Gist options
  • Select an option

  • Save Opposite34/240f27e3d6d96856e957425d5f7f079e to your computer and use it in GitHub Desktop.

Select an option

Save Opposite34/240f27e3d6d96856e957425d5f7f079e to your computer and use it in GitHub Desktop.
BlueHensCTF2022 - Wordles with Dads Solve Scripts
from pwn import *
import requests
import pickle
from bs4 import BeautifulSoup
url = "https://icanhazdadjoke.com/"
suburl = "search?term=&page="
jokes = []
try:
with open('jokes.pickle', 'rb') as handle:
jokes = pickle.load(handle)
except FileNotFoundError:
for i in range(1, 34):
r = requests.get(url + suburl + str(i))
bs = BeautifulSoup(r.content, "html.parser")
results = bs.find_all('pre')
for result in results:
jokes.append(str(result).replace('<pre style="background-color:inherit; white-space: pre-wrap">', "").replace("</pre>", "").strip())
with open('jokes.pickle', 'wb') as handle:
pickle.dump(jokes, handle, protocol=pickle.HIGHEST_PROTOCOL)
# print(jokes)
joke_wordles = []
try:
with open('joke_wordles.pickle', 'rb') as handle:
joke_wordles = pickle.load(handle)
except FileNotFoundError:
for joke in jokes:
tmp = ""
for char in joke:
if char.isalpha():
tmp += char.upper()
elif char == "ñ":
tmp += "N"
joke_wordles.append(tmp)
with open('joke_wordles.pickle', 'wb') as handle:
pickle.dump(joke_wordles, handle, protocol=pickle.HIGHEST_PROTOCOL)
# print(len(joke_wordles))
p = remote("0.cloud.chals.io", 33282)
for i in range(10):
p.recvuntil(b"Your joke is ")
ans_len = int(p.recvuntil(b" ").decode("utf-8"))
print(ans_len)
len_filtered = filter(lambda x: len(x)==ans_len, joke_wordles)
possibilities = list(len_filtered)
while(1):
total_possibilities = len(possibilities)
print(f"Possibilities left: {total_possibilities}")
p.recvuntil(b"Guess? >")
maybe = possibilities[0]
p.sendline(maybe.encode())
p.recvline()
data = p.recvline().decode('utf-8')
corrects = []
if("one down" in data.lower()):
break
else:
try:
tmp = data[13:].split("],")[0]
corrects = list(map(int, tmp.strip().split(",")))
except:
pass
# print(corrects)
pop_count = 0
for i in range(total_possibilities):
for j in range(ans_len):
if (j in corrects and maybe[j] != possibilities[i-pop_count][j]) or (j not in corrects and maybe[j] == possibilities[i-pop_count][j]):
possibilities.pop(i-pop_count)
pop_count+=1
break
p.interactive()
import requests
import pickle
from bs4 import BeautifulSoup
url = "https://icanhazdadjoke.com/"
suburl = "search?term=&page="
jokes = []
try:
with open('jokes.pickle', 'rb') as handle:
jokes = pickle.load(handle)
except FileNotFoundError:
for i in range(1, 34):
r = requests.get(url + suburl + str(i))
bs = BeautifulSoup(r.content, "html.parser")
results = bs.find_all('pre')
for result in results:
jokes.append(str(result).replace('<pre style="background-color:inherit; white-space: pre-wrap">', "").replace("</pre>", "").strip())
with open('jokes.pickle', 'wb') as handle:
pickle.dump(jokes, handle, protocol=pickle.HIGHEST_PROTOCOL)
# print(jokes)
joke_wordles = []
try:
with open('joke_wordles.pickle', 'rb') as handle:
joke_wordles = pickle.load(handle)
except FileNotFoundError:
for joke in jokes:
tmp = ""
for char in joke:
if char.isalpha():
tmp += char.upper()
elif char == "ñ":
tmp += "N"
joke_wordles.append(tmp)
with open('joke_wordles.pickle', 'wb') as handle:
pickle.dump(joke_wordles, handle, protocol=pickle.HIGHEST_PROTOCOL)
# print(len(joke_wordles))
easy = False
mode = str(input("Easy mode? "))
if mode and mode[0].lower() == "y":
easy = True
while(1):
ans_len = int(input("Length: "))
if easy:
first_two_char = str(input("First two characters: ")).upper().strip()
f2c_filtered = filter(lambda x: x[:2]==first_two_char, joke_wordles)
len_filtered = filter(lambda x: len(x)==ans_len, list(f2c_filtered))
else:
len_filtered = filter(lambda x: len(x)==ans_len, joke_wordles)
possibilities = list(len_filtered)
while(1):
# print(possibilities)
total_possibilities = len(possibilities)
print(f"Possibilities left: {total_possibilities}")
maybe = possibilities[0]
print(maybe)
if total_possibilities==1:
break
found = str(input("found? "))
if found and found[0].lower() == "y":
break
try:
corrects = list(map(int, str(input("Corrects: ")).strip().split(",")))
except:
corrects = []
print(corrects)
pop_count = 0
for i in range(total_possibilities):
for j in range(ans_len):
if (j in corrects and maybe[j] != possibilities[i-pop_count][j]) or (j not in corrects and maybe[j] == possibilities[i-pop_count][j]):
possibilities.pop(i-pop_count)
pop_count+=1
break
@Opposite34
Copy link
Author

Opposite34 commented Oct 30, 2022

manual is my earlier script which I try to input by hand, but I wasn't fast enough hence why I made the solve with pwntools (could've used sockets as well)

process:
webscraping all the jokes -> pickle the scraped jokes as cache as to not redo the webscraping -> solve it based on length with filters and also go through the correct/wrong character indexes and filter them out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment