ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How to save a file in vim when you forget to sudo

    Scheduled Pinned Locked Moved IT Discussion
    vimsudo
    9 Posts 4 Posters 1.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • IRJI
      IRJ
      last edited by

      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.

      wirestyle22W 1 Reply Last reply Reply Quote 15
      • wirestyle22W
        wirestyle22 @IRJ
        last edited by

        @IRJ Isn't privilege escalation considered exploitable?

        IRJI JaredBuschJ scottalanmillerS 3 Replies Last reply Reply Quote 0
        • IRJI
          IRJ @wirestyle22
          last edited by

          @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.

          wirestyle22W 1 Reply Last reply Reply Quote 0
          • wirestyle22W
            wirestyle22 @IRJ
            last edited by wirestyle22

            @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.

            IRJI 1 Reply Last reply Reply Quote 0
            • IRJI
              IRJ @wirestyle22
              last edited by

              @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.

              wirestyle22W 1 Reply Last reply Reply Quote 2
              • wirestyle22W
                wirestyle22 @IRJ
                last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • JaredBuschJ
                  JaredBusch @wirestyle22
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 1
                  • scottalanmillerS
                    scottalanmiller @wirestyle22
                    last edited by

                    @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?

                    1 Reply Last reply Reply Quote 0
                    • wirestyle22W
                      wirestyle22
                      last edited by

                      Yeah I'm wrong. sudo being involved means it can't be privilege escalation because you're getting the proper amount of access.

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post