Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

In Zusammenhang mit Locky Frage an die Sambaexperten

16 views
Skip to first unread message

Olaf Jaehrling

unread,
Feb 23, 2016, 2:55:14 AM2/23/16
to
Hallo allerseits,

ist sowas [1] hier mit samba möglich?

Zusammenfassung: Wenn Dateien mit bestimmten Endungen auf den Filserver geladen werden, dann blockt der diese und/oder hält den Dienst an und/oder fährt den gesamten Fileserver herunter um ein komplettes löschen der Freigaben zu verhindern.

Danke fürs Brainstorming.

Gruß

Olaf

[1] https://www.frankysweb.de/windows-fileserver-vor-ransomware-crypto-locker-schuetzen/

Thomas Bork

unread,
Feb 23, 2016, 3:36:43 PM2/23/16
to
Am 23.02.2016 um 08:55 schrieb Olaf Jaehrling:

> ist sowas [1] hier mit samba möglich?

Basteln kann man viel. Allerdings wird das nur ein Wettlauf mit
unbestimmtem Ausgang.

> Zusammenfassung: Wenn Dateien mit bestimmten Endungen auf den Filserver geladen werden, dann blockt der diese und/oder hält den Dienst an und/oder fährt den gesamten Fileserver herunter um ein komplettes löschen der Freigaben zu verhindern.

root preexec (S)

This is the same as the preexec parameter except that the command is run
as root. This is useful for mounting filesystems (such as CDROMs) when a
connection is opened.

Default: root preexec =


preexec (S)

This option specifies a command to be run whenever the service is
connected to. It takes the usual substitutions.

An interesting example is to send the users a welcome message every time
they log in. Maybe a message of the day? Here is an example:

preexec = csh -c 'echo \"Welcome to %S!\" |
/usr/local/samba/bin/smbclient -M %m -I %I' &

Of course, this could get annoying after a while :-)

See also preexec close and postexec.

Default: preexec =

Example: preexec = echo \"%u connected to %S from %m (%I)\" >> /tmp/log


Sieh Dir an, was in unserem Samba-Paket definiert wird, wenn SAMBA_DEBUG
groesser 2 gesetzt ist:

[...]
if [ $SAMBA_DEBUGLEVEL -gt 0 ]
then
debuglevel="$SAMBA_DEBUGLEVEL"

if [ $debuglevel -gt 2 ]
then
smbinfo='yes'
else
smbinfo='no'
fi
else
debuglevel='0'
smbinfo='no'
fi
[...]
do_smbinfo ()
{
if [ "$smbinfo" = "yes" ]
then

x='T=%T|d=%d|v=%v|h=%h|L=%L|N=%N|p=%p|R=%R|S=%S|P=%P|U=%U|G=%G|u=%u|g=%g|H=%H|I=%I|M=%M|m=%m|a=%a'
echo " root preexec = /var/install/bin/samba-smbinfo \"$x\" &"
fi
}
[...]
{
echo "[public]"
echo " comment = public directory on $HOSTNAME"
echo " path = $path"
echo " force create mode = 0777"
echo " force directory mode= 0777"
echo " browseable = yes"
echo " writeable = yes"
do_smbinfo
[...]

Das Skript /var/install/bin/samba-smbinfo:

#! /bin/sh
#----------------------------------------------------------------------------
# /var/install/bin/samba-smbinfo - send info with samba vars to machine
#
# Copyright (c) 2002-2015 Thomas Bork, tom(at)eisfair(dot)net
#
# Creation : 2002-07-28 tb
# Last Update: 2015-06-20 tb
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------
outputfile=`/bin/mktemp -t samba-smbinfo-XXXXXXXXXX`
if [ $? -ne 0 ]
then
outputfile="/tmp/samba-smbinfo-$$"
fi

msgcommand ()
{
cat "$outputfile" | awk '{print
gensub("<tab>","\t","g",gensub("<newline>","\n","g"))}' |
/usr/bin/smbclient -U "eisfair Samba Server" -N -M "$machine" -I "$ip"
1>/dev/null
rm -f "$outputfile"
}

>"$outputfile"

