> For the complete documentation index, see [llms.txt](https://dhaneshsivasamy07.gitbook.io/oscp-2022/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dhaneshsivasamy07.gitbook.io/oscp-2022/misc/linux.md).

# Linux

### Download Linux Image

* The mirror link : <https://kali.download/base-images/> is faster than the official download url

### Interactive SSH Prompt

{% code overflow="wrap" %}

```
~C
# brings ssh> which can be used for port forwarding ( Only after obtaining a shell)
```

{% endcode %}

### URL Encode via curl

* URL Encode the values requested via curl

{% code overflow="wrap" %}

```bash
curl -G http://url/rev.php --data-urlencode "cmd=/bin/bash -c 'whoami'"
```

{% endcode %}

### Wget

* Wget multiple files with `bash expansions`

```bash
wget http://10.10.14.29/{linpeas.sh,PwnKit}
```

### Chmod

* Chmod multiple files

```bash
# files need to be chmod +x linpeas.sh and PwnKit
chmod +x [lP]*
```

### Grep&#x20;

* Avoid multiple patterns in a file

```bash
egrep -v '(str1|str2)'
```

* Grep Multiple Contents

```bash
grep -EInRi --color=always '(str1 | str2)'
```

* Keep the grep highlighted color when piping the output

```bash
grep --color=always dnoscp whoami.txt | more
```

### Find

* Exclude specific directories from the find command

```bash
find / -writable ! -path '/proc/*' 2>/dev/null
```

* Find files with multiple extensions

```bash
find . -type f \( -name "*.txt" -o -name "*.xml" \)
```

### fzf

* Install fzf

```bash
sudo apt install fzf
```

* Make fzf to interpret the colors

```bash
grep --color=always dnoscp whoami.txt | fzf --ansi
```

### Files

* Know the files location of the services without installing the application

{% code overflow="wrap" %}

```bash
sudo apt install apt-file
apt-file search tomcat # brings all the files related to tomcat (or) the files that contains the string tomcat in its file name
```

{% endcode %}

![tomcat-users.xml default location](/files/x2SxnpBMptt9c6R5qwZc)

### apt

* Change the default repository for higher speed

```bash
# File: /etc/apt/sources.list
# From: deb http://http.kali.org/kali kali-rolling main contrib non-free
# To: deb http://kali.download/kali kali-rolling main contrib non-free

┌──(dnoscp㉿friday)-[~]
└─$ cat /etc/apt/sources.list
# See https://www.kali.org/docs/general-use/kali-linux-sources-list-repositories/
# deb http://http.kali.org/kali kali-rolling main contrib non-free
deb http://kali.download/kali kali-rolling main contrib non-free

# Additional line for source packages
# deb-src http://http.kali.org/kali kali-rolling main contrib non-free
                                                                         
```

* Know the version of the application installed from apt with `apt-cache policy <packageName>`

{% code overflow="wrap" %}

```bash
➜  dhanesh's-device apt-cache policy sudo
sudo:
  Installed: 1.8.31-1ubuntu1.2
  Candidate: 1.8.31-1ubuntu1.2
  Version table:
 *** 1.8.31-1ubuntu1.2 500
        500 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
        100 /var/lib/dpkg/status
     1.8.31-1ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu focal/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
```

{% endcode %}

* Add **Kali Linux**releases in ubuntu ( :warning: Might be slow when installing stuff and also unaware the stability)

{% code overflow="wrap" %}

```bash
# sign the kali release
wget -q -O - https://archive.kali.org/archive-key.asc  | apt-key add

# add the repo
echo "deb http://kali.download/kali kali-rolling main contrib non-free" | sudo tee -a /etc/apt/sources.list
sudo apt update
```

{% endcode %}

### Log things you have installed

* Add the following function in the .bashrc file

```bash
install(){
        echo "sudo apt install -y $@" | tee -a ~/commands.txt &&  cat ~/commands.txt | tail -1 | bash
}

# OR

install(){
        # installation part
        TOOL=$@
        INSTALL="sudo apt install -y $TOOL"
        echo $INSTALL | bash
        ISTATUS=$?

        # logging part
        if [ $ISTATUS == "0" ]; then
                echo "sudo apt install -y $TOOL" >> ~/commands/install.txt
        else
                echo "[-] Installation Error: $TOOL" >> ~/commands/failed.txt
        fi
}
```

* Source the file and install new contents with `install <packageName>`  (install xclip)
* All the installed commands will be available in the \~/install.txt

### Log only commands that executed successfully

* Add the following in the .bashrc file

```bash
a(){
        cmd=$@
        echo $cmd | bash 2>/dev/null
        exit=$?

        if [ $exit == "0" ]; then
                echo "$cmd" >> ~/successcommands.txt
        else
                echo "[+] No command found: $cmd"
        fi
}
```

* Execute commands with `a <command>` (a whoami)
* Only the commands with the successful status code will be logged in the \~/successcommands.txt file

### Date

* Date format with full date and time: `date +%F:%T` (Mostly used with `somecommand | tee $(date +%F:%T).log`)


---

# 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://dhaneshsivasamy07.gitbook.io/oscp-2022/misc/linux.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.
