meine chroot-umgebung kennt user nicht

FreeBSD, Gentoo, openSUSE, CentOS, Ubuntu, Debian
pie-ai
Posts: 16
Joined: 2004-03-10 23:47
 

meine chroot-umgebung kennt user nicht

Post by pie-ai »

Moin.
Ich habe mir eine chroot aufgesetzt, ich kann auch über

Code: Select all

chroot /server/chroot
in die Umgebung hinein und alle notwendigen Programme ausführen. Ich habe für einen User als shell ein Skript angegeben, dass per sudo ein chroot aufruft und nachher wieder per su die Rechte des Nutzers bekommt:

Code: Select all

dev:/# su pstricker
Sorry.
dev:/#
mache ich es manuell, Step by Step sieht das so aus:

Code: Select all

dev:/# chroot /server/chroot/
dev:/# su pstricker
Sorry.
dev:/#
meine /etc/passwd im chroot enthält folgendes:

Code: Select all

pstricker:x:20001:20001:Patrick Stricker:/home/pstricker:/bin/bash
meine /etc/group im chroot:

Code: Select all

pstricker:x:20001:
Mir ist aufgefallen, dass ein directory-listening keine Namen, sondern nur die Userid's enthält:

Code: Select all

dev:/home# ls -la
total 12
drwxr-xr-x    3 0        0            4096 Mar 18 21:08 .
drwxr-xr-x    8 0        0            4096 Mar 18 20:33 ..
drwxr-xr-x    2 20001    20001        4096 Mar 18 20:44 pstricker
dev:/home#
Die Dateien auf dem chroot sind folgende (ich habe jeweils per ldd die Libraries gesucht und hineinkopiert):

Code: Select all

dev:/server/chroot# ls -lR
.:
total 24
drwxr-xr-x    2 root     root         4096 Mar 18 21:42 bin
drwxr-xr-x    2 root     root         4096 Mar 18 21:33 dev
drwxr-xr-x    3 root     root         4096 Mar 18 21:35 etc
drwxr-xr-x    3 root     root         4096 Mar 18 22:08 home
drwxr-xr-x    2 root     root         4096 Mar 18 19:39 lib
drwxr-xr-x    5 root     root         4096 Mar 18 00:19 usr

./bin:
total 808
-rwxr-xr-x    1 root     root       511400 Mar 18 00:05 bash
-rwxr-xr-x    1 root     root         9308 Mar 18 21:30 cat
-rwxr-xr-x    1 root     root        15816 Mar 18 21:42 chmod
-rwxr-xr-x    1 root     root        17896 Mar 18 21:42 chown
-rwxr-xr-x    1 root     root        34664 Mar 17 23:57 cp
-rwxr-xr-x    1 root     root        43784 Mar 17 23:57 ls
-rwxr-xr-x    1 root     root        16520 Mar 17 23:57 mkdir
-rwxr-xr-x    1 root     root        42088 Mar 17 23:58 mv
-rwxr-xr-x    1 root     root        25352 Mar 17 23:58 rm
-rwxr-xr-x    1 root     root        10504 Mar 17 23:58 rmdir
-rwxr-xr-x    1 root     root        46984 Mar 18 00:15 sftp
-rwxr-xr-x    1 root     root        23176 Mar 18 19:38 su

./dev:
total 0
crw-r--r--    1 root     root      13,   2 Mar 18 21:33 null
crw-r--r--    1 root     root      13,  12 Mar 18 21:33 zero

./etc:
total 12
-rw-r--r--    1 root     root           19 Mar 18 20:58 group
drwxr-xr-x    2 root     root         4096 Mar 18 21:35 pam.d
-rw-r--r--    1 root     root           67 Mar 18 22:05 passwd

./etc/pam.d:
total 4
-rw-r--r--    1 root     root         1388 Mar 18 21:35 su

./home:
total 4
drwxr-xr-x    2 pstricke pstricke     4096 Mar 18 21:44 pstricker

