Blog O' Matty


Grabbing a protected webpage from the command line

This article was posted by Matty on 2005-02-19 23:36:00 -0400 -0400

Ever needed to grab a password protected page from the command line? This can be accomplished with curl’s “-u” option:

$ curl -k -i https://prefetch.net/secret -u me:somethingstrong |more

The username and password can be passed as an argument to the “-u” option. If you are paranoid about your password being visible on the command line, you can omit the password, and curl will prompt you for it:

$ curl -k -i https://prefetch.net/secret -u me
password:

In case you are curious, the “-k” option forces curl to dump the HTTP headers. I use both options to debug web server issues.

Reading OpenBSD PF log entries in realtime

This article was posted by Matty on 2005-02-19 00:17:00 -0400 -0400

When the OpenBSD packet filter (PF) is configured to log traffic, each packet is logged to the OpenBSD “pflog” pseudo-device. This device can be queried with several tools, including tcpdump:

$ tcpdump -i pflog0 -ttt -e -o

tcpdump: WARNING: pflog0: no IPv4 address assigned
tcpdump: listening on pflog0
Jan 23 21:27:33.361173 rule 4/0(match): block in on tun0: 12.144.129.35
> adsl-19-10-38.asm.bellsouth.net: icmp: echo request
Jan 23 21:28:01.505716 rule 4/0(match): block in on tun0:
217.20.209.217.34777 > adsl-19-10-38.asm.bellsouth.net.socks: S (src
OS: short-pkt) 3962893738:3962893738(0) win 5840 (DF)

If you are running a busy firewall, you are probably using pflogd to archive this information to a file on your FFS file system. I occassionally like to monitor pflog0 when I am testing new services, especially ones that don’t play nicely with firewalls.

Proxying connections through SSH

This article was posted by Matty on 2005-02-18 23:40:00 -0400 -0400

Ever wonder how you can tunnel web and AIM traffic securely from one location to another? This can be accomplished with ssh’s “-D” option. This allows traffic to be sent securely over a SSH session, and routed out through a remote endpoint. This looks like:

Firefox/GAIM < -- HTTP/AIM--> loopback:PORT < -- SSH --> REMOTE END < -- HTTP/AIM --> Internet

To create a local proxy on TCP port 8000, we can pass the value 8000 to the “-D” option:

$ ssh -C -D 8000 -p 443 ick@ick.net

Once the SSH connection is established, you need to configure your client (e.g., firefox, gaim) to proxy connections to the loopback interface on TCP port 8000. Once your clients are configured to use the localhost.8000 listener, all application traffic will be sent securely through your ssh session, and routed through the Internet connection on the remote end.

Since most web proxies tunnel secure connections, you can setup your remote endpoint to accept SSH connections on TCP port 443. This is amazingly useful for routing around corporate firewalls and proxies. You don’t want to get caught looking for jobs while your at work, right? ;)

Passive FTP on Solaris

This article was posted by Matty on 2005-02-18 23:39:00 -0400 -0400

The FTP protocol uses a control channel to send commands to a server, and a data channel to send and receive files. The control channel by default uses TCP port 21, and the data channel is negotiated with the FTP PORT and PASV comands. When ACTIVE mode FTP is in use, the client chooses the port to use for data transfers. When PASSIVE mode FTP is used, the server is responsible for picking the data port.

With ACTIVE mode FTP, the client picks a high numbered port to use for the data transfer, and instructs the server to use this port by issuing a PORT command. For non application aware firewalls, these connections are usually problematic.

With PASSIVE mode FTP, the client issues a PASV FTP command to the server, and the server picks a port for the client to connect back on. All data is then transfered over this channel. This method works with most stateful firewalls, and is supported in most mainstream FTP clients.

The Solaris “ftp” command defaults to ACTIVE mode FTP, but supports PASSIVE mode FTP when invoked with the “-p” option:

$ ftp -p sunsite.unc.edu

Connected to sunsite.unc.edu.
220 ProFTPD Server (Bring it on...)
Name (sunsite.unc.edu:matty): anonymous
331 Anonymous login ok, send your complete email address as your password.
Password:
230-
Welcome to ftp.ibiblio.org, the public ftp server of ibiblio.org. We
hope you find what you're looking for.

If you have any problems or questions, please send email to

ftpkeeper@ibiblio.org

Thanks!

230 Anonymous access granted, restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.

For a super detailed explanation of ACTIVE and PASSIVE FTP, check out Slacksite:

http://slacksite.com/other/ftp.html

This is a super useful resource.

Apache HTTP to HTTPS redirects

This article was posted by Matty on 2005-02-18 23:15:00 -0400 -0400

The Apache web server provides a flexible and customizable web hosting environment, and contains a plethora of features. One nice feature is the ability to redirect clients to different areas of a site based on URL location, or the port they are connecting to. Redirection is accomplished with the “Redirect” and “RedirectMatch” directives, which are part of the mod_alias module. To redirect all HTTP:// connections to HTTPS://, you can setup a VirtualHost, and use the Redirect directive to forward all requests to a secure URL:

<VirtualHost *:80>
Redirect permanent / https://www.daemons.net/something/blah.jsp
</virtualhost>

This assumes that non-secure connections are terminated on TCP port 80, and secure connections are terminated on TCP port 443.