How to save a file in vim when you forget to sudo
-
If you forget to use sudo and spend some time editing a file with vim, not all is lost. You can actually escalate using sudo without leaving vim, and losing your changes.
:w !sudo tee %
Note : this only escalates for one write. You must run the command again if you want to save file after making more changes.
-
@IRJ Isn't privilege escalation considered exploitable?
-
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ Isn't privilege escalation considered exploitable?
You are still required to authenticate. This is no different then using sudo for any other command.
-
@IRJ said in How to save a file in vim when you forget to sudo:
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ Isn't privilege escalation considered exploitable?
You are still required to authenticate. This is no different then using sudo for any other command.
I mean specifically from within a text editor. I thought that's why you couldn't do it in nano (as far as I know).
Maybe I'm wrong.
-
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ said in How to save a file in vim when you forget to sudo:
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ Isn't privilege escalation considered exploitable?
You are still required to authenticate. This is no different then using sudo for any other command.
I mean specifically from within a text editor. I thought that's why you couldn't do it in nano (as far as I know).
Maybe I'm wrong.
If you have to authenticate, what is the difference? Also you are temporary leaving vim to authenticate.
Which is why you use
tee
and%
you are essentially copying and overwriting once authenticated. -
@IRJ said in How to save a file in vim when you forget to sudo:
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ said in How to save a file in vim when you forget to sudo:
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ Isn't privilege escalation considered exploitable?
You are still required to authenticate. This is no different then using sudo for any other command.
I mean specifically from within a text editor. I thought that's why you couldn't do it in nano (as far as I know).
Maybe I'm wrong.
If you have to authenticate, what is the difference? Also you are temporary leaving vim to authenticate.
Which is why you use
tee
and%
you are essentially copying and overwriting once authenticated.Thanks for the explanation
-
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ Isn't privilege escalation considered exploitable?
More simply put, this isn’t privilege escalation.
-
@wirestyle22 said in How to save a file in vim when you forget to sudo:
@IRJ Isn't privilege escalation considered exploitable?
"What does exploitable mean to you here?"
All things that exist can be exploited. Sudo reduces the security risk. So the question is... do you want to be more secure or less?
-
Yeah I'm wrong. sudo being involved means it can't be privilege escalation because you're getting the proper amount of access.