oldifs="$IFS"
IFS='|'
set -- $1
while [ -n "$1" ]
do
if [ -n "`echo "$1" | grep '='`" ]
then
index=`echo "$1" | cut -d'=' -f1`
value=`echo "$1" | cut -d'=' -f2`
case $index in
T ) message="Datum/Zeit<tab><tab><tab><tab>(%$index)<tab>=
$value";;
d ) message="PID des Servers<tab><tab><tab><tab>(%$index)<tab>=
$value";;
v ) message="Samba-Version<tab><tab><tab><tab>(%$index)<tab>=
$value";;
h ) message="(Internet)Hostname des
Servers<tab><tab>(%$index)<tab>= $value";;
L ) message="NETBIOS-Name des
Servers<tab><tab><tab>(%$index)<tab>= $value";;
N ) message="NIS
Heimat-Verzeichnis<tab><tab><tab>(%$index)<tab>= $value";;
p ) message="Pfad des
NIS-Heimatverzeichnisses<tab><tab>(%$index)<tab>= $value";;
R ) message="Ausgehandeltes
Protokoll-Level<tab><tab>(%$index)<tab>= $value";;
S ) message="Name der aktuellen
Freigabe<tab><tab><tab>(%$index)<tab>= $value";;
P ) message="Hauptverzeichnis der aktuellen
Freigabe<tab>(%$index)<tab>= $value";;
U ) message="Vom Client angeforderter
Benutzername<tab>(%$index)<tab>= $value";;
G ) message="Primaere Gruppe des angeforderten
Benutzers<tab>(%$index)<tab>= $value";;
u ) message="Name des effektiven
Benutzers<tab><tab>(%$index)<tab>= $value";;
g ) message="Primaerer Gruppenname des effektiven
Benutzers<tab>(%$index)<tab>= $value";;
H ) message="Heimatverzeichnis des effektiven
Benutzers<tab>(%$index)<tab>= $value";;
I ) message="IP Adresse des
Client-Rechners<tab><tab>(%$index)<tab>= $value"
ip="$value"
;;
M ) message="(Internet)Hostname des
Client-Rechners<tab>(%$index)<tab>= $value";;
m ) message="NETBIOS-Name des
Client-Rechners<tab><tab>(%$index)<tab>= $value"
machine="$value"
;;
a ) message="Betriebssystem des
Client-Rechners<tab><tab>(%$index)<tab>= $value";;
esac

echo "$message" >>"$outputfile"
fi
shift
done

IFS="$oldifs"
msgcommand


Das heisst, Du kannst beliebige Dinge skripten und ausführen lassen: auf
Namen filtern, Mails senden, die Freigabe deaktivieren (smbcontrol smbd
close-share share-Name) usw.

Viel Spass beim Basteln...

--
der tom
[eisfair-team]

Olaf Jaehrling

unread,
Feb 25, 2016, 6:00:05 AM2/25/16
to
Hallo Thomas,
Danke für die ausführliche Antwort. Da es mich aber für die nächsten
Tage erstmal flachgelegt hat muss ich das leider ein paar Tage verschieben.

>
> Viel Spass beim Basteln...

Danke, Danke :)


Gruß

Olaf

>

Alex Busam

unread,
Mar 2, 2016, 1:08:16 PM3/2/16
to
http://www.heise.de/security/artikel/Erpressungs-Trojaner-wie-Locky-aussperren-3120956.html

Hier ist noch was interessantes dazu

Gruß
Alex

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

Olaf Jaehrling

unread,
Mar 2, 2016, 4:14:07 PM3/2/16
to
Hallo Alex,


Alex Busam schrieb am 02.03.2016 um 19:08:
> http://www.heise.de/security/artikel/Erpressungs-Trojaner-wie-Locky-aussperren-3120956.html

Danke für den Tip. Das kriege ich bestimmt auch in BFB rein. Muss mal
mit Tom Bork quatschen, wie wir das mit samba hinbekommen.

Jürgen, bekomme ich die Zeilen
[global]
full_audit:failure = none
full_audit:success = pwrite write rename
full_audit:prefix = IP=%I|USER=%u|MACHINE=%m|VOLUME=%S
full_audit:facility = local7
full_audit:priority = NOTICE

und bei jedem zu überwachenden [Volume]

vfs objects = full_audit

irgendwie vernüftig rein, ohne das jeder Nutzer das händisch machen muss?

Bei mir klappt zumindest schonmal der logeintrag:
Mar 2 22:12:01 server smbd:
IP=192.168.10.8|USER=movies|MACHINE=virtual|VOLUME=movies|pwrite|ok|musik/Rolling
Stones/VIDEO_TS/VIDEO_TS.BUP

Wenn da jetzt irgendwas mit locky stehen würde, würde BFB diese IP
blocken. Theoretisch könnte BFB sogar samba anhalten. Was ich
preferieren würde.


Danke und Gruß

Olaf


Thomas Bork

unread,
Mar 6, 2016, 9:13:07 AM3/6/16
to
Am 02.03.2016 um 22:14 schrieb Olaf Jaehrling:

> Jürgen, bekomme ich die Zeilen

War ich gemeint?

