Windows

HOW TO : Use netcat (nc) on Windows 7

netcat is a swiss army tool for network/security professionals. You can use it to listen on certain ports or connect to certain ports. For example, say, you configured your firewall to allow TCP 80 traffic to your web server. But your web server is not built yet and you want to validate the rule. You can run netcat on your workstation to listen on port 80, assign the IP address of the web server to your workstation and test the rule.

If I am not mistaken, nc comes as a default tool in most of the Linux distros. You can download the windows port of the tool at http://www.securityfocus.com/tools/139

The command to have netcat listen on a specific port is “nc -l PORT_NUMBER”. If you run this on a Windows 7 machine, you will get this dreaded message “local listen fuxored: INVAL”. The fix is to run it with a -L option. So the command would like this

[code]nc -L -p 80[/code]

The -L means “listen harder, re-listen on socket close” :).. Have to dig deeper and see what it really means though. I will leave that for another blog post.

And if you want to validate that netcat is indeed listening on that port, you can connect to that port from another workstation by using nmap.

HOW TO : Advanced search and replace in Notepad++

Jhanvi asked me to help with editing a text file recently. She had a file in the format


'512'
'345'
'876'

and needed to convert it into the format below


INSERT INTO BLAH VALUE ('512');
INSERT INTO BLAH VALUE ('345');
INSERT INTO BLAH VALUE ('876');

There are multiple ways, one can do this. Here is how I did this using Notepad++, an open source text editor. I used the regular expression capability of Notepad++ it’s search and replace function.

  • Press “Ctrl + h” to bring up the search and replace window.
  • Replace the single quote at the beginning of the line by using ” ^’ “
  • Replace the single quote at the end of the line by using ” ‘$ “

Screenshots from the operation

The data in it’s original format

Replacing the first quote mark

Data after the first search and replace operation

Replacing the second quote mark

Data in the final format

HOW TO : Install Wireshark on Windows 7

[UPDATE] Wireshark works without any issues as of version 1.2.3. This release includes WinPcap 4.1.1, which has support for Windows 7 and 2008. Looks like the issue was with the drivers not being signed digitally.

I recently upgraded my laptop to Windows 7 RC from the beta version I was testing earlier. As part of installing my standard set of tools, I tried to install Wireshark (open source network capture tool), and ran into an error due to the UAC security settings. Essentially, Windows was blocking the install of WinPcap (network capture driver). I solved it by enabling compatibility mode on the install executable. Here are the steps to install Wireshark on Windows 7.

  • Download the install file from http://www.wireshark.org/download.html
  • Right click on the install file (I happened to download the 64 bit install) and click on properties
  • In the properties window, click on the compatibility tab and change the option for “Run this program in compatibility mode for” to “Windows Vista (Service Pack 2)” and click on OK. Here’s a screenshot for reference

  • Right click on the install and click on “Run as Administrator”
  • Make sure you choose the option to install the NPF as a service during the install prompts. This will allow all users on the machine to use Wireshark without admin privileges.

P.S : WinPCap is apparently going to come out with a new version soon that is compatible with Windows 7.

HOW TO : Setup SOCKS proxy using SSH/Putty and configure Pidgin to use SOCKS proxy

I ran into a challenge  recently, when I tried to connect to my IM services (Yahoo, MSN, AOL, GTalk) using Pidgin in a secured network. For some reason, the network administrator thought that he/she should make life hell for people trying to log into IM. I will have a whole new rant about companies trying to lock down networks thinking they are making the employees productive..

Here’s what I did to connect to my IM services.

  1. Configure Putty/SSH to act as a SOCKS proxy.
    • Most people might not be aware, but a typical SSH client can act as a SOCKS proxy. So I decided to leverage this functionality.
    • You will need access to a SSH server and Putty (Opensource Windows SSH client)
    • Launch Putty
    • Setup a new server connection profile. I used FREE_MY_IP as the profile name in this screen shot, but you can name it anything you want

    • Expand the SSH option in the left column and click on Tunnels
    • Choose any port higher than 1024 as source port (unless you are running some kind of server software on your workstation, it is safe to use any port above 8000) and enter the SSH server in the Destination field. Then choose the “Dynamic” option and click on Add.. the screen shot below shows the options I used

    • The tunnel will show up as below

    • Click on Open and establish the SSH tunnel
  1. Configure Pidgin (open source IM client) to use the SOCKS proxy
    • Launch Pidgin
    • Click on Tools -> Preferences in the menu
    • Click on the network tab
    • Choose SOCKS4 as the proxy type and enter localhost in the host field. In the port field enter the port you selected when setting up the tunnel in Putty.

  1. Connect to your IM services.. chat away and be unproductive 🙂

HOW TO : Microsoft Windows – Routing to /dev/null

Ran into an interesting issue at work today and wanted to document it. We had a rouge process in one of our applicatoins and it was trying to send e-mails via one of our mail gateways at an alarming rate..There was no customer impact, since the mail server was rejecting all the connections. But the high number of connections were causing a strain on our firewalls..

