• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

wireshark / tshark / dumpcap als normaler user

berd

Newbie
Hallo,

ich habe ein Skript gebastelt, mit dem sich automatisch eine UDP-Verbindung (SIP) aufbauen soll und mit hile von wireshark/tshark aufgenommen werden soll.

Nun habe ich das Problem, dass das Skript als normaler User ausgeführt werden soll, aber tshark root-Rechte benötigt um von den Netzwerkinterfaces lesen zu können.

Da das Skript automatisch auf einem Webserver (über Klick auf einer webseite) gestartet werden soll, verfällt auch die Lösung mit sudo, da ja keiner das Passwort eingeben kann / darf.

Wireshark / tshark benutzen dumpcap zum capturen der Packete, ich hab die Rechte das Programms per Hand geändert:

Code:
viajante:/usr/bin# ls -l | grep dumpcap
-rwxrwxrwx 1 smoke  smoke     45352 2007-12-29 15:42 dumpcap

... aber es hat nicht bewirkt, beide Programm finden keine Interfaces aufgrund fehlender Rechte.

Hat jemand eine Lösung für dieses Problem?
 

Gimpel

Guru
Du kannst die Passwortabfrage bei sudo auch abschalten (global für einen user, oder je nach befehl. Siehe "man sudoers"). Oder du setzt das script suid root.

Sowas auf einem (anscheinend öffentlich zugänglichen) webserver laufen zu lassen.. da stellen sich mir die Haare auf. Aber das ist deine Sache.
 
OP
B

berd

Newbie
Hallo,

also ich habe versucht, in der sudoers-Datei die Gruppe "sudo" dafür freizuschalten, das diese für sudo kein Passwort mehr benötigt:

Code:
root@viajante:~# cat /etc/sudoers
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
# Defaults

Defaults        !lecture,tty_tickets,!fqdn

# Uncomment to allow members of group sudo to not need a password
 %sudo ALL=NOPASSWD: ALL

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

... und meinen Benutzer zur Gruppe "sudo" hinzugefügt:

Code:
smoke@viajante:~$ groups
adm dialout cdrom floppy sudo audio dip video plugdev scanner lpadmin admin netdev powerdev smoke

... und trotzdem kommt die Passwortabfrage für sudo:

Code:
smoke@viajante:~$ sudo tshark
[sudo] password for smoke:

Auch wenn es dir die Haare streubt, es ist nun mal geplant, das wireshark / tshark automatisch aufnehmen soll. Und wenn der webserver nicht gerade mit root-Rechten laufen soll, und tshark diese aber verlangt... bleibt ja wohl nichts anderes übrig. Für bessere Löungen bin ich immer offen :)

Trotzdem danke, für die fixe Antwort.

MfG
 

Gimpel

Guru
berd schrieb:
Code:
# Uncomment to allow members of group sudo to not need a password
 %sudo ALL=NOPASSWD: ALL

Ohne Passwortabfrage muss es so aussehen:
Code:
%sudo  ALL=(ALL)       NOPASSWD: ALL
Und /etc/sudoers will mit visudo bearbeitet werden, nicht direkt mit einem Editor.

Überleg dir gut, wirklich richtig gut, ob du ALLE Befehle für die Gruppe sudo erlauben willst. Du kannst wie gesagt auch nur bestimmte Befehle erlauben.

Dann würde ich mal überlegen, ob du das script nicht lieber als Perl-CGI script auf den server packen, und mit mod_suexec als bestimmter Benutzer laufen lassen willst, allderweil du sonst den user unter welchem der apache läuft, in eben jene sudo Gruppe packen musst, was, wenn du wirklich alles erlaubst, statt nur bestimmte Befehle, vollkommen hirnverbrannt wäre. :shock:
 
OP
B

berd

Newbie
Jetzt habe ich die Rechte für Nutzer "smoke" und der Gruppe "sudo" auf die Datei /usr/bin/dumpcap (die einzige Datei, die bei tshark root-Rechte benötigt) begrenzt:

Code:
root@viajante:~# cat /etc/sudoers
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
# Defaults

Defaults        !lecture,tty_tickets,!fqdn

# Uncomment to allow members of group sudo to not need a password
 %sudo ALL = NOPASSWD: /usr/bin/dumpcap

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
smoke   ALL = NOPASSWD: /usr/bin/dumpcap

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

... jedoch:

Code:
smoke@viajante:~$ sudo dumpcap
[sudo] password for smoke:

In den man-pages steht dazu folgendes:

Code:
       By default, sudo requires that a user authenticate him or herself
       before running a command.  This behavior can be modified via the
       NOPASSWD tag.  Like a Runas_Spec, the NOPASSWD tag sets a default for
       the commands that follow it in the Cmnd_Spec_List.  Conversely, the
       PASSWD tag can be used to reverse things.  For example:

        ray    rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

       would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm
       as root on the machine rushmore as root without authenticating himself.

Meines erachtens, habe ich es genau wie im manuel gemacht...
 
OP
B

berd

Newbie
Ok, Problem gelöst.

Es folgt die sudoers:

Code:
root@viajante:~# cat /etc/sudoers
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
# Defaults

Defaults        !lecture,tty_tickets,!fqdn

# Uncomment to allow members of group sudo to not need a password
# %sudo ALL = NOPASSWD: ALL

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
smoke   ALL = (ALL) ALL, NOPASSWD: /usr/bin/tshark

# Members of the admin group may gain root privileges
#%admin ALL=(ALL) ALL

Erklärung: Die Rechte behaken sich untereinander, wenn man sie für unterschiedliche Gruppen und für den Nutzer direkt fest legt.
Das "%admin ALL=(ALL) ALL" stand über allem, somit wurde das NOPASSWD ignoriert. Weiterhin muss man explizit sagen, das man allg. sudo-Rechte haben will, aber nur für bestimmte Datein keine Passwort will: "smoke ALL = (ALL) ALL, NOPASSWD: /usr/bin/tshark".

Vielleicht kann ich ja jemandem damit weiter helfen, wenn er auch Probleme mit so etwas hat.
 
Oben