./home/pstricker:
total 0

./lib:
total 2684
-rwxr-xr-x    1 root     root        90210 Mar 18 21:11 ld-linux.so.2
-rwxr-xr-x    1 root     root        99568 Mar  7  2001 ld.so
lrwxrwxrwx    1 root     root           14 Mar 18 00:00 libc.so.5 -> libc.so.5.4.46
-rwxr-xr-x    1 root     root      1153784 Mar 18 21:10 libc.so.6
-rwxr-xr-x    1 root     root        19136 Mar 18 21:10 libcrypt.so.1
-rwxr-xr-x    1 root     root       771908 Mar 18 00:18 libcrypto.so.0.9.6
-rwxr-xr-x    1 root     root         6200 Mar 18 21:23 libdl.so.1
-rwxr-xr-x    1 root     root         8008 Mar 18 21:10 libdl.so.2
-rwxr-xr-x    1 root     root       248132 Mar 18 00:06 libncurses.so.5
-rwxr-xr-x    1 root     root        69472 Mar 18 00:02 libnsl.so.1
-rwxr-xr-x    1 root     root        29420 Mar 18 21:10 libpam.so.0
-rwxr-xr-x    1 root     root         7500 Mar 18 19:39 libpam_misc.so.0
-rwxr-xr-x    1 root     root       102172 Mar 18 00:08 libpthread.so.0
-rwxr-xr-x    1 root     root        23388 Mar 18 00:08 librt.so.1
-rwxr-xr-x    1 root     root         7600 Mar 18 00:17 libutil.so.1
-rwxr-xr-x    1 root     root        55432 Mar 18 00:17 libz.so.1

./usr:
total 12
drwxr-xr-x    2 root     root         4096 Mar 18 00:20 bin
drwxr-xr-x    2 root     root         4096 Mar 17 23:58 libexec
drwxr-xr-x    2 root     root         4096 Mar 17 23:58 local

Ich kann mir nicht mehr helfen, ich bin mehrere Tutorials durchgegangen und habe mich bei google wund gesucht. Hat jemand Erfahrungen oder eine Idee? Würde mir sehr helfen.

MfG
Patrick Stricker
cybermage
Posts: 158
Joined: 2002-12-10 22:10
Location: Ausgburg (Germany)
 

Re: meine chroot-umgebung kennt user nicht

Post by cybermage »

das problem hatte ich auch ...
mach doch mal ein strace su, das hat bei mir damals noch dateien zu tage gebracht die ich vergessen hatte
rootmaster
Posts: 483
Joined: 2002-04-28 13:30
Location: Hannover
 

Re: meine chroot-umgebung kennt user nicht

Post by rootmaster »

Cybermage wrote:das problem hatte ich auch ...
mach doch mal ein strace su, das hat bei mir damals noch dateien zu tage gebracht die ich vergessen hatte
tippe mal auf libnss* ;)

"back to the roots"
pie-ai
Posts: 16
Joined: 2004-03-10 23:47
 

Re: meine chroot-umgebung kennt user nicht

Post by pie-ai »

Ich habe mal ein

Code: Select all

trace -o sutrace /bin/su
gemacht. Festgestellt habe ich aus folgender Ausgabe, dass ich anscheinend ein Problem bei /dev, /var/run und /proc habe. In /var/run existiert die Datei in meinem System nicht, bin ich also übergangen.

Code: Select all