> [global]
> full_audit:failure = none
> full_audit:success = pwrite write rename
> full_audit:prefix = IP=%I|USER=%u|MACHINE=%m|VOLUME=%S
> full_audit:facility = local7
> full_audit:priority = NOTICE
>
> und bei jedem zu überwachenden [Volume]
>
> vfs objects = full_audit
>
> irgendwie vernüftig rein, ohne das jeder Nutzer das händisch machen muss?

Irgendwann hatte ich schon einmal full_audit für unser Paket vorbereitet
und mit ausgeliefert. Aber ich hatte dafür nie eine
Konfigurations-Variable integriert.

Das hatte aber überhaupt nichts mit locky zu tun, sondern mit der
Verfolgung von Veränderungen auf den Freigaben.

Unterschiede:
Es wird nicht [global] verwendet, sondern immer in den
Freigabe-Sektionen, denn aus dem Manual für smb.conf:

vfs objects (S) (das S steht für Freigabe-Definition, nicht Global)

This parameter specifies the backend names which are used for Samba VFS
I/O operations. By default, normal disk I/O operations are used but
these can be overloaded with one or more VFS objects.

Default: vfs objects =

Example: vfs objects = extd_audit recycle

Und aus dem Manual für full_audit (auch hier wird wieder die
Freigabe-Definition verwendet):

EXAMPLES

Log file and directory open operations on the [records] share using the
LOCAL7 facility and ALERT priority, including the username and IP
address. Logging excludes the open VFS function on failures:

[records]
path = /data/records
vfs objects = full_audit
full_audit:prefix = %u|%I
full_audit:success = open opendir
full_audit:failure = all !open
full_audit:facility = LOCAL7
full_audit:priority = ALERT



Also habe ich in /var/install/config.d/samba.sh das hier definiert:

[...]
do_check_vfs_fullaudit ()
{
if [ "$SAMBA_FULL_AUDIT" = "yes" ]
then
if [ -z "$vfs_objects" ]
then
vfs_objects='full_audit'
else
vfs_objects="full_audit, $vfs_objects"
fi
fi
}
[...]
do_write_vfs_fullaudit ()
{
if [ "$SAMBA_FULL_AUDIT" = "yes" ]
then
{
echo " full_audit:prefix = %S|%u|%I"
echo " full_audit:success = open mkdir read write rmdir unlink"
echo " full_audit:failure = none"
echo " full_audit:facility = LOCAL7"
echo " full_audit:priority = ALERT"
}
fi
}

Und in den Freigabe-Definitionen (auto und manual) dann :

[...]
do_smbinfo
vfs_objects=''
do_check_vfs_recycle
do_check_vfs_fullaudit
do_check_vfs_dirsort
do_write_vfs_objects
do_write_vfs_fullaudit
do_write_vfs_recycle
[...]

Das loggt kompletter (open mkdir read write rmdir unlink), verwendet als
Priority ALERT und setzt keine anderen vfs_objects (dirsort, recycle)
ausser Kraft.

Zur Zeit wird zwar nur noch der Papierkorb (vfs_recycle) genutzt.
Aber vfs_dirsort wird schon mitgeliefert, wurde auch schon mal
konfiguriert, dann wegen eines Problems (Unterschlagung von
Dateien/Verzeichnissen in der sortierten Ausgabe) aber wieder heraus
genommen.


Um so etwas für alle Belange (auch - aber nicht nur locky) sinnvoll zu
integrieren, müsste man die Freigabe-Definitionen im Paket erheblich
aufblähen und alle Optionen konfigurierbar machen, also

SAMBA_SHARE_"$idx"_FULLAUDIT yes/no
SAMBA_SHARE_"$idx"_FULLAUDIT_PREFIX
SAMBA_SHARE_"$idx"_FULLAUDIT_SUCCESS
SAMBA_SHARE_"$idx"_FULLAUDIT_FAILURE
SAMBA_SHARE_"$idx"_FULLAUDIT_FACILITY
SAMBA_SHARE_"$idx"_FULLAUDIT_PRIORITY


Sorry - aber das ist mir zu fett. Und ich denke immer noch, dass das nur
ein Wettlauf mit der Zeit wäre.


Wenn Du damit experimentieren willst, kannst Du direkt in
/var/install/config.d/samba.sh eine Variable

SAMBA_FULL_AUDIT='yes'

setzen und die Funktion

do_write_vfs_fullaudit ()
{
if [ "$SAMBA_FULL_AUDIT" = "yes" ]
then
{
echo " full_audit:prefix = %S|%u|%I"
echo " full_audit:success = open mkdir read write rmdir unlink"
echo " full_audit:failure = none"
echo " full_audit:facility = LOCAL7"
echo " full_audit:priority = ALERT"
}
fi
}

