> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/picker-2.md).

# Picker 2

So, in this Challenge, I noticed that directly calling the `win()` function no longer worked and returned **"Illegal input"**. This suggested that some kind of input filtering was in place.

Looking at the source code, the main logic is inside this loop:

```python
while(True):
  try:
    user_input = input('==> ')
    if( filter(user_input) ):
      eval(user_input + '()')
    else:
      print('Illegal input')
  except Exception as e:
    print(e)
    break
```

* The program continuously takes user input.
* It passes the input through a `filter()` function.
* If the input passes the filter, it executes:

  ```python
  eval(user_input + '()')
  ```

  This means whatever the user types is treated as a function name and executed.

For example:

* Input: `getRandomNumber`
* Executed as: `getRandomNumber()`

This explains why `getRandomNumber` works.

However, when trying:

* `win` → it gets blocked by the filter → **"Illegal input"**

The key issue here is the use of `eval()` on user input.

Even though the developer tries to restrict input to function names, `eval()` can execute **any valid Python expression**, not just function calls.

Instead of calling `win()`, I bypassed the restriction by directly executing Python code:

```bash
print(open('flag.txt', 'r').read())
```

This works because:

* `print(...)` is a valid Python expression
* It does not rely on calling restricted functions like `win`
* It directly reads the `flag.txt` file

<img src="https://github.com/user-attachments/assets/9bfc1638-c8f7-457f-b334-037eda2423bc" alt="image" height="344" width="1268">


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/picker-2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
