Wednesday·04·April·2012
Tools for CLI Road Warriors: Hidden Terminals //at 00:57 //by abe
Some networks have no connection to the outside except that they allow surfing through an HTTP(S) proxy. Sometimes you are happy and the HTTPS port (443) is unrestricted. The following server-side tools allow you to exploit these weaknesses and get you a shell on your server.
sslh
sslh is an SSH/SSL multiplexor. If a client connects to sslh, it checks if the clients speaks the SSH or the SSL protocol and then passes the connection to the according real port of SSL or some SSL enabled service, e.g. an HTTPS, OpenVPN, Tinc or XMPP server. That way it’s possible to connect to one of these services and SSH on the same port.
The usual scenario where this daemon is useful are firewalls which block SSH, force HTTP to go through a proxy, but allow HTTPS connections without restriction. In that case you let sslh listen on the HTTPS port (443) and to move the real HTTPS server (e.g. Apache) to listen on either a different port number (e.g. 442, 444 or 8443) or on another IP address, e.g. on localhost, port 443.
On an Debian or Ubuntu based Apache HTTPS server, you just have to do the following to run Apache on port 442 and sslh on port 443 instead:
apt-get install sslh
as root.- Edit
/etc/default/sslh
, changeRUN=no
toRUN=yes
and--ssl 127.0.0.1:443
to--ssl 127.0.0.1:442
. - Edit
/etc/apache2/ports.conf
and all files in/etc/apache2/sites-available/
which contain a reference to port 443 (which is only/etc/apache2/sites-available/default-ssl.conf
in the default configuration) and change all occurrences of443
to442
. service apache2 restart
service sslh start
Now you should be able to ssh to your server on port 443 (ssh -p 443 your.server.example.org
) while
still being able to surf to
https://your.server.example.org/
.
sslh works as threaded or as preforking daemon, or via inetd. It also
honors tcpwrapper configurations for sshd in /etc/hosts.allow
and /etc/hosts.deny
.
sslh is available as port or package at least in Gentoo, in FreeBSD, in Debian and in Ubuntu.
AjaxTerm
A completely different approach takes AjaxTerm. It provides a terminal inside a web browser with login and ssh being its server-side backend.
Properly safe-guarded by HTTPS plus maybe HTTP based authentication this can be an interesting emergency alternative to the more common — but also more often blocked — remote login mechanisms.
AjaxTerm is available as package at least in Debian and in Ubuntu.
Happily I never were forced to use either of them myself. :-)
Tagged as: AJAX, AjaxTerm, Apache, Debian, HTTPS, libwrap, OpenVPN, SSH, SSL, sslh, tcpd, tcpwrapper, Ubuntu, XMPP
// show without comments // write a comment
Related stories
Thursday·22·March·2012
Tools for CLI Road Warriors: Tunnels //at 19:49 //by abe
Sometime the network you’re connected to is either untrusted (e.g. wireless) or castrated in some way. In both cases you want a tunnel to your trusted home base.
Following I’ll show you three completely different tunneling tools which may helpful while travelling.
sshuttle
sshuttle is a tool somewhere in between of automatic port forward and VPN. It tunnels arbitrary TCP connections and DNS through an SSH tunnel without requiring root access on the remote end of the SSH connection.
So it’s perfect for redirecting most of your traffic through an SSH tunnel to your favourite SSH server, e.g. to ensure your local privacy when you are online via a public, unencrypted WLAN (i.e. easy to sniff for everyone).
It runs on Linux and MacOS X and only needs a Python interpreter on the remote side. Requires root access (usually via sudo) on the client side, though.
It’s currently available at least in Debian Unstable and Testing (Wheezy) as well as in Ubuntu since 11.04 Natty.
Miredo
Miredo is an free and open-source implementation of Microsoft’s NAT-traversing Teredo IPv6 tunneling protocol for at least Linux, FreeBSD, NetBSD and MacOS X.
Miredo includes not only a Teredo client but also a Teredo server
implementation. The developer of Miredo also runs a public Miredo
server, so you don’t even need to install a server somewhere. If you
run Debian or Ubuntu you just need to do apt-get
install miredo
as root and you have IPv6 connectivity. It’s
that easy.
So it’s perfect to get a dynamic IPv6 tunnel for your laptop or mobile phone independently where you are and without the need to register any IPv6 tunnel or configure the Miredo client.
I usually use Miredo on my netbooks to be able to access my boxes at home (which are behind an IPv4 NAT router which is also an SixXS IPv6 tunnel endpoint) from whereever I am.
iodine
iodine is likely the most undermining tool in this set. It tunnels IPv4 over DNS, allowing you to make arbitrary network connections if you are on a network where nothing but DNS requests is allowed (i.e. only DNS packets reach the internet).
This is often the case on wireless LANs with landing page. They redirect all web traffic to the landing page. But the network’s routers try to avoid poisoning the client’s DNS cache with different DNS replies as they would get after the user is logged in. So DNS packets usually pass even the local network’s DNS servers unchanged, just TCP and other UDP packets are redirected until logging in.
With an iodine tunnel, it is possible get a network connection to the outside on such a network anyway. On startup iodine tries to automatically find the best parameters (MTU, request type, etc.) for the current environmenent. However that may fail if any DNS server in between imposes DNS request rate limits.
To be able to start such a tunnel you need to set up an iodine daemon somewhere on the internet. Choose a server which is not already a DNS server.
iodine is available in many distributions, e.g. in
Debian and in Ubuntu.
Tagged as: autossh, Debian, GitHub, iodine, IPv6, Miredo, NAT, Python, Squeeze, SSH, sshuttle, Testing, Ubuntu, Unstable, VPN
// show without comments // write a comment
Related stories
Tuesday·20·March·2012
Happy Birthday GNU Screen! //at 23:46 //by abe
According to this Usenet posting, GNU Screen became 25 years old today. (Found via Fefe.)
And no, it’s not dead. In contrary, the reaction on the mailing list to bug fixes with patches is usually impressingly prompt. :-)
I took this occassion and uploaded a current git snapshot of GNU Screen to Debian Experimental.
Bug #644788 (screen 4.1.0 can’t attach to a running or detached screen 4.0.3 session) is still an issue with that snapshot, but gladly upstream seems to work on a solution for it. There’s even talk about a 4.1.0 beta release soon — although that hasn’t happened yet.
Have fun!
Tagged as: anniversary, birthday, Debian, Experimental, Git, GNU, GNU Screen, screen, snapshot, upload
// show without comments // write a comment
Related stories
Monday·14·November·2011
grep everything //at 09:43 //by abe
During the OpenRheinRuhr I noticed that a friend of mine didn’t know
about zgrep
and friends. So I told him what other grep
variations I know and he told me about some grep variations I didn’t
know about.
So here’s our collection of grep wrappers, derivatives and variations. First I’ll list programs which search for text in different file formats:
grep through what | Fixed Strings | Wildcards / Basic RegExps | Extended RegExps | Debian package |
---|---|---|---|---|
uncompressed text files | fgrep | grep | egrep | grep |
gzip-compressed text files | zfgrep | zgrep | zegrep | zutils, gzip |
bzip2-compressed text files | bzfgrep | bzgrep | bzegrep | bzip2 |
xz-compressed text files | xzfgrep | xzgrep | xzegrep | xz-utils |
uncompressed text files in installed Debian packages | dfgrep | dgrep | degrep | debian-goodies |
gzip-compressed text files in installed Debian packages | - | dzgrep | - | debian-goodies |
PDF documents | - | - | pdfgrep | pdfgrep |
POD texts | podgrep | - | - | pmtools |
E-Mail folder (mbox, MH, Maildir) | - | mboxgrep -G | mboxgrep -E | mboxgrep |
Patches | - | grepdiff | grepdiff -E | patchutils |
Process list | - | - | pgrep | procps |
Gnumeric spreadsheets | ssgrep -F | ssgrep | ? | gnumeric |
Files in ZIP archives | - | - | zipgrep | unzip |
ID3 tags in MP3s | - | - | taggrepper | taggrepper |
Network packets | - | - | ngrep | ngrep |
Tar archives | - | - | targrep / ptargrep | perl (Experimental only for now) |
And then there are also greps for special patterns on more or less normal files:
grep for what | uncompressed files | compressed files | Debian package |
---|---|---|---|
PCRE (Perl Compatible Regular Expression) | pcregrep (see also the grep -P option) | zpcregrep | pcregrep |
IP Address in a given CIDR range | grepcidr | - | grepcidr |
XPath expression | xml_grep | - | xml-twig-tools |
One question is though still unanswered for us: Is there some kind of meta-grep which chooses per file the right grep from above by looking at the MIME type of the according files, similar to xdg-open.
Other tools which have grep in their name, but are too special to properly fit into the above lists:
- ext3grep: Tool to help recover deleted files on ext3 filesystems
- xautomation: Includes a tool named
visgrep
to grep for subimages inside other images.
Includes contributions by Frank Hofmann and Faidon Liambotis.
Tagged as: .deb, bzip2, CIDR, compression, Debian, debian-goodies, E-Mail, efho, ext3grep, Gnumeric, grep, grepcidr, gzip, ID3, list, Maildir, mbox, mboxgrep, mh, MP3, ngrep, packages, patches, PCRE, PDF, pdfgrep, Perl, pmtools, POD, podgrep, procps, taggrepper, TWIG, unzip, visgrep, xautomation, XDG, XML, xz, xz-utils, zip, zutils
// show without comments // write a comment
Related stories
Thursday·22·September·2011
Emacs Macros: Repeat on Steroids //at 16:06 //by abe
vi users have their .
(dot) redo command for repeating
the last command. The article Repeating Commands in Emacs in Mickey Petersen’s blog Mastering Emacs explained
Emacs’ equivalent for that, namely the command repeat
, by
default bound to C-x z
.
I though seldomly use it as I mostly have to repeat a chain of commands. What I use are so called Keyboard Macros.
For example for the CVE-2011-3192 vulnerability in Apache I added a line like
Include /etc/apache2/sites-common/CVE-2011-3192.conf
to
all VirtualHosts.
So I started Emacs with all the relevant files: grep
CVE-2011-3192 -l /etc/apache2/sites-available/*[^~] | xargs emacs
&
To remove those “Include” lines again M-x flush-lines
is
probably the easiest way in Emacs. So for every file I had to call
flush-lines with always the same parameter, save the buffer and then
close the file or — in Emacsish — “kill” the buffer.
So while working on the first file I recorded my doing as a keyboard macro:
C-x (
- Start recording
M-x flush-lines<Enter>CVE-2011-3192<Enter>
- flush all lines which contain the string “CVE-2011-3192”
C-x C-s
- save the current buffer
C-x C-k<Enter>
- kill the current buffer, i.e. close the file
C-x )
- Stop recording
Then I just had to call the saved macro with C-x e
. It
flushed all lines, saved the changes and switched to the next
remaining file by closing the current file with three key-strokes. And
to make it even easier, from the second occasion on I only had to
press e
to call the macro directly again. So I just
pressed e
for a bunch of time and had all files edited.
(In this case I used git diff
afterwards to check that I
didn’t wreck anything by half-automating my editing. :-)
Of course there are other ways to do this, too, e.g. use
sed
or so, but I still think it’s a neat example for
showing the power of keyboard macros in Emacs. More things you can do
with Emacs Keyboard Macros are described in the EmacsWiki entry Keyboard Macros.
And if you still miss vi’s .
command in Emacs, you can
use the dot-mode, an Emacs mode currently maintained by Robert Wyrick
which more or less automatically defines keyboard macros and lets you
call them with C-.
.
Tagged as: Apache, CLI, CVE, CVE-2011-3192, dot-mode, Emacs, EmacsWiki, git, macro, Other Blogs, redo, repeat, vi, xargs
// show without comments // write a comment
Related stories
Wednesday·10·August·2011
git $something -p //at 16:09 //by abe
git add -p
is one of my favourite git features. It lets you selectively
add the local changes hunk by hunk to the staging area. This is
especially nice if you want to commit one change in a file, but not a
second one, you also already did.
Recently I noticed that
you can also selectively revert changes already in the staging area
using git reset -p HEAD
. The user interface is exactly
the same as for git add -p
.
Today I discovered another selective undo in git by just trying it out
of curiosity if that works, too: Undoing local changes selectively
using git checkout -p
. Maybe less useful than those
mentioned above, but nevertheless most times quicker than firing up
your favourite editor and undoing the changes manually.
Another nice git feature which I discovered by accidentially using it
(this time even unwittingly) is git checkout -
which
behaves like cd -
, just for branches instead of
directories, i.e. it switches back to the previously checked out
branch. Very useful for quickly changing between two branches again
and again.
Tagged as: CLI, git, HTH, identi.ca, UUUCO
// show without comments // write a comment
Related stories
Friday·10·June·2011
How to find broken symlinks //at 20:31 //by abe
Looking through the man page of find
there is no obvious
way to find broken symbolic links. But there is a simple way involving
only find:
$ find -L . -type l $ find -L . -type l -ls
The option -L
(before the path!) causes find
to follow symbolic links and the expression -type l
causes find to report only symbolic links. But as it follows symlinks,
it only reports those it can’t follow, i.e. broken ones.
The second line also shows where the broken links point to.
To easily show that this really works, just use the color indicator of
GNU ls instead of find
’s builtin -ls
:
$ find -L . -type l -exec ls -lF --color=yes '{}' +
Et voilà, all displayed links show up in red which means they’re broken.
Kudos to CodeSnippets for showing me the right
idea. And thanks to ft of zsh and grml fame for the hint about
find -exec command {} +
instead of find -exec
command {} ;
.
Hint from mika of grml fame: With zsh it is even less code to type:
% ls **/*(-@) % ls -lF **/*(-@)
Thanks, mika!
Tagged as: CLI, coreutils, find, GNU, HTH, ls, POSIX, shell
// show without comments // write a comment