readlink("/proc/self/fd/0", 0x8054740, 4095) = -1 ENOENT (No such file or directory)
fstat64(0, 0xbffffcbc)                  = -1 ENOSYS (Function not implemented)
fstat(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
stat("/dev/pts", 0xbffffbac)            = -1 ENOENT (No such file or directory)
stat("/dev/vc", 0xbffffbac)             = -1 ENOENT (No such file or directory)
stat("/dev/tts", 0xbffffbac)            = -1 ENOENT (No such file or directory)
open("/dev/null", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = -1 ENOTDIR (Not a directory)
open("/dev", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC)         = -1 ENOSYS (Function not implemented)
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
getdents64(0x3, 0x8055778, 0x1000, 0x26) = -1 ENOSYS (Function not implemented)
getdents(3, /* 4 entries */, 2980)      = 60
getdents(3, /* 0 entries */, 2980)      = 0
close(3)                                = 0
open("/dev", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3

...

connect(3, {sin_family=AF_UNIX, path="/var/run/.nscd_socket"}, 110) = -1 ECONNREFUSED (Connection refused)

...

open("/etc/passwd", O_RDONLY)           = 3
fcntl(3, F_GETFD)                       = 0
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=67, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
_llseek(3, 0, [0], SEEK_CUR)            = 0
read(3, "pstricker:x:20001:20001:Patrick "..., 4096) = 67
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x40014000, 4096)                = 0
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
dann habe ich einfach mal mein proc in der chroot per ln -s auf mein standard proc gelinkt, ergeben hat das folgendes:

Code: Select all

readlink("/proc/self/fd/0", 0x8054740, 4095) = -1 ELOOP (Too many levels of symbolic links)
und bringt mich kein Stück weiter. Ã?brigens, der Tipp mit dem libnss hat mich nicht weiter gebracht, ich habe alle Libraries per ldd hineinkopiert, strace geht bei Bibliotheken ja nicht.

Eine Idee für mich wäre echt toll.
MfG Patrick
nn4l
Posts: 172
Joined: 2002-06-19 07:06
 

Re: meine chroot-umgebung kennt user nicht

Post by nn4l »

Warum kann /dev/null nicht geöffnet werden?

Versuch mal folgendes:

- /etc/resolv.conf kopieren
- /lib vollständig kopieren (wenn's geht, kannst Du ja später files wieder löschen)
- /proc ein zweites Mal mounten (in der chroot Umgebung)
pie-ai
Posts: 16
Joined: 2004-03-10 23:47
 

Re: meine chroot-umgebung kennt user nicht

Post by pie-ai »

Super, hat funktioniert. Ich war mir nicht im klaren darüber, dass proc kein einfaches Verzeichnis sondern halt ein Mountpoint auf was weiß ich was (proc halt) ist. Ich habe dann eben noch root in der passwd und group hinzugefügt und alles passt.
gamecrash
Posts: 339
Joined: 2002-05-27 10:52
 

Re: meine chroot-umgebung kennt user nicht

Post by gamecrash »

proc ist ein virtuelles Dateisystem, so eine Art "Fenster zum Kernel". Da werden ne ganze Menge Informatinen angezeigt, die man vielleicht gerade im chroot nicht haben will...
pie-ai
Posts: 16
Joined: 2004-03-10 23:47
 

Re: meine chroot-umgebung kennt user nicht

Post by pie-ai »

Wie geht denn das dann? Ich kann kein su ohne proc machen, proc enthält aber zu sensible Daten. Ich glaube ich setze mich mal mit fertigen chroot-scp-sftp Umgebungen auseinander. Dann bracuht keiner mehr einen ssh Zugang mit richtiger Shell.

Dank.

PA
oxygen
Posts: 2138
Joined: 2002-12-15 00:10
Location: Bergheim
 

Re: meine chroot-umgebung kennt user nicht

Post by oxygen »

mit grsec lässt sich proc so ziemlich auf das nötigste reduzieren.
compositiv
Posts: 193
Joined: 2003-01-22 14:58
Location: Hamburg
 

Re: meine chroot-umgebung kennt user nicht

Post by compositiv »

GameCrash wrote:proc ist ein virtuelles Dateisystem, so eine Art "Fenster zum Kernel". Da werden ne ganze Menge Informatinen angezeigt, die man vielleicht gerade im chroot nicht haben will...
Naja besser als ein Link aus dem Chroot, wie oben vorgeschlagen %)