Как починить chmod x bin chmod

Как починить chmod x bin chmod

Устроили «экзамен» мне на профпригодность. Откопав пару листочков с вопросами по UNIX)
Один из них звучал: «В каталоге /bin была выполнена команда chmod -x chmod». Какие ваши
дальшейшие действия?

С помощью Яндекса узнал, что это распостранённая шутка (западло?), но реального решения «проблемы» так и не нашёл) Вариант с Perl`ом не катит (вернее, поставили условие — Перла нет).
Такое ощущение что это знают все, кроме меня :-\

Высказать мнение | Ответить | Правка | Cообщить модератору

Оглавление

  • chmod -x chmod, wertik, 11:57 , 14-Янв-09, ( 1 )
  • chmod -x chmod, Andey, 12:00 , 14-Янв-09, ( 2 )
    • chmod -x chmod, wertik, 12:10 , 14-Янв-09, ( 3 )
    • chmod -x chmod, vladsol, 12:11 , 14-Янв-09, ( 4 )
      • chmod -x chmod, Andrey Mitrofanov, 12:35 , 14-Янв-09, ( 5 )
  • пойду прибавку просить! за умение пользоваться интернетом., Andrey Mitrofanov, 13:38 , 14-Янв-09, ( 6 )

Сообщения по теме [Сортировка по времени | RSS]

>Устроили «экзамен» мне на профпригодность. Откопав пару листочков с вопросами по UNIX)
>
> Один из них звучал: «В каталоге /bin была выполнена команда chmod
>-x chmod». Какие ваши
>дальшейшие действия?
>
> С помощью Яндекса узнал, что это распостранённая шутка (западло?), но
>реального решения «проблемы» так и не нашёл) Вариант с Perl`ом не
>катит (вернее, поставили условие — Перла нет).
> Такое ощущение что это знают все, кроме меня :-\

Да без проблем.
С диска бинарник достану новый.
ssh в конце концов, с иной системы скачаю.
с бэкапа инкрементального выцеплю.
да куча чего можно придумать.

1 . «chmod -x chmod»
Сообщение от wertik (ok) on 14-Янв-09, 11:57
Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

2 . «chmod -x chmod»
Сообщение от Andey (??) on 14-Янв-09, 12:00

>Устроили «экзамен» мне на профпригодность. Откопав пару листочков с вопросами по UNIX)
>
> Один из них звучал: «В каталоге /bin была выполнена команда chmod
>-x chmod». Какие ваши
>дальшейшие действия?
>
> С помощью Яндекса узнал, что это распостранённая шутка (западло?), но
>реального решения «проблемы» так и не нашёл) Вариант с Perl`ом не
>катит (вернее, поставили условие — Перла нет).
> Такое ощущение что это знают все, кроме меня :-\

cp /bin/ls /bin/ls_prev && cat /bin/chmod > /bin/ls && /bin/ls +x /bin/chmod && mv /bin/ls_prev /bin/ls

Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

3 . «chmod -x chmod»
Сообщение от wertik (ok) on 14-Янв-09, 12:10

>[оверквотинг удален]
>> Один из них звучал: «В каталоге /bin была выполнена команда chmod
>>-x chmod». Какие ваши
>>дальшейшие действия?
>>
>> С помощью Яндекса узнал, что это распостранённая шутка (западло?), но
>>реального решения «проблемы» так и не нашёл) Вариант с Perl`ом не
>>катит (вернее, поставили условие — Перла нет).
>> Такое ощущение что это знают все, кроме меня :-\
>
>cp /bin/ls /bin/ls_prev && cat /bin/chmod > /bin/ls && /bin/ls +x /bin/chmod && mv /bin/ls_prev /bin/ls

Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

4 . «chmod -x chmod»
Сообщение от vladsol (ok) on 14-Янв-09, 12:11

>
>cp /bin/ls /bin/ls_prev && cat /bin/chmod > /bin/ls && /bin/ls +x /bin/chmod && mv /bin/ls_prev /bin/ls

И как я не додумался. Ну) Тупой 🙂 Я)
Всё оказалось так просто. Спасибо за ответ! 🙂

Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

5 . «chmod -x chmod»
Сообщение от Andrey Mitrofanov on 14-Янв-09, 12:35

>>
>>cp /bin/ls /bin/ls_prev && cat /bin/chmod > /bin/ls && /bin/ls +x /bin/chmod && mv /bin/ls_prev /bin/ls

А также любая программа, умеющая вызов chmod().

0) 🙂 Midnight Commander = C-x c

1) install -m 0755 chmod chmod1 && mv chmod1 chmod

2) Скриптовые языки.

$ ls -l
итого 4
-rw-r—r— 1 user user 5 2009-01-14 12:25 chmod
$ tar c —mode 0755 chmod |tar x
$ ls -l
итого 4
-rwxr-xr-x 1 user user 5 2009-01-14 12:25 chmod
$ _

> И как я не додумался. Ну) Тупой 🙂 Я)
>Всё оказалось так просто. Спасибо за ответ! 🙂

Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

6 . «пойду прибавку просить! за умение пользоваться интернетом.»
Сообщение от Andrey Mitrofanov on 14-Янв-09, 13:38

Гм. Это подразумевает проверку способности _решить_ задачу или найти решение.

>команда chmod -x chmod». Какие ваши дальшейшие действия?

А разве надо что-то делать? _Всё_ ж работает. :-))

