# SUID PrivEsc Python

### SUID PrivEsc Python

Some files has Permissions to be executed by any user with full permissions so that means that you can execute a file and the file will execute as root.  
So to escalate our privileges we need to search for the right SUID Permissions.

`<span class="monospace">find / -type -f -user root -perm -4000 2>/dev/null</span>`

This will search for SUID permissions

find / -&gt; search in all directories  
-type -f -&gt; search for a file  
-user root -&gt; for file with user root  
-perm -4000 -&gt; 4000 are the permissions for the SUID  
2&gt;/dev/null -&gt; removes any output which is not matching our criteria

[![image.png](https://wiki.togogo.ch/uploads/images/gallery/2022-07/scaled-1680-/10Vimage.png)](https://wiki.togogo.ch/uploads/images/gallery/2022-07/10Vimage.png)

In here we see that /usr/bin/python can be executed as root. Let's exploit that with GTFOBins.

<span class="wikiexternallink">[https://gtfobins.github.io/gtfobins/python/](https://gtfobins.github.io/gtfobins/python/)</span>

[![image.png](https://wiki.togogo.ch/uploads/images/gallery/2022-07/scaled-1680-/8iwimage.png)](https://wiki.togogo.ch/uploads/images/gallery/2022-07/8iwimage.png)

[![image.png](https://wiki.togogo.ch/uploads/images/gallery/2022-07/scaled-1680-/tGtimage.png)](https://wiki.togogo.ch/uploads/images/gallery/2022-07/tGtimage.png)

<div class="wikimodel-emptyline" id="bkmrk--2">  
</div>### Path Variable Manipulation

SUID bits can be dangerous, some binaries such as passwd need to be run with elevated privileges (as its resetting your password on the system), however other custom files could that have the SUID bit can lead to all sorts of issues.

![https://i.imgur.com/LN2uOCJ.png](https://i.imgur.com/LN2uOCJ.png)

[![image.png](https://wiki.togogo.ch/uploads/images/gallery/2022-07/scaled-1680-/Bcuimage.png)](https://wiki.togogo.ch/uploads/images/gallery/2022-07/Bcuimage.png)

<div class="wikimodel-emptyline" id="bkmrk--5">  
</div>To search the a system for these type of files run the following:

`<span class="monospace">find / -perm -u=s -type f 2>/dev/null</span>`

Here we see where which “services” we are allowed to use with our account.

[![image.png](https://wiki.togogo.ch/uploads/images/gallery/2022-07/scaled-1680-/b5zimage.png)](https://wiki.togogo.ch/uploads/images/gallery/2022-07/b5zimage.png)

Sometimes it could be that for example “**usr/bin/menu**” command is displaying a menu where you can check some system information. As this file runs as the root users privileges, we can manipulate our path gain a root shell. Follow the example below.

![https://i.imgur.com/OfMkDhW.png](https://i.imgur.com/OfMkDhW.png)