sudo
by default in a standard Ubuntu installation keeps the sudo
access cached for a short time (default is a 15-minute timeout).
For your hypothetical situation to work, you need to have run sudo
earlier, and then run the code you specified with sudo
before the caching of that ability times out. In most cases, this is not as 'insecure' as you think - many hardened servers have a far shorter timeout, or in my case on my servers I actually configure it for an instant timeout after sudo
is executed, requiring the password for each sudo
command made.
To this end, sudo
is 'secure' because there's timeouts which expire, to make sure sudo
can't be used infinitely and perpetually after one use.
It is not 'insecure' in this manner, though there are times where it appears that way - disabling the credential caching solves this, of course, and is very easy for system administrators to do.
In a default install, the default 15 minute caching would appear as the balance between 'security' and 'convenience', because we don't want new users to be having headaches by entering passwords for every time. Having said this, where security is important we can lock down sudo
by changing the configuration.
TL;DR: No, sudo
is not insecure at all. It's the default caching, and your hypothetical being called while sudo
access is cached, that triggers your thought, but sudo
is NOT actually insecure when configured with a short timeout, or with instant timeout, and that's done at the system administrator's decisions on those systems whether to change the default.
sudo
depends on the user and it's not really quantifiable, not without way more details and without ending up digressing on off-topic subjects. – kos Jan 20 '16 at 15:38