Posts Tagged network
May 13, 2009 at 9:18 am · Filed under Uncategorized ·Tagged admin, debug, network, networking, networks, reverse engineeering, script, scripting, scripts, security, shell, shell script, socket, sysadmin, system, system administration
I felt I needed to write an article about netcat, so here is it !
Netcat is an incredibly usefull tool, that allows you to play with tcp connection easily from the shell.
Basically, as it name implies, it’s just cat over the network, but what its name doesn’t tell you is that it also can act as a socket listener.
So let’s play with pipes, here is one of my favourite use of netcat:
mkfifo proxypipe
cat proxypipe | nc -l -p 80 | tee -a inflow | nc localhost 81 | tee -a outflow 1>proxypipe
This command will redirect traffic from localhost:80 to localhost:81, in the inflow file you while find the incoming http request, in the outfile, you will find the http response from the server.
Similarly, you can do this:
cat proxypipe | nc -l 80 | tee -a inflow | sed 's/^Host.*/Host: www.google.fr/' | nc www.google.fr 80 | tee -a outflow >proxypipe
This will allow your browser to point to google using http://localhost .
Anyway, this is my favourite but netcat has thounds of other uses, have a look at it !
It can be usefull for file transfers (gzip|nc) , performance measurement (dd|gzip), protocol debugging (replaying requests), security testing (nc does port scan) …
Permalink
November 18, 2008 at 2:58 pm · Filed under Uncategorized ·Tagged cluster, network, networking, servers, ssh, sys, sysadmin, system, system administration
With pssh (parallel-ssh) you can execute the same command on different hosts.
Pssh is a simple python script, the uses pretty much no python module, so it’s simple to install (it’s also packaged at least in ubuntu).
To use pssh, you need to create a hosts file which contains a list of hosts (one by line) followed by a username to use on that host, then just execute this command parallel-ssh -h hosts-file "command", it will execute “command” on all the hosts that are in the given hosts-file. I copied my ssh public-key so I don’t need to type my password on any server, if you don’t have your key, pssh will prompt for a password.
Pssh has a --print option that prints the output of the command execution, host by host, on the shell you’re launching pssh from, if you don’t use that option , it creates 1 file per host with the result.
Pssh is really nice, but, would be better if I could use the aliases I use in my .ssh/config for hostnames in my hosts-file. Maybe one day, I’ll make a patch to pssh so it uses your .ssh/config to recognize hosts and users in your hosts-file. Nice tool, anyway !
Permalink
October 22, 2008 at 10:54 am · Filed under Uncategorized ·Tagged linux, mail, network, networking, smtp, ssmtp, system, unix
Unix systems often needs a local mailer, but configuring and maintaining a mailer on each system is a timeloss.
You might have a gmail or google apps account. If it’s the case, you can easily configure a mailer on your systems which uses your gmail or google apps. To do so, I’ve used ssmtp and put this in /etc/ssmtp/ssmtp.conf:
root=postmaster
mailhub=smtp.gmail.com:587
AuthUser=your-mail@yourdomain.com
AuthPass=aStr4angeP45s
UseSTARTTLS=YES
hostname=the-hostname
That’s it, simple, effective, working …
To improve the things, maybe, we can use an IP address of the smtp server, so that if our DNS server doesn’t work, we still have mail on the system, but this has a drawback, if the server for which you gave an ip address changes or temporarly doesn’t work, you don’t have mail anymore.
ssmtp doesn’t seem to be able to have several mailhubs !
Permalink
October 13, 2008 at 5:08 pm · Filed under Uncategorized ·Tagged backup, dd, disk, dump, network, networking, pipe, ssh, system
If you want to dump a disk to a disk image you will use for example:
dd if=/dev/hdx1 of=/tmp/disk.img
and then, you will probably copy this disk image to another machine. The thing is, if you have low disk space than the size of /dev/hdx1 on your machine, you won’t be able to dump the disk to transfer it to the other machine.
There is a solution that I use, as usually with, ssh and pipe:
ssh hostname "dd if=/dev/hdx1" |dd of=/tmp/disk.img
on the machine receiving the image or
dd if=/dev/hdx1 |ssh hostname "dd of=/tmp/disk.img"
on the machine sending the image, so the content of the disk is directly transmitted through ssh !
That’s it !
Maybe you can tune the blocksize of the dd command so the troughput is better, maybe a futur article on that
Permalink
October 11, 2008 at 11:22 am · Filed under Uncategorized ·Tagged browser, ip, ipv6, network, networking, scp, ssh, system, url, urls, web
URLs are written like this: protocol://host-or-address:port/path-or-function
What happens with ipv6 is that addresses contains colons (“:”) , so how do you specify the port number in your web browser ? The same happens when you do an scp: you usually do scp user@host:path/to/file /local/path, how can you differenciate the host part and the path which are also seperated with a colon ?
The answer is: USE BRACKETS !
an ipv6 url can be written like this:
http://[fe80::abcd:abcd:abcd:abcd]:8080/index.html
Also, a scp command with ipv6 addresses can be like this:
scp user@[fe80::abcd:abcd:abcd:abcd]:/etc/resolv.conf /tmp
I hope it’s usefull !
Permalink
October 6, 2008 at 4:12 pm · Filed under Uncategorized ·Tagged icmp, linux, mac, network, osx, ping, scan, script, scripting, scripts, shell, subnet, system
Today I logged in a machine I don’t want to install anything on it, but I wanted to find a machine in its network.
I came up with the little shell script that scans the subnet:
CURR=1
SUBNET="192.168.0"
while [ $CURR -lt 255 ] ; do
ping -c1 -t1 $SUBNET.$CURR 2>&1 >/dev/null
if [ "$?" -eq "0" ]; then
echo "$SUBNET.$CURR"
fi
let CURR=$CURR+1
done
This script is suboptimal but it does the stuff: It uses ping with a timeout of 1 sec, so If no machine is up, the script takes around 255 seconds to scan the subnet, it doesn’t list the machines that doesn’t reply to ping and so on … but as I said it , it does the stuff.
I tested this script in Linux and OSX.
Permalink
September 24, 2008 at 1:49 pm · Filed under Uncategorized ·Tagged bind, dns, network, networking, secure, security, sysadmin, system, system administration
To find the version of running bind version remotely, you can type that command:
nslookup -q=txt -class=CHAOS version.bind. ns1.domain.com
or with dig:
dig @ns1.domain.com version.bind chaos txt
or with host:
host -t TXT -c chaos version.bind ns1.domain.com
If you don’t want your bind to show the version you are currently running, on a ubuntu system you will add a version "[Secured]"; directive in the options section of the file /etc/bind/named.conf.options
That’s it !
Permalink
September 10, 2008 at 12:28 pm · Filed under Uncategorized ·Tagged admin, administration, bind, dns, network, sysadmin, system, tips, tips and tricks, tricks, unix, web
There a some web based bind zone generator, but searching for “zone generator” in google, I found a lot that aren’t working, refining my research didn’t helped me. I finally found one that does the stuff. It’s not optimal , but it work , and it’s there
Please, if you know of a better one, just let me know !
Permalink
August 21, 2008 at 5:12 pm · Filed under Uncategorized ·Tagged backup, bzip2, database, dump, gzip, mysql, mysqldump, network, ssh, system, tar, tip, tips
Similarly to my last tip (copying directory with ssh and tar) , you can also copy databases. It’s pretty simple, here is my magic command:
mysqldump -ppassword db |ssh user@remote "cat - | mysql -u dbuser -ppassword db"
Here, you can also gzip or bzip2 the input, and it should be very efficient, because mysqldump output is pure ascii with sql, gzip and bzip2 will easily find good pattern for compression.
Also, as usual, using my.cnf files, you don’t need -ppassword parameters.
Permalink
August 13, 2008 at 11:03 am · Filed under Uncategorized ·Tagged cli, command line, network, recursive, rsync, scp, shell, ssh, symlinks, system
To copy recursively with scp, you use scp -r.
The thing is that if you have symlinks in your directory the content of the directory being pointed to by the symlinks will be copied, this is not necessarily what you want (the symlink will be followed instead of being preserved).
Scp have no option to specify that you don’t want to follow symlinks.
If you want to preserver symlinks, you should use rsync:
rsync -avz -e ssh /src/dir user@remote.host:dst/dir
Be carefull, if you preserve symlinks, the newly created symlinks on the remote server can point to a non existant path.
It’s strange that scp seem to have no option to not follow symlinks. If you’re aware of one, please drop me a comment !
Permalink
Older Posts »