Hacking WL-500gP Part 2
Продолжаю мучить WL-500gP. В предыдущей части были разобраны такие пункты:
- SSH
- 4 Gb Flash
- Установка пакетов
- syslog-ng
- Создание пользователей
Эта часть коснется установки и настройки VSFTPD и Samba 3.
Поставить FTP сервер и Samba по отдельности - не проблема. Проблема в том, чтобы везде использовалась одинаковая кодировка и корректно отображалась кириллица. Единственное рабочее решение, которое было найдено - использовать UTF8 на файловой системе и FTP сервер, который позволяет выполнять перекодировку UTF8<->Windows-1251.
Установка и настройка Samba 3
Ставим:
ipkg install samba
Файл конфигурации по-умолчанию отсутствует, создаем:
vim /opt/etc/samba/smb.conf
[global] workgroup = MYWORKGROUP guest account = nobody security = share browseable = yes guest ok = yes guest only = no log level = 0 log file = /opt/var/log/smbd.log max log size = 100 encrypt passwords = yes dns proxy = no load printers = no invalid users = root netbios name = WL500gP interfaces = br0 bind interfaces only = yes server string = ASUS WL500g Premium socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_SNDBUF=8192 preserve case = yes short preserve case = yes dos charset = CP866 unix charset = UTF-8 display charset = UTF-8 wins support = no #wins server = 192.168.1.1 time server = yes os level = 255 local master = no [PersonalShare] path = /opt/home/SomeUser writeable = yes force user = SomeUser force group = someuser browseable = yes [GroupShare] path = /opt/home/GroupShare writeable = yes force user = SomeGroup force group = somegroup browseable = yes create mode = 0664 directory mode = 0775 [FTP] path = /opt/home/ftp writeable = yes force user = ftp force group = ftp browseable = yes create mode = 0664 directory mode = 0775
Конфигурацию расшареных папок, конечно, поменять на свои. Обратите внимание на выделенные параметры. Безопасность настроена на уровне папок, а не пользователей. Выставлены кодировки.
Скрипт запуска - /opt/etc/init.d/S08samba
. Его нужно отредактировать и, желательно, переименовать,
чтобы Samba запускалась в самом конце:
sed 's/samba_active=0/samba_active=1/' /opt/etc/init.d/S08samba > /opt/etc/init.d/S95samba rm -f /opt/etc/init.d/S08samba
Не забываем также про остановку системы, файл /usr/local/sbin/pre-shutdown
:
if [ `pidof smbd` -ne "" ]; then $log 'Terminating smbd' /bin/kill `pidof smbd` fi if [ `pidof nmbd` -ne "" ]; then $log 'Terminating nmbd' /bin/kill `pidof nmbd` fi
Установка и настройка VSFTPD
VSFTPD - единственный сервер, который удовлетворяет требованиям по кодировке. И то, прийдется поднатужиться для его сборки...
Сборка VSFTPD
С сайта http://vsftpd.devnet.ru/rus/ нужно скачать последний архив в исходниками и скомпилировать его.
Для этого нам понадобятся следующие "маленькие" пакеты:
ipkg install optware-devel ipkg install buildroot ipkg install openssl-dev
Можно смело пойти погулять полчасика.
Компилируем:
mkdir -p /opt/usr/src cd /opt/usr/src wget http://vsftpd.devnet.ru/files/2.0.5/ext.4/vsftpd-2.0.5.ext4.tar.gz tar zxvf vsftpd-2.0.5.ext4.tar.gz vsftpd-2.0.5.ext4 cd vsftpd-2.0.5.ext4 cp defs.h defs.h.orig sed 's/\/etc\/vsftpd\/vsftpd.conf/\/opt\/etc\/vsftpd.conf/' defs.h.orig > defs.h mv builddefs.h builddefs.h.orig echo "#ifndef VSF_BUILDDEFS_H" >> builddefs.h echo "#define VSF_BUILDDEFS_H" >> builddefs.h echo "" >> builddefs.h echo "#undef VSF_BUILD_TCPWRAPPERS" >> builddefs.h echo "#define VSF_BUILD_PAM" >> builddefs.h echo "#define VSF_BUILD_SSL" >> builddefs.h echo "" >> builddefs.h echo "#endif /* VSF_BUILDDEFS_H */" >> builddefs.h make ipkg install vsftpd cp vsftpd /opt/sbin/ cp vsftpd.8 /opt/share/man/man8/ cp vsftpd.conf.5 /opt/share/man/man5/
UPD: 05/04/2009
Последняя сборка 2.1.0 (ext.1). Чтобы ее собрать необходимо скачать и поставить свежую версию openssl.
cd /opt/usr/src/ wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz tar zxvf openssl-0.9.8k.tar.gz cd openssl-0.9.8k ./config --prefix=/opt --openssldir=/opt shared make install
Перед выполнением этой команды нужно убить все несистемные процессы - для сборки просто не хватает памяти. Также неплохо, чтобы образовалась следующая картинка:
[root@WL500gP lib]$ ls /opt/lib/*libssl* -al -rw-r--r-- 1 root root 480756 Apr 5 17:52 /opt/lib/libssl.a lrwxrwxrwx 1 root root 15 Apr 5 17:52 /opt/lib/libssl.so -> libssl.so.0.9.8 lrwxrwxrwx 1 root root 15 Apr 5 18:13 /opt/lib/libssl.so.0 -> libssl.so.0.9.8 -r-xr-xr-x 1 root root 351912 Apr 5 17:52 /opt/lib/libssl.so.0.9.8
Также нужно поправить файл vsf_findlibs.sh
(-lcrypt вместо -lcrypto):
if find_func SSL_library_init ssl.o; then echo "-lssl -lcrypto"; fi
Настройка VSFTPD
Создаем пользователей и правильно выставляем права (важно):
echo "ftp:x:2:ftp" >> /etc/group echo "ftp:x:1000:2:Anonymous FTP user:/opt/home/ftp:/sbin/nologin" >> /etc/passwd mkdir -p /opt/home/nobody mkdir -p /opt/home/ftp mkdir -p /opt/home/ftp/incoming chown nobody:nobody /opt/home/nobody chown -R ftp:ftp /opt/home/ftp chmod 555 /opt/home/nobody chmod 555 /opt/home/ftp chmod 775 /opt/home/ftp/incoming
Конфигурация /opt/etc/vsftpd.conf
:
# Example config file /opt/etc/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. listen=YES check_shell=NO chroot_local_user=YES secure_chroot_dir=/opt/home/nobody anon_root=/opt/home/ftp convert_charset_enable=1 local_charset=UTF-8 remote_charset=WIN1251 syslog_enable=YES # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=YES # # Uncomment this to allow local users to log in. local_enable=YES # # Uncomment this to enable any form of FTP write command. write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) local_umask=022 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will # obviously need to create a directory writable by the FTP user. anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # Activate logging of uploads/downloads. xferlog_enable=YES # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # # If you want, you can arrange for uploaded anonymous files to be owned by # a different user. Note! Using "root" for uploaded files is not # recommended! #chown_uploads=YES #chown_username=whoever # # You may override where the log file goes if you like. The default is shown # below. vsftpd_log_file=/opt/var/log/vsftpd.log # # If you want, you can have your log file in standard ftpd xferlog format #xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 # # You may change the default value for timing out a data connection. #data_connection_timeout=120 # # It is recommended that you define on your system a unique user which the # ftp server can use as a totally isolated and unprivileged user. nopriv_user=nobody # # Enable this and the server will recognise asynchronous ABOR requests. Not # recommended for security (the code is non-trivial). Not enabling it, # however, may confuse older FTP clients. #async_abor_enable=YES # # By default the server will pretend to allow ASCII mode but in fact ignore # the request. Turn on the below options to have the server actually do ASCII # mangling on files when in ASCII mode. # Beware that turning on ascii_download_enable enables malicious remote parties # to consume your I/O resources, by issuing the command "SIZE /big/file" in # ASCII mode. # These ASCII options are split into upload and download because you may wish # to enable ASCII uploads (to prevent uploaded scripts etc. from breaking), # without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be # on the client anyway.. #ascii_upload_enable=YES #ascii_download_enable=YES # # You may fully customise the login banner string: ftpd_banner=Welcome. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. #deny_email_enable=YES # (default follows) #banned_email_file=/opt/etc/vsftpd.banned_emails # # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). #chroot_list_enable=YES # (default follows) #chroot_list_file=/opt/etc/vsftpd.chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. ls_recurse_enable=YES
Запускаем:
/opt/sbin/vsftpd >/dev/null 2>&1 &
Пробуем логинится как anonymous. Если сервер отвечает 500 OOPS: child died
, то, вероятно, что-то неправильно
с правами доступа или путями.
Добавляем в автозапуск:
echo "/opt/sbin/vsftpd /opt/etc/vsftpd.conf >/dev/null 2>&1 &" > /opt/etc/init.d/S60vsftpd chmod +x /opt/etc/init.d/S60vsftpd
Последний штрих - остановка системы, файл /usr/local/sbin/pre-shutdown
:
if [ `pidof vsftpd` -ne "" ]; then $log 'Terminating vsftpd' /bin/kill `pidof vsftpd` fi
Не забываю сделать
flashfs save && flashfs commit && flashfs enable