"No creas de nosotros cuentos que otros cuenten." Eskorbuto

jueves, 11 de marzo de 2010

/dev/tcp en Ubuntu 9.10 karmic

Basicamente hay que recompilar bash con la opcion
--enable-net-redirections

Para despues proceder a crear los dispositivos /dev/tcp y /dev/udp con sus correspondientes valores:
#Create /dev/tcp and /dev/udp devices.
/usr/bin/sudo mknod /dev/tcp c 30 36
/usr/bin/sudo mknod /dev/udp c 30 39

Y testearlo:
#Test
cat </dev/tcp/time.nist.gov/13 && echo 'All ok. Enjoy!'

Como no voy a reinventar la rueda, he adaptado el script que se puede encontrar en los comentarios de esta entrada del Linux Journal.

Mas que nada porque he cambiado recientemente a ubuntu 9.10 y me interesaba practicar el segundo PDF de las Ninjitsu Series, que trata basicamente de usar netcat "sin usar netcat".

Ahi va el script:
#!/bin/bash
# Written by Joseph E. Tole 09/29/09
# Updated by G. Geurts 09/30/09
# Updated by vlan7 03/11/10
# /dev/tcp on Ubuntu.
# Tested against Ubuntu 9.10 x64, bash 4.0.x
# Enjoy!

# This creates and then changes to a new temporary directory. mktemp should always be used to avoid accidently using an active file/dir.
bash_source="$(/bin/mktemp -d)"
cd "${bash_source}"

# Install the bash source.
apt-get source bash

# Dependencies
# The -y flag causes apt-get to assume you said yes and not prompt for y/n to install
/usr/bin/sudo apt-get build-dep -y bash
/usr/bin/sudo apt-get install -y dpkg-dev fakeroot
cd bash-*

# This line changes the rules file which has the configure script options predefined in it. This causes the compile to now include network support.
/bin/sed -e 's/--disable-net-redirections/--enable-net-redirections/' -i debian/rules

# This creates new .deb packages for bash which is several but we only need to install one since the others are copies of what is already installed.
/usr/bin/dpkg-buildpackage -rfakeroot

# Install the .deb. The asterisk is used for architecture independence. In my case it * matches _amd64 but this may be different on non x64 systems.
/usr/bin/sudo /usr/bin/dpkg -i ../bash_*.deb

# The line below puts bash on hold within the package manager so that it is not automatically upgraded. If it is then you will lose this functionality.
echo 'bash hold' | /usr/bin/sudo /usr/bin/dpkg --set-selections

#Create /dev/tcp and /dev/udp devices.
/usr/bin/sudo mknod /dev/tcp c 30 36
/usr/bin/sudo mknod /dev/udp c 30 39

#Test
cat </dev/tcp/time.nist.gov/13 && echo 'All ok. Enjoy!'

Suerte!

Related Posts by Categories



0 comentarios :

Publicar un comentario

Nota: solo los miembros de este blog pueden publicar comentarios.