> С помощью Яндекса узнал, что это распостранённая шутка (западло?), но
>реального решения «проблемы» так и не нашёл)

* Самостоятельно не решил. Минус 1 бал.
* С интернетом — не решил. Переэкзаменовка?

google.ru + «chmod -x chmod» + ENTER -> Результаты 1 — 10 из примерно 2 200. -> Читать, анализировать.

Решение с «cp ls» на первой странице. Там же — загрузка с ремонтного cd.

>Вариант с Perl`ом не катит (вернее, поставили условие — Перла нет).

Уууу. Круто проверяют:
* Неумение пользоваться интернетом, читать и анализировать. . — поди и уволить могут?

.
Вот ещё вариант (да, в других дистрибутивах 0 по-другому; в сорс-бейзед — вооще не) —
$ dpkg -S bin/chmod
coreutils: /bin/chmod
$ su root -c apt-get install —reinstall coreutils_

> Такое ощущение что это знают все, кроме меня :-\

Да, никому оно, не надо. Такое ощущение.

Источник

chmod -x /bin/chmod

А возможно ли без вмешательства из вне как то решить такую штуку? 🙂

Ну первое, что приходит в голову — открыть диск как бинарный файл, поправить соответствующий бит редактором.

man 3p chmod.
Пишем простенькую обертку, компилим -> profit!

/lib/ld-linux.so.2 /bin/chmod -x /bin/chmod

No entry for chmod in section 3p of the manual

>No entry for chmod in section 3p of the manual
zypper in man-pages-posix

Решение через ld.so слишком очевидно и скучно 🙂

В исходной формулировке задачи о скучности и очевидности ничего не сказано 🙂

> Ну первое, что приходит в голову — открыть диск как бинарный файл, поправить соответствующий бит редактором.

Что ты будешь открывать как бинарный файл, умник? Атрибуты, по-твоему, в самом файле хранятся?

Тривиальное решение — запустить mc и из него поправить атрибуты.

Что ты будешь открывать как бинарный файл, умник?

Источник

How to chmod without /usr/bin/chmod?

Today I was told a tale by a Unix trainer where the root password got leaked to the students, and one of the fellas removed the execute permission from /usr/bin/chmod itself. How do you recover chmod in this case and make it executable again? Let’s say getting it from an external source or recompiling it is not a preferable option, is there some smart hack that can recover this chmod itself?

Note that this happened a long time ago and I’m not looking for a solution for some current problem, just curious about what ways Unix provides us around such an issue.

10 Answers 10

You can run the loader directly, and pass it the command you want to run:

Your path to the loader might vary. On a 64-bit system you need to choose the right one based on how chmod was compiled; the 64-bit version is named something like /lib64/ld-linux-x86-64.so.2

The chmod utility relies on the chmod() system call (see man 2 chmod ). So you could do this with a few lines of C, or just about any other language that has a wrapper around it (which would be most of them). Very few *nix systems are going to lack a C compiler and a perl interpreter; most linux distros require the later to work.

Some systems also have busybox installed in which case you may run:

Since you were asking for hacks, I just thought of another one:

Now you have a /bin/chmod that’s executable but it’s actually chown (i.e. some other binary). Now all we have to do is overwrite it with the original binary.

It keeps the +x flag so you just stole the +x of another file for this one.

Of course, if all those alternative binaries (including the loader, perl, python, gcc et cetera) were chmod -x, fixing it from a rescue system may be the only option.

Easy. What you can do is prepare some other executable file, and then cp chmod over it.

The first cp creates a file called chmod with executable permissions, but which is really the ls executable. The second cp populates this file with the binary code of chmod , while preserving the execute permissions of the target file (because we did not specify any options to carry over permissions of the source file).

Another approach is to use the install utility which is a glorified copying program which can set permissions in one step. (See the -m argument.)

The install program isn’t part of the Unix specification, but it is found in BSD, and in GNU Coreutils. Both support the -m option with chmod-like syntax, both symbolic and octal.

First things off the top of my head,

  • Boot from any other source (network book, cd, etc.) and use the chmod on that source to set the permissions.
  • Write a tiny C program to change the permissions.
  • Write a perl script (ruby, php, python, etc.) to change the permissions

/usr/bin/chmod is just making a system call to change the permissions, you can make that system call yourself in any number of ways.

This is hackier than any of the other answers (with the possible exception of the ld-linux.so answer, which is a really clever hack), but may be more adaptable to other problems (especially if you fall into a time vortex and travel back to a Land Before Perl™).

For safety, copy /bin/chmod to a safe place:

Do echo chmod | cpio -oc > chmod.cpio
This creates a cpio archive (not unlike a tar archive) containing chmod . The -c option specifies that the file metadata is written in hex (i.e., in ASCII).

vi chmod.cpio
You’ll see something like

followed by a mixture of control characters, standard ASCII characters, and extended ASCII characters. Note that 0644 = 0x1A4 and 0755 = 0x1ED. Find the 1A4 (starting at the 20th character position) and change it to 1ED . Save and exit.

  • If you have a hex editor or something similar, it might be better to use that to avoid the risk that vi will contaminate the binary executable code in the file. But I tried this with vi , and it seemed to work OK.
  • cpio -i
    You now have a copy of chmod in your directory, protected 755.
  • Other archive programs may have similar capabilities. In particular, cpio is old and may be deprecated; if you don’t have it, look for pax .

    Источник

    Читайте также:  Не работает крышка багажника w211
    Оцените статью