Thứ Sáu, 29 tháng 9, 2017

IO::Socket::SSL breaks sendEmail

Line 1907 needs to be modifed from:
1907: if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) {
to something like:
1907: if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv23:!SSLv2')) {
Note that the "SSLv23:!SSLv2" string is the default in IO::Socket::SSL, and inherently includes TLSv1. There may be better/alternative specifications that can be used, but the current string is syntactically invalid, which now causes IO::Socket::SSL to fail (previously, this would have been ignored).
I hope this helps.
# yum install perl-Net-SSLeay perl-IO-Socket-SSL -y


Line 1907 needs to be modifed from:

1907: if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) {

to something like:

1907: if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv23:!SSLv2')) {

./sendEmail -o tls=yes -f fromemail@gmail.com -t toemail@gmail.com -s smtp.gmail.com:587 -xu fromemail@gmail.com -xp 'PASSWORD' -u "Hello from sendEmail" -m "How are you? I'm testing sendEmail from the command line."

Read More

Thứ Sáu, 22 tháng 9, 2017

Phát hiện và ngăn chặn web shells - Giới thiệu về web shells phần 5



Phát hiện:
Trong error log và access log xuất hiện một số từ khóa thông dụng sử dụng bởi web shells, bao gồm tên file và tên các thông số

root@secureserver:/var/www/html# cat /var/log/apache2/access.log | awk -F\" ' { print $1,$2 } ' | grep "file"
--> 192.168.5.26 - - [30/Apr/2016:08:30:53 +0100] GET /demo/shell.php?file=/etc/passwd
Tìm các từ khóa thường gặp trong file hoặc tên file:
root@secureserver:/var/www/html/demo# grep -RPn "(passthru|exec|eval|shell_exec|assert|str_rot13|system|phpinfo|base64_decode|chmod|mkdir|fopen|fclose|readfile) *\("
--> Shell.php:8: eval($string);
eval.php:1:?php system($_SERVER['HTTP_USER_AGENT']); ?>
Ad.php:9: eval($string);
Tìm các string dài, có thể là code đã được mã hóa:
root@secureserver:/var/www/html/demo# awk 'length($0)>100' *.php
--> eval(gzinflate(base64_decode('HJ3HkqNQEkU/ZzqCBd4t8V4YAQI2E3jvPV8/1Gw6orsVFLyXefMcFUL5EXf/yqceii7e8n9JvOYE9t8sT8cs//cfWUXldLpKsQ2LCH7EcnuYdrqeqDHEDz+4uJYWH3YLflGUnDJ40DjU/AL1miwEJPpBWlsAxTrgB46jRW/00XpggW00yDI/H1kD7UqxI/3qjQZ4vz7HLsfNVW1BeQKiVH2VTrXtoiaKYdkT4o/p1E8W/n5eVhagV7GanBn0U7OCfD7zPbCQyO0N/QGtstthqJBia5QJsR6xCgkHpBo1kQMlLt6u++SBvtw5KSMwtG4R2yctd0mBNrlB3QQo4aQKGRgRjTa0xYFw1vVM9ySOMd44sSrPe…
Tìm các file được chỉnh sửa gần nhất:
root@secureserver:/var/www/html/# find -name '*.php' -mtime -1 -ls
--> root@secureserver:/var/www/html/# find -name '*.php' -mtime -1 -ls
2885788 4 drwxrwxr-x 2 secuser secuser 4096 Apr 30 06:590 /demo/shell.php
2886629 4 -rw-rw-r-- 1 secuser secuser 260 Apr 29 11:25 /demo/b.php
2897510 4 -rw-r--r-- 1 root root 35 Apr 29 13:46 /demo/source.php
2883635 4 -rw-r--r-- 1 www-data www-data 1332 Apr 29 12:09 ./ma.php
Monitor Network
root@secureserver:/var/www/html/demo# netstat -nputw
--> Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.5.25:37040 192.168.5.26:8181 ESTABLISHED 2150/nc
tcp 0 0 192.168.5.25:22 192.168.5.1:52455 ESTABLISHED 2001/sshd: secuser
tcp6 1 0 ::1:46672 ::1:631 CLOSE_WAIT 918/cups-browsed
tcp6 0 0 192.168.5.25:80 192.168.5.26:39470 ESTABLISHED 1766/apache2
tcp6 1 0 ::1:46674 ::1:631 CLOSE_WAIT 918/cups-browsed
Phân tích file .htaccess
# The AddType directive maps the given filename extensions onto the specified content type
AddType application/x-httpd-php .htaccess
AddType application/x-httpd-php .jpg
Ngăn chặn:
- Nếu không sử dụng, hãy disable các hàm như: exec()shell_exec()passthru()system()show_source()proc_open()pcntl_exec()eval() and assert()
- Sử dụng escapeshellarg() và escapeshellcmd() để đảm bảo không bị chèn shell command vào các biến đầu vào.\
- Nếu sử dụng upload form cần whitelist các định dạng file được phép upload
- Không bao giờ tin tưởng vào đầu vào nhập từ người dùng
- Không sử dụng code được share trên mạng hay forum
- Với wordpress, hạn chế cài đặt plugin từ bên thứ 3
- Disable quyền thực thi PHP trên các thư mục images, upload…






Read More