If this was Linux, we would have done something simple like adding a route to point all the traffic destined to mail server to /dev/null by running “route add IP_ADDRESS_OF_MAIL_SERVER MASK /dev/null

A search on Google showed that you can achieve similar results by doing the following “route ADD IP_ADDRESS_OF_MAIL_SERVER MASK 255.255.255.255 127.0.0.1“. 127.0.0.1 being the IP address of the loopback interface in this case. But when we ran the command, we got an error “incorrect gateway 127.0.0.1”.. So there is NO way to route traffic in Microsoft Windows to a null device..

Finaly, we figured out a round about way to achieve this.. Since the main aim was to reduce the load on the firewall, we identifid an un used IP in the same network as the application server and added a static route to point all traffic going to the mail server to this IP. We ran the following command “route ADD IP_ADDRESS_OF_MAIL_SERVER MASK 255.255.255.255 UN_USED_IP_ADDRESS

For example, if you application server is in the range 192.168.1.0/24, the mail server is 192.168.2.20.. and an unused IP in the application server range is 192.168.1.10.. the command would look like this “route ADD 192.168.2.20 MASK 255.255.255.255 192.168.1.10“.. You will see a lot of SYN_SENT status in the network connections, since the application is trying to connect t othe mail server via an IP address that doesn’t exist..

Might not be the smartest way to achive this.. but it did the trick.

Windows 7 : Installer Issues

As posted here, I have been playing around with the Beta version of Windows 7. Everything was working great, until I started getting  a mysterious error “Installer stopped working”, when I tried to install any new software. A Google search, led me to this site (http://www.sevenforums.com/general-discussion/2349-windows-installer-cant-install-any-msi-package-4.html) . Here’s the solution to the issue. 

start regedit
navigate to HKLM\Software\Microsoft\SQMClient\Windows\DisabledSessions
rename MachineThrottling to _MachineThrottling

Beta for the Beta

I got a copy of the Windows 7 Beta copy from my colleague and installed it on my Lenovo X61 tablet. The install went through pretty smoothly and . upon booting up the computer, me and my colleague had the following conversation..

Colleague : Thats a Beta!!

Me : Yes.. it is Beta..

Colleague : No.. No.. that”s a beta!!

Me : Dude.. seriously.. it is Beta.. I know it..

Colleague : (almost smacking me on my head) No..that is a Beta Fish!!

Looks like a smart programmer (or marketing person) put the picture of a Beta fish as the default background for Windows 7 Beta :-).. Here’s a screenshot.

Hopefully, Windows 7 will finally convince us XP lovers to upgrade. Vista is a failed operating system as far as I am concerned. Not in the league of “Windows Millenium“, but it is going to be shoved away into the annals of history soon if Windows 7 delivers as promised.

HOW TO : Configure AT&T 3G on Windows Vista without Communication Manager

This is a howto for the geek in you :-). You can easily configure a AT&T 3G Wireless card on your workstation using the Communication Manager software provided by AT&T.. But then I have always been against using bloated software for something you can configure on your own.

I recently got a 3G card at work and needed to install it on my laptop. I figured that the AT&T  provided software was just setting up a dial-up connection with specific settings. Guessing that some Linux geek might have already figured out what the settings where, I used the following search term in Google “Linux Ubuntu Configure AT&T 3G card”.. Lo and behold, the following link showed up http://redmonk.com/sogrady/2008/12/07/how-to-use-an-att-ericsson-f3507g-card-on-ubuntu-intrepid/.

Here are the steps, I follwed to configure the card in Microsoft Vista

  • Insert card into the laptop and use the “search online” feature for installing the required drivers.
  • Open “Network and Sharing Center”.
  • Click on “Setup up a connection or network”.
  • Choose “Connect to the Internet” option and click on Next.
  • If you are already connected to the Internet, you will get a message stating the same, but choose the “Setup a new connection anyway”.
  • If you already have existing dial-up or DSL connections, choose “No, create a new connection” and click on Next
  • Choose “Dial-up”
  • Choose the modem related to your 3G card.. For example, mine was “Sierra Wireless AirCard 875 HSDPA Modem”
  • Enter the following information in the ISP Information
    • Dial-up phone number : *99#
    • User name : *
    • Password : *
    • Connection Name : Whatever you want to name it

  • Click on Connect and enjoy the broadband speed without bloatware :-).

Loose the shackles..

If you need to edit documents, create spreadsheets and presentations… and don’t want to spend $$$ for Microsoft Office, download the latest version of OpenOffice for free and give it a try. You might be pleasantly surprised.

I wrote a post earlier about using OpenOffice as a free PDF Editor.. And that is just the tip of the iceberg of what you can do with OpenOffice.

Most of the people that use Microsoft Office, only use the basic functionality. As my old boss used to say, “95% of the people use 5% of the functionality in Office”. And switching to OpenOffice would be a breeze for then. OpenOffice is available for Microsoft Windows, Linux and Apple Mac OS X.

Since OpenOffice 3.0 was released back in October, the software has been downloaded more than 10 million times. And we are close to hitting 20 million downloads..Here’s a live counter from the OpenOffice website