Author Topic: Sudo without passwd  (Read 9545 times)

0 Members and 5 Guests are viewing this topic.

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Sudo without passwd
« Reply #15 on: February 01, 2013, 09:11:15 pm »
Eh, I just said fuckit and used proxx's approach of user ALL=(ALL) NOPASSWD: ALL.

Thanks for the help guys.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Sudo without passwd
« Reply #16 on: February 01, 2013, 10:51:38 pm »
Haha +1 for me.
Its strange I have been trying different things before I got it to work.
I wish I knew why, or at least where to look.

Well as long as it works.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline 0poitr

  • Peasant
  • *
  • Posts: 149
  • Cookies: 64
    • View Profile
Re: Sudo without passwd
« Reply #17 on: February 02, 2013, 08:50:13 pm »
============
EDIT :: You already got a fix I see
============
Either run
sudo visudo and add
Code: [Select]
your_username ALL= NOPASSWD: path_to_script
or setup systemd service files to start up and configure the interface at boot. Here's an example regarding static ethernet configuration.
https://wiki.archlinux.org/index.php/Systemd/Services#Static_Ethernet_network

The EnvironmentFile is the text file that contains your network parameters and is sourced in the service file. In the example, ${interface}, ${address} all are defined in the environment file. It can be anywhere in any name.
You could probably use something like:
Code: [Select]
[Unit]   
Description=Network Connectivity   
Wants=network.target   
Before=network.target
   
[Service]   
Type=oneshot   
RemainAfterExit=yes   
EnvironmentFile=/etc/conf.d/wrless_conf_file
ExecStart=/sbin/ip link set dev ${interface} up
ExecStart=wpa_supplicant -B -Dwext -i wlan0 -c ${wpa_conf}
ExecStop=/sbin/ip addr flush dev ${interface}
ExecStop=/sbin/ip link set dev ${interface} down
   
[Install]   
WantedBy=multi-user.target

With a /etc/conf.d/wrless_conf_file like
Code: [Select]
interface=wlan0
wpa_conf=/etc/wpa_supplicant.conf

I use the same method to start up my eth0 network. Other than these, you can try netcfg.
« Last Edit: February 02, 2013, 08:57:05 pm by 0poitr »
Imagination is the first step towards Creation.

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: Sudo without passwd
« Reply #18 on: February 06, 2013, 02:22:06 am »
Try this, works for me.

Code: (python) [Select]
#!/usr/bin/python2

import os

command = "pacman -Syu"
sudo_pass = "lulz"

os.system('echo %s|sudo -S %s' % (sudo_pass, command)

I have seen other ways using popen with writing to the pipe, but the code provided should work okay.
The shebang might need to be modified cause I'm using python2.7.X on Arch and I imagine you are too. If you insist on python3 you'll need to intall it and use #!/usr/bin/python instead.

Also, found via:
http://stackoverflow.com/questions/13045593/using-sudo-with-python-script
With search term (google):
sudo inside python script

 ;D

------EDIT------
Also works with popen if you need something returned.
Code: (python) [Select]
import os

command = "hddtemp /dev/sda | cut -c24-25"
sudo_pass = "lulz"

x = os.popen("echo %s | sudo -S %s" % (sudo_pass, command))
x = x.read()
print "*" * 15
print x.strip()

strip() is needed. Just used this on a conky and pythons print returned some format chars or something. strip() fixed it.

But there is a safer way:
http://askubuntu.com/questions/155791/how-do-i-sudo-a-command-in-a-script-without-being-asked-for-a-password

 
« Last Edit: February 08, 2013, 01:06:24 am by techb »
>>>import this
-----------------------------

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Sudo without passwd
« Reply #19 on: February 06, 2013, 04:39:29 am »
Haha yeah and storing your userpassword in the clear ;)
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: Sudo without passwd
« Reply #20 on: February 06, 2013, 04:46:13 am »
Haha yeah and storing your userpassword in the clear ;)

Because you locale machine has been rooted eh?

Despite the clear text, I don't see another way without making the ENTIRE user root, and if the afformentioned user was hacked, I really don't see a diff since they are running on root anyway.

You 'could' obfusicate the script making it a bit better, but really, with mentiond methods, I would rather do to the script then having the entire user in root.
>>>import this
-----------------------------