# Lonely bot #3

**Flag:** HACKDAY{D4MN;YOU\&HAD(A\_L0T\_oF\_T1M3\_T0\_SP3ND}

## Challenge

{% hint style="info" %}
**Description**

***

You wander through the deserted streets of the abandoned docks south of Dagenham, convinced they might serve as a hideout for criminals. After exploring ruined buildings and broken machinery, your attention is caught by a strange light shining from beneath a rusty door. Forcing it open, you are surprised to find a small robot that seems eager to communicate with you. Try to uncover the secrets it holds, though you’re beginning to realize this might take some time...

***

More instances of the challenge:

* challenges.hackday.fr:41521
* challenges.hackday.fr:41522
* challenges.hackday.fr:41523
* challenges.hackday.fr:41524
* challenges.hackday.fr:41525

***

There's an currently issue with the trailing newlines handling in the buffer from the server side. The challenge can still be solved. You have to send your answers without any trailing newlines added in the buffer. We are looking for a hotfix.

***

For the current date question, the server get it through a lib method that abstract the 0 in front of the day/month. For example, if the current date si the 17/07/2016, the server ask for 17/7/2016. The asked format have been updated in the bot

challenges.hackday.fr:41521
{% endhint %}

{% hint style="warning" %}
Ce challenge tourne sur un docker et n'est pas disponible
{% endhint %}

## Solution

Suite du challenge [lonely-bot-2](lonely-bot-2 "mention"). Un tour dessus pour avoir les réponses le code ellipsé.

```python
import socket
import hashlib
from deep_translator import GoogleTranslator
import re
from rich.console import Console
from datetime import datetime

console = Console()


# Ajout d'une nouvelle fonction pour chercher un hash dans rockyou
def find_in_rockyou(hash: str) -> str | None:
  with open('rockyou.txt', 'r', encoding='latin-1') as f:
    for i in range(100):
      word = f.readline().strip()
      if hashlib.md5(word.encode()).hexdigest() == hash:
        return word
  return None


class Solver:
  [...] chall précédent

  # Résolution du chall
  def run(self):
    [...] chall précédent
    # Le flag est là
    lines = self.recvlines(8)
    
    # Ils nous donnent un hash issue de rockyou, il faut le retrouver
    hash = re.findall('/([^/]+)/', lines[-1])[0]
    word = find_in_rockyou(hash)
    self.send(word)
    
    # Il faut simplement extraire un mot de la phrase
    lines = self.recvlines(6)
    color = lines[-1].split(' ')[-2]
    self.send(color)
    
    # Il faut envoyer la date du jour au format d/m/yyyy (et pas dd/mm/yyyy comme indiqué...)
    lines = self.recvlines(2)
    date = datetime.today().strftime('%#d/%#m/%Y') # remplacer # par - pour Linux
    self.send(date)

    # Vous vous souvenez de son nom ? On l'a enregistré à la toute première question
    # Il faut simplement lui renvoyer    
    lines = self.recvlines(3)
    self.send(name)
    
    # Le flag est là
    lines = self.recvlines(5)
    return True

while True:
  try:
    solver = Solver('challenges.hackday.fr', 41521)
    if solver.run():
      break
  except TimeoutError:
    break
  except KeyboardInterrupt:
    break
  except Exception as e:
    print(e.with_traceback())
    pass
```

```
< This time, we're going to play with hashes!
<  I'm going to give you a password, but I'm not going to tell you what it is!
<  I'll give you the md5 hash of it, and you'll have to find the password!
<  I'm giving you a hint, you're kind to me, so I'm kind to you!
<  The password is in the first hundred lines of the rockyou.txt file!
< Here's the hash: /aa47f8215c6f30a0dcdb2a36a9f4168e/

> daniel
< Wow, you're a hacker!
< Let's move on!
< We are almost at the end of our conversation, and I must say that I'm having a great time with you!
<  I have a few more questions for you, and if you answer them correctly, I'll give you the last flag!
<  Get ready, this one is no joke! I'll ask you three questions!
< What's the color of Henri IV's black horse?

> black
< Not bad, you're not colorblind!
< Which day are we? (dd/mm/yyyy)

> 27/1/2025
< Bravo, you know your calendar!
< Last but not the least, do you remember my name?
<  Because I remember yours, ThaySan, and I'm happy to have met you!

> Cassandra Clockspire
< Good memory, you're a good friend!
< I'm happy to have talked to you, and I hope we can do it again!
<  I hope you'll come back to see me my friend!
<  In the meantime, here's the last flag: HACKDAY{D4MN;YOU&HAD(A_L0T_oF_T1M3_T0_SP3ND}
< See you next time!
```