anpassen. Natürlich sind die Änderungen nach einem Samba-Update dann
wieder weg...

--
der tom
[eisfair-team]

Olaf Jaehrling

unread,
Mar 6, 2016, 11:23:57 AM3/6/16
to
Hallo Thomas,

Thomas Bork schrieb am 06.03.2016 um 15:13:
> Am 02.03.2016 um 22:14 schrieb Olaf Jaehrling:
>
>> Jürgen, bekomme ich die Zeilen
>
> War ich gemeint?

Ja, ist mir gestern dann auch aufgefallen, was ich da für Mist
geschrieben habe. Muss mal Tom fragen, spreche aber Jürgen an. Wer weis
wo ich mit meinen Gedanken war. Sorry.

>

>

>
> [records]
> path = /data/records
> vfs objects = full_audit
> full_audit:prefix = %u|%I
> full_audit:success = open opendir
> full_audit:failure = all !open
> full_audit:facility = LOCAL7
> full_audit:priority = ALERT
>
>
vfs objects = full_audit
full_audit:failure = none
full_audit:success = pwrite write rename
full_audit:prefix = IP=%I|USER=%u|MACHINE=%m|VOLUME=%S
full_audit:facility = local7
full_audit:priority = NOTICE

sieht doch fast gleich aus ....

>

>
> Um so etwas für alle Belange (auch - aber nicht nur locky) sinnvoll zu
> integrieren, müsste man die Freigabe-Definitionen im Paket erheblich
> aufblähen und alle Optionen konfigurierbar machen, also
>
> SAMBA_SHARE_"$idx"_FULLAUDIT yes/no
> SAMBA_SHARE_"$idx"_FULLAUDIT_PREFIX
> SAMBA_SHARE_"$idx"_FULLAUDIT_SUCCESS
> SAMBA_SHARE_"$idx"_FULLAUDIT_FAILURE
> SAMBA_SHARE_"$idx"_FULLAUDIT_FACILITY
> SAMBA_SHARE_"$idx"_FULLAUDIT_PRIORITY
>
>
> Sorry - aber das ist mir zu fett. Und ich denke immer noch, dass das nur
> ein Wettlauf mit der Zeit wäre.

Warum so viel? Alles als Standartwerte reicht nicht? Ich frage nur für
mein Verständnis?

> SAMBA_FULL_AUDIT='yes'
>
> setzen und die Funktion
>
> do_write_vfs_fullaudit ()
> {
> if [ "$SAMBA_FULL_AUDIT" = "yes" ]
> then
> {
> echo " full_audit:prefix = %S|%u|%I"
> echo " full_audit:success = open mkdir read write rmdir unlink"
> echo " full_audit:failure = none"
> echo " full_audit:facility = LOCAL7"
> echo " full_audit:priority = ALERT"
> }
> fi
> }

Genau, Nur SAMBA_FULL_AUDIT=yes/no und dann diese Optionen festgenagelt.
Geht das nicht?


>
> anpassen. Natürlich sind die Änderungen nach einem Samba-Update dann
> wieder weg...

Naja, bei meiner Lösung im Moment ja noch schlimmer (schon beim setup
alles weg)


Danke und Gruß

Olaf

>

Thomas Bork

unread,
Mar 6, 2016, 11:36:25 AM3/6/16
to
Am 06.03.2016 um 17:23 schrieb Olaf Jaehrling:

> sieht doch fast gleich aus ....

Das oben war ein Beispiel aus der manpage.

> Warum so viel? Alles als Standartwerte reicht nicht? Ich frage nur für
> mein Verständnis?

Siehe unten.

> Genau, Nur SAMBA_FULL_AUDIT=yes/no und dann diese Optionen festgenagelt.
> Geht das nicht?

Du definierst:
full_audit:prefix = IP=%I|USER=%u|MACHINE=%m|VOLUME=%S

Ich definiere:
full_audit:prefix = %S|%u|%I

Du definierst:
full_audit:success = pwrite write rename

Ich definiere:
full_audit:success = open mkdir read write rmdir unlink

Du definierst:
full_audit:priority = NOTICE

Ich definiere:
full_audit:priority = ALERT

Nein, das ist alles nicht das selbe. Und der nächste will wieder ganz
etwas anderes.

Ich schrieb:

> Um so etwas für alle Belange (auch - aber nicht nur locky) sinnvoll
> zu integrieren, müsste man die Freigabe-Definitionen im Paket
> erheblich aufblähen und alle Optionen konfigurierbar machen, also

--
der tom
[eisfair-team]
0 new messages